blob: dc1dea097153e41aeb872c86af0308e108f3d9af [file] [log] [blame]
Devin Lim142b5342017-07-20 15:22:39 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Devin Lim58046fa2017-07-05 16:55:00 -07003
Devin Lim142b5342017-07-20 15:22:39 -07004Please 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.
Devin Lim142b5342017-07-20 15:22:39 -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"""
Devin Lim58046fa2017-07-05 16:55:00 -070021import re
Jon Hall43060f62020-06-23 13:13:33 -070022import os
Devin Lim58046fa2017-07-05 16:55:00 -070023
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070024
Devin Lim58046fa2017-07-05 16:55:00 -070025class ONOSSetup:
Jon Hall4f360bc2017-09-07 10:19:52 -070026
Devin Lim58046fa2017-07-05 16:55:00 -070027 def __init__( self ):
28 self.default = ''
Jon Hall627b1572020-12-01 12:01:15 -080029 try:
30 main.persistentSetup
31 except ( NameError, AttributeError ):
32 main.persistentSetup = False
Jon Hall4f360bc2017-09-07 10:19:52 -070033
Devin Lim0c972b72018-02-08 14:53:59 -080034 def envSetupDescription( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070035 """
36 Introduction part of the test. It will initialize some basic vairables.
37 """
Devin Lim0c972b72018-02-08 14:53:59 -080038 if includeCaseDesc:
39 main.case( "Constructing test variables and building ONOS package" )
40 main.caseExplanation = "For loading from params file, and pull" + \
41 " and build the latest ONOS package"
Jon Halla604fd42018-05-04 14:27:27 -070042 main.step( "Constructing test variables" )
Devin Lim142b5342017-07-20 15:22:39 -070043 try:
44 from tests.dependencies.Cluster import Cluster
45 except ImportError:
46 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070047 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070048 try:
49 main.Cluster
50 except ( NameError, AttributeError ):
Jon Hall3c0114c2020-08-11 15:07:42 -070051 main.Cluster = Cluster( main.ONOScell.nodes, useDocker=main.ONOScell.useDocker )
Devin Lim142b5342017-07-20 15:22:39 -070052 main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
Jon Halld74d2952018-03-01 13:26:39 -080053 main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
Devin Lim58046fa2017-07-05 16:55:00 -070054
Devin Lim0c972b72018-02-08 14:53:59 -080055 def gitPulling( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070056 """
57 it will do git checkout or pull if they are enabled from the params file.
58 """
Devin Lim0c972b72018-02-08 14:53:59 -080059
60 if includeCaseDesc:
61 main.case( "Pull onos branch and build onos on Teststation." )
62
Devin Lim58046fa2017-07-05 16:55:00 -070063 gitPull = main.params[ 'GIT' ][ 'pull' ]
64 gitBranch = main.params[ 'GIT' ][ 'branch' ]
65 if gitPull == 'True':
66 main.step( "Git Checkout ONOS branch: " + gitBranch )
67 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
68 utilities.assert_equals( expect=main.TRUE,
69 actual=stepResult,
70 onpass="Successfully checkout onos branch.",
71 onfail="Failed to checkout onos branch. Exiting test..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070072 if not stepResult:
73 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070074
75 main.step( "Git Pull on ONOS branch:" + gitBranch )
76 stepResult = main.ONOSbench.gitPull()
77 utilities.assert_equals( expect=main.TRUE,
78 actual=stepResult,
79 onpass="Successfully pull onos. ",
80 onfail="Failed to pull onos. Exiting test ..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070081 if not stepResult:
82 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070083
84 else:
85 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
86
Devin Lim0c972b72018-02-08 14:53:59 -080087 def envSetup( self, includeGitPull=True, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070088 """
89 Description:
90 some environment setup for the test.
91 Required:
92 * includeGitPull - if wish to git pulling function to be executed.
93 Returns:
94 Returns main.TRUE
95 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070096 if includeGitPull:
Devin Lim0c972b72018-02-08 14:53:59 -080097 self.gitPulling( includeCaseDesc )
Jon Hallca319892017-06-15 15:25:22 -070098
Devin Lim142b5342017-07-20 15:22:39 -070099 try:
100 from tests.dependencies.Cluster import Cluster
101 except ImportError:
102 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700103 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -0700104 try:
105 main.Cluster
106 except ( NameError, AttributeError ):
Jon Hall3c0114c2020-08-11 15:07:42 -0700107 main.Cluster = Cluster( main.ONOScell.nodes, useDocker=main.ONOScell.useDocker )
Devin Lim142b5342017-07-20 15:22:39 -0700108
Devin Lim58046fa2017-07-05 16:55:00 -0700109 main.cellData = {} # For creating cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700110
Jon Hallca319892017-06-15 15:25:22 -0700111 return main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700112
Jon Hall3c0114c2020-08-11 15:07:42 -0700113 def envSetupException( self, error ):
Devin Lim142b5342017-07-20 15:22:39 -0700114 """
115 Description:
116 handles the exception that might occur from the environment setup.
117 Required:
Jon Hall3c0114c2020-08-11 15:07:42 -0700118 * error - exception returned from except.
Devin Lim142b5342017-07-20 15:22:39 -0700119 """
Jon Hall3c0114c2020-08-11 15:07:42 -0700120 main.log.exception( error )
Devin Lim44075962017-08-11 10:56:37 -0700121 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700122
Jon Hallaa1d9b82020-07-30 13:49:42 -0700123 def envSetupConclusion( self, stepResult ):
Devin Lim142b5342017-07-20 15:22:39 -0700124 """
125 Description:
126 compare the result of the envSetup of the test.
127 Required:
128 * stepResult - Result of the envSetup.
129 """
Devin Lim58046fa2017-07-05 16:55:00 -0700130 utilities.assert_equals( expect=main.TRUE,
131 actual=stepResult,
132 onpass="Successfully construct " +
133 "test variables ",
134 onfail="Failed to construct test variables" )
135
Jon Hallf2527902020-07-30 12:56:08 -0700136 if main.params[ 'GRAPH' ].get('jobName'):
137 url = self.generateGraphURL( testname=main.params[ 'GRAPH' ][ 'jobName' ] )
138 else:
139 url = self.generateGraphURL()
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800140 main.log.wiki( url )
141
Devin Lim58046fa2017-07-05 16:55:00 -0700142 main.commit = main.ONOSbench.getVersion( report=True )
143
Jon Hallf2527902020-07-30 12:56:08 -0700144 def generateGraphURL( self, testname=main.TEST, width=525, height=350 ):
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800145 """
146 Description:
147 Obtain the URL for the graph that corresponds to the test being run.
148 """
149
150 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800151 branch = main.ONOSbench.getBranchName()
152 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
153
154 return '<ac:structured-macro ac:name="html">\n' + \
155 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800156 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800157 nodeCluster + \
158 '/lastSuccessfulBuild/artifact/' + \
159 testname + \
160 '_' + \
161 branch + \
162 '_' + \
163 maxBuildsToShow + \
164 '-builds_graph.jpg", alt="' + \
165 testname + \
166 '", style="width:' + \
167 str( width ) + \
168 'px;height:' + \
169 str( height ) + \
170 'px;border:0"' + \
171 '>' + \
172 ']]></ac:plain-text-body>\n' + \
173 '</ac:structured-macro>\n'
174
Devin Lim142b5342017-07-20 15:22:39 -0700175 def setNumCtrls( self, hasMultiNodeRounds ):
176 """
177 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700178 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700179 different number of nodes should be pre-defined in main.scale.
180 Required:
181 * hasMultiNodeRouds - if the test is testing different number of nodes.
182 """
Devin Lim58046fa2017-07-05 16:55:00 -0700183 if hasMultiNodeRounds:
184 try:
185 main.cycle
186 except Exception:
187 main.cycle = 0
188 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700189 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700190 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700191
You Wangf9d95be2018-08-01 14:35:37 -0700192 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
193 """
194 Description:
195 killing atomix. It will either kill the current runningnodes or
196 max number of the nodes.
197 Required:
198 * cluster - the cluster driver that will be used.
199 * killRemoveMax - The boolean that will decide either to kill
200 only running nodes ( False ) or max number of nodes ( True ).
201 * stopAtomix - If wish to stop atomix before killing it. True for
202 enable stop, False for disable stop.
203 Returns:
204 Returns main.TRUE if successfully killing it.
205 """
206 main.log.info( "Safety check, killing all Atomix processes" )
207 return cluster.killAtomix( killRemoveMax, stopAtomix )
208
Devin Lim142b5342017-07-20 15:22:39 -0700209 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
210 """
211 Description:
212 killing the onos. It will either kill the current runningnodes or
213 max number of the nodes.
214 Required:
215 * cluster - the cluster driver that will be used.
216 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700217 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700218 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700219 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700220 Returns:
221 Returns main.TRUE if successfully killing it.
222 """
223 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700224 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700225
Jon Hall3c0114c2020-08-11 15:07:42 -0700226 def killingAllOnosDocker( self, cluster, killRemoveMax ):
227 """
228 Description:
229 killing the onos docker images . It will either kill the
230 current runningnodes or max number of the nodes.
231 Required:
232 * cluster - the cluster driver that will be used.
233 * killRemoveMax - The boolean that will decide either to kill
234 only running nodes ( False ) or max number of nodes ( True ).
235 Returns:
236 Returns main.TRUE if successfully killing it.
237 """
238 main.log.info( "Safety check, stopping all ONOS docker containers" )
239 return cluster.dockerStop( killRemoveMax )
240
You Wang09b596b2018-01-10 10:42:38 -0800241 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700242 mininetIp, useSSH, onosIps, installMax=False,
243 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700244 """
245 Description:
246 create new cell ( optional ) and apply it. It will also verify the
247 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700248 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700249 * cluster - the cluster driver that will be used.
250 * newCell - True for making a new cell and False for not making it.
251 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800252 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800253 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700254 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700255 * onosIps - ip( s ) of the ONOS node( s ).
256 Optional Arguments:
257 * installMax
258 * atomixClusterSize - The size of the atomix cluster. Defaults to same
259 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700260 Returns:
261 Returns main.TRUE if it successfully executed.
262 """
Jon Hall3e6edb32018-08-21 16:20:30 -0700263 if atomixClusterSize is None:
264 atomixClusterSize = len( cluster.runningNodes )
Jon Hall3c0114c2020-08-11 15:07:42 -0700265 if atomixClusterSize is 1:
266 atomixClusterSize = len( cluster.controllers )
Jon Hall3e6edb32018-08-21 16:20:30 -0700267 atomixClusterSize = int( atomixClusterSize )
268 cluster.setAtomixNodes( atomixClusterSize )
269 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
270 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700271 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700272 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
273 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700274 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700275 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700276 utilities.assert_equals( expect=main.TRUE,
277 actual=stepResult,
278 onpass="Successfully applied cell to " +
279 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700280 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700281 return stepResult
282
You Wangf9d95be2018-08-01 14:35:37 -0700283 def uninstallAtomix( self, cluster, uninstallMax ):
284 """
285 Description:
286 uninstalling atomix and verify the result.
287 Required:
288 * cluster - a cluster driver that will be used.
289 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700290 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700291 Returns:
292 Returns main.TRUE if it successfully uninstalled.
293 """
294 main.step( "Uninstalling Atomix" )
295 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
296 utilities.assert_equals( expect=main.TRUE,
297 actual=atomixUninstallResult,
298 onpass="Successfully uninstalled Atomix",
299 onfail="Failed to uninstall Atomix" )
300 return atomixUninstallResult
301
Devin Lim142b5342017-07-20 15:22:39 -0700302 def uninstallOnos( self, cluster, uninstallMax ):
303 """
304 Description:
305 uninstalling onos and verify the result.
306 Required:
307 * cluster - a cluster driver that will be used.
308 * uninstallMax - True for uninstalling max number of nodes
309 False for uninstalling the current running nodes.
310 Returns:
311 Returns main.TRUE if it successfully uninstalled.
312 """
Devin Lim58046fa2017-07-05 16:55:00 -0700313 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700314 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700315 utilities.assert_equals( expect=main.TRUE,
316 actual=onosUninstallResult,
317 onpass="Successfully uninstalled ONOS package",
318 onfail="Failed to uninstall ONOS package" )
319 return onosUninstallResult
320
Devin Lim142b5342017-07-20 15:22:39 -0700321 def buildOnos( self, cluster ):
322 """
323 Description:
You Wangd54c7052018-08-07 16:06:27 -0700324 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700325 Required:
326 * cluster - the cluster driver that will be used.
327 Returns:
328 Returns main.TRUE if it successfully built.
329 """
Devin Lim58046fa2017-07-05 16:55:00 -0700330 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700331 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700332 utilities.assert_equals( expect=main.TRUE,
333 actual=packageResult,
334 onpass="Successfully created ONOS package",
335 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800336 if not packageResult:
337 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700338 return packageResult
339
Jon Hall3c0114c2020-08-11 15:07:42 -0700340 def buildDocker( self, cluster ):
341 """
342 Description:
343 Build the latest docker
344 Required:
345 * cluster - the cluster driver that will be used.
346 Returns:
347 Returns main.TRUE if it successfully built.
348 """
349 main.step( "Building ONOS Docker image" )
350 buildResult = cluster.dockerBuild()
351 utilities.assert_equals( expect=main.TRUE,
352 actual=buildResult,
353 onpass="Successfully created ONOS docker",
354 onfail="Failed to create ONOS docker" )
355 if not buildResult:
356 main.cleanAndExit()
357 return buildResult
358
Jon Hall3e6edb32018-08-21 16:20:30 -0700359 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700360 """
361 Description:
362 Installing atomix and verify the result
363 Required:
364 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700365 False for installing current running nodes only.
366 Returns:
367 Returns main.TRUE if it successfully installed
368 """
369 main.step( "Installing Atomix" )
370 atomixInstallResult = main.TRUE
371
Jon Hallb685a1c2018-10-30 15:17:01 -0700372 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700373 utilities.assert_equals( expect=main.TRUE,
374 actual=atomixInstallResult,
375 onpass="Successfully installed Atomix",
376 onfail="Failed to install Atomix" )
377 if not atomixInstallResult:
378 main.cleanAndExit()
379 return atomixInstallResult
380
Devin Lime9f0ccf2017-08-11 17:25:12 -0700381 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700382 """
383 Description:
384 Installing onos and verify the result
385 Required:
386 * cluster - the cluster driver that will be used.
387 * installMax - True for installing max number of nodes
388 False for installing current running nodes only.
389 Returns:
390 Returns main.TRUE if it successfully installed
391 """
Devin Lim58046fa2017-07-05 16:55:00 -0700392 main.step( "Installing ONOS package" )
393 onosInstallResult = main.TRUE
394
You Wangf9d95be2018-08-01 14:35:37 -0700395 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700396 utilities.assert_equals( expect=main.TRUE,
397 actual=onosInstallResult,
398 onpass="Successfully installed ONOS package",
399 onfail="Failed to install ONOS package" )
400 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700401 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700402 return onosInstallResult
403
Jon Hall3c0114c2020-08-11 15:07:42 -0700404 def startDocker( self, cluster, installMax, parallel=True ):
405 """
406 Description:
407 Start onos docker containers and verify the result
408 Required:
409 * cluster - the cluster driver that will be used.
410 * installMax - True for installing max number of nodes
411 False for installing current running nodes only.
412 Returns:
413 Returns main.TRUE if it successfully installed
414 """
415 main.step( "Create Cluster Config" )
416 configResult = cluster.genPartitions()
417 utilities.assert_equals( expect=main.TRUE,
418 actual=configResult,
419 onpass="Successfully create cluster config",
420 onfail="Failed to create cluster config" )
421
422 # install atomix docker containers
423 main.step( "Installing Atomix via docker containers" )
424 atomixInstallResult = cluster.startAtomixDocker( parallel )
425 utilities.assert_equals( expect=main.TRUE,
426 actual=atomixInstallResult,
427 onpass="Successfully start atomix containers",
428 onfail="Failed to start atomix containers" )
429
430 main.step( "Installing ONOS via docker containers" )
431 onosInstallResult = cluster.startONOSDocker( installMax, parallel )
432 utilities.assert_equals( expect=main.TRUE,
433 actual=onosInstallResult,
434 onpass="Successfully start ONOS containers",
435 onfail="Failed to start ONOS containers" )
436 if not onosInstallResult and atomixInstallResult:
437 main.cleanAndExit()
438 return onosInstallResult and atomixInstallResult
439
Devin Lim142b5342017-07-20 15:22:39 -0700440 def setupSsh( self, cluster ):
441 """
442 Description:
443 set up ssh to the onos and verify the result
444 Required:
445 * cluster - the cluster driver that will be used.
446 Returns:
447 Returns main.TRUE if it successfully setup the ssh to
448 the onos.
449 """
Devin Lim58046fa2017-07-05 16:55:00 -0700450 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700451 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700452 utilities.assert_equals( expect=main.TRUE,
453 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700454 onpass="Secured ONOS ssh",
455 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700456 return secureSshResult
457
Devin Lim142b5342017-07-20 15:22:39 -0700458 def checkOnosService( self, cluster ):
459 """
460 Description:
461 Checking if the onos service is up and verify the result
462 Required:
463 * cluster - the cluster driver that will be used.
464 Returns:
465 Returns main.TRUE if it successfully checked
466 """
467 main.step( "Checking ONOS service" )
468 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700469 utilities.assert_equals( expect=main.TRUE,
470 actual=stepResult,
471 onpass="ONOS service is ready on all nodes",
472 onfail="ONOS service did not start properly on all nodes" )
473 return stepResult
474
Jon Hallca319892017-06-15 15:25:22 -0700475 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700476 """
477 Description:
478 starting Onos using onosCli driver and verify the result
479 Required:
480 * cluster - the cluster driver that will be used.
481 Returns:
482 Returns main.TRUE if it successfully started. It will exit
483 the test if not started properly.
484 """
Devin Lim58046fa2017-07-05 16:55:00 -0700485 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700486 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700487 if not startCliResult:
488 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700489 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700490 else:
491 main.log.info( "Successful CLI startup" )
492 utilities.assert_equals( expect=main.TRUE,
493 actual=startCliResult,
494 onpass="Successfully start ONOS cli",
495 onfail="Failed to start ONOS cli" )
496 return startCliResult
497
You Wang0d9f2c02018-08-10 14:56:32 -0700498 def checkOnosNodes( self, cluster ):
499 """
500 Description:
501 Checking if the onos nodes are in READY state
502 Required:
503 * cluster - the cluster driver that will be used.
504 Returns:
505 Returns main.TRUE if it successfully checked
506 """
507 main.step( "Checking ONOS nodes" )
508 stepResult = utilities.retry( main.Cluster.nodesCheck,
509 False,
You Wang07831cb2018-09-04 12:18:04 -0700510 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700511
512 utilities.assert_equals( expect=True,
513 actual=stepResult,
514 onpass="All ONOS nodes are in READY state",
515 onfail="Not all ONOS nodes are in READY state" )
516
517 if not stepResult:
518 for ctrl in main.Cluster.active():
519 main.log.debug( "{} components not ACTIVE: \n{}".format(
520 ctrl.name,
Jon Hallf29368d2020-07-31 12:23:56 -0700521 # FIXME: This output has changed a lot
522 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) )
You Wang0d9f2c02018-08-10 14:56:32 -0700523 main.log.error( "Failed to start ONOS, stopping test" )
You Wang7880b372019-02-27 16:50:47 -0800524 main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
You Wangba973f02018-08-30 12:33:41 -0700525 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700526
527 def checkOnosApps( self, cluster, apps ):
528 """
529 Description:
530 Checking if the onos applications are activated
531 Required:
532 * cluster - the cluster driver that will be used.
533 * apps: list of applications that are expected to be activated
534 Returns:
535 Returns main.TRUE if it successfully checked
536 """
537 main.step( "Checking ONOS applications" )
538 stepResult = utilities.retry( main.Cluster.appsCheck,
539 False,
540 args = [ apps ],
541 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700542 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700543
544 utilities.assert_equals( expect=True,
545 actual=stepResult,
546 onpass="All ONOS apps are activated",
547 onfail="Not all ONOS apps are activated" )
548
549 return main.TRUE if stepResult else main.FALSE
550
Jon Hall4f360bc2017-09-07 10:19:52 -0700551 def processList( self, functions, args ):
552 if functions is not None:
553 if isinstance( functions, list ):
554 i = 0
555 for f in functions:
556 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
557 i += 1
558 else:
559 functions( *args ) if args is not None else functions()
560
You Wangb1665b52019-02-01 15:49:48 -0800561 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700562 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700563 mininetIp="", extraApply=None, applyArgs=None,
564 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
565 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
566 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700567 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700568 """
569 Description:
570 Initial ONOS setting up of the tests. It will also verify the result of each steps.
571 The procedures will be:
572 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700573 creating ( optional ) /applying cell
574 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700575 uninstalling onos
576 extra procedure to be applied( optional )
577 building onos
578 installing onos
579 extra cleanup to be applied ( optional )
580 setting up ssh to the onos
581 checking the onos service
582 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700583 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700584 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700585 Optional Arguments:
586 * hasMultiNodeRounds - True if the test is testing different set of nodes
You Wangb1665b52019-02-01 15:49:48 -0800587 * startOnosCli - True if wish to start onos CLI.
Devin Lim142b5342017-07-20 15:22:39 -0700588 * newCell - True for making a new cell and False for not making it.
589 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700590 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700591 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800592 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700593 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
594 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
595 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
596 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700597 * skipPack - True if wish to skip some packing.
598 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700599 False if wish to install onos of running nodes only
600 * atomixClusterSize - The number of Atomix nodes in the cluster.
601 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700602 * useSSH - True for using ssh when creating a cell
603 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700604 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700605 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700606 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700607 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700608 Returns:
609 Returns main.TRUE if it everything successfully proceeded.
610 """
611 self.setNumCtrls( hasMultiNodeRounds )
Jon Hall627b1572020-12-01 12:01:15 -0800612 if not main.persistentSetup:
613 if includeCaseDesc:
614 main.case( "Starting up " + str( cluster.numCtrls ) +
615 " node(s) ONOS cluster" )
616 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
617 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700618
Jon Hall3e6edb32018-08-21 16:20:30 -0700619 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700620 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800621 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700622 try:
623 apps = main.apps
624 except ( NameError, AttributeError ):
625 apps = cellApps
626 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700627 tempOnosIp = []
628 for ctrl in cluster.runningNodes:
629 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800630 if mininetIp == "":
631 mininetIp = "localhost"
632 for key, value in main.componentDictionary.items():
633 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
634 mininetIp = getattr( main, key ).ip_address
635 break
Devin Lim142b5342017-07-20 15:22:39 -0700636 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700637 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800638 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700639 tempOnosIp, installMax,
640 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700641
Jon Hall627b1572020-12-01 12:01:15 -0800642 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700643 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
644 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Jon Hall3c0114c2020-08-11 15:07:42 -0700645 dockerKillResult = self.killingAllOnosDocker( cluster, killRemoveMax )
You Wangdbb95d62018-09-05 15:58:08 -0700646 killResult = atomixKillResult and onosKillResult
647 else:
648 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700649
Jon Hall627b1572020-12-01 12:01:15 -0800650 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700651 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
652 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
653 uninstallResult = atomixUninstallResult and onosUninstallResult
654 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800655
You Wangdbb95d62018-09-05 15:58:08 -0700656 packageResult = main.TRUE
657 if not skipPack:
Jon Hall3c0114c2020-08-11 15:07:42 -0700658 if cluster.useDocker:
659 packageResult = self.buildDocker( cluster )
660 else:
661 packageResult = self.buildOnos( cluster )
Devin Lim142b5342017-07-20 15:22:39 -0700662
Jon Hall3c0114c2020-08-11 15:07:42 -0700663 if cluster.useDocker:
664 installResult = self.startDocker( cluster, installMax, installParallel )
665 else:
666 atomixInstallResult = self.installAtomix( cluster, installParallel )
667 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
668 installResult = atomixInstallResult and onosInstallResult
669
670 preCLIResult = main.TRUE
671 if cluster.useDocker:
672 attachResult = cluster.attachToONOSDocker()
673 prepareResult = cluster.prepareForCLI()
674
675 preCLIResult = preCLIResult and attachResult and prepareResult
Devin Lim58046fa2017-07-05 16:55:00 -0700676
You Wangdbb95d62018-09-05 15:58:08 -0700677 self.processList( extraClean, cleanArgs )
678 secureSshResult = self.setupSsh( cluster )
679 else:
680 packageResult = main.TRUE
681 uninstallResult = main.TRUE
682 installResult = main.TRUE
683 secureSshResult = main.TRUE
Jon Hall3c0114c2020-08-11 15:07:42 -0700684 preCLIResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700685
Jon Hall3c0114c2020-08-11 15:07:42 -0700686 onosServiceResult = main.TRUE
687 if not cluster.useDocker:
688 onosServiceResult = self.checkOnosService( cluster )
Jon Hall627b1572020-12-01 12:01:15 -0800689 elif main.persistentSetup:
690 for ctrl in cluster.getRunningNodes():
691 ctrl.inDocker = True
Devin Lim58046fa2017-07-05 16:55:00 -0700692
You Wang4cc61912018-08-28 10:10:58 -0700693 onosCliResult = main.TRUE
You Wangb1665b52019-02-01 15:49:48 -0800694 if startOnosCli:
Jon Hallca319892017-06-15 15:25:22 -0700695 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700696
You Wang0d9f2c02018-08-10 14:56:32 -0700697 onosNodesResult = self.checkOnosNodes( cluster )
698
Jon Hall39570262020-11-17 12:18:19 -0800699 externalAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800700 if not main.persistentSetup and main.params.get( 'EXTERNAL_APPS' ):
Jon Hall39570262020-11-17 12:18:19 -0800701 node = main.Cluster.controllers[0]
702 for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems():
703 path, fileName = os.path.split( url )
704 main.ONOSbench.onosApp( node.ipAddress, "reinstall!", fileName, appName=app, user=node.karafUser, password=node.karafPass )
705
706
You Wang0d9f2c02018-08-10 14:56:32 -0700707 onosAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800708 if not main.persistentSetup and cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700709 if apps:
Jon Hall39570262020-11-17 12:18:19 -0800710 newApps = []
711 appNames = apps.split( ',' )
Jon Hall3c0114c2020-08-11 15:07:42 -0700712 if cluster.useDocker:
713 node = main.Cluster.active( 0 )
Jon Hall39570262020-11-17 12:18:19 -0800714 for app in appNames:
715 appName = app if "org." in app else appPrefix + app
716 node.activateApp( appName )
717 newApps.append( appName )
Jon Hall3c0114c2020-08-11 15:07:42 -0700718
Jon Hall39570262020-11-17 12:18:19 -0800719 onosAppsResult = self.checkOnosApps( cluster, newApps )
You Wang0d9f2c02018-08-10 14:56:32 -0700720 else:
721 main.log.warn( "No apps were specified to be checked after startup" )
722
You Wangf9d95be2018-08-01 14:35:37 -0700723 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700724 installResult and secureSshResult and onosServiceResult and onosCliResult and \
Jon Hall3c0114c2020-08-11 15:07:42 -0700725 onosNodesResult and onosAppsResult and preCLIResult