blob: ac5e8b5df72ad4adc2a1cceb5a1234da100a2fe3 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2016 Open Networking Foundation (ONF)
3
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
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 zhang116647a2016-05-06 16:30:09 -070021
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
alison12f34c32016-06-10 14:39:21 -070025class SAMPstartTemplate_3node:
suibin zhang116647a2016-05-06 16:30:09 -070026
27 def __init__( self ):
28 self.default = ''
29
30
31 def CASE0(self, main):
32 '''
alison12f34c32016-06-10 14:39:21 -070033 Pull specific ONOS branch, then Build ONOS on ONOS Bench.
suibin zhang116647a2016-05-06 16:30:09 -070034 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 Lim58046fa2017-07-05 16:55:00 -070038 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 zhang116647a2016-05-06 16:30:09 -070047
Devin Lim58046fa2017-07-05 16:55:00 -070048 main.testSetUp.gitPulling()
suibin zhang116647a2016-05-06 16:30:09 -070049
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 Lim58046fa2017-07-05 16:55:00 -070057 try:
58 from tests.dependencies.ONOSSetup import ONOSSetup
Jon Hallca319892017-06-15 15:25:22 -070059 from dependencies.Cluster import Cluster
Devin Lim58046fa2017-07-05 16:55:00 -070060 except ImportError:
61 main.log.error( "ONOSSetup not found. exiting the test" )
62 main.exit()
63 try:
Jon Hallca319892017-06-15 15:25:22 -070064 main.Cluster = Cluster( main.ONOScell.nodes )
Devin Lim58046fa2017-07-05 16:55:00 -070065 main.testSetUp
66 except ( NameError, AttributeError ):
67 main.testSetUp = ONOSSetup()
suibin zhang116647a2016-05-06 16:30:09 -070068
Devin Lim58046fa2017-07-05 16:55:00 -070069 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 zhang116647a2016-05-06 16:30:09 -070082
suibin zhang116647a2016-05-06 16:30:09 -070083
Jon Hallca319892017-06-15 15:25:22 -070084
suibin zhang116647a2016-05-06 16:30:09 -070085 def CASE2( self, main ):
86 '''
87 Report errors/warnings/exceptions
88 '''
89 main.log.info("Error report: \n" )
Jon Hallca319892017-06-15 15:25:22 -070090 ONOSbench = main.ONOScell.nodes[0].Bench
91 ONOSbench.logReport( main.Cluster.controllers[0].ipAddress,
suibin zhang116647a2016-05-06 16:30:09 -070092 [ "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 Lim58046fa2017-07-05 16:55:00 -0700107 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 zhang116647a2016-05-06 16:30:09 -0700116
117 import time
118
Jon Hallca319892017-06-15 15:25:22 -0700119 size = len( main.Cluster.controllers )
120 main.case( "Start up " + str( size ) + "-node onos cluster." )
121
suibin zhang116647a2016-05-06 16:30:09 -0700122 main.step( "Start ONOS cluster with basic (drivers) app.")
Jon Hallca319892017-06-15 15:25:22 -0700123 stepResult = ONOSbench.startBasicONOS( nodeList=main.Cluster.getIps(), opSleep=200,
124 onosUser=main.ONOScell.karafUser )
suibin zhang116647a2016-05-06 16:30:09 -0700125 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 Lim58046fa2017-07-05 16:55:00 -0700130 main.testSetUp.startOnosClis()
suibin zhang116647a2016-05-06 16:30:09 -0700131
132 main.step( "Activate onos apps.")
Devin Lim58046fa2017-07-05 16:55:00 -0700133 main.apps = main.params['CASE10'].get( 'Apps' )
134 if main.apps:
135 main.log.info( "Apps to activate: " + main.apps )
suibin zhang116647a2016-05-06 16:30:09 -0700136 activateResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700137 for a in main.apps.split(","):
suibin zhang116647a2016-05-06 16:30:09 -0700138 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 Hallca319892017-06-15 15:25:22 -0700144 actual=activateResult,
145 onpass="Successfully set config",
146 onfail="Failed to set config" )
suibin zhang116647a2016-05-06 16:30:09 -0700147
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 Hallca319892017-06-15 15:25:22 -0700156 check = main.Cluster.controllers[0].setCfg( component, setting, value )
suibin zhang116647a2016-05-06 16:30:09 -0700157 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 zhang116647a2016-05-06 16:30:09 -0700172 topology = main.params['CASE11']['topo']
173 main.log.report( "Start Mininet topology" )
Jon Hall6509dbf2016-06-21 17:01:17 -0700174 main.case( "Start Mininet topology" )
suibin zhang116647a2016-05-06 16:30:09 -0700175
176 main.step( "Starting Mininet Topology" )
alison12f34c32016-06-10 14:39:21 -0700177 topoResult = main.Mininet1.startNet(mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700178 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 zhang116647a2016-05-06 16:30:09 -0700190 for i in range(1, 8):
191 assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ),
Jon Hallca319892017-06-15 15:25:22 -0700192 ip=main.Cluster.getIps(),
193 port='6653' )
suibin zhang116647a2016-05-06 16:30:09 -0700194 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 Hall6509dbf2016-06-21 17:01:17 -0700206 main.case( "Test some onos commands through CLI. ")
Jon Hallca319892017-06-15 15:25:22 -0700207 main.log.debug( main.Cluster.controllers[1].sendline("summary") )
208 main.log.debug( main.Cluster.controllers[2].sendline("devices") )
suibin zhang116647a2016-05-06 16:30:09 -0700209
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 Hallca319892017-06-15 15:25:22 -0700216 main.log.debug( main.Cluster.controllers[2].send("/devices") )
217 main.log.debug( main.Cluster.controllers[-1].apps() )
alison12f34c32016-06-10 14:39:21 -0700218
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 Hallca319892017-06-15 15:25:22 -0700228 installResults = main.Cluster.controllers[0].activateApp( "org.onosproject.fwd" )
alison12f34c32016-06-10 14:39:21 -0700229 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" )