blob: cb54f21c385307be6dd69609df328ba4918bdb32 [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/"
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -080069 main.forLinkFailure = "linkFailure/"
Devin Lim58046fa2017-07-05 16:55:00 -070070 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
You Wangd87b2312018-01-30 12:47:17 -080071 main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None
72 main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070073 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070074 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070075 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070076
Devin Lim0c972b72018-02-08 14:53:59 -080077 stepResult = main.testSetUp.envSetup( False )
Devin Lim58046fa2017-07-05 16:55:00 -070078 except Exception as e:
79 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070080
Devin Lim58046fa2017-07-05 16:55:00 -070081 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070082
Jon Hall1efcb3f2016-08-23 13:42:15 -070083 @staticmethod
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080084 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10,
85 parallel=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070086 """
87 - Set up cell
88 - Create cell file
89 - Set cell file
90 - Verify cell file
91 - Kill ONOS process
92 - Uninstall ONOS cluster
93 - Verify ONOS start up
94 - Install ONOS cluster
95 - Connect to cli
96 """
97 # main.scale[ 0 ] determines the current number of ONOS controller
You Wangd87b2312018-01-30 12:47:17 -080098 if not main.apps:
Jon Hall1efcb3f2016-08-23 13:42:15 -070099 main.log.error( "App list is empty" )
Jon Hall3c910162018-03-07 14:42:16 -0800100 main.log.info( "Cluster size: " + str( main.Cluster.numCtrls ) )
101 main.log.info( "Cluster ips: " + ', '.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700102 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -0800103 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800104 skipPack=skipPackage,
105 useSSH=Testcaselib.useSSH,
Devin Lim0c972b72018-02-08 14:53:59 -0800106 installParallel=parallel, includeCaseDesc=False )
Devin Lim142b5342017-07-20 15:22:39 -0700107 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
108 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800109 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700110 attempts=10 )
111 if ready:
112 ready = main.TRUE
113 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700114 onpass="ONOS summary command succeded",
115 onfail="ONOS summary command failed" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700116 if not ready:
117 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700118 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700119
Devin Lim142b5342017-07-20 15:22:39 -0700120 for ctrl in main.Cluster.active():
121 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
You Wangf5f104f2018-03-30 17:09:10 -0700122 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver" )
Devin Lim142b5342017-07-20 15:22:39 -0700123 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
You Wangf5f104f2018-03-30 17:09:10 -0700124 ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.impl" )
125 ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.store" )
126 ctrl.CLI.logSet( "DEBUG", "org.onosproject.routing.fpm" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700127
128 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800129 def loadCount( main ):
130 with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count:
131 main.count = json.load(count)
132
133 @staticmethod
Devin Lim57221b02018-02-14 15:45:36 -0800134 def loadJson( main ):
135 with open( "%s%s.json" % ( main.configPath + main.forJson,
136 main.cfgName ) ) as cfg:
137 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
138
139 @staticmethod
140 def loadChart( main ):
141 try:
142 with open( "%s%s.chart" % ( main.configPath + main.forChart,
143 main.cfgName ) ) as chart:
144 main.pingChart = json.load(chart)
145 except IOError:
146 main.log.warn( "No chart file found." )
147
148 @staticmethod
149 def loadHost( main ):
150 with open( "%s%s.host" % ( main.configPath + main.forHost,
151 main.cfgName ) ) as host:
152 main.expectedHosts = json.load( host )
153
154 @staticmethod
You Wang27317572018-03-06 12:13:11 -0800155 def loadSwitchFailureChart( main ):
156 with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure,
157 main.cfgName ) ) as sfc:
158 main.switchFailureChart = json.load( sfc )
159
160 @staticmethod
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800161 def loadLinkFailureChart( main ):
162 with open( "%s%s.linkFailureChart" % ( main.configPath + main.forLinkFailure,
163 main.cfgName ) ) as sfc:
164 main.linkFailureChart = json.load( sfc )
165
166 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700167 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800168 copyResult = main.ONOSbench.scp( main.Mininet1,
169 main.topoPath + main.topology,
170 main.Mininet1.home,
171 direction="to" )
172 if main.topologyLib:
173 for lib in main.topologyLib.split(","):
174 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
175 main.topoPath + lib,
176 main.Mininet1.home,
177 direction="to" )
178 if main.topologyConf:
179 for conf in main.topologyConf.split(","):
180 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
Devin Lim57221b02018-02-14 15:45:36 -0800181 main.configPath + main.forConfig + conf,
You Wangd87b2312018-01-30 12:47:17 -0800182 "~/",
183 direction="to" )
184 stepResult = copyResult
185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
187 onpass="Successfully copied topo files",
188 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700189 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700190 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700191 main.topology = topology
192 topoResult = main.Mininet1.startNet(
193 topoFile=main.Mininet1.home + main.topology, args=arg )
194 stepResult = topoResult
195 utilities.assert_equals( expect=main.TRUE,
196 actual=stepResult,
197 onpass="Successfully loaded topology",
198 onfail="Failed to load topology" )
199 # Exit if topology did not load properly
200 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700201 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700202
203 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800204 def connectToPhysicalNetwork( main, switchNames ):
205 main.step( "Connecting to physical netowrk" )
206 topoResult = main.NetworkBench.connectToNet()
207 stepResult = topoResult
208 utilities.assert_equals( expect=main.TRUE,
209 actual=stepResult,
210 onpass="Successfully loaded topology",
211 onfail="Failed to load topology" )
212 # Exit if topology did not load properly
213 if not topoResult:
214 main.cleanAndExit()
215
216 main.step( "Assign switches to controllers." )
217 assignResult = main.TRUE
218 for name in switchNames:
219 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
220 ip=main.Cluster.getIps(),
221 port='6653' )
222 utilities.assert_equals( expect=main.TRUE,
223 actual=stepResult,
224 onpass="Successfully assign switches to controllers",
225 onfail="Failed to assign switches to controllers" )
226
227 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700228 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700229 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700230
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700231 main.failures = int( main.params[ 'failures' ] )
232 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700233
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700234 if main.cfgName == '2x2':
235 spine = {}
236 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
237 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
238 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700239
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700240 spine = {}
241 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
242 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
243 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700244
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700245 elif main.cfgName == '4x4':
246 spine = {}
247 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
248 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
249 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700250
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700251 spine = {}
252 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
253 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
254 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700255
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700256 spine = {}
257 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
258 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
259 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700260
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700261 spine = {}
262 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
263 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
264 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700265
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700266 else:
Piera2a7e1b2016-10-04 11:51:43 -0700267 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700268 main.cleanAndExit()
You Wang27317572018-03-06 12:13:11 -0800269
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800270 @staticmethod
271 def addStaticOnosRoute( main, subnet, intf):
272 """
273 Adds an ONOS static route with the use route-add command.
274 """
275 main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf))
276 routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf)
277
278 utilities.assert_equals( expect=True, actual=( not routeResult ),
279 onpass="route-add command succeeded",
280 onfail="route-add command failed")
Piera2a7e1b2016-10-04 11:51:43 -0700281
282 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900283 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700284 main.step(
Jon Hall3c910162018-03-07 14:42:16 -0800285 "Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900286 if tag == "":
287 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700288 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700289 main.FALSE,
290 kwargs={ 'min': minFlowCount },
291 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800292 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700293 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700294 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700295 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700296 onpass="Flow count looks correct: " + str( count ),
297 onfail="Flow count looks wrong: " + str( count ) )
298
299 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700300 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700301 main.FALSE,
302 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800303 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800304 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700305 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700306 expect=main.TRUE,
307 actual=flowCheck,
308 onpass="Flow status is correct!",
309 onfail="Flow status is wrong!" )
310 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700311 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700312 "flows",
313 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900314 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700315 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700316 "groups",
317 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900318 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700319
320 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700321 def checkDevices( main, switches, tag="", sleep=10 ):
322 main.step(
323 "Check whether the switches count is equal to %s" % switches )
324 if tag == "":
325 tag = 'CASE%d' % main.CurrentTestCaseNumber
326 result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
327 main.FALSE,
328 kwargs={ 'numoswitch': switches},
329 attempts=10,
330 sleep=sleep )
331 utilities.assert_equals( expect=main.TRUE, actual=result,
332 onpass="Device up successful",
333 onfail="Failed to boot up devices?" )
334
335 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800336 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
337 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800338 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
339 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
340 main.FALSE,
341 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800342 attempts=5,
343 sleep=sleep )
344 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800345 expect=True,
346 actual=( count > minFlowCount ),
347 onpass="Flow count looks correct: " + str( count ),
348 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800349
350 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800351 def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10):
352 main.step(
353 " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) )
354 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
355 main.FALSE,
356 args=( dpid, flowCount, False, 1),
357 attempts=5,
358 sleep=sleep )
359
360 utilities.assertEquals(
361 expect=True,
362 actual=( int( count ) == flowCount ),
363 onpass="Flow count looks correct: " + str(count) ,
364 onfail="Flow count looks wrong, should be " + str(flowCount))
365
366 @staticmethod
367 def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10):
368 main.step(
369 " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) )
370 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount,
371 main.FALSE,
372 args=( dpid, groupCount, False, 1),
373 attempts=5,
374 sleep=sleep )
375
376 utilities.assertEquals(
377 expect=True,
378 actual=( count == groupCount ),
379 onpass="Group count looks correct: " + str(count) ,
380 onfail="Group count looks wrong: should be " + str(groupCount))
381
382 @staticmethod
383 def checkFlowsGroupsFromFile(main):
384
385 for dpid, values in main.count.items():
386 flowCount = values["flows"]
387 groupCount = values["groups"]
388 main.log.report( "Check flow count for dpid " + str(dpid) +
389 ", should be " + str(flowCount))
390 Testcaselib.checkFlowEqualityByDpid(main, dpid, flowCount)
391
392 main.log.report( "Check group count for dpid " + str(dpid) +
393 ", should be " + str(groupCount))
394 Testcaselib.checkGroupEqualityByDpid(main, dpid, groupCount)
395
396 return
397
398 @staticmethod
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800399 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1 ):
You Wangf19d9f42018-02-23 16:34:19 -0800400 '''
You Wangba231e72018-03-01 13:18:21 -0800401 Verify connectivity between hosts according to the ping chart
402 acceptableFailed: max number of acceptable failed pings.
You Wangf19d9f42018-02-23 16:34:19 -0800403 basedOnIp: if True, run ping or ping6 based on suffix of host names
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800404 retryAttempts: the number of retry ping. Only works for IPv4 hosts.
You Wangf19d9f42018-02-23 16:34:19 -0800405 '''
You Wangba231e72018-03-01 13:18:21 -0800406 main.log.report( "Check host connectivity" )
407 main.log.debug( "Ping chart: %s" % main.pingChart )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800408 if tag == "":
409 tag = 'CASE%d' % main.CurrentTestCaseNumber
410 for entry in main.pingChart.itervalues():
You Wangba231e72018-03-01 13:18:21 -0800411 main.log.debug( "Entry in ping chart: %s" % entry )
412 expect = entry[ 'expect' ]
413 if expect == "Unidirectional":
414 # Verify ping from each src host to each dst host
415 src = entry[ 'src' ]
416 dst = entry[ 'dst' ]
417 expect = main.TRUE
418 main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) )
419 if basedOnIp:
420 if ("v4" in src[0]):
421 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
422 utilities.assert_equals( expect=expect, actual=pa,
423 onpass="IPv4 connectivity successfully tested",
424 onfail="IPv4 connectivity failed" )
425 if ("v6" in src[0]):
426 pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed )
427 utilities.assert_equals( expect=expect, actual=pa,
428 onpass="IPv6 connectivity successfully tested",
429 onfail="IPv6 connectivity failed" )
430 else:
431 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
432 utilities.assert_equals( expect=expect, actual=pa,
433 onpass="IP connectivity successfully tested",
434 onfail="IP connectivity failed" )
435 else:
436 # Verify ping between each host pair
437 hosts = entry[ 'hosts' ]
438 try:
439 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
440 except:
441 expect = main.FALSE
442 main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) )
443 if basedOnIp:
444 if ("v4" in hosts[0]):
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800445 pa = utilities.retry( main.Network.pingallHosts,
446 main.FALSE if expect else main.TRUE,
447 args=(hosts,),
448 attempts=retryAttempts,
449 sleep=sleep )
You Wangba231e72018-03-01 13:18:21 -0800450 utilities.assert_equals( expect=expect, actual=pa,
451 onpass="IPv4 connectivity successfully tested",
452 onfail="IPv4 connectivity failed" )
453 if ("v6" in hosts[0]):
454 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
455 utilities.assert_equals( expect=expect, actual=pa,
456 onpass="IPv6 connectivity successfully tested",
457 onfail="IPv6 connectivity failed" )
458 else:
You Wangf19d9f42018-02-23 16:34:19 -0800459 pa = main.Network.pingallHosts( hosts )
460 utilities.assert_equals( expect=expect, actual=pa,
You Wangba231e72018-03-01 13:18:21 -0800461 onpass="IP connectivity successfully tested",
462 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800463
464 if dumpflows:
465 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
466 "flows",
467 main.logdir,
468 tag + "_FlowsOn" )
469 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
470 "groups",
471 main.logdir,
472 tag + "_GroupsOn" )
473
474 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700475 def killLink( main, end1, end2, switches, links ):
476 """
477 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
478 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
479 Kill a link and verify ONOS can see the proper link change
480 """
481 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700482 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800483 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
484 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700485 main.log.info(
486 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
487 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700488 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700489 main.FALSE,
490 kwargs={ 'numoswitch': switches,
491 'numolink': links },
492 attempts=10,
493 sleep=main.linkSleep )
494 result = topology & LinkDown
495 utilities.assert_equals( expect=main.TRUE, actual=result,
496 onpass="Link down successful",
497 onfail="Failed to turn off link?" )
498
499 @staticmethod
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800500 def killLinkBatch( main, links, linksAfter, switches=7):
501 """
502 links = list of links (src, dst) to bring down.
503 """
504
505 main.step("Killing a batch of links {0}".format(links))
506
507 for end1, end2 in links:
508 main.Network.link( END1=end1, END2=end2, OPTION="down")
509 main.Network.link( END1=end2, END2=end1, OPTION="down")
510
511 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
512 main.log.info(
513 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
514 time.sleep( main.linkSleep )
515
516 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
517 main.FALSE,
518 kwargs={ 'numoswitch': switches,
519 'numolink': linksAfter },
520 attempts=10,
521 sleep=main.linkSleep )
522
You Wang2854bce2018-03-30 10:15:32 -0700523 utilities.assert_equals( expect=main.TRUE, actual=topology,
524 onpass="Link batch down successful",
525 onfail="Link batch down failed" )
526
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800527 @staticmethod
528 def restoreLinkBatch( main, links, linksAfter, switches=7):
529 """
530 links = list of link (src, dst) to bring up again.
531 """
532
533 main.step("Restoring a batch of links {0}".format(links))
534
535 for end1, end2 in links:
536 main.Network.link( END1=end1, END2=end2, OPTION="up")
537 main.Network.link( END1=end2, END2=end1, OPTION="up")
538
539 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
540 main.log.info(
541 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
542 time.sleep( main.linkSleep )
543
544 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
545 main.FALSE,
546 kwargs={ 'numoswitch': switches,
547 'numolink': linksAfter },
548 attempts=10,
549 sleep=main.linkSleep )
550
You Wang2854bce2018-03-30 10:15:32 -0700551 utilities.assert_equals( expect=main.TRUE, actual=topology,
552 onpass="Link batch up successful",
553 onfail="Link batch up failed" )
554
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800555 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700556 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
557 links ):
558 """
559 Params:
560 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
561 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
562 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
563 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
564 Kill a link and verify ONOS can see the proper link change
565 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700566 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700567 result = False
568 count = 0
569 while True:
570 count += 1
You Wangd5873482018-01-24 12:30:00 -0800571 main.Network.link( END1=end1, END2=end2, OPTION="up" )
572 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700573 main.log.info(
574 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
575 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700576
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700577 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700578 ctrl = main.Cluster.runningNodes[ i ]
579 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700580 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900581 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
582 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700583 time.sleep( main.linkSleep )
584
Devin Lim142b5342017-07-20 15:22:39 -0700585 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
586 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700587 if count > 5 or result:
588 break
589 utilities.assert_equals( expect=main.TRUE, actual=result,
590 onpass="Link up successful",
591 onfail="Failed to bring link up" )
592
593 @staticmethod
594 def killSwitch( main, switch, switches, links ):
595 """
596 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
597 Completely kill a switch and verify ONOS can see the proper change
598 """
599 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
600 main.step( "Kill " + switch )
601 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800602 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700603 # todo make this repeatable
604 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700605 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700606 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700607 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700608 main.FALSE,
609 kwargs={ 'numoswitch': switches,
610 'numolink': links },
611 attempts=10,
612 sleep=main.switchSleep )
613 utilities.assert_equals( expect=main.TRUE, actual=topology,
614 onpass="Kill switch successful",
615 onfail="Failed to kill switch?" )
616
617 @staticmethod
618 def recoverSwitch( main, switch, switches, links ):
619 """
620 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
621 Recover a switch and verify ONOS can see the proper change
622 """
623 # todo make this repeatable
624 main.step( "Recovering " + switch )
625 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800626 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700627 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700628 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700629 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700630 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700631 main.FALSE,
632 kwargs={ 'numoswitch': switches,
633 'numolink': links },
634 attempts=10,
635 sleep=main.switchSleep )
636 utilities.assert_equals( expect=main.TRUE, actual=topology,
637 onpass="Switch recovery successful",
638 onfail="Failed to recover switch?" )
639
640 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700641 def cleanup( main, physical=False):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700642 """
643 Stop Onos-cluster.
644 Stops Mininet
645 Copies ONOS log
646 """
Devin Lim58046fa2017-07-05 16:55:00 -0700647 try:
648 from tests.dependencies.utils import Utils
649 except ImportError:
650 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700651 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700652 try:
Devin Lim142b5342017-07-20 15:22:39 -0700653 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700654 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700655 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700656
Pier6a0c4de2018-03-18 16:01:30 -0700657 if not physical:
658 main.utils.mininetCleanup( main.Mininet1 )
Devin Lim58046fa2017-07-05 16:55:00 -0700659
Devin Lim0c972b72018-02-08 14:53:59 -0800660 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700661
Devin Lim142b5342017-07-20 15:22:39 -0700662 for ctrl in main.Cluster.active():
663 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700664
665 @staticmethod
666 def killOnos( main, nodes, switches, links, expNodes ):
667 """
668 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
669 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
670 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
671 """
Jon Hall3c910162018-03-07 14:42:16 -0800672 main.step( "Killing ONOS instances with index(es): {}".format( nodes ) )
Pier3b58c652016-09-26 12:03:31 -0700673
Jon Hall1efcb3f2016-08-23 13:42:15 -0700674 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700675 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700676 utilities.assert_equals( expect=main.TRUE, actual=killResult,
677 onpass="ONOS instance Killed",
678 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700679 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700680 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700681
Devin Lim142b5342017-07-20 15:22:39 -0700682 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700683
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700684 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700685 False,
Pier3b58c652016-09-26 12:03:31 -0700686 attempts=5,
687 sleep=10 )
688 utilities.assert_equals( expect=True, actual=nodeResults,
689 onpass="Nodes check successful",
690 onfail="Nodes check NOT successful" )
691
692 if not nodeResults:
693 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700694 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700695 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700696 ctrl.name,
697 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700698 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700699 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700700
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900701 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700702 main.FALSE,
703 kwargs={ 'numoswitch': switches,
704 'numolink': links,
705 'numoctrl': expNodes },
706 attempts=10,
707 sleep=12 )
708 utilities.assert_equals( expect=main.TRUE, actual=topology,
709 onpass="ONOS Instance down successful",
710 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700711
712 @staticmethod
713 def recoverOnos( main, nodes, switches, links, expNodes ):
714 """
715 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
716 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
717 Recover an ONOS instance and verify the ONOS cluster can see the proper change
718 """
Jon Hall3c910162018-03-07 14:42:16 -0800719 main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) )
Devin Lim142b5342017-07-20 15:22:39 -0700720 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700721 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700722 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700723 utilities.assert_equals( expect=main.TRUE, actual=isUp,
724 onpass="ONOS service is ready",
725 onfail="ONOS service did not start properly" )
726 for i in nodes:
727 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700728 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900729 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700730 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
731 commandlineTimeout=60,
732 onosStartTimeout=100 )
733 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700734 utilities.assert_equals( expect=main.TRUE,
735 actual=cliResult,
736 onpass="ONOS CLI is ready",
737 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700738
Pier3b58c652016-09-26 12:03:31 -0700739 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700740 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700741 False,
Pier3b58c652016-09-26 12:03:31 -0700742 attempts=5,
743 sleep=10 )
744 utilities.assert_equals( expect=True, actual=nodeResults,
745 onpass="Nodes check successful",
746 onfail="Nodes check NOT successful" )
747
748 if not nodeResults:
749 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700750 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700751 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700752 ctrl.name,
753 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700754 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700755 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700756
Devin Lim142b5342017-07-20 15:22:39 -0700757 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700758 main.FALSE,
759 kwargs={ 'numoswitch': switches,
760 'numolink': links,
761 'numoctrl': expNodes },
762 attempts=10,
763 sleep=12 )
764 utilities.assert_equals( expect=main.TRUE, actual=topology,
765 onpass="ONOS Instance down successful",
766 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700767 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
768 main.FALSE,
769 attempts=10,
770 sleep=12 )
771 if ready:
772 ready = main.TRUE
773 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700774 onpass="ONOS summary command succeded",
775 onfail="ONOS summary command failed" )
776 if not ready:
777 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700778 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700779
780 @staticmethod
781 def addHostCfg( main ):
782 """
783 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700784 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700785 """
786 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700787 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800788 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700789 hostCfg = json.load( template )
790 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
791 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700792 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700793 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
794 subjectClass="hosts",
795 subjectKey=urllib.quote( mac,
796 safe='' ),
797 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700798 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
799 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700800 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700801 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
802 subjectClass="hosts",
803 subjectKey=urllib.quote( mac,
804 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700805 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700806 main.pingChart.update( { 'vlan1': { "expect": "True",
807 "hosts": [ "olt1", "vsg1" ] } } )
808 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
809 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700810 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700811 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700812 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
813 subjectClass="apps",
814 subjectKey="org.onosproject.segmentrouting",
815 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700816
817 @staticmethod
818 def delHostCfg( main ):
819 """
820 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700821 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700822 """
823 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700824 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800825 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700826 hostCfg = json.load( template )
827 main.step( "Removing host configuration" )
828 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700829 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700830 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
831 subjectKey=urllib.quote(
832 mac,
833 safe='' ),
834 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700835 main.step( "Removing configuration" )
836 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700837 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700838 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
839 subjectKey=urllib.quote(
840 mac,
841 safe='' ),
842 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700843 main.step( "Removing vlan configuration" )
844 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700845 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
846 subjectKey="org.onosproject.segmentrouting",
847 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800848
849 @staticmethod
850 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
851 """
852 Verifies IP address assignment from the hosts
853 """
854 main.step( "Verify IP address assignment from hosts" )
855 ipResult = main.TRUE
856 for hostName, ip in main.expectedHosts[ "network" ].items():
857 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
858 main.FALSE,
859 kwargs={ 'hostList': [ hostName ],
860 'prefix': ip },
861 attempts=attempts,
862 sleep=sleep )
863 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
864 onpass="Verify network host IP succeded",
865 onfail="Verify network host IP failed" )
866
867 @staticmethod
868 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
869 """
870 Verifies host IP address assignment from ONOS
871 """
872 main.step( "Verify host IP address assignment in ONOS" )
873 ipResult = main.TRUE
874 for hostName, ip in main.expectedHosts[ "onos" ].items():
875 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
876 main.FALSE,
877 kwargs={ 'hostList': [ hostName ],
878 'prefix': ip },
879 attempts=attempts,
880 sleep=sleep )
881 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
882 onpass="Verify ONOS host IP succeded",
883 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800884
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800885 @staticmethod
886 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
887 """
888 Description:
889 Updates interface configuration in ONOS, with given IP and vlan parameters
890 Required:
891 * connectPoint: connect point to update configuration
892 Optional:
893 * ips: list of IP addresses, combined with '/xx' subnet representation,
894 corresponding to 'ips' field in the configuration
895 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
896 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
897 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
898 """
899 cfg = dict()
900 cfg[ "ports" ] = dict()
901 cfg[ "ports" ][ connectPoint ] = dict()
902 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
903 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
904 if untagged > 0:
905 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
906 else:
907 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
908 if native > 0:
909 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
910
911 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )