blob: 03275a1c2de22cdec3508b99f4d4df21c8927fb7 [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 Hall3e6edb32018-08-21 16:20:30 -0700269 if atomixClusterSize is None:
270 atomixClusterSize = len( cluster.runningNodes )
Jon Hall3c0114c2020-08-11 15:07:42 -0700271 if atomixClusterSize is 1:
272 atomixClusterSize = len( cluster.controllers )
Jon Hall3e6edb32018-08-21 16:20:30 -0700273 atomixClusterSize = int( atomixClusterSize )
274 cluster.setAtomixNodes( atomixClusterSize )
275 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
276 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700277 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700278 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
279 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700280 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700281 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700282 utilities.assert_equals( expect=main.TRUE,
283 actual=stepResult,
284 onpass="Successfully applied cell to " +
285 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700286 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700287 return stepResult
288
You Wangf9d95be2018-08-01 14:35:37 -0700289 def uninstallAtomix( self, cluster, uninstallMax ):
290 """
291 Description:
292 uninstalling atomix and verify the result.
293 Required:
294 * cluster - a cluster driver that will be used.
295 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700296 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700297 Returns:
298 Returns main.TRUE if it successfully uninstalled.
299 """
300 main.step( "Uninstalling Atomix" )
301 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
302 utilities.assert_equals( expect=main.TRUE,
303 actual=atomixUninstallResult,
304 onpass="Successfully uninstalled Atomix",
305 onfail="Failed to uninstall Atomix" )
306 return atomixUninstallResult
307
Devin Lim142b5342017-07-20 15:22:39 -0700308 def uninstallOnos( self, cluster, uninstallMax ):
309 """
310 Description:
311 uninstalling onos and verify the result.
312 Required:
313 * cluster - a cluster driver that will be used.
314 * uninstallMax - True for uninstalling max number of nodes
315 False for uninstalling the current running nodes.
316 Returns:
317 Returns main.TRUE if it successfully uninstalled.
318 """
Devin Lim58046fa2017-07-05 16:55:00 -0700319 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700320 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700321 utilities.assert_equals( expect=main.TRUE,
322 actual=onosUninstallResult,
323 onpass="Successfully uninstalled ONOS package",
324 onfail="Failed to uninstall ONOS package" )
325 return onosUninstallResult
326
Devin Lim142b5342017-07-20 15:22:39 -0700327 def buildOnos( self, cluster ):
328 """
329 Description:
You Wangd54c7052018-08-07 16:06:27 -0700330 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700331 Required:
332 * cluster - the cluster driver that will be used.
333 Returns:
334 Returns main.TRUE if it successfully built.
335 """
Devin Lim58046fa2017-07-05 16:55:00 -0700336 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700337 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700338 utilities.assert_equals( expect=main.TRUE,
339 actual=packageResult,
340 onpass="Successfully created ONOS package",
341 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800342 if not packageResult:
343 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700344 return packageResult
345
Jon Hall3c0114c2020-08-11 15:07:42 -0700346 def buildDocker( self, cluster ):
347 """
348 Description:
349 Build the latest docker
350 Required:
351 * cluster - the cluster driver that will be used.
352 Returns:
353 Returns main.TRUE if it successfully built.
354 """
355 main.step( "Building ONOS Docker image" )
356 buildResult = cluster.dockerBuild()
357 utilities.assert_equals( expect=main.TRUE,
358 actual=buildResult,
359 onpass="Successfully created ONOS docker",
360 onfail="Failed to create ONOS docker" )
361 if not buildResult:
362 main.cleanAndExit()
363 return buildResult
364
Jon Hall3e6edb32018-08-21 16:20:30 -0700365 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700366 """
367 Description:
368 Installing atomix and verify the result
369 Required:
370 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700371 False for installing current running nodes only.
372 Returns:
373 Returns main.TRUE if it successfully installed
374 """
375 main.step( "Installing Atomix" )
376 atomixInstallResult = main.TRUE
377
Jon Hallb685a1c2018-10-30 15:17:01 -0700378 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700379 utilities.assert_equals( expect=main.TRUE,
380 actual=atomixInstallResult,
381 onpass="Successfully installed Atomix",
382 onfail="Failed to install Atomix" )
383 if not atomixInstallResult:
384 main.cleanAndExit()
385 return atomixInstallResult
386
Devin Lime9f0ccf2017-08-11 17:25:12 -0700387 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700388 """
389 Description:
390 Installing onos and verify the result
391 Required:
392 * cluster - the cluster driver that will be used.
393 * installMax - True for installing max number of nodes
394 False for installing current running nodes only.
395 Returns:
396 Returns main.TRUE if it successfully installed
397 """
Devin Lim58046fa2017-07-05 16:55:00 -0700398 main.step( "Installing ONOS package" )
399 onosInstallResult = main.TRUE
400
You Wangf9d95be2018-08-01 14:35:37 -0700401 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700402 utilities.assert_equals( expect=main.TRUE,
403 actual=onosInstallResult,
404 onpass="Successfully installed ONOS package",
405 onfail="Failed to install ONOS package" )
406 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700407 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700408 return onosInstallResult
409
Jon Hall3c0114c2020-08-11 15:07:42 -0700410 def startDocker( self, cluster, installMax, parallel=True ):
411 """
412 Description:
413 Start onos docker containers and verify the result
414 Required:
415 * cluster - the cluster driver that will be used.
416 * installMax - True for installing max number of nodes
417 False for installing current running nodes only.
418 Returns:
419 Returns main.TRUE if it successfully installed
420 """
421 main.step( "Create Cluster Config" )
422 configResult = cluster.genPartitions()
423 utilities.assert_equals( expect=main.TRUE,
424 actual=configResult,
425 onpass="Successfully create cluster config",
426 onfail="Failed to create cluster config" )
427
428 # install atomix docker containers
429 main.step( "Installing Atomix via docker containers" )
430 atomixInstallResult = cluster.startAtomixDocker( parallel )
431 utilities.assert_equals( expect=main.TRUE,
432 actual=atomixInstallResult,
433 onpass="Successfully start atomix containers",
434 onfail="Failed to start atomix containers" )
435
436 main.step( "Installing ONOS via docker containers" )
437 onosInstallResult = cluster.startONOSDocker( installMax, parallel )
438 utilities.assert_equals( expect=main.TRUE,
439 actual=onosInstallResult,
440 onpass="Successfully start ONOS containers",
441 onfail="Failed to start ONOS containers" )
442 if not onosInstallResult and atomixInstallResult:
443 main.cleanAndExit()
444 return onosInstallResult and atomixInstallResult
445
Devin Lim142b5342017-07-20 15:22:39 -0700446 def setupSsh( self, cluster ):
447 """
448 Description:
449 set up ssh to the onos and verify the result
450 Required:
451 * cluster - the cluster driver that will be used.
452 Returns:
453 Returns main.TRUE if it successfully setup the ssh to
454 the onos.
455 """
Devin Lim58046fa2017-07-05 16:55:00 -0700456 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700457 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700458 utilities.assert_equals( expect=main.TRUE,
459 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700460 onpass="Secured ONOS ssh",
461 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700462 return secureSshResult
463
Devin Lim142b5342017-07-20 15:22:39 -0700464 def checkOnosService( self, cluster ):
465 """
466 Description:
467 Checking if the onos service is up and verify the result
468 Required:
469 * cluster - the cluster driver that will be used.
470 Returns:
471 Returns main.TRUE if it successfully checked
472 """
473 main.step( "Checking ONOS service" )
474 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700475 utilities.assert_equals( expect=main.TRUE,
476 actual=stepResult,
477 onpass="ONOS service is ready on all nodes",
478 onfail="ONOS service did not start properly on all nodes" )
479 return stepResult
480
Jon Hallca319892017-06-15 15:25:22 -0700481 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700482 """
483 Description:
484 starting Onos using onosCli driver and verify the result
485 Required:
486 * cluster - the cluster driver that will be used.
487 Returns:
488 Returns main.TRUE if it successfully started. It will exit
489 the test if not started properly.
490 """
Devin Lim58046fa2017-07-05 16:55:00 -0700491 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700492 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700493 if not startCliResult:
494 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700495 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700496 else:
497 main.log.info( "Successful CLI startup" )
498 utilities.assert_equals( expect=main.TRUE,
499 actual=startCliResult,
500 onpass="Successfully start ONOS cli",
501 onfail="Failed to start ONOS cli" )
502 return startCliResult
503
You Wang0d9f2c02018-08-10 14:56:32 -0700504 def checkOnosNodes( self, cluster ):
505 """
506 Description:
507 Checking if the onos nodes are in READY state
508 Required:
509 * cluster - the cluster driver that will be used.
510 Returns:
511 Returns main.TRUE if it successfully checked
512 """
513 main.step( "Checking ONOS nodes" )
514 stepResult = utilities.retry( main.Cluster.nodesCheck,
515 False,
You Wang07831cb2018-09-04 12:18:04 -0700516 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700517
518 utilities.assert_equals( expect=True,
519 actual=stepResult,
520 onpass="All ONOS nodes are in READY state",
521 onfail="Not all ONOS nodes are in READY state" )
522
523 if not stepResult:
524 for ctrl in main.Cluster.active():
525 main.log.debug( "{} components not ACTIVE: \n{}".format(
526 ctrl.name,
Jon Hallf29368d2020-07-31 12:23:56 -0700527 # FIXME: This output has changed a lot
528 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) )
You Wang0d9f2c02018-08-10 14:56:32 -0700529 main.log.error( "Failed to start ONOS, stopping test" )
You Wang7880b372019-02-27 16:50:47 -0800530 main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
You Wangba973f02018-08-30 12:33:41 -0700531 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700532
533 def checkOnosApps( self, cluster, apps ):
534 """
535 Description:
536 Checking if the onos applications are activated
537 Required:
538 * cluster - the cluster driver that will be used.
539 * apps: list of applications that are expected to be activated
540 Returns:
541 Returns main.TRUE if it successfully checked
542 """
543 main.step( "Checking ONOS applications" )
544 stepResult = utilities.retry( main.Cluster.appsCheck,
545 False,
546 args = [ apps ],
547 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700548 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700549
550 utilities.assert_equals( expect=True,
551 actual=stepResult,
552 onpass="All ONOS apps are activated",
553 onfail="Not all ONOS apps are activated" )
554
555 return main.TRUE if stepResult else main.FALSE
556
Jon Hall4f360bc2017-09-07 10:19:52 -0700557 def processList( self, functions, args ):
558 if functions is not None:
559 if isinstance( functions, list ):
560 i = 0
561 for f in functions:
562 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
563 i += 1
564 else:
565 functions( *args ) if args is not None else functions()
566
You Wangb1665b52019-02-01 15:49:48 -0800567 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700568 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700569 mininetIp="", extraApply=None, applyArgs=None,
570 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
571 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
572 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700573 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700574 """
575 Description:
576 Initial ONOS setting up of the tests. It will also verify the result of each steps.
577 The procedures will be:
578 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700579 creating ( optional ) /applying cell
580 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700581 uninstalling onos
582 extra procedure to be applied( optional )
583 building onos
584 installing onos
585 extra cleanup to be applied ( optional )
586 setting up ssh to the onos
587 checking the onos service
588 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700589 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700590 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700591 Optional Arguments:
592 * hasMultiNodeRounds - True if the test is testing different set of nodes
You Wangb1665b52019-02-01 15:49:48 -0800593 * startOnosCli - True if wish to start onos CLI.
Devin Lim142b5342017-07-20 15:22:39 -0700594 * newCell - True for making a new cell and False for not making it.
595 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700596 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700597 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800598 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700599 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
600 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
601 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
602 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700603 * skipPack - True if wish to skip some packing.
604 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700605 False if wish to install onos of running nodes only
606 * atomixClusterSize - The number of Atomix nodes in the cluster.
607 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700608 * useSSH - True for using ssh when creating a cell
609 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700610 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700611 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700612 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700613 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700614 Returns:
615 Returns main.TRUE if it everything successfully proceeded.
616 """
617 self.setNumCtrls( hasMultiNodeRounds )
Jon Hall627b1572020-12-01 12:01:15 -0800618 if not main.persistentSetup:
619 if includeCaseDesc:
620 main.case( "Starting up " + str( cluster.numCtrls ) +
621 " node(s) ONOS cluster" )
622 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
623 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700624
Jon Hall3e6edb32018-08-21 16:20:30 -0700625 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700626 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800627 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700628 try:
629 apps = main.apps
630 except ( NameError, AttributeError ):
631 apps = cellApps
632 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700633 tempOnosIp = []
634 for ctrl in cluster.runningNodes:
635 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800636 if mininetIp == "":
637 mininetIp = "localhost"
638 for key, value in main.componentDictionary.items():
639 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
640 mininetIp = getattr( main, key ).ip_address
641 break
Devin Lim142b5342017-07-20 15:22:39 -0700642 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700643 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800644 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700645 tempOnosIp, installMax,
646 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700647
Jon Hall627b1572020-12-01 12:01:15 -0800648 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700649 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
650 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Jon Hall3c0114c2020-08-11 15:07:42 -0700651 dockerKillResult = self.killingAllOnosDocker( cluster, killRemoveMax )
You Wangdbb95d62018-09-05 15:58:08 -0700652 killResult = atomixKillResult and onosKillResult
653 else:
654 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700655
Jon Hall627b1572020-12-01 12:01:15 -0800656 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700657 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
658 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
659 uninstallResult = atomixUninstallResult and onosUninstallResult
660 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800661
You Wangdbb95d62018-09-05 15:58:08 -0700662 packageResult = main.TRUE
663 if not skipPack:
Jon Hall3c0114c2020-08-11 15:07:42 -0700664 if cluster.useDocker:
665 packageResult = self.buildDocker( cluster )
666 else:
667 packageResult = self.buildOnos( cluster )
Devin Lim142b5342017-07-20 15:22:39 -0700668
Jon Hall3c0114c2020-08-11 15:07:42 -0700669 if cluster.useDocker:
670 installResult = self.startDocker( cluster, installMax, installParallel )
671 else:
672 atomixInstallResult = self.installAtomix( cluster, installParallel )
673 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
674 installResult = atomixInstallResult and onosInstallResult
675
676 preCLIResult = main.TRUE
677 if cluster.useDocker:
678 attachResult = cluster.attachToONOSDocker()
679 prepareResult = cluster.prepareForCLI()
680
681 preCLIResult = preCLIResult and attachResult and prepareResult
Devin Lim58046fa2017-07-05 16:55:00 -0700682
You Wangdbb95d62018-09-05 15:58:08 -0700683 self.processList( extraClean, cleanArgs )
684 secureSshResult = self.setupSsh( cluster )
685 else:
686 packageResult = main.TRUE
687 uninstallResult = main.TRUE
688 installResult = main.TRUE
689 secureSshResult = main.TRUE
Jon Hall3c0114c2020-08-11 15:07:42 -0700690 preCLIResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700691
Jon Hall3c0114c2020-08-11 15:07:42 -0700692 onosServiceResult = main.TRUE
693 if not cluster.useDocker:
694 onosServiceResult = self.checkOnosService( cluster )
Jon Hall627b1572020-12-01 12:01:15 -0800695 elif main.persistentSetup:
696 for ctrl in cluster.getRunningNodes():
697 ctrl.inDocker = True
Devin Lim58046fa2017-07-05 16:55:00 -0700698
You Wang4cc61912018-08-28 10:10:58 -0700699 onosCliResult = main.TRUE
You Wangb1665b52019-02-01 15:49:48 -0800700 if startOnosCli:
Jon Hallca319892017-06-15 15:25:22 -0700701 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700702
You Wang0d9f2c02018-08-10 14:56:32 -0700703 onosNodesResult = self.checkOnosNodes( cluster )
704
Jon Hall39570262020-11-17 12:18:19 -0800705 externalAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800706 if not main.persistentSetup and main.params.get( 'EXTERNAL_APPS' ):
Jon Hall39570262020-11-17 12:18:19 -0800707 node = main.Cluster.controllers[0]
708 for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems():
709 path, fileName = os.path.split( url )
710 main.ONOSbench.onosApp( node.ipAddress, "reinstall!", fileName, appName=app, user=node.karafUser, password=node.karafPass )
711
712
You Wang0d9f2c02018-08-10 14:56:32 -0700713 onosAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800714 if not main.persistentSetup and cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700715 if apps:
Jon Hall39570262020-11-17 12:18:19 -0800716 newApps = []
717 appNames = apps.split( ',' )
Jon Hall3c0114c2020-08-11 15:07:42 -0700718 if cluster.useDocker:
719 node = main.Cluster.active( 0 )
Jon Hall39570262020-11-17 12:18:19 -0800720 for app in appNames:
721 appName = app if "org." in app else appPrefix + app
722 node.activateApp( appName )
723 newApps.append( appName )
Jon Hall3c0114c2020-08-11 15:07:42 -0700724
Jon Hall39570262020-11-17 12:18:19 -0800725 onosAppsResult = self.checkOnosApps( cluster, newApps )
You Wang0d9f2c02018-08-10 14:56:32 -0700726 else:
727 main.log.warn( "No apps were specified to be checked after startup" )
728
You Wangf9d95be2018-08-01 14:35:37 -0700729 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700730 installResult and secureSshResult and onosServiceResult and onosCliResult and \
Jon Hall3c0114c2020-08-11 15:07:42 -0700731 onosNodesResult and onosAppsResult and preCLIResult