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