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