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