Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 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. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -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 | """ |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 21 | # This is a sample template that starts up ONOS cluster, this template |
| 22 | # can be use as a base script for ONOS System Testing. |
| 23 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 24 | |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 25 | class SAMPstartTemplate_3node: |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 26 | |
| 27 | def __init__( self ): |
| 28 | self.default = '' |
| 29 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 30 | def CASE0( self, main ): |
| 31 | """ |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 32 | Pull specific ONOS branch, then Build ONOS on ONOS Bench. |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 33 | This step is usually skipped. Because in a Jenkins driven automated |
| 34 | test env. We want Jenkins jobs to pull&build for flexibility to handle |
| 35 | different versions of ONOS. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 36 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 37 | try: |
| 38 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 39 | except ImportError: |
| 40 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 41 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 42 | try: |
| 43 | main.testSetUp |
| 44 | except ( NameError, AttributeError ): |
| 45 | main.testSetUp = ONOSSetup() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 46 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 47 | main.testSetUp.gitPulling() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 48 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 49 | def CASE1( self, main ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 50 | """ |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 51 | Set up global test variables; |
| 52 | Uninstall all running cells in test env defined in .topo file |
| 53 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 54 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 55 | try: |
| 56 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 57 | except ImportError: |
| 58 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 59 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 60 | try: |
| 61 | main.testSetUp |
| 62 | except ( NameError, AttributeError ): |
| 63 | main.testSetUp = ONOSSetup() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 64 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 65 | main.testSetUp.envSetupDescription() |
| 66 | stepResult = main.FALSE |
| 67 | try: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 68 | main.onosStartupSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'onosStartup' ] ) |
| 69 | main.onosCfgSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'onosCfg' ] ) |
| 70 | main.mnStartupSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'mnStartup' ] ) |
| 71 | main.mnCfgSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'mnCfg' ] ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 72 | stepResult = main.testSetUp.envSetup( includeGitPull=False ) |
| 73 | except Exception as e: |
| 74 | main.testSetUp.envSetupException( e ) |
| 75 | main.testSetUp.evnSetupConclusion( stepResult ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 76 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 77 | def CASE2( self, main ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 78 | """ |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 79 | Report errors/warnings/exceptions |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 80 | """ |
| 81 | main.log.info( "Error report: \n" ) |
| 82 | main.ONOSbench.logReport( main.Cluster.runningNodes[ 0 ].ipAddress, |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 83 | [ "INFO", |
| 84 | "FOLLOWER", |
| 85 | "WARN", |
| 86 | "flow", |
| 87 | "ERROR", |
| 88 | "Except" ], |
| 89 | "s" ) |
| 90 | |
| 91 | def CASE10( self, main ): |
| 92 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 93 | Start ONOS cluster ( 3 nodes in this example ) in three steps: |
| 94 | 1 ) start a basic cluster with drivers app via ONOSDriver; |
| 95 | 2 ) activate apps via ONOSCliDriver; |
| 96 | 3 ) configure onos via ONOSCliDriver; |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 97 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 98 | try: |
| 99 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 100 | except ImportError: |
| 101 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 102 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 103 | try: |
| 104 | main.testSetUp |
| 105 | except ( NameError, AttributeError ): |
| 106 | main.testSetUp = ONOSSetup() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 107 | |
| 108 | import time |
| 109 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 110 | main.case( "Start up " + str( main.Cluster.numCtrls ) + "-node onos cluster." ) |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 111 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 112 | main.step( "Start ONOS cluster with basic (drivers) app." ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 113 | stepResult = main.ONOSbench.startBasicONOS( nodeList=main.Cluster.getIps(), opSleep=200, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 114 | onosUser=main.ONOScell.karafUser ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 115 | utilities.assert_equals( expect=main.TRUE, |
| 116 | actual=stepResult, |
| 117 | onpass="Successfully started basic ONOS cluster ", |
| 118 | onfail="Failed to start basic ONOS Cluster " ) |
| 119 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 120 | main.testSetUp.startOnosClis() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 121 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 122 | main.step( "Activate onos apps." ) |
| 123 | main.apps = main.params[ 'CASE10' ].get( 'Apps' ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 124 | if main.apps: |
| 125 | main.log.info( "Apps to activate: " + main.apps ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 126 | activateResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 127 | for a in main.apps.split( "," ): |
| 128 | activateResult = activateResult & main.Cluster.active( 0 ).CLI.activateApp( a ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 129 | # TODO: check this worked |
| 130 | time.sleep( main.onosCfgSleep ) # wait for apps to activate |
| 131 | else: |
| 132 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 133 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 134 | actual=activateResult, |
| 135 | onpass="Successfully set config", |
| 136 | onfail="Failed to set config" ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 137 | |
| 138 | main.step( "Set ONOS configurations" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 139 | config = main.params[ 'CASE10' ].get( 'ONOS_Configuration' ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 140 | if config: |
| 141 | main.log.debug( config ) |
| 142 | checkResult = main.TRUE |
| 143 | for component in config: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 144 | for setting in config[ component ]: |
| 145 | value = config[ component ][ setting ] |
| 146 | check = main.Cluster.runningNodes[ 0 ].setCfg( component, setting, value ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 147 | main.log.info( "Value was changed? {}".format( main.TRUE == check ) ) |
| 148 | checkResult = check and checkResult |
| 149 | utilities.assert_equals( expect=main.TRUE, |
| 150 | actual=checkResult, |
| 151 | onpass="Successfully set config", |
| 152 | onfail="Failed to set config" ) |
| 153 | else: |
| 154 | main.log.warn( "No configurations were specified to be changed after startup" ) |
| 155 | |
| 156 | def CASE11( self, main ): |
| 157 | """ |
| 158 | Start mininet and assign controllers |
| 159 | """ |
| 160 | import time |
| 161 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 162 | topology = main.params[ 'CASE11' ][ 'topo' ] |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 163 | main.log.report( "Start Mininet topology" ) |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 164 | main.case( "Start Mininet topology" ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 165 | |
| 166 | main.step( "Starting Mininet Topology" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 167 | topoResult = main.Mininet1.startNet( mnCmd=topology ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 168 | stepResult = topoResult |
| 169 | utilities.assert_equals( expect=main.TRUE, |
| 170 | actual=stepResult, |
| 171 | onpass="Successfully loaded topology", |
| 172 | onfail="Failed to load topology" ) |
| 173 | # Exit if topology did not load properly |
| 174 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 175 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 176 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 177 | main.step( "Assign switches to controllers." ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 178 | assignResult = main.TRUE |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 179 | for i in range( 1, 8 ): |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 180 | assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ), |
Jon Hall | ca31989 | 2017-06-15 15:25:22 -0700 | [diff] [blame] | 181 | ip=main.Cluster.getIps(), |
| 182 | port='6653' ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 183 | time.sleep( main.mnCfgSleep ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 184 | utilities.assert_equals( expect=main.TRUE, |
| 185 | actual=stepResult, |
| 186 | onpass="Successfully assign switches to controllers", |
| 187 | onfail="Failed to assign switches to controllers" ) |
| 188 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 189 | def CASE12( self, main ): |
| 190 | """ |
| 191 | Tests using through ONOS CLI handles |
| 192 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 193 | main.case( "Test some onos commands through CLI. " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 194 | main.log.debug( main.Cluster.active( 0 ).CLI.sendline( "summary" ) ) |
| 195 | main.log.debug( main.Cluster.active( 1 ).CLI.sendline( "devices" ) ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 196 | |
| 197 | def CASE22( self, main ): |
| 198 | """ |
| 199 | Tests using ONOS REST API handles |
| 200 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 201 | main.case( " Sample tests using ONOS REST API handles. " ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 202 | main.log.debug( main.Cluster.active( 0 ).REST.send( "/devices" ) ) |
| 203 | main.log.debug( main.Cluster.active( 2 ).REST.apps() ) |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 204 | |
| 205 | def CASE32( self, main ): |
| 206 | """ |
| 207 | Configure fwd app from .params json string with parameter configured |
| 208 | Check if configuration successful |
| 209 | Run pingall to check connectivity |
| 210 | Check ONOS log for warning/error/exceptions |
| 211 | """ |
| 212 | main.case( "Configure onos-app-fwd and check if configuration successful. " ) |
| 213 | main.step( "Install reactive forwarding app." ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 214 | installResults = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" ) |
| 215 | utilities.assert_equals( expect=main.TRUE, |
| 216 | actual=installResults, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 217 | onpass="Configure fwd successful", |
| 218 | onfail="Configure fwd failed" ) |
alison | 12f34c3 | 2016-06-10 14:39:21 -0700 | [diff] [blame] | 219 | main.step( "Run pingall to check connectivity. " ) |
| 220 | pingResult = main.FALSE |
| 221 | passMsg = "Reactive Pingall test passed" |
| 222 | pingResult = main.Mininet1.pingall() |
| 223 | if not pingResult: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 224 | main.log.warn( "First pingall failed. Trying again..." ) |
| 225 | pingResult = main.Mininet1.pingall() |
| 226 | passMsg += "on the second try" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 227 | utilities.assert_equals( expect=main.TRUE, |
| 228 | actual=pingResult, |
| 229 | onpass=passMsg, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 230 | onfail="Reactive Pingall failed, " + "one or more ping pairs failed" ) |