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