blob: 20a549422eb48f71e1b56505fbddd3bf80f23012 [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" )
Jon Hall7633c382020-12-15 17:30:42 -0800135 branch = main.params[ 'GRAPH' ].get('branch')
Devin Lim58046fa2017-07-05 16:55:00 -0700136
Jon Hallf2527902020-07-30 12:56:08 -0700137 if main.params[ 'GRAPH' ].get('jobName'):
Jon Hall7633c382020-12-15 17:30:42 -0800138 url = self.generateGraphURL( testname=main.params[ 'GRAPH' ][ 'jobName' ], branch=branch )
Jon Hallf2527902020-07-30 12:56:08 -0700139 else:
Jon Hall7633c382020-12-15 17:30:42 -0800140 url = self.generateGraphURL( branch=branch )
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800141 main.log.wiki( url )
142
Jon Hallc5b4c1c2020-12-15 16:50:54 -0800143 if not main.persistentSetup:
144 # ONOS is not deployed by the test
145 # TODO: Try to get commit another way, maybe container labels?
146 # Or try to link to deployment job?
147 main.commit = main.ONOSbench.getVersion( report=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700148
Jon Hall7633c382020-12-15 17:30:42 -0800149 def generateGraphURL( self, testname=main.TEST, width=525, height=350, branch=None ):
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800150 """
151 Description:
152 Obtain the URL for the graph that corresponds to the test being run.
153 """
154
155 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
Jon Hall7633c382020-12-15 17:30:42 -0800156 if not branch:
157 branch = main.ONOSbench.getBranchName()
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800158 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
159
160 return '<ac:structured-macro ac:name="html">\n' + \
161 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800162 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800163 nodeCluster + \
164 '/lastSuccessfulBuild/artifact/' + \
165 testname + \
166 '_' + \
167 branch + \
168 '_' + \
169 maxBuildsToShow + \
170 '-builds_graph.jpg", alt="' + \
171 testname + \
172 '", style="width:' + \
173 str( width ) + \
174 'px;height:' + \
175 str( height ) + \
176 'px;border:0"' + \
177 '>' + \
178 ']]></ac:plain-text-body>\n' + \
179 '</ac:structured-macro>\n'
180
Devin Lim142b5342017-07-20 15:22:39 -0700181 def setNumCtrls( self, hasMultiNodeRounds ):
182 """
183 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700184 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700185 different number of nodes should be pre-defined in main.scale.
186 Required:
187 * hasMultiNodeRouds - if the test is testing different number of nodes.
188 """
Devin Lim58046fa2017-07-05 16:55:00 -0700189 if hasMultiNodeRounds:
190 try:
191 main.cycle
192 except Exception:
193 main.cycle = 0
194 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700195 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700196 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700197
You Wangf9d95be2018-08-01 14:35:37 -0700198 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
199 """
200 Description:
201 killing atomix. It will either kill the current runningnodes or
202 max number of the nodes.
203 Required:
204 * cluster - the cluster driver that will be used.
205 * killRemoveMax - The boolean that will decide either to kill
206 only running nodes ( False ) or max number of nodes ( True ).
207 * stopAtomix - If wish to stop atomix before killing it. True for
208 enable stop, False for disable stop.
209 Returns:
210 Returns main.TRUE if successfully killing it.
211 """
212 main.log.info( "Safety check, killing all Atomix processes" )
213 return cluster.killAtomix( killRemoveMax, stopAtomix )
214
Devin Lim142b5342017-07-20 15:22:39 -0700215 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
216 """
217 Description:
218 killing the onos. It will either kill the current runningnodes or
219 max number of the nodes.
220 Required:
221 * cluster - the cluster driver that will be used.
222 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700223 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700224 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700225 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700226 Returns:
227 Returns main.TRUE if successfully killing it.
228 """
229 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700230 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700231
Jon Hall3c0114c2020-08-11 15:07:42 -0700232 def killingAllOnosDocker( self, cluster, killRemoveMax ):
233 """
234 Description:
235 killing the onos docker images . It will either kill the
236 current runningnodes or max number of the nodes.
237 Required:
238 * cluster - the cluster driver that will be used.
239 * killRemoveMax - The boolean that will decide either to kill
240 only running nodes ( False ) or max number of nodes ( True ).
241 Returns:
242 Returns main.TRUE if successfully killing it.
243 """
244 main.log.info( "Safety check, stopping all ONOS docker containers" )
245 return cluster.dockerStop( killRemoveMax )
246
You Wang09b596b2018-01-10 10:42:38 -0800247 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700248 mininetIp, useSSH, onosIps, installMax=False,
249 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700250 """
251 Description:
252 create new cell ( optional ) and apply it. It will also verify the
253 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700254 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700255 * cluster - the cluster driver that will be used.
256 * newCell - True for making a new cell and False for not making it.
257 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800258 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800259 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700260 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700261 * onosIps - ip( s ) of the ONOS node( s ).
262 Optional Arguments:
263 * installMax
264 * atomixClusterSize - The size of the atomix cluster. Defaults to same
265 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700266 Returns:
267 Returns main.TRUE if it successfully executed.
268 """
Jon Hall579d21e2021-04-14 12:27:38 -0700269 stepResult = main.TRUE
Jon Hall3e6edb32018-08-21 16:20:30 -0700270 if atomixClusterSize is None:
271 atomixClusterSize = len( cluster.runningNodes )
Jon Hall3c0114c2020-08-11 15:07:42 -0700272 if atomixClusterSize is 1:
273 atomixClusterSize = len( cluster.controllers )
Jon Hall3e6edb32018-08-21 16:20:30 -0700274 atomixClusterSize = int( atomixClusterSize )
275 cluster.setAtomixNodes( atomixClusterSize )
276 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
277 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Jon Hall579d21e2021-04-14 12:27:38 -0700278 if not main.persistentSetup:
279 if newCell:
280 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
281 atomixIps, installMax )
282 main.step( "Apply cell to environment" )
283 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700284 utilities.assert_equals( expect=main.TRUE,
285 actual=stepResult,
286 onpass="Successfully applied cell to " +
287 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700288 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700289 return stepResult
290
You Wangf9d95be2018-08-01 14:35:37 -0700291 def uninstallAtomix( self, cluster, uninstallMax ):
292 """
293 Description:
294 uninstalling atomix and verify the result.
295 Required:
296 * cluster - a cluster driver that will be used.
297 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700298 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700299 Returns:
300 Returns main.TRUE if it successfully uninstalled.
301 """
302 main.step( "Uninstalling Atomix" )
303 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
304 utilities.assert_equals( expect=main.TRUE,
305 actual=atomixUninstallResult,
306 onpass="Successfully uninstalled Atomix",
307 onfail="Failed to uninstall Atomix" )
308 return atomixUninstallResult
309
Devin Lim142b5342017-07-20 15:22:39 -0700310 def uninstallOnos( self, cluster, uninstallMax ):
311 """
312 Description:
313 uninstalling onos and verify the result.
314 Required:
315 * cluster - a cluster driver that will be used.
316 * uninstallMax - True for uninstalling max number of nodes
317 False for uninstalling the current running nodes.
318 Returns:
319 Returns main.TRUE if it successfully uninstalled.
320 """
Devin Lim58046fa2017-07-05 16:55:00 -0700321 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700322 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700323 utilities.assert_equals( expect=main.TRUE,
324 actual=onosUninstallResult,
325 onpass="Successfully uninstalled ONOS package",
326 onfail="Failed to uninstall ONOS package" )
327 return onosUninstallResult
328
Devin Lim142b5342017-07-20 15:22:39 -0700329 def buildOnos( self, cluster ):
330 """
331 Description:
You Wangd54c7052018-08-07 16:06:27 -0700332 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700333 Required:
334 * cluster - the cluster driver that will be used.
335 Returns:
336 Returns main.TRUE if it successfully built.
337 """
Devin Lim58046fa2017-07-05 16:55:00 -0700338 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700339 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700340 utilities.assert_equals( expect=main.TRUE,
341 actual=packageResult,
342 onpass="Successfully created ONOS package",
343 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800344 if not packageResult:
345 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700346 return packageResult
347
Jon Hall3c0114c2020-08-11 15:07:42 -0700348 def buildDocker( self, cluster ):
349 """
350 Description:
351 Build the latest docker
352 Required:
353 * cluster - the cluster driver that will be used.
354 Returns:
355 Returns main.TRUE if it successfully built.
356 """
357 main.step( "Building ONOS Docker image" )
358 buildResult = cluster.dockerBuild()
359 utilities.assert_equals( expect=main.TRUE,
360 actual=buildResult,
361 onpass="Successfully created ONOS docker",
362 onfail="Failed to create ONOS docker" )
363 if not buildResult:
364 main.cleanAndExit()
365 return buildResult
366
Jon Hall3e6edb32018-08-21 16:20:30 -0700367 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700368 """
369 Description:
370 Installing atomix and verify the result
371 Required:
372 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700373 False for installing current running nodes only.
374 Returns:
375 Returns main.TRUE if it successfully installed
376 """
377 main.step( "Installing Atomix" )
378 atomixInstallResult = main.TRUE
379
Jon Hallb685a1c2018-10-30 15:17:01 -0700380 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700381 utilities.assert_equals( expect=main.TRUE,
382 actual=atomixInstallResult,
383 onpass="Successfully installed Atomix",
384 onfail="Failed to install Atomix" )
385 if not atomixInstallResult:
386 main.cleanAndExit()
387 return atomixInstallResult
388
Devin Lime9f0ccf2017-08-11 17:25:12 -0700389 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700390 """
391 Description:
392 Installing onos and verify the result
393 Required:
394 * cluster - the cluster driver that will be used.
395 * installMax - True for installing max number of nodes
396 False for installing current running nodes only.
397 Returns:
398 Returns main.TRUE if it successfully installed
399 """
Devin Lim58046fa2017-07-05 16:55:00 -0700400 main.step( "Installing ONOS package" )
401 onosInstallResult = main.TRUE
402
You Wangf9d95be2018-08-01 14:35:37 -0700403 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700404 utilities.assert_equals( expect=main.TRUE,
405 actual=onosInstallResult,
406 onpass="Successfully installed ONOS package",
407 onfail="Failed to install ONOS package" )
408 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700409 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700410 return onosInstallResult
411
Jon Hall3c0114c2020-08-11 15:07:42 -0700412 def startDocker( self, cluster, installMax, parallel=True ):
413 """
414 Description:
415 Start onos docker containers and verify the result
416 Required:
417 * cluster - the cluster driver that will be used.
418 * installMax - True for installing max number of nodes
419 False for installing current running nodes only.
420 Returns:
421 Returns main.TRUE if it successfully installed
422 """
423 main.step( "Create Cluster Config" )
424 configResult = cluster.genPartitions()
425 utilities.assert_equals( expect=main.TRUE,
426 actual=configResult,
427 onpass="Successfully create cluster config",
428 onfail="Failed to create cluster config" )
429
430 # install atomix docker containers
431 main.step( "Installing Atomix via docker containers" )
432 atomixInstallResult = cluster.startAtomixDocker( parallel )
433 utilities.assert_equals( expect=main.TRUE,
434 actual=atomixInstallResult,
435 onpass="Successfully start atomix containers",
436 onfail="Failed to start atomix containers" )
437
438 main.step( "Installing ONOS via docker containers" )
439 onosInstallResult = cluster.startONOSDocker( installMax, parallel )
440 utilities.assert_equals( expect=main.TRUE,
441 actual=onosInstallResult,
442 onpass="Successfully start ONOS containers",
443 onfail="Failed to start ONOS containers" )
444 if not onosInstallResult and atomixInstallResult:
445 main.cleanAndExit()
446 return onosInstallResult and atomixInstallResult
447
Devin Lim142b5342017-07-20 15:22:39 -0700448 def setupSsh( self, cluster ):
449 """
450 Description:
451 set up ssh to the onos and verify the result
452 Required:
453 * cluster - the cluster driver that will be used.
454 Returns:
455 Returns main.TRUE if it successfully setup the ssh to
456 the onos.
457 """
Devin Lim58046fa2017-07-05 16:55:00 -0700458 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700459 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700460 utilities.assert_equals( expect=main.TRUE,
461 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700462 onpass="Secured ONOS ssh",
463 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700464 return secureSshResult
465
Devin Lim142b5342017-07-20 15:22:39 -0700466 def checkOnosService( self, cluster ):
467 """
468 Description:
469 Checking if the onos service is up and verify the result
470 Required:
471 * cluster - the cluster driver that will be used.
472 Returns:
473 Returns main.TRUE if it successfully checked
474 """
475 main.step( "Checking ONOS service" )
476 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700477 utilities.assert_equals( expect=main.TRUE,
478 actual=stepResult,
479 onpass="ONOS service is ready on all nodes",
480 onfail="ONOS service did not start properly on all nodes" )
481 return stepResult
482
Jon Hallca319892017-06-15 15:25:22 -0700483 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700484 """
485 Description:
486 starting Onos using onosCli driver and verify the result
487 Required:
488 * cluster - the cluster driver that will be used.
489 Returns:
490 Returns main.TRUE if it successfully started. It will exit
491 the test if not started properly.
492 """
Devin Lim58046fa2017-07-05 16:55:00 -0700493 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700494 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700495 if not startCliResult:
496 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700497 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700498 else:
499 main.log.info( "Successful CLI startup" )
500 utilities.assert_equals( expect=main.TRUE,
501 actual=startCliResult,
502 onpass="Successfully start ONOS cli",
503 onfail="Failed to start ONOS cli" )
504 return startCliResult
505
You Wang0d9f2c02018-08-10 14:56:32 -0700506 def checkOnosNodes( self, cluster ):
507 """
508 Description:
509 Checking if the onos nodes are in READY state
510 Required:
511 * cluster - the cluster driver that will be used.
512 Returns:
513 Returns main.TRUE if it successfully checked
514 """
515 main.step( "Checking ONOS nodes" )
516 stepResult = utilities.retry( main.Cluster.nodesCheck,
517 False,
You Wang07831cb2018-09-04 12:18:04 -0700518 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700519
520 utilities.assert_equals( expect=True,
521 actual=stepResult,
522 onpass="All ONOS nodes are in READY state",
523 onfail="Not all ONOS nodes are in READY state" )
524
525 if not stepResult:
526 for ctrl in main.Cluster.active():
527 main.log.debug( "{} components not ACTIVE: \n{}".format(
528 ctrl.name,
Jon Hallf29368d2020-07-31 12:23:56 -0700529 # FIXME: This output has changed a lot
530 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) )
You Wang0d9f2c02018-08-10 14:56:32 -0700531 main.log.error( "Failed to start ONOS, stopping test" )
You Wang7880b372019-02-27 16:50:47 -0800532 main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
You Wangba973f02018-08-30 12:33:41 -0700533 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700534
535 def checkOnosApps( self, cluster, apps ):
536 """
537 Description:
538 Checking if the onos applications are activated
539 Required:
540 * cluster - the cluster driver that will be used.
541 * apps: list of applications that are expected to be activated
542 Returns:
543 Returns main.TRUE if it successfully checked
544 """
545 main.step( "Checking ONOS applications" )
546 stepResult = utilities.retry( main.Cluster.appsCheck,
547 False,
548 args = [ apps ],
549 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700550 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700551
552 utilities.assert_equals( expect=True,
553 actual=stepResult,
554 onpass="All ONOS apps are activated",
555 onfail="Not all ONOS apps are activated" )
556
557 return main.TRUE if stepResult else main.FALSE
558
Jon Hall4f360bc2017-09-07 10:19:52 -0700559 def processList( self, functions, args ):
560 if functions is not None:
561 if isinstance( functions, list ):
562 i = 0
563 for f in functions:
564 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
565 i += 1
566 else:
567 functions( *args ) if args is not None else functions()
568
You Wangb1665b52019-02-01 15:49:48 -0800569 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700570 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700571 mininetIp="", extraApply=None, applyArgs=None,
572 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
573 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
574 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700575 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700576 """
577 Description:
578 Initial ONOS setting up of the tests. It will also verify the result of each steps.
579 The procedures will be:
580 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700581 creating ( optional ) /applying cell
582 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700583 uninstalling onos
584 extra procedure to be applied( optional )
585 building onos
586 installing onos
587 extra cleanup to be applied ( optional )
588 setting up ssh to the onos
589 checking the onos service
590 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700591 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700592 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700593 Optional Arguments:
594 * hasMultiNodeRounds - True if the test is testing different set of nodes
You Wangb1665b52019-02-01 15:49:48 -0800595 * startOnosCli - True if wish to start onos CLI.
Devin Lim142b5342017-07-20 15:22:39 -0700596 * newCell - True for making a new cell and False for not making it.
597 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700598 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700599 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800600 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700601 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
602 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
603 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
604 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700605 * skipPack - True if wish to skip some packing.
606 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700607 False if wish to install onos of running nodes only
608 * atomixClusterSize - The number of Atomix nodes in the cluster.
609 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700610 * useSSH - True for using ssh when creating a cell
611 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700612 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700613 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700614 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700615 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700616 Returns:
617 Returns main.TRUE if it everything successfully proceeded.
618 """
619 self.setNumCtrls( hasMultiNodeRounds )
Jon Hall627b1572020-12-01 12:01:15 -0800620 if not main.persistentSetup:
621 if includeCaseDesc:
622 main.case( "Starting up " + str( cluster.numCtrls ) +
623 " node(s) ONOS cluster" )
624 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
625 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700626
Jon Hall3e6edb32018-08-21 16:20:30 -0700627 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700628 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800629 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700630 try:
631 apps = main.apps
632 except ( NameError, AttributeError ):
633 apps = cellApps
634 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700635 tempOnosIp = []
636 for ctrl in cluster.runningNodes:
637 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800638 if mininetIp == "":
639 mininetIp = "localhost"
640 for key, value in main.componentDictionary.items():
641 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
642 mininetIp = getattr( main, key ).ip_address
643 break
Devin Lim142b5342017-07-20 15:22:39 -0700644 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700645 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800646 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700647 tempOnosIp, installMax,
648 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700649
Jon Hall627b1572020-12-01 12:01:15 -0800650 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700651 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
652 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Jon Hall3c0114c2020-08-11 15:07:42 -0700653 dockerKillResult = self.killingAllOnosDocker( cluster, killRemoveMax )
You Wangdbb95d62018-09-05 15:58:08 -0700654 killResult = atomixKillResult and onosKillResult
655 else:
656 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700657
Jon Hall627b1572020-12-01 12:01:15 -0800658 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700659 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
660 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
661 uninstallResult = atomixUninstallResult and onosUninstallResult
662 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800663
You Wangdbb95d62018-09-05 15:58:08 -0700664 packageResult = main.TRUE
665 if not skipPack:
Jon Hall3c0114c2020-08-11 15:07:42 -0700666 if cluster.useDocker:
667 packageResult = self.buildDocker( cluster )
668 else:
669 packageResult = self.buildOnos( cluster )
Devin Lim142b5342017-07-20 15:22:39 -0700670
Jon Hall3c0114c2020-08-11 15:07:42 -0700671 if cluster.useDocker:
672 installResult = self.startDocker( cluster, installMax, installParallel )
673 else:
674 atomixInstallResult = self.installAtomix( cluster, installParallel )
675 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
676 installResult = atomixInstallResult and onosInstallResult
677
678 preCLIResult = main.TRUE
679 if cluster.useDocker:
680 attachResult = cluster.attachToONOSDocker()
681 prepareResult = cluster.prepareForCLI()
682
683 preCLIResult = preCLIResult and attachResult and prepareResult
Devin Lim58046fa2017-07-05 16:55:00 -0700684
You Wangdbb95d62018-09-05 15:58:08 -0700685 self.processList( extraClean, cleanArgs )
686 secureSshResult = self.setupSsh( cluster )
687 else:
688 packageResult = main.TRUE
689 uninstallResult = main.TRUE
690 installResult = main.TRUE
691 secureSshResult = main.TRUE
Jon Hall3c0114c2020-08-11 15:07:42 -0700692 preCLIResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700693
Jon Hall3c0114c2020-08-11 15:07:42 -0700694 onosServiceResult = main.TRUE
695 if not cluster.useDocker:
696 onosServiceResult = self.checkOnosService( cluster )
Jon Hall627b1572020-12-01 12:01:15 -0800697 elif main.persistentSetup:
698 for ctrl in cluster.getRunningNodes():
699 ctrl.inDocker = True
Jon Hall06fd0df2021-01-25 15:50:06 -0800700 ctrl.CLI.inDocker = True
Devin Lim58046fa2017-07-05 16:55:00 -0700701
You Wang4cc61912018-08-28 10:10:58 -0700702 onosCliResult = main.TRUE
You Wangb1665b52019-02-01 15:49:48 -0800703 if startOnosCli:
Jon Hallca319892017-06-15 15:25:22 -0700704 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700705
You Wang0d9f2c02018-08-10 14:56:32 -0700706 onosNodesResult = self.checkOnosNodes( cluster )
707
Jon Hall39570262020-11-17 12:18:19 -0800708 externalAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800709 if not main.persistentSetup and main.params.get( 'EXTERNAL_APPS' ):
Jon Hall39570262020-11-17 12:18:19 -0800710 node = main.Cluster.controllers[0]
711 for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems():
712 path, fileName = os.path.split( url )
713 main.ONOSbench.onosApp( node.ipAddress, "reinstall!", fileName, appName=app, user=node.karafUser, password=node.karafPass )
714
715
You Wang0d9f2c02018-08-10 14:56:32 -0700716 onosAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800717 if not main.persistentSetup and cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700718 if apps:
Jon Hall39570262020-11-17 12:18:19 -0800719 newApps = []
720 appNames = apps.split( ',' )
Jon Hall3c0114c2020-08-11 15:07:42 -0700721 if cluster.useDocker:
722 node = main.Cluster.active( 0 )
Jon Hall39570262020-11-17 12:18:19 -0800723 for app in appNames:
724 appName = app if "org." in app else appPrefix + app
725 node.activateApp( appName )
726 newApps.append( appName )
Jon Hall3c0114c2020-08-11 15:07:42 -0700727
Jon Hall39570262020-11-17 12:18:19 -0800728 onosAppsResult = self.checkOnosApps( cluster, newApps )
You Wang0d9f2c02018-08-10 14:56:32 -0700729 else:
730 main.log.warn( "No apps were specified to be checked after startup" )
731
You Wangf9d95be2018-08-01 14:35:37 -0700732 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700733 installResult and secureSshResult and onosServiceResult and onosCliResult and \
Jon Hall3c0114c2020-08-11 15:07:42 -0700734 onosNodesResult and onosAppsResult and preCLIResult