blob: c940bde242beca02056a46531ecdd7ffa32b0bad [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 """
You Wang09b596b2018-01-10 10:42:38 -080037 from tests.dependencies.ONOSSetup import ONOSSetup
38 main.testSetUp = ONOSSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070039 main.testSetUp.gitPulling()
suibin zhang116647a2016-05-06 16:30:09 -070040
41 def CASE1( self, main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070042 """
suibin zhang116647a2016-05-06 16:30:09 -070043 Set up global test variables;
44 Uninstall all running cells in test env defined in .topo file
45
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070046 """
Devin Lim58046fa2017-07-05 16:55:00 -070047 main.testSetUp.envSetupDescription()
48 stepResult = main.FALSE
49 try:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070050 main.onosStartupSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'onosStartup' ] )
51 main.onosCfgSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'onosCfg' ] )
52 main.mnStartupSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'mnStartup' ] )
53 main.mnCfgSleep = float( main.params[ 'CASE1' ][ 'SleepTimers' ][ 'mnCfg' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070054 stepResult = main.testSetUp.envSetup( includeGitPull=False )
55 except Exception as e:
56 main.testSetUp.envSetupException( e )
57 main.testSetUp.evnSetupConclusion( stepResult )
suibin zhang116647a2016-05-06 16:30:09 -070058
suibin zhang116647a2016-05-06 16:30:09 -070059 def CASE2( self, main ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070060 """
suibin zhang116647a2016-05-06 16:30:09 -070061 Report errors/warnings/exceptions
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070062 """
63 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -070064 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
suibin zhang116647a2016-05-06 16:30:09 -070065 [ "INFO",
66 "FOLLOWER",
67 "WARN",
68 "flow",
69 "ERROR",
70 "Except" ],
71 "s" )
72
73 def CASE10( self, main ):
74 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070075 Start ONOS cluster ( 1 node in this example ) in three steps:
76 1 ) start a basic cluster with drivers app via ONOSDriver;
77 2 ) activate apps via ONOSCliDriver;
78 3 ) configure onos via ONOSCliDriver;
suibin zhang116647a2016-05-06 16:30:09 -070079 """
suibin zhang116647a2016-05-06 16:30:09 -070080 import time
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070081 main.case( "Start up " + str( main.Cluster.numCtrls ) + "-node onos cluster." )
82 main.step( "Start ONOS cluster with basic (drivers) app." )
You Wang09b596b2018-01-10 10:42:38 -080083 stepResult = main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster )
suibin zhang116647a2016-05-06 16:30:09 -070084 utilities.assert_equals( expect=main.TRUE,
85 actual=stepResult,
86 onpass="Successfully started basic ONOS cluster ",
87 onfail="Failed to start basic ONOS Cluster " )
88
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070089 main.step( "Activate onos apps." )
90 main.apps = main.params[ 'CASE10' ].get( 'Apps' )
Devin Lim58046fa2017-07-05 16:55:00 -070091 if main.apps:
92 main.log.info( "Apps to activate: " + main.apps )
suibin zhang116647a2016-05-06 16:30:09 -070093 activateResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070094 for a in main.apps.split( "," ):
Devin Lim142b5342017-07-20 15:22:39 -070095 activateResult = activateResult & main.Cluster.active( 0 ).CLI.activateApp( a )
suibin zhang116647a2016-05-06 16:30:09 -070096 # TODO: check this worked
97 time.sleep( main.onosCfgSleep ) # wait for apps to activate
98 else:
99 main.log.warn( "No configurations were specified to be changed after startup" )
100 utilities.assert_equals( expect=main.TRUE,
Devin Lim142b5342017-07-20 15:22:39 -0700101 actual=activateResult,
102 onpass="Successfully set config",
103 onfail="Failed to set config" )
suibin zhang116647a2016-05-06 16:30:09 -0700104
105 main.step( "Set ONOS configurations" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700106 config = main.params[ 'CASE10' ].get( 'ONOS_Configuration' )
suibin zhang116647a2016-05-06 16:30:09 -0700107 if config:
108 main.log.debug( config )
109 checkResult = main.TRUE
110 for component in config:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700111 for setting in config[ component ]:
112 value = config[ component ][ setting ]
Devin Lim142b5342017-07-20 15:22:39 -0700113 check = main.Cluster.active( 0 ).CLI.setCfg( component, setting, value )
suibin zhang116647a2016-05-06 16:30:09 -0700114 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
115 checkResult = check and checkResult
116 utilities.assert_equals( expect=main.TRUE,
117 actual=checkResult,
118 onpass="Successfully set config",
119 onfail="Failed to set config" )
120 else:
121 main.log.warn( "No configurations were specified to be changed after startup" )
122
123 def CASE11( self, main ):
124 """
125 Start mininet and assign controllers
126 """
127 import time
128
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700129 topology = main.params[ 'CASE11' ][ 'topo' ]
suibin zhang116647a2016-05-06 16:30:09 -0700130 main.log.report( "Start Mininet topology" )
Jon Hall6509dbf2016-06-21 17:01:17 -0700131 main.case( "Start Mininet topology" )
suibin zhang116647a2016-05-06 16:30:09 -0700132
133 main.step( "Starting Mininet Topology" )
alison12f34c32016-06-10 14:39:21 -0700134 topoResult = main.Mininet1.startNet( mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700135 stepResult = topoResult
136 utilities.assert_equals( expect=main.TRUE,
137 actual=stepResult,
138 onpass="Successfully loaded topology",
139 onfail="Failed to load topology" )
140 # Exit if topology did not load properly
141 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700142 main.cleanAndExit()
suibin zhang116647a2016-05-06 16:30:09 -0700143
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700144 main.step( "Assign switches to controllers." )
suibin zhang116647a2016-05-06 16:30:09 -0700145 assignResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700146 for i in range( 1, 8 ):
Devin Lim142b5342017-07-20 15:22:39 -0700147 assignResult = assignResult & \
148 main.Mininet1.assignSwController( sw="s" + str( i ),
149 ip=main.Cluster.getIps(),
150 port='6653' )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700151 time.sleep( main.mnCfgSleep )
suibin zhang116647a2016-05-06 16:30:09 -0700152 utilities.assert_equals( expect=main.TRUE,
153 actual=stepResult,
154 onpass="Successfully assign switches to controllers",
155 onfail="Failed to assign switches to controllers" )
156
suibin zhang116647a2016-05-06 16:30:09 -0700157 def CASE12( self, main ):
158 """
159 Tests using through ONOS CLI handles
160 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700161 main.case( "Test some onos commands through CLI. " )
162 main.log.debug( main.Cluster.active( 0 ).CLI.sendline( "summary" ) )
163 main.log.debug( main.Cluster.active( 0 ).CLI.sendline( "devices" ) )
suibin zhang116647a2016-05-06 16:30:09 -0700164
165 def CASE22( self, main ):
166 """
167 Tests using ONOS REST API handles
168 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700169 main.case( " Sample tests using ONOS REST API handles. " )
170 main.log.debug( main.Cluster.active( 0 ).REST.send( "/devices" ) )
Devin Lim142b5342017-07-20 15:22:39 -0700171 main.log.debug( main.Cluster.active( 0 ).REST.apps() )
alison12f34c32016-06-10 14:39:21 -0700172
173 def CASE32( self, main ):
174 """
175 Configure fwd app from .param json string with parameter configured.
176 Check if configuration successful
177 Run pingall to check connectivity
178 Check ONOS log for warning/error/exceptions
179 """
180 main.case( "Configure onos-app-fwd and check if configuration successful. " )
181 main.step( "Install reactive forwarding app." )
Devin Lim142b5342017-07-20 15:22:39 -0700182 installResults = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
183 utilities.assert_equals( expect=main.TRUE,
184 actual=installResults,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700185 onpass="Configure fwd successful",
Devin Lim142b5342017-07-20 15:22:39 -0700186 onfail="Configure fwd failed" )
alison12f34c32016-06-10 14:39:21 -0700187 main.step( "Run pingall to check connectivity. " )
188 pingResult = main.FALSE
189 passMsg = "Reactive Pingall test passed"
190 pingResult = main.Mininet1.pingall()
191 if not pingResult:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700192 main.log.warn( "First pingall failed. Trying again..." )
193 pingResult = main.Mininet1.pingall()
194 passMsg += "on the second try"
Devin Lim142b5342017-07-20 15:22:39 -0700195 utilities.assert_equals( expect=main.TRUE,
196 actual=pingResult,
197 onpass=passMsg,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700198 onfail="Reactive Pingall failed, " + "one or more ping pairs failed." )