blob: 3afb6d3f437f22e8ab6e231ced8621d93fd473df [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 Wang5df1c6d2018-04-06 18:02:02 -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
You Wang5df1c6d2018-04-06 18:02:02 -0700240 def saveOnosDiagnostics( main ):
241 """
242 Get onos-diags.tar.gz and save it to the log directory.
243 suffix: suffix string of the file name. E.g. onos-diags-case1.tar.gz
244 """
245 main.log.info( "Collecting onos-diags..." )
246 main.ONOSbench.onosDiagnostics( [ctrl.ipAddress for ctrl in main.Cluster.runningNodes],
247 main.logdir,
248 "-CASE%d" % main.CurrentTestCaseNumber )
249
250 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700251 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700252 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700253
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700254 main.failures = int( main.params[ 'failures' ] )
255 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700256
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700257 if main.cfgName == '2x2':
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 elif main.cfgName == '4x4':
269 spine = {}
270 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
271 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
272 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700273
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700274 spine = {}
275 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
276 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
277 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700278
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700279 spine = {}
280 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
281 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
282 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700283
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700284 spine = {}
285 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
286 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
287 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700288
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700289 else:
Piera2a7e1b2016-10-04 11:51:43 -0700290 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700291 main.cleanAndExit()
You Wang27317572018-03-06 12:13:11 -0800292
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800293 @staticmethod
294 def addStaticOnosRoute( main, subnet, intf):
295 """
296 Adds an ONOS static route with the use route-add command.
297 """
298 main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf))
299 routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf)
300
301 utilities.assert_equals( expect=True, actual=( not routeResult ),
302 onpass="route-add command succeeded",
303 onfail="route-add command failed")
Piera2a7e1b2016-10-04 11:51:43 -0700304
305 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900306 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700307 main.step(
Jon Hall3c910162018-03-07 14:42:16 -0800308 "Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900309 if tag == "":
310 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700311 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700312 main.FALSE,
313 kwargs={ 'min': minFlowCount },
314 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800315 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700316 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700317 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700318 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700319 onpass="Flow count looks correct: " + str( count ),
320 onfail="Flow count looks wrong: " + str( count ) )
321
322 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700323 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700324 main.FALSE,
325 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800326 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800327 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700328 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700329 expect=main.TRUE,
330 actual=flowCheck,
331 onpass="Flow status is correct!",
332 onfail="Flow status is wrong!" )
333 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700334 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700335 "flows",
336 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900337 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700338 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700339 "groups",
340 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900341 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700342
343 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700344 def checkDevices( main, switches, tag="", sleep=10 ):
345 main.step(
346 "Check whether the switches count is equal to %s" % switches )
347 if tag == "":
348 tag = 'CASE%d' % main.CurrentTestCaseNumber
349 result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
350 main.FALSE,
351 kwargs={ 'numoswitch': switches},
352 attempts=10,
353 sleep=sleep )
354 utilities.assert_equals( expect=main.TRUE, actual=result,
355 onpass="Device up successful",
356 onfail="Failed to boot up devices?" )
357
358 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800359 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
360 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800361 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
362 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
363 main.FALSE,
364 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800365 attempts=5,
366 sleep=sleep )
367 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800368 expect=True,
369 actual=( count > minFlowCount ),
370 onpass="Flow count looks correct: " + str( count ),
371 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800372
373 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800374 def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10):
375 main.step(
376 " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) )
377 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
378 main.FALSE,
379 args=( dpid, flowCount, False, 1),
380 attempts=5,
381 sleep=sleep )
382
383 utilities.assertEquals(
384 expect=True,
385 actual=( int( count ) == flowCount ),
386 onpass="Flow count looks correct: " + str(count) ,
387 onfail="Flow count looks wrong, should be " + str(flowCount))
388
389 @staticmethod
390 def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10):
391 main.step(
392 " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) )
393 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount,
394 main.FALSE,
395 args=( dpid, groupCount, False, 1),
396 attempts=5,
397 sleep=sleep )
398
399 utilities.assertEquals(
400 expect=True,
401 actual=( count == groupCount ),
402 onpass="Group count looks correct: " + str(count) ,
403 onfail="Group count looks wrong: should be " + str(groupCount))
404
405 @staticmethod
406 def checkFlowsGroupsFromFile(main):
407
408 for dpid, values in main.count.items():
409 flowCount = values["flows"]
410 groupCount = values["groups"]
411 main.log.report( "Check flow count for dpid " + str(dpid) +
412 ", should be " + str(flowCount))
413 Testcaselib.checkFlowEqualityByDpid(main, dpid, flowCount)
414
415 main.log.report( "Check group count for dpid " + str(dpid) +
416 ", should be " + str(groupCount))
417 Testcaselib.checkGroupEqualityByDpid(main, dpid, groupCount)
418
419 return
420
421 @staticmethod
You Wang5df1c6d2018-04-06 18:02:02 -0700422 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1, skipOnFail=False ):
You Wangf19d9f42018-02-23 16:34:19 -0800423 '''
You Wangba231e72018-03-01 13:18:21 -0800424 Verify connectivity between hosts according to the ping chart
425 acceptableFailed: max number of acceptable failed pings.
You Wangf19d9f42018-02-23 16:34:19 -0800426 basedOnIp: if True, run ping or ping6 based on suffix of host names
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800427 retryAttempts: the number of retry ping. Only works for IPv4 hosts.
You Wangf19d9f42018-02-23 16:34:19 -0800428 '''
You Wangba231e72018-03-01 13:18:21 -0800429 main.log.report( "Check host connectivity" )
430 main.log.debug( "Ping chart: %s" % main.pingChart )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800431 if tag == "":
432 tag = 'CASE%d' % main.CurrentTestCaseNumber
433 for entry in main.pingChart.itervalues():
You Wangba231e72018-03-01 13:18:21 -0800434 main.log.debug( "Entry in ping chart: %s" % entry )
435 expect = entry[ 'expect' ]
436 if expect == "Unidirectional":
437 # Verify ping from each src host to each dst host
438 src = entry[ 'src' ]
439 dst = entry[ 'dst' ]
440 expect = main.TRUE
441 main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) )
442 if basedOnIp:
443 if ("v4" in src[0]):
444 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
445 utilities.assert_equals( expect=expect, actual=pa,
446 onpass="IPv4 connectivity successfully tested",
447 onfail="IPv4 connectivity failed" )
448 if ("v6" in src[0]):
449 pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed )
450 utilities.assert_equals( expect=expect, actual=pa,
451 onpass="IPv6 connectivity successfully tested",
452 onfail="IPv6 connectivity failed" )
453 else:
454 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
455 utilities.assert_equals( expect=expect, actual=pa,
456 onpass="IP connectivity successfully tested",
457 onfail="IP connectivity failed" )
458 else:
459 # Verify ping between each host pair
460 hosts = entry[ 'hosts' ]
461 try:
462 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
463 except:
464 expect = main.FALSE
465 main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) )
466 if basedOnIp:
467 if ("v4" in hosts[0]):
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800468 pa = utilities.retry( main.Network.pingallHosts,
469 main.FALSE if expect else main.TRUE,
470 args=(hosts,),
471 attempts=retryAttempts,
472 sleep=sleep )
You Wangba231e72018-03-01 13:18:21 -0800473 utilities.assert_equals( expect=expect, actual=pa,
474 onpass="IPv4 connectivity successfully tested",
475 onfail="IPv4 connectivity failed" )
476 if ("v6" in hosts[0]):
477 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
478 utilities.assert_equals( expect=expect, actual=pa,
479 onpass="IPv6 connectivity successfully tested",
480 onfail="IPv6 connectivity failed" )
481 else:
You Wangf19d9f42018-02-23 16:34:19 -0800482 pa = main.Network.pingallHosts( hosts )
483 utilities.assert_equals( expect=expect, actual=pa,
You Wangba231e72018-03-01 13:18:21 -0800484 onpass="IP connectivity successfully tested",
485 onfail="IP connectivity failed" )
You Wang5df1c6d2018-04-06 18:02:02 -0700486 if skipOnFail and pa != expect:
487 Testcaselib.saveOnosDiagnostics( main )
You Wang24ad2f52018-04-10 10:47:12 -0700488 Testcaselib.cleanup( main, copyKarafLog=False )
You Wang5df1c6d2018-04-06 18:02:02 -0700489 main.skipCase()
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800490
491 if dumpflows:
492 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
493 "flows",
494 main.logdir,
495 tag + "_FlowsOn" )
496 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
497 "groups",
498 main.logdir,
499 tag + "_GroupsOn" )
500
501 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700502 def killLink( main, end1, end2, switches, links ):
503 """
504 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
505 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
506 Kill a link and verify ONOS can see the proper link change
507 """
508 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700509 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800510 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
511 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700512 main.log.info(
513 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
514 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700515 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700516 main.FALSE,
517 kwargs={ 'numoswitch': switches,
518 'numolink': links },
519 attempts=10,
520 sleep=main.linkSleep )
521 result = topology & LinkDown
522 utilities.assert_equals( expect=main.TRUE, actual=result,
523 onpass="Link down successful",
524 onfail="Failed to turn off link?" )
525
526 @staticmethod
You Wangeb717bc2018-04-05 17:36:11 -0700527 def killLinkBatch( main, links, linksAfter, switches ):
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800528 """
529 links = list of links (src, dst) to bring down.
530 """
531
532 main.step("Killing a batch of links {0}".format(links))
533
534 for end1, end2 in links:
535 main.Network.link( END1=end1, END2=end2, OPTION="down")
536 main.Network.link( END1=end2, END2=end1, OPTION="down")
537
538 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
539 main.log.info(
540 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
541 time.sleep( main.linkSleep )
542
543 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
544 main.FALSE,
545 kwargs={ 'numoswitch': switches,
546 'numolink': linksAfter },
547 attempts=10,
548 sleep=main.linkSleep )
549
You Wang2854bce2018-03-30 10:15:32 -0700550 utilities.assert_equals( expect=main.TRUE, actual=topology,
551 onpass="Link batch down successful",
552 onfail="Link batch down failed" )
553
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800554 @staticmethod
You Wangeb717bc2018-04-05 17:36:11 -0700555 def restoreLinkBatch( main, links, linksAfter, switches ):
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800556 """
557 links = list of link (src, dst) to bring up again.
558 """
559
560 main.step("Restoring a batch of links {0}".format(links))
561
562 for end1, end2 in links:
563 main.Network.link( END1=end1, END2=end2, OPTION="up")
564 main.Network.link( END1=end2, END2=end1, OPTION="up")
565
566 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
567 main.log.info(
568 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
569 time.sleep( main.linkSleep )
570
571 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
572 main.FALSE,
573 kwargs={ 'numoswitch': switches,
574 'numolink': linksAfter },
575 attempts=10,
576 sleep=main.linkSleep )
577
You Wang2854bce2018-03-30 10:15:32 -0700578 utilities.assert_equals( expect=main.TRUE, actual=topology,
579 onpass="Link batch up successful",
580 onfail="Link batch up failed" )
581
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800582 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700583 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
584 links ):
585 """
586 Params:
587 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
588 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
589 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
590 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
591 Kill a link and verify ONOS can see the proper link change
592 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700593 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700594 result = False
595 count = 0
596 while True:
597 count += 1
You Wangd5873482018-01-24 12:30:00 -0800598 main.Network.link( END1=end1, END2=end2, OPTION="up" )
599 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700600 main.log.info(
601 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
602 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700603
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700604 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700605 ctrl = main.Cluster.runningNodes[ i ]
606 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700607 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900608 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
609 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700610 time.sleep( main.linkSleep )
611
Devin Lim142b5342017-07-20 15:22:39 -0700612 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
613 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700614 if count > 5 or result:
615 break
616 utilities.assert_equals( expect=main.TRUE, actual=result,
617 onpass="Link up successful",
618 onfail="Failed to bring link up" )
619
620 @staticmethod
621 def killSwitch( main, switch, switches, links ):
622 """
623 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
624 Completely kill a switch and verify ONOS can see the proper change
625 """
626 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
627 main.step( "Kill " + switch )
628 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800629 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700630 # todo make this repeatable
631 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700632 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700633 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700634 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700635 main.FALSE,
636 kwargs={ 'numoswitch': switches,
637 'numolink': links },
638 attempts=10,
639 sleep=main.switchSleep )
640 utilities.assert_equals( expect=main.TRUE, actual=topology,
641 onpass="Kill switch successful",
642 onfail="Failed to kill switch?" )
643
644 @staticmethod
645 def recoverSwitch( main, switch, switches, links ):
646 """
647 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
648 Recover a switch and verify ONOS can see the proper change
649 """
650 # todo make this repeatable
651 main.step( "Recovering " + switch )
652 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800653 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700654 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700655 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700656 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700657 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700658 main.FALSE,
659 kwargs={ 'numoswitch': switches,
660 'numolink': links },
661 attempts=10,
662 sleep=main.switchSleep )
663 utilities.assert_equals( expect=main.TRUE, actual=topology,
664 onpass="Switch recovery successful",
665 onfail="Failed to recover switch?" )
666
667 @staticmethod
You Wang5df1c6d2018-04-06 18:02:02 -0700668 def cleanup( main, copyKarafLog=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700669 """
670 Stop Onos-cluster.
671 Stops Mininet
672 Copies ONOS log
673 """
Devin Lim58046fa2017-07-05 16:55:00 -0700674 try:
675 from tests.dependencies.utils import Utils
676 except ImportError:
677 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700678 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700679 try:
Devin Lim142b5342017-07-20 15:22:39 -0700680 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700681 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700682 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700683
You Wang5df1c6d2018-04-06 18:02:02 -0700684 if hasattr( main, 'Mininet1' ):
Pier6a0c4de2018-03-18 16:01:30 -0700685 main.utils.mininetCleanup( main.Mininet1 )
Devin Lim58046fa2017-07-05 16:55:00 -0700686
You Wang5df1c6d2018-04-06 18:02:02 -0700687 if copyKarafLog:
688 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700689
Devin Lim142b5342017-07-20 15:22:39 -0700690 for ctrl in main.Cluster.active():
691 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700692
693 @staticmethod
694 def killOnos( main, nodes, switches, links, expNodes ):
695 """
696 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
697 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
698 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
699 """
Jon Hall3c910162018-03-07 14:42:16 -0800700 main.step( "Killing ONOS instances with index(es): {}".format( nodes ) )
You Wang5df1c6d2018-04-06 18:02:02 -0700701 main.onosSleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] )
Pier3b58c652016-09-26 12:03:31 -0700702
Jon Hall1efcb3f2016-08-23 13:42:15 -0700703 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700704 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700705 utilities.assert_equals( expect=main.TRUE, actual=killResult,
706 onpass="ONOS instance Killed",
707 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700708 main.Cluster.runningNodes[ i ].active = False
You Wang5df1c6d2018-04-06 18:02:02 -0700709 time.sleep( main.onosSleep )
Pier3b58c652016-09-26 12:03:31 -0700710
Devin Lim142b5342017-07-20 15:22:39 -0700711 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700712
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700713 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700714 False,
Pier3b58c652016-09-26 12:03:31 -0700715 attempts=5,
716 sleep=10 )
717 utilities.assert_equals( expect=True, actual=nodeResults,
718 onpass="Nodes check successful",
719 onfail="Nodes check NOT successful" )
720
721 if not nodeResults:
722 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700723 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700724 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700725 ctrl.name,
726 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700727 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700728 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700729
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900730 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700731 main.FALSE,
732 kwargs={ 'numoswitch': switches,
733 'numolink': links,
734 'numoctrl': expNodes },
735 attempts=10,
736 sleep=12 )
737 utilities.assert_equals( expect=main.TRUE, actual=topology,
738 onpass="ONOS Instance down successful",
739 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700740
741 @staticmethod
742 def recoverOnos( main, nodes, switches, links, expNodes ):
743 """
744 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
745 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
746 Recover an ONOS instance and verify the ONOS cluster can see the proper change
747 """
Jon Hall3c910162018-03-07 14:42:16 -0800748 main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) )
Devin Lim142b5342017-07-20 15:22:39 -0700749 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
You Wang5df1c6d2018-04-06 18:02:02 -0700750 time.sleep( main.onosSleep )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700751 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700752 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700753 utilities.assert_equals( expect=main.TRUE, actual=isUp,
754 onpass="ONOS service is ready",
755 onfail="ONOS service did not start properly" )
756 for i in nodes:
757 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700758 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900759 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700760 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
761 commandlineTimeout=60,
762 onosStartTimeout=100 )
763 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700764 utilities.assert_equals( expect=main.TRUE,
765 actual=cliResult,
766 onpass="ONOS CLI is ready",
767 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700768
Pier3b58c652016-09-26 12:03:31 -0700769 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700770 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700771 False,
Pier3b58c652016-09-26 12:03:31 -0700772 attempts=5,
773 sleep=10 )
774 utilities.assert_equals( expect=True, actual=nodeResults,
775 onpass="Nodes check successful",
776 onfail="Nodes check NOT successful" )
777
778 if not nodeResults:
779 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700780 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700781 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700782 ctrl.name,
783 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700784 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700785 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700786
Devin Lim142b5342017-07-20 15:22:39 -0700787 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700788 main.FALSE,
789 kwargs={ 'numoswitch': switches,
790 'numolink': links,
791 'numoctrl': expNodes },
792 attempts=10,
793 sleep=12 )
794 utilities.assert_equals( expect=main.TRUE, actual=topology,
795 onpass="ONOS Instance down successful",
796 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700797 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
798 main.FALSE,
799 attempts=10,
800 sleep=12 )
801 if ready:
802 ready = main.TRUE
803 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700804 onpass="ONOS summary command succeded",
805 onfail="ONOS summary command failed" )
806 if not ready:
807 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700808 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700809
810 @staticmethod
811 def addHostCfg( main ):
812 """
813 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700814 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700815 """
816 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700817 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800818 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700819 hostCfg = json.load( template )
820 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
821 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700822 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700823 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
824 subjectClass="hosts",
825 subjectKey=urllib.quote( mac,
826 safe='' ),
827 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700828 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
829 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700830 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700831 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
832 subjectClass="hosts",
833 subjectKey=urllib.quote( mac,
834 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700835 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700836 main.pingChart.update( { 'vlan1': { "expect": "True",
837 "hosts": [ "olt1", "vsg1" ] } } )
838 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
839 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700840 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700841 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700842 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
843 subjectClass="apps",
844 subjectKey="org.onosproject.segmentrouting",
845 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700846
847 @staticmethod
848 def delHostCfg( main ):
849 """
850 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700851 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700852 """
853 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700854 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800855 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700856 hostCfg = json.load( template )
857 main.step( "Removing host configuration" )
858 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700859 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700860 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
861 subjectKey=urllib.quote(
862 mac,
863 safe='' ),
864 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700865 main.step( "Removing configuration" )
866 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700867 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700868 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
869 subjectKey=urllib.quote(
870 mac,
871 safe='' ),
872 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700873 main.step( "Removing vlan configuration" )
874 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700875 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
876 subjectKey="org.onosproject.segmentrouting",
877 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800878
879 @staticmethod
880 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
881 """
882 Verifies IP address assignment from the hosts
883 """
884 main.step( "Verify IP address assignment from hosts" )
885 ipResult = main.TRUE
886 for hostName, ip in main.expectedHosts[ "network" ].items():
887 ipResult = ipResult and utilities.retry( main.Network.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 network host IP succeded",
895 onfail="Verify network host IP failed" )
896
897 @staticmethod
898 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
899 """
900 Verifies host IP address assignment from ONOS
901 """
902 main.step( "Verify host IP address assignment in ONOS" )
903 ipResult = main.TRUE
904 for hostName, ip in main.expectedHosts[ "onos" ].items():
905 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
906 main.FALSE,
907 kwargs={ 'hostList': [ hostName ],
908 'prefix': ip },
909 attempts=attempts,
910 sleep=sleep )
911 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
912 onpass="Verify ONOS host IP succeded",
913 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800914
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800915 @staticmethod
916 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
917 """
918 Description:
919 Updates interface configuration in ONOS, with given IP and vlan parameters
920 Required:
921 * connectPoint: connect point to update configuration
922 Optional:
923 * ips: list of IP addresses, combined with '/xx' subnet representation,
924 corresponding to 'ips' field in the configuration
925 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
926 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
927 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
928 """
929 cfg = dict()
930 cfg[ "ports" ] = dict()
931 cfg[ "ports" ][ connectPoint ] = dict()
932 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
933 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
934 if untagged > 0:
935 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
936 else:
937 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
938 if native > 0:
939 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
940
941 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )