blob: d8c537ef09a8989430abea34d2b1cca2057b8c7a [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 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"""
Jon Hall1efcb3f2016-08-23 13:42:15 -070021import os
22import imp
23import time
24import json
25import urllib
26from core import utilities
27
28
29class Testcaselib:
Pierfb719b12016-09-19 14:51:44 -070030
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070031 useSSH = True
Pierfb719b12016-09-19 14:51:44 -070032
Jon Hall1efcb3f2016-08-23 13:42:15 -070033 @staticmethod
34 def initTest( main ):
35 """
36 - Construct tests variables
37 - GIT ( optional )
38 - Checkout ONOS master branch
39 - Pull latest ONOS code
40 - Building ONOS ( optional )
41 - Install ONOS package
42 - Build ONOS package
43 """
Devin Lim58046fa2017-07-05 16:55:00 -070044 try:
45 from tests.dependencies.ONOSSetup import ONOSSetup
46 main.testSetUp = ONOSSetup()
47 except ImportError:
48 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070049 main.cleanAndExit()
You Wangd5873482018-01-24 12:30:00 -080050 from tests.dependencies.Network import Network
51 main.Network = Network()
Devin Lim0c972b72018-02-08 14:53:59 -080052 main.testSetUp.envSetupDescription( False )
Devin Lim58046fa2017-07-05 16:55:00 -070053 stepResult = main.FALSE
54 try:
55 main.step( "Constructing test variables" )
56 # Test variables
57 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
58 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Devin Lim58046fa2017-07-05 16:55:00 -070059 main.path = os.path.dirname( main.testFile )
Devin Lim57221b02018-02-14 15:45:36 -080060 main.useCommonTopo = main.params[ 'DEPENDENCY' ][ 'useCommonTopo' ] == 'True'
61 main.topoPath = main.path + ( "/.." if main.useCommonTopo else "" ) + "/dependencies/"
62 main.useCommonConf = main.params[ 'DEPENDENCY' ][ 'useCommonConf' ] == 'True'
63 main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/"
64 main.forJson = "json/"
65 main.forChart = "chart/"
66 main.forConfig = "conf/"
67 main.forHost = "host/"
You Wang27317572018-03-06 12:13:11 -080068 main.forSwitchFailure = "switchFailure/"
Devin Lim58046fa2017-07-05 16:55:00 -070069 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
You Wangd87b2312018-01-30 12:47:17 -080070 main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None
71 main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070072 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070073 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070074 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070075
Devin Lim0c972b72018-02-08 14:53:59 -080076 stepResult = main.testSetUp.envSetup( False )
Devin Lim58046fa2017-07-05 16:55:00 -070077 except Exception as e:
78 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070079
Devin Lim58046fa2017-07-05 16:55:00 -070080 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070081
Jon Hall1efcb3f2016-08-23 13:42:15 -070082 @staticmethod
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080083 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10,
84 parallel=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070085 """
86 - Set up cell
87 - Create cell file
88 - Set cell file
89 - Verify cell file
90 - Kill ONOS process
91 - Uninstall ONOS cluster
92 - Verify ONOS start up
93 - Install ONOS cluster
94 - Connect to cli
95 """
96 # main.scale[ 0 ] determines the current number of ONOS controller
You Wangd87b2312018-01-30 12:47:17 -080097 if not main.apps:
Jon Hall1efcb3f2016-08-23 13:42:15 -070098 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -070099 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
100 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700101 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -0800102 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800103 skipPack=skipPackage,
104 useSSH=Testcaselib.useSSH,
Devin Lim0c972b72018-02-08 14:53:59 -0800105 installParallel=parallel, includeCaseDesc=False )
Devin Lim142b5342017-07-20 15:22:39 -0700106 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
107 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800108 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700109 attempts=10 )
110 if ready:
111 ready = main.TRUE
112 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700113 onpass="ONOS summary command succeded",
114 onfail="ONOS summary command failed" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700115 if not ready:
116 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700117 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700118
Devin Lim142b5342017-07-20 15:22:39 -0700119 for ctrl in main.Cluster.active():
120 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
121 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
122 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
123 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700124
125 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800126 def loadCount( main ):
127 with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count:
128 main.count = json.load(count)
129
130 @staticmethod
Devin Lim57221b02018-02-14 15:45:36 -0800131 def loadJson( main ):
132 with open( "%s%s.json" % ( main.configPath + main.forJson,
133 main.cfgName ) ) as cfg:
134 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
135
136 @staticmethod
137 def loadChart( main ):
138 try:
139 with open( "%s%s.chart" % ( main.configPath + main.forChart,
140 main.cfgName ) ) as chart:
141 main.pingChart = json.load(chart)
142 except IOError:
143 main.log.warn( "No chart file found." )
144
145 @staticmethod
146 def loadHost( main ):
147 with open( "%s%s.host" % ( main.configPath + main.forHost,
148 main.cfgName ) ) as host:
149 main.expectedHosts = json.load( host )
150
151 @staticmethod
You Wang27317572018-03-06 12:13:11 -0800152 def loadSwitchFailureChart( main ):
153 with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure,
154 main.cfgName ) ) as sfc:
155 main.switchFailureChart = json.load( sfc )
156
157 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700158 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800159 copyResult = main.ONOSbench.scp( main.Mininet1,
160 main.topoPath + main.topology,
161 main.Mininet1.home,
162 direction="to" )
163 if main.topologyLib:
164 for lib in main.topologyLib.split(","):
165 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
166 main.topoPath + lib,
167 main.Mininet1.home,
168 direction="to" )
169 if main.topologyConf:
170 for conf in main.topologyConf.split(","):
171 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
Devin Lim57221b02018-02-14 15:45:36 -0800172 main.configPath + main.forConfig + conf,
You Wangd87b2312018-01-30 12:47:17 -0800173 "~/",
174 direction="to" )
175 stepResult = copyResult
176 utilities.assert_equals( expect=main.TRUE,
177 actual=stepResult,
178 onpass="Successfully copied topo files",
179 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700180 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700181 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700182 main.topology = topology
183 topoResult = main.Mininet1.startNet(
184 topoFile=main.Mininet1.home + main.topology, args=arg )
185 stepResult = topoResult
186 utilities.assert_equals( expect=main.TRUE,
187 actual=stepResult,
188 onpass="Successfully loaded topology",
189 onfail="Failed to load topology" )
190 # Exit if topology did not load properly
191 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700192 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700193
194 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800195 def connectToPhysicalNetwork( main, switchNames ):
196 main.step( "Connecting to physical netowrk" )
197 topoResult = main.NetworkBench.connectToNet()
198 stepResult = topoResult
199 utilities.assert_equals( expect=main.TRUE,
200 actual=stepResult,
201 onpass="Successfully loaded topology",
202 onfail="Failed to load topology" )
203 # Exit if topology did not load properly
204 if not topoResult:
205 main.cleanAndExit()
206
207 main.step( "Assign switches to controllers." )
208 assignResult = main.TRUE
209 for name in switchNames:
210 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
211 ip=main.Cluster.getIps(),
212 port='6653' )
213 utilities.assert_equals( expect=main.TRUE,
214 actual=stepResult,
215 onpass="Successfully assign switches to controllers",
216 onfail="Failed to assign switches to controllers" )
217
218 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700219 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700220 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700221
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700222 main.failures = int( main.params[ 'failures' ] )
223 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700224
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700225 if main.cfgName == '2x2':
226 spine = {}
227 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
228 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
229 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700230
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700231 spine = {}
232 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
233 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
234 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700235
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700236 elif main.cfgName == '4x4':
237 spine = {}
238 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
239 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
240 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700241
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700242 spine = {}
243 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
244 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
245 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700246
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700247 spine = {}
248 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
249 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
250 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700251
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700252 spine = {}
253 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
254 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
255 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700256
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700257 else:
Piera2a7e1b2016-10-04 11:51:43 -0700258 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700259 main.cleanAndExit()
You Wang27317572018-03-06 12:13:11 -0800260
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800261 @staticmethod
262 def addStaticOnosRoute( main, subnet, intf):
263 """
264 Adds an ONOS static route with the use route-add command.
265 """
266 main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf))
267 routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf)
268
269 utilities.assert_equals( expect=True, actual=( not routeResult ),
270 onpass="route-add command succeeded",
271 onfail="route-add command failed")
Piera2a7e1b2016-10-04 11:51:43 -0700272
273 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900274 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700275 main.step(
276 " Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900277 if tag == "":
278 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700279 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700280 main.FALSE,
281 kwargs={ 'min': minFlowCount },
282 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800283 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700284 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700285 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700286 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700287 onpass="Flow count looks correct: " + str( count ),
288 onfail="Flow count looks wrong: " + str( count ) )
289
290 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700291 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700292 main.FALSE,
293 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800294 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800295 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700296 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700297 expect=main.TRUE,
298 actual=flowCheck,
299 onpass="Flow status is correct!",
300 onfail="Flow status is wrong!" )
301 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700302 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700303 "flows",
304 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900305 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700306 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700307 "groups",
308 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900309 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700310
311 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800312 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
313 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800314 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
315 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
316 main.FALSE,
317 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800318 attempts=5,
319 sleep=sleep )
320 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800321 expect=True,
322 actual=( count > minFlowCount ),
323 onpass="Flow count looks correct: " + str( count ),
324 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800325
326 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800327 def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10):
328 main.step(
329 " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) )
330 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
331 main.FALSE,
332 args=( dpid, flowCount, False, 1),
333 attempts=5,
334 sleep=sleep )
335
336 utilities.assertEquals(
337 expect=True,
338 actual=( int( count ) == flowCount ),
339 onpass="Flow count looks correct: " + str(count) ,
340 onfail="Flow count looks wrong, should be " + str(flowCount))
341
342 @staticmethod
343 def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10):
344 main.step(
345 " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) )
346 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount,
347 main.FALSE,
348 args=( dpid, groupCount, False, 1),
349 attempts=5,
350 sleep=sleep )
351
352 utilities.assertEquals(
353 expect=True,
354 actual=( count == groupCount ),
355 onpass="Group count looks correct: " + str(count) ,
356 onfail="Group count looks wrong: should be " + str(groupCount))
357
358 @staticmethod
359 def checkFlowsGroupsFromFile(main):
360
361 for dpid, values in main.count.items():
362 flowCount = values["flows"]
363 groupCount = values["groups"]
364 main.log.report( "Check flow count for dpid " + str(dpid) +
365 ", should be " + str(flowCount))
366 Testcaselib.checkFlowEqualityByDpid(main, dpid, flowCount)
367
368 main.log.report( "Check group count for dpid " + str(dpid) +
369 ", should be " + str(groupCount))
370 Testcaselib.checkGroupEqualityByDpid(main, dpid, groupCount)
371
372 return
373
374 @staticmethod
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800375 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1 ):
You Wangf19d9f42018-02-23 16:34:19 -0800376 '''
You Wangba231e72018-03-01 13:18:21 -0800377 Verify connectivity between hosts according to the ping chart
378 acceptableFailed: max number of acceptable failed pings.
You Wangf19d9f42018-02-23 16:34:19 -0800379 basedOnIp: if True, run ping or ping6 based on suffix of host names
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800380 retryAttempts: the number of retry ping. Only works for IPv4 hosts.
You Wangf19d9f42018-02-23 16:34:19 -0800381 '''
You Wangba231e72018-03-01 13:18:21 -0800382 main.log.report( "Check host connectivity" )
383 main.log.debug( "Ping chart: %s" % main.pingChart )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800384 if tag == "":
385 tag = 'CASE%d' % main.CurrentTestCaseNumber
386 for entry in main.pingChart.itervalues():
You Wangba231e72018-03-01 13:18:21 -0800387 main.log.debug( "Entry in ping chart: %s" % entry )
388 expect = entry[ 'expect' ]
389 if expect == "Unidirectional":
390 # Verify ping from each src host to each dst host
391 src = entry[ 'src' ]
392 dst = entry[ 'dst' ]
393 expect = main.TRUE
394 main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) )
395 if basedOnIp:
396 if ("v4" in src[0]):
397 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
398 utilities.assert_equals( expect=expect, actual=pa,
399 onpass="IPv4 connectivity successfully tested",
400 onfail="IPv4 connectivity failed" )
401 if ("v6" in src[0]):
402 pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed )
403 utilities.assert_equals( expect=expect, actual=pa,
404 onpass="IPv6 connectivity successfully tested",
405 onfail="IPv6 connectivity failed" )
406 else:
407 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
408 utilities.assert_equals( expect=expect, actual=pa,
409 onpass="IP connectivity successfully tested",
410 onfail="IP connectivity failed" )
411 else:
412 # Verify ping between each host pair
413 hosts = entry[ 'hosts' ]
414 try:
415 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
416 except:
417 expect = main.FALSE
418 main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) )
419 if basedOnIp:
420 if ("v4" in hosts[0]):
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800421 pa = utilities.retry( main.Network.pingallHosts,
422 main.FALSE if expect else main.TRUE,
423 args=(hosts,),
424 attempts=retryAttempts,
425 sleep=sleep )
You Wangba231e72018-03-01 13:18:21 -0800426 utilities.assert_equals( expect=expect, actual=pa,
427 onpass="IPv4 connectivity successfully tested",
428 onfail="IPv4 connectivity failed" )
429 if ("v6" in hosts[0]):
430 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
431 utilities.assert_equals( expect=expect, actual=pa,
432 onpass="IPv6 connectivity successfully tested",
433 onfail="IPv6 connectivity failed" )
434 else:
You Wangf19d9f42018-02-23 16:34:19 -0800435 pa = main.Network.pingallHosts( hosts )
436 utilities.assert_equals( expect=expect, actual=pa,
You Wangba231e72018-03-01 13:18:21 -0800437 onpass="IP connectivity successfully tested",
438 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800439
440 if dumpflows:
441 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
442 "flows",
443 main.logdir,
444 tag + "_FlowsOn" )
445 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
446 "groups",
447 main.logdir,
448 tag + "_GroupsOn" )
449
450 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700451 def killLink( main, end1, end2, switches, links ):
452 """
453 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
454 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
455 Kill a link and verify ONOS can see the proper link change
456 """
457 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700458 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800459 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
460 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700461 main.log.info(
462 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
463 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700464 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700465 main.FALSE,
466 kwargs={ 'numoswitch': switches,
467 'numolink': links },
468 attempts=10,
469 sleep=main.linkSleep )
470 result = topology & LinkDown
471 utilities.assert_equals( expect=main.TRUE, actual=result,
472 onpass="Link down successful",
473 onfail="Failed to turn off link?" )
474
475 @staticmethod
476 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
477 links ):
478 """
479 Params:
480 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
481 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
482 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
483 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
484 Kill a link and verify ONOS can see the proper link change
485 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700486 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700487 result = False
488 count = 0
489 while True:
490 count += 1
You Wangd5873482018-01-24 12:30:00 -0800491 main.Network.link( END1=end1, END2=end2, OPTION="up" )
492 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700493 main.log.info(
494 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
495 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700496
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700497 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700498 ctrl = main.Cluster.runningNodes[ i ]
499 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700500 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900501 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
502 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700503 time.sleep( main.linkSleep )
504
Devin Lim142b5342017-07-20 15:22:39 -0700505 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
506 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700507 if count > 5 or result:
508 break
509 utilities.assert_equals( expect=main.TRUE, actual=result,
510 onpass="Link up successful",
511 onfail="Failed to bring link up" )
512
513 @staticmethod
514 def killSwitch( main, switch, switches, links ):
515 """
516 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
517 Completely kill a switch and verify ONOS can see the proper change
518 """
519 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
520 main.step( "Kill " + switch )
521 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800522 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700523 # todo make this repeatable
524 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700525 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700526 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700527 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700528 main.FALSE,
529 kwargs={ 'numoswitch': switches,
530 'numolink': links },
531 attempts=10,
532 sleep=main.switchSleep )
533 utilities.assert_equals( expect=main.TRUE, actual=topology,
534 onpass="Kill switch successful",
535 onfail="Failed to kill switch?" )
536
537 @staticmethod
538 def recoverSwitch( main, switch, switches, links ):
539 """
540 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
541 Recover a switch and verify ONOS can see the proper change
542 """
543 # todo make this repeatable
544 main.step( "Recovering " + switch )
545 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800546 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700547 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700548 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700549 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700550 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700551 main.FALSE,
552 kwargs={ 'numoswitch': switches,
553 'numolink': links },
554 attempts=10,
555 sleep=main.switchSleep )
556 utilities.assert_equals( expect=main.TRUE, actual=topology,
557 onpass="Switch recovery successful",
558 onfail="Failed to recover switch?" )
559
560 @staticmethod
561 def cleanup( main ):
562 """
563 Stop Onos-cluster.
564 Stops Mininet
565 Copies ONOS log
566 """
Devin Lim58046fa2017-07-05 16:55:00 -0700567 try:
568 from tests.dependencies.utils import Utils
569 except ImportError:
570 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700571 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700572 try:
Devin Lim142b5342017-07-20 15:22:39 -0700573 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700574 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700575 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700576
577 main.utils.mininetCleanup( main.Mininet1 )
578
Devin Lim0c972b72018-02-08 14:53:59 -0800579 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700580
Devin Lim142b5342017-07-20 15:22:39 -0700581 for ctrl in main.Cluster.active():
582 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700583
584 @staticmethod
585 def killOnos( main, nodes, switches, links, expNodes ):
586 """
587 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
588 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
589 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
590 """
591 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700592
Jon Hall1efcb3f2016-08-23 13:42:15 -0700593 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700594 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700595 utilities.assert_equals( expect=main.TRUE, actual=killResult,
596 onpass="ONOS instance Killed",
597 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700598 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700599 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700600
Devin Lim142b5342017-07-20 15:22:39 -0700601 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700602
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700603 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700604 False,
Pier3b58c652016-09-26 12:03:31 -0700605 attempts=5,
606 sleep=10 )
607 utilities.assert_equals( expect=True, actual=nodeResults,
608 onpass="Nodes check successful",
609 onfail="Nodes check NOT successful" )
610
611 if not nodeResults:
612 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700613 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700614 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700615 ctrl.name,
616 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700617 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700618 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700619
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900620 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700621 main.FALSE,
622 kwargs={ 'numoswitch': switches,
623 'numolink': links,
624 'numoctrl': expNodes },
625 attempts=10,
626 sleep=12 )
627 utilities.assert_equals( expect=main.TRUE, actual=topology,
628 onpass="ONOS Instance down successful",
629 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700630
631 @staticmethod
632 def recoverOnos( main, nodes, switches, links, expNodes ):
633 """
634 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
635 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
636 Recover an ONOS instance and verify the ONOS cluster can see the proper change
637 """
638 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700639 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700640 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700641 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700642 utilities.assert_equals( expect=main.TRUE, actual=isUp,
643 onpass="ONOS service is ready",
644 onfail="ONOS service did not start properly" )
645 for i in nodes:
646 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700647 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900648 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700649 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
650 commandlineTimeout=60,
651 onosStartTimeout=100 )
652 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700653 utilities.assert_equals( expect=main.TRUE,
654 actual=cliResult,
655 onpass="ONOS CLI is ready",
656 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700657
Pier3b58c652016-09-26 12:03:31 -0700658 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700659 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700660 False,
Pier3b58c652016-09-26 12:03:31 -0700661 attempts=5,
662 sleep=10 )
663 utilities.assert_equals( expect=True, actual=nodeResults,
664 onpass="Nodes check successful",
665 onfail="Nodes check NOT successful" )
666
667 if not nodeResults:
668 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700669 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700670 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700671 ctrl.name,
672 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700673 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700674 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700675
Devin Lim142b5342017-07-20 15:22:39 -0700676 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700677 main.FALSE,
678 kwargs={ 'numoswitch': switches,
679 'numolink': links,
680 'numoctrl': expNodes },
681 attempts=10,
682 sleep=12 )
683 utilities.assert_equals( expect=main.TRUE, actual=topology,
684 onpass="ONOS Instance down successful",
685 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700686 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
687 main.FALSE,
688 attempts=10,
689 sleep=12 )
690 if ready:
691 ready = main.TRUE
692 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700693 onpass="ONOS summary command succeded",
694 onfail="ONOS summary command failed" )
695 if not ready:
696 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700697 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700698
699 @staticmethod
700 def addHostCfg( main ):
701 """
702 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700703 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700704 """
705 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700706 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800707 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700708 hostCfg = json.load( template )
709 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
710 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700711 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700712 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
713 subjectClass="hosts",
714 subjectKey=urllib.quote( mac,
715 safe='' ),
716 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700717 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
718 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700719 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700720 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
721 subjectClass="hosts",
722 subjectKey=urllib.quote( mac,
723 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700724 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700725 main.pingChart.update( { 'vlan1': { "expect": "True",
726 "hosts": [ "olt1", "vsg1" ] } } )
727 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
728 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700729 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700730 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700731 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
732 subjectClass="apps",
733 subjectKey="org.onosproject.segmentrouting",
734 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700735
736 @staticmethod
737 def delHostCfg( main ):
738 """
739 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700740 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700741 """
742 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700743 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800744 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700745 hostCfg = json.load( template )
746 main.step( "Removing host configuration" )
747 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700748 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700749 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
750 subjectKey=urllib.quote(
751 mac,
752 safe='' ),
753 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700754 main.step( "Removing configuration" )
755 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700756 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700757 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
758 subjectKey=urllib.quote(
759 mac,
760 safe='' ),
761 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700762 main.step( "Removing vlan configuration" )
763 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700764 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
765 subjectKey="org.onosproject.segmentrouting",
766 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800767
768 @staticmethod
769 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
770 """
771 Verifies IP address assignment from the hosts
772 """
773 main.step( "Verify IP address assignment from hosts" )
774 ipResult = main.TRUE
775 for hostName, ip in main.expectedHosts[ "network" ].items():
776 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
777 main.FALSE,
778 kwargs={ 'hostList': [ hostName ],
779 'prefix': ip },
780 attempts=attempts,
781 sleep=sleep )
782 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
783 onpass="Verify network host IP succeded",
784 onfail="Verify network host IP failed" )
785
786 @staticmethod
787 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
788 """
789 Verifies host IP address assignment from ONOS
790 """
791 main.step( "Verify host IP address assignment in ONOS" )
792 ipResult = main.TRUE
793 for hostName, ip in main.expectedHosts[ "onos" ].items():
794 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
795 main.FALSE,
796 kwargs={ 'hostList': [ hostName ],
797 'prefix': ip },
798 attempts=attempts,
799 sleep=sleep )
800 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
801 onpass="Verify ONOS host IP succeded",
802 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800803
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800804 @staticmethod
805 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
806 """
807 Description:
808 Updates interface configuration in ONOS, with given IP and vlan parameters
809 Required:
810 * connectPoint: connect point to update configuration
811 Optional:
812 * ips: list of IP addresses, combined with '/xx' subnet representation,
813 corresponding to 'ips' field in the configuration
814 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
815 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
816 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
817 """
818 cfg = dict()
819 cfg[ "ports" ] = dict()
820 cfg[ "ports" ][ connectPoint ] = dict()
821 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
822 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
823 if untagged > 0:
824 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
825 else:
826 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
827 if native > 0:
828 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
829
830 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )