Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 3 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 12 | |
| 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 Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 21 | import re |
Jon Hall | bef6d9b | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 22 | import os |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 23 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 24 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 25 | class ONOSSetup: |
| 26 | main = None |
Jon Hall | 4f360bc | 2017-09-07 10:19:52 -0700 | [diff] [blame] | 27 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 28 | def __init__( self ): |
| 29 | self.default = '' |
Jon Hall | 4f360bc | 2017-09-07 10:19:52 -0700 | [diff] [blame] | 30 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 31 | def envSetupDescription( self, includeCaseDesc=True ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 32 | """ |
| 33 | Introduction part of the test. It will initialize some basic vairables. |
| 34 | """ |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 35 | if includeCaseDesc: |
| 36 | main.case( "Constructing test variables and building ONOS package" ) |
| 37 | main.caseExplanation = "For loading from params file, and pull" + \ |
| 38 | " and build the latest ONOS package" |
Jon Hall | a604fd4 | 2018-05-04 14:27:27 -0700 | [diff] [blame] | 39 | main.step( "Constructing test variables" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 40 | try: |
| 41 | from tests.dependencies.Cluster import Cluster |
| 42 | except ImportError: |
| 43 | main.log.error( "Cluster not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 44 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 45 | try: |
| 46 | main.Cluster |
| 47 | except ( NameError, AttributeError ): |
| 48 | main.Cluster = Cluster( main.ONOScell.nodes ) |
| 49 | main.ONOSbench = main.Cluster.controllers[ 0 ].Bench |
Jon Hall | d74d295 | 2018-03-01 13:26:39 -0800 | [diff] [blame] | 50 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 51 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 52 | def gitPulling( self, includeCaseDesc=True ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 53 | """ |
| 54 | it will do git checkout or pull if they are enabled from the params file. |
| 55 | """ |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 56 | |
| 57 | if includeCaseDesc: |
| 58 | main.case( "Pull onos branch and build onos on Teststation." ) |
| 59 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 60 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 61 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 62 | if gitPull == 'True': |
| 63 | main.step( "Git Checkout ONOS branch: " + gitBranch ) |
| 64 | stepResult = main.ONOSbench.gitCheckout( branch=gitBranch ) |
| 65 | utilities.assert_equals( expect=main.TRUE, |
| 66 | actual=stepResult, |
| 67 | onpass="Successfully checkout onos branch.", |
| 68 | onfail="Failed to checkout onos branch. Exiting test..." ) |
Jon Hall | 4f360bc | 2017-09-07 10:19:52 -0700 | [diff] [blame] | 69 | if not stepResult: |
| 70 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 71 | |
| 72 | main.step( "Git Pull on ONOS branch:" + gitBranch ) |
| 73 | stepResult = main.ONOSbench.gitPull() |
| 74 | utilities.assert_equals( expect=main.TRUE, |
| 75 | actual=stepResult, |
| 76 | onpass="Successfully pull onos. ", |
| 77 | onfail="Failed to pull onos. Exiting test ..." ) |
Jon Hall | 4f360bc | 2017-09-07 10:19:52 -0700 | [diff] [blame] | 78 | if not stepResult: |
| 79 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 80 | |
| 81 | else: |
| 82 | main.log.info( "Skipped git checkout and pull as they are disabled in params file" ) |
| 83 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 84 | def envSetup( self, includeGitPull=True, includeCaseDesc=True ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 85 | """ |
| 86 | Description: |
| 87 | some environment setup for the test. |
| 88 | Required: |
| 89 | * includeGitPull - if wish to git pulling function to be executed. |
| 90 | Returns: |
| 91 | Returns main.TRUE |
| 92 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 93 | if includeGitPull: |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 94 | self.gitPulling( includeCaseDesc ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 95 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 96 | try: |
| 97 | from tests.dependencies.Cluster import Cluster |
| 98 | except ImportError: |
| 99 | main.log.error( "Cluster not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 100 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 101 | try: |
| 102 | main.Cluster |
| 103 | except ( NameError, AttributeError ): |
| 104 | main.Cluster = Cluster( main.ONOScell.nodes ) |
| 105 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 106 | main.cellData = {} # For creating cell file |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 107 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 108 | return main.TRUE |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 109 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 110 | def envSetupException( self, e ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 111 | """ |
| 112 | Description: |
| 113 | handles the exception that might occur from the environment setup. |
| 114 | Required: |
| 115 | * includeGitPull - exceeption code e. |
| 116 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 117 | main.log.exception( e ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 118 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 119 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 120 | def evnSetupConclusion( self, stepResult ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 121 | """ |
| 122 | Description: |
| 123 | compare the result of the envSetup of the test. |
| 124 | Required: |
| 125 | * stepResult - Result of the envSetup. |
| 126 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 127 | utilities.assert_equals( expect=main.TRUE, |
| 128 | actual=stepResult, |
| 129 | onpass="Successfully construct " + |
| 130 | "test variables ", |
| 131 | onfail="Failed to construct test variables" ) |
| 132 | |
Jeremy Ronquillo | 7f8fb57 | 2017-11-14 08:28:41 -0800 | [diff] [blame] | 133 | url = self.generateGraphURL() |
| 134 | main.log.wiki( url ) |
| 135 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 136 | main.commit = main.ONOSbench.getVersion( report=True ) |
| 137 | |
Jeremy Ronquillo | 7f8fb57 | 2017-11-14 08:28:41 -0800 | [diff] [blame] | 138 | def generateGraphURL( self, width=525, height=350 ): |
| 139 | """ |
| 140 | Description: |
| 141 | Obtain the URL for the graph that corresponds to the test being run. |
| 142 | """ |
| 143 | |
| 144 | nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ] |
| 145 | testname = main.TEST |
| 146 | branch = main.ONOSbench.getBranchName() |
| 147 | maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ] |
| 148 | |
| 149 | return '<ac:structured-macro ac:name="html">\n' + \ |
| 150 | '<ac:plain-text-body><![CDATA[\n' + \ |
Devin Lim | d1fb8e9 | 2018-02-28 16:29:33 -0800 | [diff] [blame] | 151 | '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \ |
Jeremy Ronquillo | 7f8fb57 | 2017-11-14 08:28:41 -0800 | [diff] [blame] | 152 | nodeCluster + \ |
| 153 | '/lastSuccessfulBuild/artifact/' + \ |
| 154 | testname + \ |
| 155 | '_' + \ |
| 156 | branch + \ |
| 157 | '_' + \ |
| 158 | maxBuildsToShow + \ |
| 159 | '-builds_graph.jpg", alt="' + \ |
| 160 | testname + \ |
| 161 | '", style="width:' + \ |
| 162 | str( width ) + \ |
| 163 | 'px;height:' + \ |
| 164 | str( height ) + \ |
| 165 | 'px;border:0"' + \ |
| 166 | '>' + \ |
| 167 | ']]></ac:plain-text-body>\n' + \ |
| 168 | '</ac:structured-macro>\n' |
| 169 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 170 | def setNumCtrls( self, hasMultiNodeRounds ): |
| 171 | """ |
| 172 | Description: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 173 | Set new number of controllers if it uses different number of nodes. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 174 | different number of nodes should be pre-defined in main.scale. |
| 175 | Required: |
| 176 | * hasMultiNodeRouds - if the test is testing different number of nodes. |
| 177 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 178 | if hasMultiNodeRounds: |
| 179 | try: |
| 180 | main.cycle |
| 181 | except Exception: |
| 182 | main.cycle = 0 |
| 183 | main.cycle += 1 |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 184 | # main.scale[ 0 ] determines the current number of ONOS controllers |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 185 | main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 186 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 187 | def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ): |
| 188 | """ |
| 189 | Description: |
| 190 | killing atomix. It will either kill the current runningnodes or |
| 191 | max number of the nodes. |
| 192 | Required: |
| 193 | * cluster - the cluster driver that will be used. |
| 194 | * killRemoveMax - The boolean that will decide either to kill |
| 195 | only running nodes ( False ) or max number of nodes ( True ). |
| 196 | * stopAtomix - If wish to stop atomix before killing it. True for |
| 197 | enable stop, False for disable stop. |
| 198 | Returns: |
| 199 | Returns main.TRUE if successfully killing it. |
| 200 | """ |
| 201 | main.log.info( "Safety check, killing all Atomix processes" ) |
| 202 | return cluster.killAtomix( killRemoveMax, stopAtomix ) |
| 203 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 204 | def killingAllOnos( self, cluster, killRemoveMax, stopOnos ): |
| 205 | """ |
| 206 | Description: |
| 207 | killing the onos. It will either kill the current runningnodes or |
| 208 | max number of the nodes. |
| 209 | Required: |
| 210 | * cluster - the cluster driver that will be used. |
| 211 | * killRemoveMax - The boolean that will decide either to kill |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 212 | only running nodes ( False ) or max number of nodes ( True ). |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 213 | * stopOnos - If wish to stop onos before killing it. True for |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 214 | enable stop, False for disable stop. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 215 | Returns: |
| 216 | Returns main.TRUE if successfully killing it. |
| 217 | """ |
| 218 | main.log.info( "Safety check, killing all ONOS processes" ) |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 219 | return cluster.killOnos( killRemoveMax, stopOnos ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 220 | |
You Wang | 09b596b | 2018-01-10 10:42:38 -0800 | [diff] [blame] | 221 | def createApplyCell( self, cluster, newCell, cellName, cellApps, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 222 | mininetIp, useSSH, onosIps, installMax=False, |
| 223 | atomixClusterSize=None ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 224 | """ |
| 225 | Description: |
| 226 | create new cell ( optional ) and apply it. It will also verify the |
| 227 | cell. |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 228 | Required Arguments: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 229 | * cluster - the cluster driver that will be used. |
| 230 | * newCell - True for making a new cell and False for not making it. |
| 231 | * cellName - The name of the cell. |
You Wang | 09b596b | 2018-01-10 10:42:38 -0800 | [diff] [blame] | 232 | * cellApps - The onos apps string. |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 233 | * mininetIp - Mininet IP address. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 234 | * useSSH - True for using ssh when creating a cell |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 235 | * onosIps - ip( s ) of the ONOS node( s ). |
| 236 | Optional Arguments: |
| 237 | * installMax |
| 238 | * atomixClusterSize - The size of the atomix cluster. Defaults to same |
| 239 | as ONOS Cluster size |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 240 | Returns: |
| 241 | Returns main.TRUE if it successfully executed. |
| 242 | """ |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 243 | if atomixClusterSize is None: |
| 244 | atomixClusterSize = len( cluster.runningNodes ) |
| 245 | atomixClusterSize = int( atomixClusterSize ) |
| 246 | cluster.setAtomixNodes( atomixClusterSize ) |
| 247 | atomixIps = [ node.ipAddress for node in cluster.atomixNodes ] |
| 248 | main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 249 | if newCell: |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 250 | cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps, |
| 251 | atomixIps, installMax ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 252 | main.step( "Apply cell to environment" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 253 | stepResult = cluster.applyCell( cellName ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 254 | utilities.assert_equals( expect=main.TRUE, |
| 255 | actual=stepResult, |
| 256 | onpass="Successfully applied cell to " + |
| 257 | "environment", |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 258 | onfail="Failed to apply cell to environment" ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 259 | return stepResult |
| 260 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 261 | def uninstallAtomix( self, cluster, uninstallMax ): |
| 262 | """ |
| 263 | Description: |
| 264 | uninstalling atomix and verify the result. |
| 265 | Required: |
| 266 | * cluster - a cluster driver that will be used. |
| 267 | * uninstallMax - True for uninstalling max number of nodes |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 268 | False for uninstalling the current running nodes. |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 269 | Returns: |
| 270 | Returns main.TRUE if it successfully uninstalled. |
| 271 | """ |
| 272 | main.step( "Uninstalling Atomix" ) |
| 273 | atomixUninstallResult = cluster.uninstallAtomix( uninstallMax ) |
| 274 | utilities.assert_equals( expect=main.TRUE, |
| 275 | actual=atomixUninstallResult, |
| 276 | onpass="Successfully uninstalled Atomix", |
| 277 | onfail="Failed to uninstall Atomix" ) |
| 278 | return atomixUninstallResult |
| 279 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 280 | def uninstallOnos( self, cluster, uninstallMax ): |
| 281 | """ |
| 282 | Description: |
| 283 | uninstalling onos and verify the result. |
| 284 | Required: |
| 285 | * cluster - a cluster driver that will be used. |
| 286 | * uninstallMax - True for uninstalling max number of nodes |
| 287 | False for uninstalling the current running nodes. |
| 288 | Returns: |
| 289 | Returns main.TRUE if it successfully uninstalled. |
| 290 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 291 | main.step( "Uninstalling ONOS package" ) |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 292 | onosUninstallResult = cluster.uninstallOnos( uninstallMax ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 293 | utilities.assert_equals( expect=main.TRUE, |
| 294 | actual=onosUninstallResult, |
| 295 | onpass="Successfully uninstalled ONOS package", |
| 296 | onfail="Failed to uninstall ONOS package" ) |
| 297 | return onosUninstallResult |
| 298 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 299 | def buildOnos( self, cluster ): |
| 300 | """ |
| 301 | Description: |
You Wang | d54c705 | 2018-08-07 16:06:27 -0700 | [diff] [blame] | 302 | build the onos using bazel build onos and verify the result |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 303 | Required: |
| 304 | * cluster - the cluster driver that will be used. |
| 305 | Returns: |
| 306 | Returns main.TRUE if it successfully built. |
| 307 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 308 | main.step( "Creating ONOS package" ) |
You Wang | d54c705 | 2018-08-07 16:06:27 -0700 | [diff] [blame] | 309 | packageResult = main.ONOSbench.bazelBuild() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 310 | utilities.assert_equals( expect=main.TRUE, |
| 311 | actual=packageResult, |
| 312 | onpass="Successfully created ONOS package", |
| 313 | onfail="Failed to create ONOS package" ) |
You Wang | 8f5ff15 | 2019-02-28 11:35:25 -0800 | [diff] [blame] | 314 | if not packageResult: |
| 315 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 316 | return packageResult |
| 317 | |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 318 | def installAtomix( self, cluster, parallel=True ): |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 319 | """ |
| 320 | Description: |
| 321 | Installing atomix and verify the result |
| 322 | Required: |
| 323 | * cluster - the cluster driver that will be used. |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 324 | False for installing current running nodes only. |
| 325 | Returns: |
| 326 | Returns main.TRUE if it successfully installed |
| 327 | """ |
| 328 | main.step( "Installing Atomix" ) |
| 329 | atomixInstallResult = main.TRUE |
| 330 | |
Jon Hall | b685a1c | 2018-10-30 15:17:01 -0700 | [diff] [blame] | 331 | atomixInstallResult = cluster.installAtomix( parallel ) |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 332 | utilities.assert_equals( expect=main.TRUE, |
| 333 | actual=atomixInstallResult, |
| 334 | onpass="Successfully installed Atomix", |
| 335 | onfail="Failed to install Atomix" ) |
| 336 | if not atomixInstallResult: |
| 337 | main.cleanAndExit() |
| 338 | return atomixInstallResult |
| 339 | |
Devin Lim | e9f0ccf | 2017-08-11 17:25:12 -0700 | [diff] [blame] | 340 | def installOnos( self, cluster, installMax, parallel=True ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 341 | """ |
| 342 | Description: |
| 343 | Installing onos and verify the result |
| 344 | Required: |
| 345 | * cluster - the cluster driver that will be used. |
| 346 | * installMax - True for installing max number of nodes |
| 347 | False for installing current running nodes only. |
| 348 | Returns: |
| 349 | Returns main.TRUE if it successfully installed |
| 350 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 351 | main.step( "Installing ONOS package" ) |
| 352 | onosInstallResult = main.TRUE |
| 353 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 354 | cluster.installOnos( installMax, parallel ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 355 | utilities.assert_equals( expect=main.TRUE, |
| 356 | actual=onosInstallResult, |
| 357 | onpass="Successfully installed ONOS package", |
| 358 | onfail="Failed to install ONOS package" ) |
| 359 | if not onosInstallResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 360 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 361 | return onosInstallResult |
| 362 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 363 | def setupSsh( self, cluster ): |
| 364 | """ |
| 365 | Description: |
| 366 | set up ssh to the onos and verify the result |
| 367 | Required: |
| 368 | * cluster - the cluster driver that will be used. |
| 369 | Returns: |
| 370 | Returns main.TRUE if it successfully setup the ssh to |
| 371 | the onos. |
| 372 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 373 | main.step( "Set up ONOS secure SSH" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 374 | secureSshResult = cluster.ssh() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 375 | utilities.assert_equals( expect=main.TRUE, |
| 376 | actual=secureSshResult, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 377 | onpass="Secured ONOS ssh", |
| 378 | onfail="Failed to secure ssh" ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 379 | return secureSshResult |
| 380 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 381 | def checkOnosService( self, cluster ): |
| 382 | """ |
| 383 | Description: |
| 384 | Checking if the onos service is up and verify the result |
| 385 | Required: |
| 386 | * cluster - the cluster driver that will be used. |
| 387 | Returns: |
| 388 | Returns main.TRUE if it successfully checked |
| 389 | """ |
| 390 | main.step( "Checking ONOS service" ) |
| 391 | stepResult = cluster.checkService() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 392 | utilities.assert_equals( expect=main.TRUE, |
| 393 | actual=stepResult, |
| 394 | onpass="ONOS service is ready on all nodes", |
| 395 | onfail="ONOS service did not start properly on all nodes" ) |
| 396 | return stepResult |
| 397 | |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 398 | def startOnosClis( self, cluster ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 399 | """ |
| 400 | Description: |
| 401 | starting Onos using onosCli driver and verify the result |
| 402 | Required: |
| 403 | * cluster - the cluster driver that will be used. |
| 404 | Returns: |
| 405 | Returns main.TRUE if it successfully started. It will exit |
| 406 | the test if not started properly. |
| 407 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 408 | main.step( "Starting ONOS CLI sessions" ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 409 | startCliResult = cluster.startCLIs() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 410 | if not startCliResult: |
| 411 | main.log.info( "ONOS CLI did not start up properly" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 412 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 413 | else: |
| 414 | main.log.info( "Successful CLI startup" ) |
| 415 | utilities.assert_equals( expect=main.TRUE, |
| 416 | actual=startCliResult, |
| 417 | onpass="Successfully start ONOS cli", |
| 418 | onfail="Failed to start ONOS cli" ) |
| 419 | return startCliResult |
| 420 | |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 421 | def checkOnosNodes( self, cluster ): |
| 422 | """ |
| 423 | Description: |
| 424 | Checking if the onos nodes are in READY state |
| 425 | Required: |
| 426 | * cluster - the cluster driver that will be used. |
| 427 | Returns: |
| 428 | Returns main.TRUE if it successfully checked |
| 429 | """ |
| 430 | main.step( "Checking ONOS nodes" ) |
| 431 | stepResult = utilities.retry( main.Cluster.nodesCheck, |
| 432 | False, |
You Wang | 07831cb | 2018-09-04 12:18:04 -0700 | [diff] [blame] | 433 | attempts=90 ) |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 434 | |
| 435 | utilities.assert_equals( expect=True, |
| 436 | actual=stepResult, |
| 437 | onpass="All ONOS nodes are in READY state", |
| 438 | onfail="Not all ONOS nodes are in READY state" ) |
| 439 | |
| 440 | if not stepResult: |
| 441 | for ctrl in main.Cluster.active(): |
| 442 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
| 443 | ctrl.name, |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 444 | ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) #FIXME: This output has changed a lot |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 445 | main.log.error( "Failed to start ONOS, stopping test" ) |
You Wang | 7880b37 | 2019-02-27 16:50:47 -0800 | [diff] [blame] | 446 | main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" ) |
You Wang | ba973f0 | 2018-08-30 12:33:41 -0700 | [diff] [blame] | 447 | return main.TRUE |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 448 | |
| 449 | def checkOnosApps( self, cluster, apps ): |
| 450 | """ |
| 451 | Description: |
| 452 | Checking if the onos applications are activated |
| 453 | Required: |
| 454 | * cluster - the cluster driver that will be used. |
| 455 | * apps: list of applications that are expected to be activated |
| 456 | Returns: |
| 457 | Returns main.TRUE if it successfully checked |
| 458 | """ |
| 459 | main.step( "Checking ONOS applications" ) |
| 460 | stepResult = utilities.retry( main.Cluster.appsCheck, |
| 461 | False, |
| 462 | args = [ apps ], |
| 463 | sleep=5, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 464 | attempts=90 ) |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 465 | |
| 466 | utilities.assert_equals( expect=True, |
| 467 | actual=stepResult, |
| 468 | onpass="All ONOS apps are activated", |
| 469 | onfail="Not all ONOS apps are activated" ) |
| 470 | |
| 471 | return main.TRUE if stepResult else main.FALSE |
| 472 | |
Jon Hall | 4f360bc | 2017-09-07 10:19:52 -0700 | [diff] [blame] | 473 | def processList( self, functions, args ): |
| 474 | if functions is not None: |
| 475 | if isinstance( functions, list ): |
| 476 | i = 0 |
| 477 | for f in functions: |
| 478 | f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f() |
| 479 | i += 1 |
| 480 | else: |
| 481 | functions( *args ) if args is not None else functions() |
| 482 | |
You Wang | b1665b5 | 2019-02-01 15:49:48 -0800 | [diff] [blame] | 483 | def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True, |
You Wang | cdc51fe | 2018-08-12 17:14:56 -0700 | [diff] [blame] | 484 | cellName="temp", cellApps="drivers", appPrefix="org.onosproject.", |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 485 | mininetIp="", extraApply=None, applyArgs=None, |
| 486 | extraClean=None, cleanArgs=None, skipPack=False, installMax=False, |
| 487 | atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False, |
| 488 | stopOnos=False, installParallel=True, cellApply=True, |
You Wang | dbb95d6 | 2018-09-05 15:58:08 -0700 | [diff] [blame] | 489 | includeCaseDesc=True, restartCluster=True ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 490 | """ |
| 491 | Description: |
| 492 | Initial ONOS setting up of the tests. It will also verify the result of each steps. |
| 493 | The procedures will be: |
| 494 | killing onos |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 495 | creating ( optional ) /applying cell |
| 496 | removing raft logs ( optional ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 497 | uninstalling onos |
| 498 | extra procedure to be applied( optional ) |
| 499 | building onos |
| 500 | installing onos |
| 501 | extra cleanup to be applied ( optional ) |
| 502 | setting up ssh to the onos |
| 503 | checking the onos service |
| 504 | starting onos |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 505 | Required Arguments: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 506 | * cluster - the cluster driver that will be used. |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 507 | Optional Arguments: |
| 508 | * hasMultiNodeRounds - True if the test is testing different set of nodes |
You Wang | b1665b5 | 2019-02-01 15:49:48 -0800 | [diff] [blame] | 509 | * startOnosCli - True if wish to start onos CLI. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 510 | * newCell - True for making a new cell and False for not making it. |
| 511 | * cellName - Name of the cell that will be used. |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 512 | * cellApps - The cell apps string. Will be overwritten by main.apps if it exists |
You Wang | cdc51fe | 2018-08-12 17:14:56 -0700 | [diff] [blame] | 513 | * appPrefix - Prefix of app names. Will use "org.onosproject." by default |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 514 | * mininetIp - Mininet IP address. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 515 | * extraApply - Function( s ) that will be called before building ONOS. Default to None. |
| 516 | * applyArgs - argument of the functon( s ) of the extraApply. Should be in list. |
| 517 | * extraClean - Function( s ) that will be called after building ONOS. Defaults to None. |
| 518 | * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 519 | * skipPack - True if wish to skip some packing. |
| 520 | * installMax - True if wish to install onos max number of nodes |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 521 | False if wish to install onos of running nodes only |
| 522 | * atomixClusterSize - The number of Atomix nodes in the cluster. |
| 523 | Defaults to None which will be the number of OC# nodes in the cell |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 524 | * useSSH - True for using ssh when creating a cell |
| 525 | * killRemoveMax - True for removing/killing max number of nodes. False for |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 526 | removing/killing running nodes only. |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 527 | * stopAtomix - True if wish to stop atomix before killing it. |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 528 | * stopOnos - True if wish to stop onos before killing it. |
You Wang | dbb95d6 | 2018-09-05 15:58:08 -0700 | [diff] [blame] | 529 | * restartCluster - True if wish to kill and restart atomix and onos clusters |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 530 | Returns: |
| 531 | Returns main.TRUE if it everything successfully proceeded. |
| 532 | """ |
| 533 | self.setNumCtrls( hasMultiNodeRounds ) |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 534 | if includeCaseDesc: |
| 535 | main.case( "Starting up " + str( cluster.numCtrls ) + |
| 536 | " node(s) ONOS cluster" ) |
| 537 | main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \ |
| 538 | " node(s) ONOS cluster" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 539 | |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 540 | main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 541 | cellResult = main.TRUE |
Devin Lim | 6437c9c | 2018-01-29 17:24:16 -0800 | [diff] [blame] | 542 | if cellApply: |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 543 | try: |
| 544 | apps = main.apps |
| 545 | except ( NameError, AttributeError ): |
| 546 | apps = cellApps |
| 547 | main.log.debug( "Apps: " + str( apps ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 548 | tempOnosIp = [] |
| 549 | for ctrl in cluster.runningNodes: |
| 550 | tempOnosIp.append( ctrl.ipAddress ) |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 551 | if mininetIp == "": |
| 552 | mininetIp = "localhost" |
| 553 | for key, value in main.componentDictionary.items(): |
| 554 | if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ): |
| 555 | mininetIp = getattr( main, key ).ip_address |
| 556 | break |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 557 | cellResult = self.createApplyCell( cluster, newCell, |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 558 | cellName, apps, |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 559 | mininetIp, useSSH, |
Jon Hall | 3e6edb3 | 2018-08-21 16:20:30 -0700 | [diff] [blame] | 560 | tempOnosIp, installMax, |
| 561 | atomixClusterSize ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 562 | |
You Wang | dbb95d6 | 2018-09-05 15:58:08 -0700 | [diff] [blame] | 563 | if restartCluster: |
| 564 | atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix ) |
| 565 | onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos ) |
| 566 | killResult = atomixKillResult and onosKillResult |
| 567 | else: |
| 568 | killResult = main.TRUE |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 569 | |
You Wang | dbb95d6 | 2018-09-05 15:58:08 -0700 | [diff] [blame] | 570 | if restartCluster: |
| 571 | atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax ) |
| 572 | onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax ) |
| 573 | uninstallResult = atomixUninstallResult and onosUninstallResult |
| 574 | self.processList( extraApply, applyArgs ) |
Devin Lim | 6437c9c | 2018-01-29 17:24:16 -0800 | [diff] [blame] | 575 | |
You Wang | dbb95d6 | 2018-09-05 15:58:08 -0700 | [diff] [blame] | 576 | packageResult = main.TRUE |
| 577 | if not skipPack: |
| 578 | packageResult = self.buildOnos(cluster) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 579 | |
You Wang | dbb95d6 | 2018-09-05 15:58:08 -0700 | [diff] [blame] | 580 | atomixInstallResult = self.installAtomix( cluster, installParallel ) |
| 581 | onosInstallResult = self.installOnos( cluster, installMax, installParallel ) |
| 582 | installResult = atomixInstallResult and onosInstallResult |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 583 | |
You Wang | dbb95d6 | 2018-09-05 15:58:08 -0700 | [diff] [blame] | 584 | self.processList( extraClean, cleanArgs ) |
| 585 | secureSshResult = self.setupSsh( cluster ) |
| 586 | else: |
| 587 | packageResult = main.TRUE |
| 588 | uninstallResult = main.TRUE |
| 589 | installResult = main.TRUE |
| 590 | secureSshResult = main.TRUE |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 591 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 592 | onosServiceResult = self.checkOnosService( cluster ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 593 | |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 594 | onosCliResult = main.TRUE |
You Wang | b1665b5 | 2019-02-01 15:49:48 -0800 | [diff] [blame] | 595 | if startOnosCli: |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 596 | onosCliResult = self.startOnosClis( cluster ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 597 | |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 598 | onosNodesResult = self.checkOnosNodes( cluster ) |
| 599 | |
| 600 | onosAppsResult = main.TRUE |
| 601 | if cellApply: |
| 602 | if apps: |
| 603 | apps = apps.split( ',' ) |
You Wang | cdc51fe | 2018-08-12 17:14:56 -0700 | [diff] [blame] | 604 | apps = [ appPrefix + app for app in apps ] |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 605 | onosAppsResult = self.checkOnosApps( cluster, apps ) |
| 606 | else: |
| 607 | main.log.warn( "No apps were specified to be checked after startup" ) |
| 608 | |
Jon Hall | bef6d9b | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 609 | externalAppsResult = main.TRUE |
| 610 | if main.params.get( 'EXTERNAL_APPS' ): |
| 611 | for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems(): |
| 612 | path, fileName = os.path.split( url ) |
| 613 | main.ONOSbench.onosApp( main.Cluster.controllers[0].ipAddress, "install!", fileName ) |
| 614 | |
You Wang | f9d95be | 2018-08-01 14:35:37 -0700 | [diff] [blame] | 615 | return killResult and cellResult and packageResult and uninstallResult and \ |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 616 | installResult and secureSshResult and onosServiceResult and onosCliResult and \ |
| 617 | onosNodesResult and onosAppsResult |