blob: bc31374358a27745a534ab80aafabc72f52d4c1d [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" )
122 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
123 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
124 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700125
126 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800127 def loadCount( main ):
128 with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count:
129 main.count = json.load(count)
130
131 @staticmethod
Devin Lim57221b02018-02-14 15:45:36 -0800132 def loadJson( main ):
133 with open( "%s%s.json" % ( main.configPath + main.forJson,
134 main.cfgName ) ) as cfg:
135 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
136
137 @staticmethod
138 def loadChart( main ):
139 try:
140 with open( "%s%s.chart" % ( main.configPath + main.forChart,
141 main.cfgName ) ) as chart:
142 main.pingChart = json.load(chart)
143 except IOError:
144 main.log.warn( "No chart file found." )
145
146 @staticmethod
147 def loadHost( main ):
148 with open( "%s%s.host" % ( main.configPath + main.forHost,
149 main.cfgName ) ) as host:
150 main.expectedHosts = json.load( host )
151
152 @staticmethod
You Wang27317572018-03-06 12:13:11 -0800153 def loadSwitchFailureChart( main ):
154 with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure,
155 main.cfgName ) ) as sfc:
156 main.switchFailureChart = json.load( sfc )
157
158 @staticmethod
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800159 def loadLinkFailureChart( main ):
160 with open( "%s%s.linkFailureChart" % ( main.configPath + main.forLinkFailure,
161 main.cfgName ) ) as sfc:
162 main.linkFailureChart = json.load( sfc )
163
164 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700165 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800166 copyResult = main.ONOSbench.scp( main.Mininet1,
167 main.topoPath + main.topology,
168 main.Mininet1.home,
169 direction="to" )
170 if main.topologyLib:
171 for lib in main.topologyLib.split(","):
172 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
173 main.topoPath + lib,
174 main.Mininet1.home,
175 direction="to" )
176 if main.topologyConf:
177 for conf in main.topologyConf.split(","):
178 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
Devin Lim57221b02018-02-14 15:45:36 -0800179 main.configPath + main.forConfig + conf,
You Wangd87b2312018-01-30 12:47:17 -0800180 "~/",
181 direction="to" )
182 stepResult = copyResult
183 utilities.assert_equals( expect=main.TRUE,
184 actual=stepResult,
185 onpass="Successfully copied topo files",
186 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700187 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700188 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700189 main.topology = topology
190 topoResult = main.Mininet1.startNet(
191 topoFile=main.Mininet1.home + main.topology, args=arg )
192 stepResult = topoResult
193 utilities.assert_equals( expect=main.TRUE,
194 actual=stepResult,
195 onpass="Successfully loaded topology",
196 onfail="Failed to load topology" )
197 # Exit if topology did not load properly
198 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700199 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700200
201 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800202 def connectToPhysicalNetwork( main, switchNames ):
203 main.step( "Connecting to physical netowrk" )
204 topoResult = main.NetworkBench.connectToNet()
205 stepResult = topoResult
206 utilities.assert_equals( expect=main.TRUE,
207 actual=stepResult,
208 onpass="Successfully loaded topology",
209 onfail="Failed to load topology" )
210 # Exit if topology did not load properly
211 if not topoResult:
212 main.cleanAndExit()
213
214 main.step( "Assign switches to controllers." )
215 assignResult = main.TRUE
216 for name in switchNames:
217 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
218 ip=main.Cluster.getIps(),
219 port='6653' )
220 utilities.assert_equals( expect=main.TRUE,
221 actual=stepResult,
222 onpass="Successfully assign switches to controllers",
223 onfail="Failed to assign switches to controllers" )
224
225 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700226 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700227 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700228
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700229 main.failures = int( main.params[ 'failures' ] )
230 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700231
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700232 if main.cfgName == '2x2':
233 spine = {}
234 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
235 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
236 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700237
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700238 spine = {}
239 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
240 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
241 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700242
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700243 elif main.cfgName == '4x4':
244 spine = {}
245 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
246 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
247 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700248
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700249 spine = {}
250 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
251 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
252 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700253
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700254 spine = {}
255 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
256 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
257 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700258
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700259 spine = {}
260 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
261 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
262 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700263
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700264 else:
Piera2a7e1b2016-10-04 11:51:43 -0700265 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700266 main.cleanAndExit()
You Wang27317572018-03-06 12:13:11 -0800267
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800268 @staticmethod
269 def addStaticOnosRoute( main, subnet, intf):
270 """
271 Adds an ONOS static route with the use route-add command.
272 """
273 main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf))
274 routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf)
275
276 utilities.assert_equals( expect=True, actual=( not routeResult ),
277 onpass="route-add command succeeded",
278 onfail="route-add command failed")
Piera2a7e1b2016-10-04 11:51:43 -0700279
280 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900281 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700282 main.step(
Jon Hall3c910162018-03-07 14:42:16 -0800283 "Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900284 if tag == "":
285 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700286 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700287 main.FALSE,
288 kwargs={ 'min': minFlowCount },
289 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800290 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700291 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700292 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700293 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700294 onpass="Flow count looks correct: " + str( count ),
295 onfail="Flow count looks wrong: " + str( count ) )
296
297 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700298 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700299 main.FALSE,
300 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800301 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800302 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700303 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700304 expect=main.TRUE,
305 actual=flowCheck,
306 onpass="Flow status is correct!",
307 onfail="Flow status is wrong!" )
308 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700309 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700310 "flows",
311 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900312 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700313 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700314 "groups",
315 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900316 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700317
318 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700319 def checkDevices( main, switches, tag="", sleep=10 ):
320 main.step(
321 "Check whether the switches count is equal to %s" % switches )
322 if tag == "":
323 tag = 'CASE%d' % main.CurrentTestCaseNumber
324 result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
325 main.FALSE,
326 kwargs={ 'numoswitch': switches},
327 attempts=10,
328 sleep=sleep )
329 utilities.assert_equals( expect=main.TRUE, actual=result,
330 onpass="Device up successful",
331 onfail="Failed to boot up devices?" )
332
333 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800334 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
335 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800336 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
337 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
338 main.FALSE,
339 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800340 attempts=5,
341 sleep=sleep )
342 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800343 expect=True,
344 actual=( count > minFlowCount ),
345 onpass="Flow count looks correct: " + str( count ),
346 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800347
348 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800349 def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10):
350 main.step(
351 " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) )
352 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
353 main.FALSE,
354 args=( dpid, flowCount, False, 1),
355 attempts=5,
356 sleep=sleep )
357
358 utilities.assertEquals(
359 expect=True,
360 actual=( int( count ) == flowCount ),
361 onpass="Flow count looks correct: " + str(count) ,
362 onfail="Flow count looks wrong, should be " + str(flowCount))
363
364 @staticmethod
365 def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10):
366 main.step(
367 " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) )
368 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount,
369 main.FALSE,
370 args=( dpid, groupCount, False, 1),
371 attempts=5,
372 sleep=sleep )
373
374 utilities.assertEquals(
375 expect=True,
376 actual=( count == groupCount ),
377 onpass="Group count looks correct: " + str(count) ,
378 onfail="Group count looks wrong: should be " + str(groupCount))
379
380 @staticmethod
381 def checkFlowsGroupsFromFile(main):
382
383 for dpid, values in main.count.items():
384 flowCount = values["flows"]
385 groupCount = values["groups"]
386 main.log.report( "Check flow count for dpid " + str(dpid) +
387 ", should be " + str(flowCount))
388 Testcaselib.checkFlowEqualityByDpid(main, dpid, flowCount)
389
390 main.log.report( "Check group count for dpid " + str(dpid) +
391 ", should be " + str(groupCount))
392 Testcaselib.checkGroupEqualityByDpid(main, dpid, groupCount)
393
394 return
395
396 @staticmethod
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800397 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1 ):
You Wangf19d9f42018-02-23 16:34:19 -0800398 '''
You Wangba231e72018-03-01 13:18:21 -0800399 Verify connectivity between hosts according to the ping chart
400 acceptableFailed: max number of acceptable failed pings.
You Wangf19d9f42018-02-23 16:34:19 -0800401 basedOnIp: if True, run ping or ping6 based on suffix of host names
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800402 retryAttempts: the number of retry ping. Only works for IPv4 hosts.
You Wangf19d9f42018-02-23 16:34:19 -0800403 '''
You Wangba231e72018-03-01 13:18:21 -0800404 main.log.report( "Check host connectivity" )
405 main.log.debug( "Ping chart: %s" % main.pingChart )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800406 if tag == "":
407 tag = 'CASE%d' % main.CurrentTestCaseNumber
408 for entry in main.pingChart.itervalues():
You Wangba231e72018-03-01 13:18:21 -0800409 main.log.debug( "Entry in ping chart: %s" % entry )
410 expect = entry[ 'expect' ]
411 if expect == "Unidirectional":
412 # Verify ping from each src host to each dst host
413 src = entry[ 'src' ]
414 dst = entry[ 'dst' ]
415 expect = main.TRUE
416 main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) )
417 if basedOnIp:
418 if ("v4" in src[0]):
419 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
420 utilities.assert_equals( expect=expect, actual=pa,
421 onpass="IPv4 connectivity successfully tested",
422 onfail="IPv4 connectivity failed" )
423 if ("v6" in src[0]):
424 pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed )
425 utilities.assert_equals( expect=expect, actual=pa,
426 onpass="IPv6 connectivity successfully tested",
427 onfail="IPv6 connectivity failed" )
428 else:
429 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
430 utilities.assert_equals( expect=expect, actual=pa,
431 onpass="IP connectivity successfully tested",
432 onfail="IP connectivity failed" )
433 else:
434 # Verify ping between each host pair
435 hosts = entry[ 'hosts' ]
436 try:
437 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
438 except:
439 expect = main.FALSE
440 main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) )
441 if basedOnIp:
442 if ("v4" in hosts[0]):
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800443 pa = utilities.retry( main.Network.pingallHosts,
444 main.FALSE if expect else main.TRUE,
445 args=(hosts,),
446 attempts=retryAttempts,
447 sleep=sleep )
You Wangba231e72018-03-01 13:18:21 -0800448 utilities.assert_equals( expect=expect, actual=pa,
449 onpass="IPv4 connectivity successfully tested",
450 onfail="IPv4 connectivity failed" )
451 if ("v6" in hosts[0]):
452 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
453 utilities.assert_equals( expect=expect, actual=pa,
454 onpass="IPv6 connectivity successfully tested",
455 onfail="IPv6 connectivity failed" )
456 else:
You Wangf19d9f42018-02-23 16:34:19 -0800457 pa = main.Network.pingallHosts( hosts )
458 utilities.assert_equals( expect=expect, actual=pa,
You Wangba231e72018-03-01 13:18:21 -0800459 onpass="IP connectivity successfully tested",
460 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800461
462 if dumpflows:
463 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
464 "flows",
465 main.logdir,
466 tag + "_FlowsOn" )
467 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
468 "groups",
469 main.logdir,
470 tag + "_GroupsOn" )
471
472 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700473 def killLink( main, end1, end2, switches, links ):
474 """
475 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
476 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
477 Kill a link and verify ONOS can see the proper link change
478 """
479 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700480 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800481 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
482 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700483 main.log.info(
484 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
485 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700486 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700487 main.FALSE,
488 kwargs={ 'numoswitch': switches,
489 'numolink': links },
490 attempts=10,
491 sleep=main.linkSleep )
492 result = topology & LinkDown
493 utilities.assert_equals( expect=main.TRUE, actual=result,
494 onpass="Link down successful",
495 onfail="Failed to turn off link?" )
496
497 @staticmethod
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800498 def killLinkBatch( main, links, linksAfter, switches=7):
499 """
500 links = list of links (src, dst) to bring down.
501 """
502
503 main.step("Killing a batch of links {0}".format(links))
504
505 for end1, end2 in links:
506 main.Network.link( END1=end1, END2=end2, OPTION="down")
507 main.Network.link( END1=end2, END2=end1, OPTION="down")
508
509 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
510 main.log.info(
511 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
512 time.sleep( main.linkSleep )
513
514 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
515 main.FALSE,
516 kwargs={ 'numoswitch': switches,
517 'numolink': linksAfter },
518 attempts=10,
519 sleep=main.linkSleep )
520
You Wang2854bce2018-03-30 10:15:32 -0700521 utilities.assert_equals( expect=main.TRUE, actual=topology,
522 onpass="Link batch down successful",
523 onfail="Link batch down failed" )
524
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800525 @staticmethod
526 def restoreLinkBatch( main, links, linksAfter, switches=7):
527 """
528 links = list of link (src, dst) to bring up again.
529 """
530
531 main.step("Restoring a batch of links {0}".format(links))
532
533 for end1, end2 in links:
534 main.Network.link( END1=end1, END2=end2, OPTION="up")
535 main.Network.link( END1=end2, END2=end1, OPTION="up")
536
537 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
538 main.log.info(
539 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
540 time.sleep( main.linkSleep )
541
542 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
543 main.FALSE,
544 kwargs={ 'numoswitch': switches,
545 'numolink': linksAfter },
546 attempts=10,
547 sleep=main.linkSleep )
548
You Wang2854bce2018-03-30 10:15:32 -0700549 utilities.assert_equals( expect=main.TRUE, actual=topology,
550 onpass="Link batch up successful",
551 onfail="Link batch up failed" )
552
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800553 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700554 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
555 links ):
556 """
557 Params:
558 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
559 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
560 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
561 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
562 Kill a link and verify ONOS can see the proper link change
563 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700564 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700565 result = False
566 count = 0
567 while True:
568 count += 1
You Wangd5873482018-01-24 12:30:00 -0800569 main.Network.link( END1=end1, END2=end2, OPTION="up" )
570 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700571 main.log.info(
572 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
573 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700574
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700575 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700576 ctrl = main.Cluster.runningNodes[ i ]
577 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700578 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900579 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
580 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700581 time.sleep( main.linkSleep )
582
Devin Lim142b5342017-07-20 15:22:39 -0700583 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
584 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700585 if count > 5 or result:
586 break
587 utilities.assert_equals( expect=main.TRUE, actual=result,
588 onpass="Link up successful",
589 onfail="Failed to bring link up" )
590
591 @staticmethod
592 def killSwitch( main, switch, switches, links ):
593 """
594 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
595 Completely kill a switch and verify ONOS can see the proper change
596 """
597 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
598 main.step( "Kill " + switch )
599 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800600 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700601 # todo make this repeatable
602 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700603 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700604 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700605 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700606 main.FALSE,
607 kwargs={ 'numoswitch': switches,
608 'numolink': links },
609 attempts=10,
610 sleep=main.switchSleep )
611 utilities.assert_equals( expect=main.TRUE, actual=topology,
612 onpass="Kill switch successful",
613 onfail="Failed to kill switch?" )
614
615 @staticmethod
616 def recoverSwitch( main, switch, switches, links ):
617 """
618 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
619 Recover a switch and verify ONOS can see the proper change
620 """
621 # todo make this repeatable
622 main.step( "Recovering " + switch )
623 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800624 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700625 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700626 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700627 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700628 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700629 main.FALSE,
630 kwargs={ 'numoswitch': switches,
631 'numolink': links },
632 attempts=10,
633 sleep=main.switchSleep )
634 utilities.assert_equals( expect=main.TRUE, actual=topology,
635 onpass="Switch recovery successful",
636 onfail="Failed to recover switch?" )
637
638 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700639 def cleanup( main, physical=False):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700640 """
641 Stop Onos-cluster.
642 Stops Mininet
643 Copies ONOS log
644 """
Devin Lim58046fa2017-07-05 16:55:00 -0700645 try:
646 from tests.dependencies.utils import Utils
647 except ImportError:
648 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700649 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700650 try:
Devin Lim142b5342017-07-20 15:22:39 -0700651 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700652 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700653 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700654
Pier6a0c4de2018-03-18 16:01:30 -0700655 if not physical:
656 main.utils.mininetCleanup( main.Mininet1 )
Devin Lim58046fa2017-07-05 16:55:00 -0700657
Devin Lim0c972b72018-02-08 14:53:59 -0800658 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700659
Devin Lim142b5342017-07-20 15:22:39 -0700660 for ctrl in main.Cluster.active():
661 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700662
663 @staticmethod
664 def killOnos( main, nodes, switches, links, expNodes ):
665 """
666 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
667 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
668 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
669 """
Jon Hall3c910162018-03-07 14:42:16 -0800670 main.step( "Killing ONOS instances with index(es): {}".format( nodes ) )
Pier3b58c652016-09-26 12:03:31 -0700671
Jon Hall1efcb3f2016-08-23 13:42:15 -0700672 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700673 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700674 utilities.assert_equals( expect=main.TRUE, actual=killResult,
675 onpass="ONOS instance Killed",
676 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700677 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700678 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700679
Devin Lim142b5342017-07-20 15:22:39 -0700680 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700681
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700682 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700683 False,
Pier3b58c652016-09-26 12:03:31 -0700684 attempts=5,
685 sleep=10 )
686 utilities.assert_equals( expect=True, actual=nodeResults,
687 onpass="Nodes check successful",
688 onfail="Nodes check NOT successful" )
689
690 if not nodeResults:
691 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700692 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700693 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700694 ctrl.name,
695 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700696 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700697 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700698
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900699 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700700 main.FALSE,
701 kwargs={ 'numoswitch': switches,
702 'numolink': links,
703 'numoctrl': expNodes },
704 attempts=10,
705 sleep=12 )
706 utilities.assert_equals( expect=main.TRUE, actual=topology,
707 onpass="ONOS Instance down successful",
708 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700709
710 @staticmethod
711 def recoverOnos( main, nodes, switches, links, expNodes ):
712 """
713 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
714 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
715 Recover an ONOS instance and verify the ONOS cluster can see the proper change
716 """
Jon Hall3c910162018-03-07 14:42:16 -0800717 main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) )
Devin Lim142b5342017-07-20 15:22:39 -0700718 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700719 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700720 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700721 utilities.assert_equals( expect=main.TRUE, actual=isUp,
722 onpass="ONOS service is ready",
723 onfail="ONOS service did not start properly" )
724 for i in nodes:
725 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700726 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900727 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700728 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
729 commandlineTimeout=60,
730 onosStartTimeout=100 )
731 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700732 utilities.assert_equals( expect=main.TRUE,
733 actual=cliResult,
734 onpass="ONOS CLI is ready",
735 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700736
Pier3b58c652016-09-26 12:03:31 -0700737 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700738 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700739 False,
Pier3b58c652016-09-26 12:03:31 -0700740 attempts=5,
741 sleep=10 )
742 utilities.assert_equals( expect=True, actual=nodeResults,
743 onpass="Nodes check successful",
744 onfail="Nodes check NOT successful" )
745
746 if not nodeResults:
747 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700748 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700749 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700750 ctrl.name,
751 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700752 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700753 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700754
Devin Lim142b5342017-07-20 15:22:39 -0700755 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700756 main.FALSE,
757 kwargs={ 'numoswitch': switches,
758 'numolink': links,
759 'numoctrl': expNodes },
760 attempts=10,
761 sleep=12 )
762 utilities.assert_equals( expect=main.TRUE, actual=topology,
763 onpass="ONOS Instance down successful",
764 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700765 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
766 main.FALSE,
767 attempts=10,
768 sleep=12 )
769 if ready:
770 ready = main.TRUE
771 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700772 onpass="ONOS summary command succeded",
773 onfail="ONOS summary command failed" )
774 if not ready:
775 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700776 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700777
778 @staticmethod
779 def addHostCfg( main ):
780 """
781 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700782 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700783 """
784 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700785 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800786 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700787 hostCfg = json.load( template )
788 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
789 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700790 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700791 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
792 subjectClass="hosts",
793 subjectKey=urllib.quote( mac,
794 safe='' ),
795 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700796 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
797 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700798 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700799 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
800 subjectClass="hosts",
801 subjectKey=urllib.quote( mac,
802 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700803 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700804 main.pingChart.update( { 'vlan1': { "expect": "True",
805 "hosts": [ "olt1", "vsg1" ] } } )
806 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
807 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700808 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700809 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700810 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
811 subjectClass="apps",
812 subjectKey="org.onosproject.segmentrouting",
813 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700814
815 @staticmethod
816 def delHostCfg( main ):
817 """
818 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700819 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700820 """
821 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700822 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800823 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700824 hostCfg = json.load( template )
825 main.step( "Removing host configuration" )
826 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700827 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700828 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
829 subjectKey=urllib.quote(
830 mac,
831 safe='' ),
832 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700833 main.step( "Removing configuration" )
834 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700835 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700836 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
837 subjectKey=urllib.quote(
838 mac,
839 safe='' ),
840 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700841 main.step( "Removing vlan configuration" )
842 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700843 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
844 subjectKey="org.onosproject.segmentrouting",
845 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800846
847 @staticmethod
848 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
849 """
850 Verifies IP address assignment from the hosts
851 """
852 main.step( "Verify IP address assignment from hosts" )
853 ipResult = main.TRUE
854 for hostName, ip in main.expectedHosts[ "network" ].items():
855 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
856 main.FALSE,
857 kwargs={ 'hostList': [ hostName ],
858 'prefix': ip },
859 attempts=attempts,
860 sleep=sleep )
861 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
862 onpass="Verify network host IP succeded",
863 onfail="Verify network host IP failed" )
864
865 @staticmethod
866 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
867 """
868 Verifies host IP address assignment from ONOS
869 """
870 main.step( "Verify host IP address assignment in ONOS" )
871 ipResult = main.TRUE
872 for hostName, ip in main.expectedHosts[ "onos" ].items():
873 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
874 main.FALSE,
875 kwargs={ 'hostList': [ hostName ],
876 'prefix': ip },
877 attempts=attempts,
878 sleep=sleep )
879 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
880 onpass="Verify ONOS host IP succeded",
881 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800882
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800883 @staticmethod
884 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
885 """
886 Description:
887 Updates interface configuration in ONOS, with given IP and vlan parameters
888 Required:
889 * connectPoint: connect point to update configuration
890 Optional:
891 * ips: list of IP addresses, combined with '/xx' subnet representation,
892 corresponding to 'ips' field in the configuration
893 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
894 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
895 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
896 """
897 cfg = dict()
898 cfg[ "ports" ] = dict()
899 cfg[ "ports" ][ connectPoint ] = dict()
900 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
901 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
902 if untagged > 0:
903 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
904 else:
905 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
906 if native > 0:
907 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
908
909 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )