blob: 37020b3a2161d6fa70d68da6b765a4401cfd4bfa [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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 Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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 zhang116647a2016-05-06 16:30:09 -070021# 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 Ronquillo23fb2162017-09-15 14:59:57 -070024
alison12f34c32016-06-10 14:39:21 -070025class SAMPstartTemplate_1node:
suibin zhang116647a2016-05-06 16:30:09 -070026
27 def __init__( self ):
28 self.default = ''
29
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070030 def CASE0( self, main ):
31 """
alison12f34c32016-06-10 14:39:21 -070032 Pull specific ONOS branch, then Build ONOS on ONOS Bench.
suibin zhang116647a2016-05-06 16:30:09 -070033 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 Ronquillo23fb2162017-09-15 14:59:57 -070036 """
Devin Lim58046fa2017-07-05 16:55:00 -070037 try:
38 from tests.dependencies.ONOSSetup import ONOSSetup
39 except ImportError:
40 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070041 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070042 try:
43 main.testSetUp
44 except ( NameError, AttributeError ):
45 main.testSetUp = ONOSSetup()
46 main.testSetUp.gitPulling()
suibin zhang116647a2016-05-06 16:30:09 -070047
48 def CASE1( self, main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070049 """
suibin zhang116647a2016-05-06 16:30:09 -070050 Set up global test variables;
51 Uninstall all running cells in test env defined in .topo file
52
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070053 """
Devin Lim58046fa2017-07-05 16:55:00 -070054 try:
55 from tests.dependencies.ONOSSetup import ONOSSetup
56 except ImportError:
57 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070058 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070059 try:
60 main.testSetUp
61 except ( NameError, AttributeError ):
62 main.testSetUp = ONOSSetup()
suibin zhang116647a2016-05-06 16:30:09 -070063
Devin Lim58046fa2017-07-05 16:55:00 -070064 main.testSetUp.envSetupDescription()
65 stepResult = main.FALSE
66 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070067 main.onosStartupSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'onosStartup' ] )
68 main.onosCfgSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'onosCfg' ] )
69 main.mnStartupSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'mnStartup' ] )
70 main.mnCfgSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'mnCfg' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070071 stepResult = main.testSetUp.envSetup( includeGitPull=False )
72 except Exception as e:
73 main.testSetUp.envSetupException( e )
74 main.testSetUp.evnSetupConclusion( stepResult )
suibin zhang116647a2016-05-06 16:30:09 -070075
suibin zhang116647a2016-05-06 16:30:09 -070076 def CASE2( self, main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070077 """
suibin zhang116647a2016-05-06 16:30:09 -070078 Report errors/warnings/exceptions
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070079 """
80 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -070081 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
suibin zhang116647a2016-05-06 16:30:09 -070082 [ "INFO",
83 "FOLLOWER",
84 "WARN",
85 "flow",
86 "ERROR",
87 "Except" ],
88 "s" )
89
90 def CASE10( self, main ):
91 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070092 Start ONOS cluster ( 1 node in this example ) in three steps:
93 1 ) start a basic cluster with drivers app via ONOSDriver;
94 2 ) activate apps via ONOSCliDriver;
95 3 ) configure onos via ONOSCliDriver;
suibin zhang116647a2016-05-06 16:30:09 -070096 """
suibin zhang116647a2016-05-06 16:30:09 -070097 import time
Devin Lim58046fa2017-07-05 16:55:00 -070098 try:
99 from tests.dependencies.ONOSSetup import ONOSSetup
100 except ImportError:
101 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700102 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700103 try:
104 main.testSetUp
105 except ( NameError, AttributeError ):
106 main.testSetUp = ONOSSetup()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700107 main.case( "Start up " + str( main.Cluster.numCtrls ) + "-node onos cluster." )
108 main.step( "Start ONOS cluster with basic (drivers) app." )
Devin Lim142b5342017-07-20 15:22:39 -0700109 stepResult = main.ONOSbench.startBasicONOS( nodeList=main.Cluster.getIps(),
110 opSleep=200,
111 onosUser=main.ONOScell.karafUser )
suibin zhang116647a2016-05-06 16:30:09 -0700112 utilities.assert_equals( expect=main.TRUE,
113 actual=stepResult,
114 onpass="Successfully started basic ONOS cluster ",
115 onfail="Failed to start basic ONOS Cluster " )
116
Devin Lim142b5342017-07-20 15:22:39 -0700117 main.testSetUp.startOnosClis( main.Cluster )
suibin zhang116647a2016-05-06 16:30:09 -0700118
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700119 main.step( "Activate onos apps." )
120 main.apps = main.params[ 'CASE10' ].get( 'Apps' )
Devin Lim58046fa2017-07-05 16:55:00 -0700121 if main.apps:
122 main.log.info( "Apps to activate: " + main.apps )
suibin zhang116647a2016-05-06 16:30:09 -0700123 activateResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700124 for a in main.apps.split( "," ):
Devin Lim142b5342017-07-20 15:22:39 -0700125 activateResult = activateResult & main.Cluster.active( 0 ).CLI.activateApp( a )
suibin zhang116647a2016-05-06 16:30:09 -0700126 # TODO: check this worked
127 time.sleep( main.onosCfgSleep ) # wait for apps to activate
128 else:
129 main.log.warn( "No configurations were specified to be changed after startup" )
130 utilities.assert_equals( expect=main.TRUE,
Devin Lim142b5342017-07-20 15:22:39 -0700131 actual=activateResult,
132 onpass="Successfully set config",
133 onfail="Failed to set config" )
suibin zhang116647a2016-05-06 16:30:09 -0700134
135 main.step( "Set ONOS configurations" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700136 config = main.params[ 'CASE10' ].get( 'ONOS_Configuration' )
suibin zhang116647a2016-05-06 16:30:09 -0700137 if config:
138 main.log.debug( config )
139 checkResult = main.TRUE
140 for component in config:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700141 for setting in config[ component ]:
142 value = config[ component ][ setting ]
Devin Lim142b5342017-07-20 15:22:39 -0700143 check = main.Cluster.active( 0 ).CLI.setCfg( component, setting, value )
suibin zhang116647a2016-05-06 16:30:09 -0700144 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
145 checkResult = check and checkResult
146 utilities.assert_equals( expect=main.TRUE,
147 actual=checkResult,
148 onpass="Successfully set config",
149 onfail="Failed to set config" )
150 else:
151 main.log.warn( "No configurations were specified to be changed after startup" )
152
153 def CASE11( self, main ):
154 """
155 Start mininet and assign controllers
156 """
157 import time
158
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700159 topology = main.params[ 'CASE11' ][ 'topo' ]
suibin zhang116647a2016-05-06 16:30:09 -0700160 main.log.report( "Start Mininet topology" )
Jon Hall6509dbf2016-06-21 17:01:17 -0700161 main.case( "Start Mininet topology" )
suibin zhang116647a2016-05-06 16:30:09 -0700162
163 main.step( "Starting Mininet Topology" )
alison12f34c32016-06-10 14:39:21 -0700164 topoResult = main.Mininet1.startNet( mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700165 stepResult = topoResult
166 utilities.assert_equals( expect=main.TRUE,
167 actual=stepResult,
168 onpass="Successfully loaded topology",
169 onfail="Failed to load topology" )
170 # Exit if topology did not load properly
171 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700172 main.cleanAndExit()
suibin zhang116647a2016-05-06 16:30:09 -0700173
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700174 main.step( "Assign switches to controllers." )
suibin zhang116647a2016-05-06 16:30:09 -0700175 assignResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700176 for i in range( 1, 8 ):
Devin Lim142b5342017-07-20 15:22:39 -0700177 assignResult = assignResult & \
178 main.Mininet1.assignSwController( sw="s" + str( i ),
179 ip=main.Cluster.getIps(),
180 port='6653' )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700181 time.sleep( main.mnCfgSleep )
suibin zhang116647a2016-05-06 16:30:09 -0700182 utilities.assert_equals( expect=main.TRUE,
183 actual=stepResult,
184 onpass="Successfully assign switches to controllers",
185 onfail="Failed to assign switches to controllers" )
186
suibin zhang116647a2016-05-06 16:30:09 -0700187 def CASE12( self, main ):
188 """
189 Tests using through ONOS CLI handles
190 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700191 main.case( "Test some onos commands through CLI. " )
192 main.log.debug( main.Cluster.active( 0 ).CLI.sendline( "summary" ) )
193 main.log.debug( main.Cluster.active( 0 ).CLI.sendline( "devices" ) )
suibin zhang116647a2016-05-06 16:30:09 -0700194
195 def CASE22( self, main ):
196 """
197 Tests using ONOS REST API handles
198 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700199 main.case( " Sample tests using ONOS REST API handles. " )
200 main.log.debug( main.Cluster.active( 0 ).REST.send( "/devices" ) )
Devin Lim142b5342017-07-20 15:22:39 -0700201 main.log.debug( main.Cluster.active( 0 ).REST.apps() )
alison12f34c32016-06-10 14:39:21 -0700202
203 def CASE32( self, main ):
204 """
205 Configure fwd app from .param json string with parameter configured.
206 Check if configuration successful
207 Run pingall to check connectivity
208 Check ONOS log for warning/error/exceptions
209 """
210 main.case( "Configure onos-app-fwd and check if configuration successful. " )
211 main.step( "Install reactive forwarding app." )
Devin Lim142b5342017-07-20 15:22:39 -0700212 installResults = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
213 utilities.assert_equals( expect=main.TRUE,
214 actual=installResults,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700215 onpass="Configure fwd successful",
Devin Lim142b5342017-07-20 15:22:39 -0700216 onfail="Configure fwd failed" )
alison12f34c32016-06-10 14:39:21 -0700217 main.step( "Run pingall to check connectivity. " )
218 pingResult = main.FALSE
219 passMsg = "Reactive Pingall test passed"
220 pingResult = main.Mininet1.pingall()
221 if not pingResult:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700222 main.log.warn( "First pingall failed. Trying again..." )
223 pingResult = main.Mininet1.pingall()
224 passMsg += "on the second try"
Devin Lim142b5342017-07-20 15:22:39 -0700225 utilities.assert_equals( expect=main.TRUE,
226 actual=pingResult,
227 onpass=passMsg,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700228 onfail="Reactive Pingall failed, " + "one or more ping pairs failed." )