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