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