blob: 020af9d26e8d257e4e56fbb6f269f31161aaf2b6 [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 Hall4f360bc2017-09-07 10:19:52 -070029
Devin Lim0c972b72018-02-08 14:53:59 -080030 def envSetupDescription( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070031 """
32 Introduction part of the test. It will initialize some basic vairables.
33 """
Devin Lim0c972b72018-02-08 14:53:59 -080034 if includeCaseDesc:
35 main.case( "Constructing test variables and building ONOS package" )
36 main.caseExplanation = "For loading from params file, and pull" + \
37 " and build the latest ONOS package"
Jon Halla604fd42018-05-04 14:27:27 -070038 main.step( "Constructing test variables" )
Devin Lim142b5342017-07-20 15:22:39 -070039 try:
40 from tests.dependencies.Cluster import Cluster
41 except ImportError:
42 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070043 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070044 try:
45 main.Cluster
46 except ( NameError, AttributeError ):
Jon Hall3c0114c2020-08-11 15:07:42 -070047 main.Cluster = Cluster( main.ONOScell.nodes, useDocker=main.ONOScell.useDocker )
Devin Lim142b5342017-07-20 15:22:39 -070048 main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
Jon Halld74d2952018-03-01 13:26:39 -080049 main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
Devin Lim58046fa2017-07-05 16:55:00 -070050
Devin Lim0c972b72018-02-08 14:53:59 -080051 def gitPulling( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070052 """
53 it will do git checkout or pull if they are enabled from the params file.
54 """
Devin Lim0c972b72018-02-08 14:53:59 -080055
56 if includeCaseDesc:
57 main.case( "Pull onos branch and build onos on Teststation." )
58
Devin Lim58046fa2017-07-05 16:55:00 -070059 gitPull = main.params[ 'GIT' ][ 'pull' ]
60 gitBranch = main.params[ 'GIT' ][ 'branch' ]
61 if gitPull == 'True':
62 main.step( "Git Checkout ONOS branch: " + gitBranch )
63 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
64 utilities.assert_equals( expect=main.TRUE,
65 actual=stepResult,
66 onpass="Successfully checkout onos branch.",
67 onfail="Failed to checkout onos branch. Exiting test..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070068 if not stepResult:
69 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070070
71 main.step( "Git Pull on ONOS branch:" + gitBranch )
72 stepResult = main.ONOSbench.gitPull()
73 utilities.assert_equals( expect=main.TRUE,
74 actual=stepResult,
75 onpass="Successfully pull onos. ",
76 onfail="Failed to pull onos. Exiting test ..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070077 if not stepResult:
78 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070079
80 else:
81 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
82
Devin Lim0c972b72018-02-08 14:53:59 -080083 def envSetup( self, includeGitPull=True, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070084 """
85 Description:
86 some environment setup for the test.
87 Required:
88 * includeGitPull - if wish to git pulling function to be executed.
89 Returns:
90 Returns main.TRUE
91 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070092 if includeGitPull:
Devin Lim0c972b72018-02-08 14:53:59 -080093 self.gitPulling( includeCaseDesc )
Jon Hallca319892017-06-15 15:25:22 -070094
Devin Lim142b5342017-07-20 15:22:39 -070095 try:
96 from tests.dependencies.Cluster import Cluster
97 except ImportError:
98 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070099 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -0700100 try:
101 main.Cluster
102 except ( NameError, AttributeError ):
Jon Hall3c0114c2020-08-11 15:07:42 -0700103 main.Cluster = Cluster( main.ONOScell.nodes, useDocker=main.ONOScell.useDocker )
Devin Lim142b5342017-07-20 15:22:39 -0700104
Devin Lim58046fa2017-07-05 16:55:00 -0700105 main.cellData = {} # For creating cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700106
Jon Hallca319892017-06-15 15:25:22 -0700107 return main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700108
Jon Hall3c0114c2020-08-11 15:07:42 -0700109 def envSetupException( self, error ):
Devin Lim142b5342017-07-20 15:22:39 -0700110 """
111 Description:
112 handles the exception that might occur from the environment setup.
113 Required:
Jon Hall3c0114c2020-08-11 15:07:42 -0700114 * error - exception returned from except.
Devin Lim142b5342017-07-20 15:22:39 -0700115 """
Jon Hall3c0114c2020-08-11 15:07:42 -0700116 main.log.exception( error )
Devin Lim44075962017-08-11 10:56:37 -0700117 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700118
Jon Hallaa1d9b82020-07-30 13:49:42 -0700119 def envSetupConclusion( self, stepResult ):
Devin Lim142b5342017-07-20 15:22:39 -0700120 """
121 Description:
122 compare the result of the envSetup of the test.
123 Required:
124 * stepResult - Result of the envSetup.
125 """
Devin Lim58046fa2017-07-05 16:55:00 -0700126 utilities.assert_equals( expect=main.TRUE,
127 actual=stepResult,
128 onpass="Successfully construct " +
129 "test variables ",
130 onfail="Failed to construct test variables" )
131
Jon Hallf2527902020-07-30 12:56:08 -0700132 if main.params[ 'GRAPH' ].get('jobName'):
133 url = self.generateGraphURL( testname=main.params[ 'GRAPH' ][ 'jobName' ] )
134 else:
135 url = self.generateGraphURL()
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800136 main.log.wiki( url )
137
Devin Lim58046fa2017-07-05 16:55:00 -0700138 main.commit = main.ONOSbench.getVersion( report=True )
139
Jon Hallf2527902020-07-30 12:56:08 -0700140 def generateGraphURL( self, testname=main.TEST, width=525, height=350 ):
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800141 """
142 Description:
143 Obtain the URL for the graph that corresponds to the test being run.
144 """
145
146 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800147 branch = main.ONOSbench.getBranchName()
148 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
149
150 return '<ac:structured-macro ac:name="html">\n' + \
151 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800152 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800153 nodeCluster + \
154 '/lastSuccessfulBuild/artifact/' + \
155 testname + \
156 '_' + \
157 branch + \
158 '_' + \
159 maxBuildsToShow + \
160 '-builds_graph.jpg", alt="' + \
161 testname + \
162 '", style="width:' + \
163 str( width ) + \
164 'px;height:' + \
165 str( height ) + \
166 'px;border:0"' + \
167 '>' + \
168 ']]></ac:plain-text-body>\n' + \
169 '</ac:structured-macro>\n'
170
Devin Lim142b5342017-07-20 15:22:39 -0700171 def setNumCtrls( self, hasMultiNodeRounds ):
172 """
173 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700174 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700175 different number of nodes should be pre-defined in main.scale.
176 Required:
177 * hasMultiNodeRouds - if the test is testing different number of nodes.
178 """
Devin Lim58046fa2017-07-05 16:55:00 -0700179 if hasMultiNodeRounds:
180 try:
181 main.cycle
182 except Exception:
183 main.cycle = 0
184 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700185 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700186 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700187
You Wangf9d95be2018-08-01 14:35:37 -0700188 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
189 """
190 Description:
191 killing atomix. It will either kill the current runningnodes or
192 max number of the nodes.
193 Required:
194 * cluster - the cluster driver that will be used.
195 * killRemoveMax - The boolean that will decide either to kill
196 only running nodes ( False ) or max number of nodes ( True ).
197 * stopAtomix - If wish to stop atomix before killing it. True for
198 enable stop, False for disable stop.
199 Returns:
200 Returns main.TRUE if successfully killing it.
201 """
202 main.log.info( "Safety check, killing all Atomix processes" )
203 return cluster.killAtomix( killRemoveMax, stopAtomix )
204
Devin Lim142b5342017-07-20 15:22:39 -0700205 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
206 """
207 Description:
208 killing the onos. It will either kill the current runningnodes or
209 max number of the nodes.
210 Required:
211 * cluster - the cluster driver that will be used.
212 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700213 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700214 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700215 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700216 Returns:
217 Returns main.TRUE if successfully killing it.
218 """
219 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700220 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700221
Jon Hall3c0114c2020-08-11 15:07:42 -0700222 def killingAllOnosDocker( self, cluster, killRemoveMax ):
223 """
224 Description:
225 killing the onos docker images . It will either kill the
226 current runningnodes or max number of the nodes.
227 Required:
228 * cluster - the cluster driver that will be used.
229 * killRemoveMax - The boolean that will decide either to kill
230 only running nodes ( False ) or max number of nodes ( True ).
231 Returns:
232 Returns main.TRUE if successfully killing it.
233 """
234 main.log.info( "Safety check, stopping all ONOS docker containers" )
235 return cluster.dockerStop( killRemoveMax )
236
You Wang09b596b2018-01-10 10:42:38 -0800237 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700238 mininetIp, useSSH, onosIps, installMax=False,
239 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700240 """
241 Description:
242 create new cell ( optional ) and apply it. It will also verify the
243 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700244 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700245 * cluster - the cluster driver that will be used.
246 * newCell - True for making a new cell and False for not making it.
247 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800248 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800249 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700250 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700251 * onosIps - ip( s ) of the ONOS node( s ).
252 Optional Arguments:
253 * installMax
254 * atomixClusterSize - The size of the atomix cluster. Defaults to same
255 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700256 Returns:
257 Returns main.TRUE if it successfully executed.
258 """
Jon Hall3e6edb32018-08-21 16:20:30 -0700259 if atomixClusterSize is None:
260 atomixClusterSize = len( cluster.runningNodes )
Jon Hall3c0114c2020-08-11 15:07:42 -0700261 if atomixClusterSize is 1:
262 atomixClusterSize = len( cluster.controllers )
Jon Hall3e6edb32018-08-21 16:20:30 -0700263 atomixClusterSize = int( atomixClusterSize )
264 cluster.setAtomixNodes( atomixClusterSize )
265 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
266 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700267 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700268 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
269 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700270 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700271 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700272 utilities.assert_equals( expect=main.TRUE,
273 actual=stepResult,
274 onpass="Successfully applied cell to " +
275 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700276 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700277 return stepResult
278
You Wangf9d95be2018-08-01 14:35:37 -0700279 def uninstallAtomix( self, cluster, uninstallMax ):
280 """
281 Description:
282 uninstalling atomix and verify the result.
283 Required:
284 * cluster - a cluster driver that will be used.
285 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700286 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700287 Returns:
288 Returns main.TRUE if it successfully uninstalled.
289 """
290 main.step( "Uninstalling Atomix" )
291 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
292 utilities.assert_equals( expect=main.TRUE,
293 actual=atomixUninstallResult,
294 onpass="Successfully uninstalled Atomix",
295 onfail="Failed to uninstall Atomix" )
296 return atomixUninstallResult
297
Devin Lim142b5342017-07-20 15:22:39 -0700298 def uninstallOnos( self, cluster, uninstallMax ):
299 """
300 Description:
301 uninstalling onos and verify the result.
302 Required:
303 * cluster - a cluster driver that will be used.
304 * uninstallMax - True for uninstalling max number of nodes
305 False for uninstalling the current running nodes.
306 Returns:
307 Returns main.TRUE if it successfully uninstalled.
308 """
Devin Lim58046fa2017-07-05 16:55:00 -0700309 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700310 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700311 utilities.assert_equals( expect=main.TRUE,
312 actual=onosUninstallResult,
313 onpass="Successfully uninstalled ONOS package",
314 onfail="Failed to uninstall ONOS package" )
315 return onosUninstallResult
316
Devin Lim142b5342017-07-20 15:22:39 -0700317 def buildOnos( self, cluster ):
318 """
319 Description:
You Wangd54c7052018-08-07 16:06:27 -0700320 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700321 Required:
322 * cluster - the cluster driver that will be used.
323 Returns:
324 Returns main.TRUE if it successfully built.
325 """
Devin Lim58046fa2017-07-05 16:55:00 -0700326 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700327 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700328 utilities.assert_equals( expect=main.TRUE,
329 actual=packageResult,
330 onpass="Successfully created ONOS package",
331 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800332 if not packageResult:
333 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700334 return packageResult
335
Jon Hall3c0114c2020-08-11 15:07:42 -0700336 def buildDocker( self, cluster ):
337 """
338 Description:
339 Build the latest docker
340 Required:
341 * cluster - the cluster driver that will be used.
342 Returns:
343 Returns main.TRUE if it successfully built.
344 """
345 main.step( "Building ONOS Docker image" )
346 buildResult = cluster.dockerBuild()
347 utilities.assert_equals( expect=main.TRUE,
348 actual=buildResult,
349 onpass="Successfully created ONOS docker",
350 onfail="Failed to create ONOS docker" )
351 if not buildResult:
352 main.cleanAndExit()
353 return buildResult
354
Jon Hall3e6edb32018-08-21 16:20:30 -0700355 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700356 """
357 Description:
358 Installing atomix and verify the result
359 Required:
360 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700361 False for installing current running nodes only.
362 Returns:
363 Returns main.TRUE if it successfully installed
364 """
365 main.step( "Installing Atomix" )
366 atomixInstallResult = main.TRUE
367
Jon Hallb685a1c2018-10-30 15:17:01 -0700368 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700369 utilities.assert_equals( expect=main.TRUE,
370 actual=atomixInstallResult,
371 onpass="Successfully installed Atomix",
372 onfail="Failed to install Atomix" )
373 if not atomixInstallResult:
374 main.cleanAndExit()
375 return atomixInstallResult
376
Devin Lime9f0ccf2017-08-11 17:25:12 -0700377 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700378 """
379 Description:
380 Installing onos and verify the result
381 Required:
382 * cluster - the cluster driver that will be used.
383 * installMax - True for installing max number of nodes
384 False for installing current running nodes only.
385 Returns:
386 Returns main.TRUE if it successfully installed
387 """
Devin Lim58046fa2017-07-05 16:55:00 -0700388 main.step( "Installing ONOS package" )
389 onosInstallResult = main.TRUE
390
You Wangf9d95be2018-08-01 14:35:37 -0700391 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700392 utilities.assert_equals( expect=main.TRUE,
393 actual=onosInstallResult,
394 onpass="Successfully installed ONOS package",
395 onfail="Failed to install ONOS package" )
396 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700397 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700398 return onosInstallResult
399
Jon Hall3c0114c2020-08-11 15:07:42 -0700400 def startDocker( self, cluster, installMax, parallel=True ):
401 """
402 Description:
403 Start onos docker containers and verify the result
404 Required:
405 * cluster - the cluster driver that will be used.
406 * installMax - True for installing max number of nodes
407 False for installing current running nodes only.
408 Returns:
409 Returns main.TRUE if it successfully installed
410 """
411 main.step( "Create Cluster Config" )
412 configResult = cluster.genPartitions()
413 utilities.assert_equals( expect=main.TRUE,
414 actual=configResult,
415 onpass="Successfully create cluster config",
416 onfail="Failed to create cluster config" )
417
418 # install atomix docker containers
419 main.step( "Installing Atomix via docker containers" )
420 atomixInstallResult = cluster.startAtomixDocker( parallel )
421 utilities.assert_equals( expect=main.TRUE,
422 actual=atomixInstallResult,
423 onpass="Successfully start atomix containers",
424 onfail="Failed to start atomix containers" )
425
426 main.step( "Installing ONOS via docker containers" )
427 onosInstallResult = cluster.startONOSDocker( installMax, parallel )
428 utilities.assert_equals( expect=main.TRUE,
429 actual=onosInstallResult,
430 onpass="Successfully start ONOS containers",
431 onfail="Failed to start ONOS containers" )
432 if not onosInstallResult and atomixInstallResult:
433 main.cleanAndExit()
434 return onosInstallResult and atomixInstallResult
435
Devin Lim142b5342017-07-20 15:22:39 -0700436 def setupSsh( self, cluster ):
437 """
438 Description:
439 set up ssh to the onos and verify the result
440 Required:
441 * cluster - the cluster driver that will be used.
442 Returns:
443 Returns main.TRUE if it successfully setup the ssh to
444 the onos.
445 """
Devin Lim58046fa2017-07-05 16:55:00 -0700446 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700447 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700448 utilities.assert_equals( expect=main.TRUE,
449 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700450 onpass="Secured ONOS ssh",
451 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700452 return secureSshResult
453
Devin Lim142b5342017-07-20 15:22:39 -0700454 def checkOnosService( self, cluster ):
455 """
456 Description:
457 Checking if the onos service is up and verify the result
458 Required:
459 * cluster - the cluster driver that will be used.
460 Returns:
461 Returns main.TRUE if it successfully checked
462 """
463 main.step( "Checking ONOS service" )
464 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700465 utilities.assert_equals( expect=main.TRUE,
466 actual=stepResult,
467 onpass="ONOS service is ready on all nodes",
468 onfail="ONOS service did not start properly on all nodes" )
469 return stepResult
470
Jon Hallca319892017-06-15 15:25:22 -0700471 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700472 """
473 Description:
474 starting Onos using onosCli driver and verify the result
475 Required:
476 * cluster - the cluster driver that will be used.
477 Returns:
478 Returns main.TRUE if it successfully started. It will exit
479 the test if not started properly.
480 """
Devin Lim58046fa2017-07-05 16:55:00 -0700481 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700482 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700483 if not startCliResult:
484 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700485 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700486 else:
487 main.log.info( "Successful CLI startup" )
488 utilities.assert_equals( expect=main.TRUE,
489 actual=startCliResult,
490 onpass="Successfully start ONOS cli",
491 onfail="Failed to start ONOS cli" )
492 return startCliResult
493
You Wang0d9f2c02018-08-10 14:56:32 -0700494 def checkOnosNodes( self, cluster ):
495 """
496 Description:
497 Checking if the onos nodes are in READY state
498 Required:
499 * cluster - the cluster driver that will be used.
500 Returns:
501 Returns main.TRUE if it successfully checked
502 """
503 main.step( "Checking ONOS nodes" )
504 stepResult = utilities.retry( main.Cluster.nodesCheck,
505 False,
You Wang07831cb2018-09-04 12:18:04 -0700506 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700507
508 utilities.assert_equals( expect=True,
509 actual=stepResult,
510 onpass="All ONOS nodes are in READY state",
511 onfail="Not all ONOS nodes are in READY state" )
512
513 if not stepResult:
514 for ctrl in main.Cluster.active():
515 main.log.debug( "{} components not ACTIVE: \n{}".format(
516 ctrl.name,
Jon Hallf29368d2020-07-31 12:23:56 -0700517 # FIXME: This output has changed a lot
518 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) )
You Wang0d9f2c02018-08-10 14:56:32 -0700519 main.log.error( "Failed to start ONOS, stopping test" )
You Wang7880b372019-02-27 16:50:47 -0800520 main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
You Wangba973f02018-08-30 12:33:41 -0700521 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700522
523 def checkOnosApps( self, cluster, apps ):
524 """
525 Description:
526 Checking if the onos applications are activated
527 Required:
528 * cluster - the cluster driver that will be used.
529 * apps: list of applications that are expected to be activated
530 Returns:
531 Returns main.TRUE if it successfully checked
532 """
533 main.step( "Checking ONOS applications" )
534 stepResult = utilities.retry( main.Cluster.appsCheck,
535 False,
536 args = [ apps ],
537 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700538 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700539
540 utilities.assert_equals( expect=True,
541 actual=stepResult,
542 onpass="All ONOS apps are activated",
543 onfail="Not all ONOS apps are activated" )
544
545 return main.TRUE if stepResult else main.FALSE
546
Jon Hall4f360bc2017-09-07 10:19:52 -0700547 def processList( self, functions, args ):
548 if functions is not None:
549 if isinstance( functions, list ):
550 i = 0
551 for f in functions:
552 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
553 i += 1
554 else:
555 functions( *args ) if args is not None else functions()
556
You Wangb1665b52019-02-01 15:49:48 -0800557 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700558 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700559 mininetIp="", extraApply=None, applyArgs=None,
560 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
561 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
562 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700563 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700564 """
565 Description:
566 Initial ONOS setting up of the tests. It will also verify the result of each steps.
567 The procedures will be:
568 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700569 creating ( optional ) /applying cell
570 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700571 uninstalling onos
572 extra procedure to be applied( optional )
573 building onos
574 installing onos
575 extra cleanup to be applied ( optional )
576 setting up ssh to the onos
577 checking the onos service
578 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700579 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700580 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700581 Optional Arguments:
582 * hasMultiNodeRounds - True if the test is testing different set of nodes
You Wangb1665b52019-02-01 15:49:48 -0800583 * startOnosCli - True if wish to start onos CLI.
Devin Lim142b5342017-07-20 15:22:39 -0700584 * newCell - True for making a new cell and False for not making it.
585 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700586 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700587 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800588 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700589 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
590 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
591 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
592 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700593 * skipPack - True if wish to skip some packing.
594 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700595 False if wish to install onos of running nodes only
596 * atomixClusterSize - The number of Atomix nodes in the cluster.
597 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700598 * useSSH - True for using ssh when creating a cell
599 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700600 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700601 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700602 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700603 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700604 Returns:
605 Returns main.TRUE if it everything successfully proceeded.
606 """
607 self.setNumCtrls( hasMultiNodeRounds )
Devin Lim0c972b72018-02-08 14:53:59 -0800608 if includeCaseDesc:
609 main.case( "Starting up " + str( cluster.numCtrls ) +
610 " node(s) ONOS cluster" )
611 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
612 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700613
Jon Hall3e6edb32018-08-21 16:20:30 -0700614 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700615 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800616 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700617 try:
618 apps = main.apps
619 except ( NameError, AttributeError ):
620 apps = cellApps
621 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700622 tempOnosIp = []
623 for ctrl in cluster.runningNodes:
624 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800625 if mininetIp == "":
626 mininetIp = "localhost"
627 for key, value in main.componentDictionary.items():
628 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
629 mininetIp = getattr( main, key ).ip_address
630 break
Devin Lim142b5342017-07-20 15:22:39 -0700631 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700632 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800633 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700634 tempOnosIp, installMax,
635 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700636
You Wangdbb95d62018-09-05 15:58:08 -0700637 if restartCluster:
638 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
639 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Jon Hall3c0114c2020-08-11 15:07:42 -0700640 dockerKillResult = self.killingAllOnosDocker( cluster, killRemoveMax )
You Wangdbb95d62018-09-05 15:58:08 -0700641 killResult = atomixKillResult and onosKillResult
642 else:
643 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700644
You Wangdbb95d62018-09-05 15:58:08 -0700645 if restartCluster:
646 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
647 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
648 uninstallResult = atomixUninstallResult and onosUninstallResult
649 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800650
You Wangdbb95d62018-09-05 15:58:08 -0700651 packageResult = main.TRUE
652 if not skipPack:
Jon Hall3c0114c2020-08-11 15:07:42 -0700653 if cluster.useDocker:
654 packageResult = self.buildDocker( cluster )
655 else:
656 packageResult = self.buildOnos( cluster )
Devin Lim142b5342017-07-20 15:22:39 -0700657
Jon Hall3c0114c2020-08-11 15:07:42 -0700658 if cluster.useDocker:
659 installResult = self.startDocker( cluster, installMax, installParallel )
660 else:
661 atomixInstallResult = self.installAtomix( cluster, installParallel )
662 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
663 installResult = atomixInstallResult and onosInstallResult
664
665 preCLIResult = main.TRUE
666 if cluster.useDocker:
667 attachResult = cluster.attachToONOSDocker()
668 prepareResult = cluster.prepareForCLI()
669
670 preCLIResult = preCLIResult and attachResult and prepareResult
Devin Lim58046fa2017-07-05 16:55:00 -0700671
You Wangdbb95d62018-09-05 15:58:08 -0700672 self.processList( extraClean, cleanArgs )
673 secureSshResult = self.setupSsh( cluster )
674 else:
675 packageResult = main.TRUE
676 uninstallResult = main.TRUE
677 installResult = main.TRUE
678 secureSshResult = main.TRUE
Jon Hall3c0114c2020-08-11 15:07:42 -0700679 preCLIResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700680
Jon Hall3c0114c2020-08-11 15:07:42 -0700681 onosServiceResult = main.TRUE
682 if not cluster.useDocker:
683 onosServiceResult = self.checkOnosService( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700684
You Wang4cc61912018-08-28 10:10:58 -0700685 onosCliResult = main.TRUE
You Wangb1665b52019-02-01 15:49:48 -0800686 if startOnosCli:
Jon Hallca319892017-06-15 15:25:22 -0700687 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700688
You Wang0d9f2c02018-08-10 14:56:32 -0700689 onosNodesResult = self.checkOnosNodes( cluster )
690
691 onosAppsResult = main.TRUE
692 if cellApply:
693 if apps:
694 apps = apps.split( ',' )
You Wangcdc51fe2018-08-12 17:14:56 -0700695 apps = [ appPrefix + app for app in apps ]
Jon Hall3c0114c2020-08-11 15:07:42 -0700696 if cluster.useDocker:
697 node = main.Cluster.active( 0 )
698 for app in apps:
699 node.activateApp( app )
700
You Wang0d9f2c02018-08-10 14:56:32 -0700701 onosAppsResult = self.checkOnosApps( cluster, apps )
702 else:
703 main.log.warn( "No apps were specified to be checked after startup" )
704
Jon Hall43060f62020-06-23 13:13:33 -0700705 externalAppsResult = main.TRUE
706 if main.params.get( 'EXTERNAL_APPS' ):
707 for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems():
708 path, fileName = os.path.split( url )
709 main.ONOSbench.onosApp( main.Cluster.controllers[0].ipAddress, "install!", fileName )
710
You Wangf9d95be2018-08-01 14:35:37 -0700711 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700712 installResult and secureSshResult and onosServiceResult and onosCliResult and \
Jon Hall3c0114c2020-08-11 15:07:42 -0700713 onosNodesResult and onosAppsResult and preCLIResult