blob: 980db4d162eac6f1cd04d8776f652593096b72b1 [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:
You Wanga877ea42018-04-05 15:27:40 -0700131 main.count = json.load(count)
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800132
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:
You Wanga877ea42018-04-05 15:27:40 -0700179 import re
180 controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ]
181 index = 0
You Wangd87b2312018-01-30 12:47:17 -0800182 for conf in main.topologyConf.split(","):
You Wanga877ea42018-04-05 15:27:40 -0700183 # Update zebra configurations with correct ONOS instance IP
184 if conf in [ "zebradbgp1.conf", "zebradbgp2.conf" ]:
185 ip = controllerIPs[ index ]
186 index = ( index + 1 ) % len( controllerIPs )
187 with open( main.configPath + main.forConfig + conf ) as f:
188 s = f.read()
189 s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s )
190 with open( main.configPath + main.forConfig + conf, "w" ) as f:
191 f.write( s )
You Wangd87b2312018-01-30 12:47:17 -0800192 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
Devin Lim57221b02018-02-14 15:45:36 -0800193 main.configPath + main.forConfig + conf,
You Wangd87b2312018-01-30 12:47:17 -0800194 "~/",
195 direction="to" )
196 stepResult = copyResult
197 utilities.assert_equals( expect=main.TRUE,
198 actual=stepResult,
199 onpass="Successfully copied topo files",
200 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700201 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700202 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700203 main.topology = topology
204 topoResult = main.Mininet1.startNet(
205 topoFile=main.Mininet1.home + main.topology, args=arg )
206 stepResult = topoResult
207 utilities.assert_equals( expect=main.TRUE,
208 actual=stepResult,
209 onpass="Successfully loaded topology",
210 onfail="Failed to load topology" )
211 # Exit if topology did not load properly
212 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700213 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700214
215 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800216 def connectToPhysicalNetwork( main, switchNames ):
217 main.step( "Connecting to physical netowrk" )
218 topoResult = main.NetworkBench.connectToNet()
219 stepResult = topoResult
220 utilities.assert_equals( expect=main.TRUE,
221 actual=stepResult,
222 onpass="Successfully loaded topology",
223 onfail="Failed to load topology" )
224 # Exit if topology did not load properly
225 if not topoResult:
226 main.cleanAndExit()
227
228 main.step( "Assign switches to controllers." )
229 assignResult = main.TRUE
230 for name in switchNames:
231 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
232 ip=main.Cluster.getIps(),
233 port='6653' )
234 utilities.assert_equals( expect=main.TRUE,
235 actual=stepResult,
236 onpass="Successfully assign switches to controllers",
237 onfail="Failed to assign switches to controllers" )
238
239 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700240 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700241 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700242
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700243 main.failures = int( main.params[ 'failures' ] )
244 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700245
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700246 if main.cfgName == '2x2':
247 spine = {}
248 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
249 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
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' ][ 'spine2' ]
254 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
255 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700256
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700257 elif main.cfgName == '4x4':
258 spine = {}
259 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
260 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
261 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700262
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700263 spine = {}
264 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
265 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
266 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700267
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700268 spine = {}
269 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
270 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
271 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700272
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700273 spine = {}
274 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
275 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
276 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700277
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700278 else:
Piera2a7e1b2016-10-04 11:51:43 -0700279 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700280 main.cleanAndExit()
You Wang27317572018-03-06 12:13:11 -0800281
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800282 @staticmethod
283 def addStaticOnosRoute( main, subnet, intf):
284 """
285 Adds an ONOS static route with the use route-add command.
286 """
287 main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf))
288 routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf)
289
290 utilities.assert_equals( expect=True, actual=( not routeResult ),
291 onpass="route-add command succeeded",
292 onfail="route-add command failed")
Piera2a7e1b2016-10-04 11:51:43 -0700293
294 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900295 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700296 main.step(
Jon Hall3c910162018-03-07 14:42:16 -0800297 "Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900298 if tag == "":
299 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700300 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700301 main.FALSE,
302 kwargs={ 'min': minFlowCount },
303 attempts=10,
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=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700307 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700308 onpass="Flow count looks correct: " + str( count ),
309 onfail="Flow count looks wrong: " + str( count ) )
310
311 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700312 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700313 main.FALSE,
314 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800315 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800316 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700317 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700318 expect=main.TRUE,
319 actual=flowCheck,
320 onpass="Flow status is correct!",
321 onfail="Flow status is wrong!" )
322 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700323 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700324 "flows",
325 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900326 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700327 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700328 "groups",
329 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900330 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700331
332 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700333 def checkDevices( main, switches, tag="", sleep=10 ):
334 main.step(
335 "Check whether the switches count is equal to %s" % switches )
336 if tag == "":
337 tag = 'CASE%d' % main.CurrentTestCaseNumber
338 result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
339 main.FALSE,
340 kwargs={ 'numoswitch': switches},
341 attempts=10,
342 sleep=sleep )
343 utilities.assert_equals( expect=main.TRUE, actual=result,
344 onpass="Device up successful",
345 onfail="Failed to boot up devices?" )
346
347 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800348 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
349 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800350 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
351 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
352 main.FALSE,
353 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800354 attempts=5,
355 sleep=sleep )
356 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800357 expect=True,
358 actual=( count > minFlowCount ),
359 onpass="Flow count looks correct: " + str( count ),
360 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800361
362 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800363 def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10):
364 main.step(
365 " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) )
366 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
367 main.FALSE,
368 args=( dpid, flowCount, False, 1),
369 attempts=5,
370 sleep=sleep )
371
372 utilities.assertEquals(
373 expect=True,
374 actual=( int( count ) == flowCount ),
375 onpass="Flow count looks correct: " + str(count) ,
376 onfail="Flow count looks wrong, should be " + str(flowCount))
377
378 @staticmethod
379 def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10):
380 main.step(
381 " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) )
382 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount,
383 main.FALSE,
384 args=( dpid, groupCount, False, 1),
385 attempts=5,
386 sleep=sleep )
387
388 utilities.assertEquals(
389 expect=True,
390 actual=( count == groupCount ),
391 onpass="Group count looks correct: " + str(count) ,
392 onfail="Group count looks wrong: should be " + str(groupCount))
393
394 @staticmethod
395 def checkFlowsGroupsFromFile(main):
396
397 for dpid, values in main.count.items():
398 flowCount = values["flows"]
399 groupCount = values["groups"]
400 main.log.report( "Check flow count for dpid " + str(dpid) +
401 ", should be " + str(flowCount))
402 Testcaselib.checkFlowEqualityByDpid(main, dpid, flowCount)
403
404 main.log.report( "Check group count for dpid " + str(dpid) +
405 ", should be " + str(groupCount))
406 Testcaselib.checkGroupEqualityByDpid(main, dpid, groupCount)
407
408 return
409
410 @staticmethod
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800411 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1 ):
You Wangf19d9f42018-02-23 16:34:19 -0800412 '''
You Wangba231e72018-03-01 13:18:21 -0800413 Verify connectivity between hosts according to the ping chart
414 acceptableFailed: max number of acceptable failed pings.
You Wangf19d9f42018-02-23 16:34:19 -0800415 basedOnIp: if True, run ping or ping6 based on suffix of host names
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800416 retryAttempts: the number of retry ping. Only works for IPv4 hosts.
You Wangf19d9f42018-02-23 16:34:19 -0800417 '''
You Wangba231e72018-03-01 13:18:21 -0800418 main.log.report( "Check host connectivity" )
419 main.log.debug( "Ping chart: %s" % main.pingChart )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800420 if tag == "":
421 tag = 'CASE%d' % main.CurrentTestCaseNumber
422 for entry in main.pingChart.itervalues():
You Wangba231e72018-03-01 13:18:21 -0800423 main.log.debug( "Entry in ping chart: %s" % entry )
424 expect = entry[ 'expect' ]
425 if expect == "Unidirectional":
426 # Verify ping from each src host to each dst host
427 src = entry[ 'src' ]
428 dst = entry[ 'dst' ]
429 expect = main.TRUE
430 main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) )
431 if basedOnIp:
432 if ("v4" in src[0]):
433 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
434 utilities.assert_equals( expect=expect, actual=pa,
435 onpass="IPv4 connectivity successfully tested",
436 onfail="IPv4 connectivity failed" )
437 if ("v6" in src[0]):
438 pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed )
439 utilities.assert_equals( expect=expect, actual=pa,
440 onpass="IPv6 connectivity successfully tested",
441 onfail="IPv6 connectivity failed" )
442 else:
443 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
444 utilities.assert_equals( expect=expect, actual=pa,
445 onpass="IP connectivity successfully tested",
446 onfail="IP connectivity failed" )
447 else:
448 # Verify ping between each host pair
449 hosts = entry[ 'hosts' ]
450 try:
451 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
452 except:
453 expect = main.FALSE
454 main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) )
455 if basedOnIp:
456 if ("v4" in hosts[0]):
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800457 pa = utilities.retry( main.Network.pingallHosts,
458 main.FALSE if expect else main.TRUE,
459 args=(hosts,),
460 attempts=retryAttempts,
461 sleep=sleep )
You Wangba231e72018-03-01 13:18:21 -0800462 utilities.assert_equals( expect=expect, actual=pa,
463 onpass="IPv4 connectivity successfully tested",
464 onfail="IPv4 connectivity failed" )
465 if ("v6" in hosts[0]):
466 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
467 utilities.assert_equals( expect=expect, actual=pa,
468 onpass="IPv6 connectivity successfully tested",
469 onfail="IPv6 connectivity failed" )
470 else:
You Wangf19d9f42018-02-23 16:34:19 -0800471 pa = main.Network.pingallHosts( hosts )
472 utilities.assert_equals( expect=expect, actual=pa,
You Wangba231e72018-03-01 13:18:21 -0800473 onpass="IP connectivity successfully tested",
474 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800475
476 if dumpflows:
477 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
478 "flows",
479 main.logdir,
480 tag + "_FlowsOn" )
481 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
482 "groups",
483 main.logdir,
484 tag + "_GroupsOn" )
485
486 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700487 def killLink( main, end1, end2, switches, links ):
488 """
489 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
490 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
491 Kill a link and verify ONOS can see the proper link change
492 """
493 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700494 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800495 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
496 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700497 main.log.info(
498 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
499 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700500 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700501 main.FALSE,
502 kwargs={ 'numoswitch': switches,
503 'numolink': links },
504 attempts=10,
505 sleep=main.linkSleep )
506 result = topology & LinkDown
507 utilities.assert_equals( expect=main.TRUE, actual=result,
508 onpass="Link down successful",
509 onfail="Failed to turn off link?" )
510
511 @staticmethod
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800512 def killLinkBatch( main, links, linksAfter, switches=7):
513 """
514 links = list of links (src, dst) to bring down.
515 """
516
517 main.step("Killing a batch of links {0}".format(links))
518
519 for end1, end2 in links:
520 main.Network.link( END1=end1, END2=end2, OPTION="down")
521 main.Network.link( END1=end2, END2=end1, OPTION="down")
522
523 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
524 main.log.info(
525 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
526 time.sleep( main.linkSleep )
527
528 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
529 main.FALSE,
530 kwargs={ 'numoswitch': switches,
531 'numolink': linksAfter },
532 attempts=10,
533 sleep=main.linkSleep )
534
You Wang2854bce2018-03-30 10:15:32 -0700535 utilities.assert_equals( expect=main.TRUE, actual=topology,
536 onpass="Link batch down successful",
537 onfail="Link batch down failed" )
538
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800539 @staticmethod
540 def restoreLinkBatch( main, links, linksAfter, switches=7):
541 """
542 links = list of link (src, dst) to bring up again.
543 """
544
545 main.step("Restoring a batch of links {0}".format(links))
546
547 for end1, end2 in links:
548 main.Network.link( END1=end1, END2=end2, OPTION="up")
549 main.Network.link( END1=end2, END2=end1, OPTION="up")
550
551 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
552 main.log.info(
553 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
554 time.sleep( main.linkSleep )
555
556 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
557 main.FALSE,
558 kwargs={ 'numoswitch': switches,
559 'numolink': linksAfter },
560 attempts=10,
561 sleep=main.linkSleep )
562
You Wang2854bce2018-03-30 10:15:32 -0700563 utilities.assert_equals( expect=main.TRUE, actual=topology,
564 onpass="Link batch up successful",
565 onfail="Link batch up failed" )
566
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800567 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700568 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
569 links ):
570 """
571 Params:
572 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
573 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
574 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
575 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
576 Kill a link and verify ONOS can see the proper link change
577 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700578 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700579 result = False
580 count = 0
581 while True:
582 count += 1
You Wangd5873482018-01-24 12:30:00 -0800583 main.Network.link( END1=end1, END2=end2, OPTION="up" )
584 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700585 main.log.info(
586 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
587 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700588
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700589 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700590 ctrl = main.Cluster.runningNodes[ i ]
591 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700592 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900593 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
594 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700595 time.sleep( main.linkSleep )
596
Devin Lim142b5342017-07-20 15:22:39 -0700597 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
598 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700599 if count > 5 or result:
600 break
601 utilities.assert_equals( expect=main.TRUE, actual=result,
602 onpass="Link up successful",
603 onfail="Failed to bring link up" )
604
605 @staticmethod
606 def killSwitch( main, switch, switches, links ):
607 """
608 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
609 Completely kill a switch and verify ONOS can see the proper change
610 """
611 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
612 main.step( "Kill " + switch )
613 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800614 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700615 # todo make this repeatable
616 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700617 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700618 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700619 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700620 main.FALSE,
621 kwargs={ 'numoswitch': switches,
622 'numolink': links },
623 attempts=10,
624 sleep=main.switchSleep )
625 utilities.assert_equals( expect=main.TRUE, actual=topology,
626 onpass="Kill switch successful",
627 onfail="Failed to kill switch?" )
628
629 @staticmethod
630 def recoverSwitch( main, switch, switches, links ):
631 """
632 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
633 Recover a switch and verify ONOS can see the proper change
634 """
635 # todo make this repeatable
636 main.step( "Recovering " + switch )
637 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800638 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700639 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700640 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700641 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700642 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700643 main.FALSE,
644 kwargs={ 'numoswitch': switches,
645 'numolink': links },
646 attempts=10,
647 sleep=main.switchSleep )
648 utilities.assert_equals( expect=main.TRUE, actual=topology,
649 onpass="Switch recovery successful",
650 onfail="Failed to recover switch?" )
651
652 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700653 def cleanup( main, physical=False):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700654 """
655 Stop Onos-cluster.
656 Stops Mininet
657 Copies ONOS log
658 """
Devin Lim58046fa2017-07-05 16:55:00 -0700659 try:
660 from tests.dependencies.utils import Utils
661 except ImportError:
662 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700663 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700664 try:
Devin Lim142b5342017-07-20 15:22:39 -0700665 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700666 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700667 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700668
Pier6a0c4de2018-03-18 16:01:30 -0700669 if not physical:
670 main.utils.mininetCleanup( main.Mininet1 )
Devin Lim58046fa2017-07-05 16:55:00 -0700671
Devin Lim0c972b72018-02-08 14:53:59 -0800672 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700673
Devin Lim142b5342017-07-20 15:22:39 -0700674 for ctrl in main.Cluster.active():
675 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700676
677 @staticmethod
678 def killOnos( main, nodes, switches, links, expNodes ):
679 """
680 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
681 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
682 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
683 """
Jon Hall3c910162018-03-07 14:42:16 -0800684 main.step( "Killing ONOS instances with index(es): {}".format( nodes ) )
Pier3b58c652016-09-26 12:03:31 -0700685
Jon Hall1efcb3f2016-08-23 13:42:15 -0700686 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700687 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700688 utilities.assert_equals( expect=main.TRUE, actual=killResult,
689 onpass="ONOS instance Killed",
690 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700691 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700692 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700693
Devin Lim142b5342017-07-20 15:22:39 -0700694 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700695
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700696 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700697 False,
Pier3b58c652016-09-26 12:03:31 -0700698 attempts=5,
699 sleep=10 )
700 utilities.assert_equals( expect=True, actual=nodeResults,
701 onpass="Nodes check successful",
702 onfail="Nodes check NOT successful" )
703
704 if not nodeResults:
705 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700706 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700707 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700708 ctrl.name,
709 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700710 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700711 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700712
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900713 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700714 main.FALSE,
715 kwargs={ 'numoswitch': switches,
716 'numolink': links,
717 'numoctrl': expNodes },
718 attempts=10,
719 sleep=12 )
720 utilities.assert_equals( expect=main.TRUE, actual=topology,
721 onpass="ONOS Instance down successful",
722 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700723
724 @staticmethod
725 def recoverOnos( main, nodes, switches, links, expNodes ):
726 """
727 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
728 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
729 Recover an ONOS instance and verify the ONOS cluster can see the proper change
730 """
Jon Hall3c910162018-03-07 14:42:16 -0800731 main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) )
Devin Lim142b5342017-07-20 15:22:39 -0700732 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700733 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700734 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700735 utilities.assert_equals( expect=main.TRUE, actual=isUp,
736 onpass="ONOS service is ready",
737 onfail="ONOS service did not start properly" )
738 for i in nodes:
739 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700740 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900741 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700742 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
743 commandlineTimeout=60,
744 onosStartTimeout=100 )
745 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700746 utilities.assert_equals( expect=main.TRUE,
747 actual=cliResult,
748 onpass="ONOS CLI is ready",
749 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700750
Pier3b58c652016-09-26 12:03:31 -0700751 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700752 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700753 False,
Pier3b58c652016-09-26 12:03:31 -0700754 attempts=5,
755 sleep=10 )
756 utilities.assert_equals( expect=True, actual=nodeResults,
757 onpass="Nodes check successful",
758 onfail="Nodes check NOT successful" )
759
760 if not nodeResults:
761 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700762 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700763 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700764 ctrl.name,
765 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700766 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700767 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700768
Devin Lim142b5342017-07-20 15:22:39 -0700769 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700770 main.FALSE,
771 kwargs={ 'numoswitch': switches,
772 'numolink': links,
773 'numoctrl': expNodes },
774 attempts=10,
775 sleep=12 )
776 utilities.assert_equals( expect=main.TRUE, actual=topology,
777 onpass="ONOS Instance down successful",
778 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700779 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
780 main.FALSE,
781 attempts=10,
782 sleep=12 )
783 if ready:
784 ready = main.TRUE
785 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700786 onpass="ONOS summary command succeded",
787 onfail="ONOS summary command failed" )
788 if not ready:
789 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700790 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700791
792 @staticmethod
793 def addHostCfg( main ):
794 """
795 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700796 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700797 """
798 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700799 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800800 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700801 hostCfg = json.load( template )
802 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
803 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700804 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700805 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
806 subjectClass="hosts",
807 subjectKey=urllib.quote( mac,
808 safe='' ),
809 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700810 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
811 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700812 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700813 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
814 subjectClass="hosts",
815 subjectKey=urllib.quote( mac,
816 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700817 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700818 main.pingChart.update( { 'vlan1': { "expect": "True",
819 "hosts": [ "olt1", "vsg1" ] } } )
820 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
821 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700822 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700823 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700824 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
825 subjectClass="apps",
826 subjectKey="org.onosproject.segmentrouting",
827 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700828
829 @staticmethod
830 def delHostCfg( main ):
831 """
832 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700833 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700834 """
835 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700836 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800837 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700838 hostCfg = json.load( template )
839 main.step( "Removing host configuration" )
840 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700841 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700842 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
843 subjectKey=urllib.quote(
844 mac,
845 safe='' ),
846 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700847 main.step( "Removing configuration" )
848 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700849 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700850 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
851 subjectKey=urllib.quote(
852 mac,
853 safe='' ),
854 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700855 main.step( "Removing vlan configuration" )
856 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700857 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
858 subjectKey="org.onosproject.segmentrouting",
859 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800860
861 @staticmethod
862 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
863 """
864 Verifies IP address assignment from the hosts
865 """
866 main.step( "Verify IP address assignment from hosts" )
867 ipResult = main.TRUE
868 for hostName, ip in main.expectedHosts[ "network" ].items():
869 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
870 main.FALSE,
871 kwargs={ 'hostList': [ hostName ],
872 'prefix': ip },
873 attempts=attempts,
874 sleep=sleep )
875 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
876 onpass="Verify network host IP succeded",
877 onfail="Verify network host IP failed" )
878
879 @staticmethod
880 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
881 """
882 Verifies host IP address assignment from ONOS
883 """
884 main.step( "Verify host IP address assignment in ONOS" )
885 ipResult = main.TRUE
886 for hostName, ip in main.expectedHosts[ "onos" ].items():
887 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
888 main.FALSE,
889 kwargs={ 'hostList': [ hostName ],
890 'prefix': ip },
891 attempts=attempts,
892 sleep=sleep )
893 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
894 onpass="Verify ONOS host IP succeded",
895 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800896
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800897 @staticmethod
898 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
899 """
900 Description:
901 Updates interface configuration in ONOS, with given IP and vlan parameters
902 Required:
903 * connectPoint: connect point to update configuration
904 Optional:
905 * ips: list of IP addresses, combined with '/xx' subnet representation,
906 corresponding to 'ips' field in the configuration
907 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
908 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
909 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
910 """
911 cfg = dict()
912 cfg[ "ports" ] = dict()
913 cfg[ "ports" ][ connectPoint ] = dict()
914 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
915 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
916 if untagged > 0:
917 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
918 else:
919 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
920 if native > 0:
921 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
922
923 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )