blob: 80994b8ab9e85e1176b524aeb156205c2a1eff96 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 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_3node:
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
suibin zhang116647a2016-05-06 16:30:09 -070041 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" )
64 main.ONOSbench.logReport( main.Cluster.runningNodes[ 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 ( 3 nodes 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
81
Devin Lim142b5342017-07-20 15:22:39 -070082 main.case( "Start up " + str( main.Cluster.numCtrls ) + "-node onos cluster." )
Jon Hallca319892017-06-15 15:25:22 -070083
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070084 main.step( "Start ONOS cluster with basic (drivers) app." )
You Wang09b596b2018-01-10 10:42:38 -080085 stepResult = main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster )
suibin zhang116647a2016-05-06 16:30:09 -070086 utilities.assert_equals( expect=main.TRUE,
87 actual=stepResult,
88 onpass="Successfully started basic ONOS cluster ",
89 onfail="Failed to start basic ONOS Cluster " )
90
Devin Lim1abeb442017-12-30 12:17:38 -080091 main.testSetUp.startOnosClis( main.Cluster )
suibin zhang116647a2016-05-06 16:30:09 -070092
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070093 main.step( "Activate onos apps." )
94 main.apps = main.params[ 'CASE10' ].get( 'Apps' )
Devin Lim58046fa2017-07-05 16:55:00 -070095 if main.apps:
96 main.log.info( "Apps to activate: " + main.apps )
suibin zhang116647a2016-05-06 16:30:09 -070097 activateResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070098 for a in main.apps.split( "," ):
99 activateResult = activateResult & main.Cluster.active( 0 ).CLI.activateApp( a )
suibin zhang116647a2016-05-06 16:30:09 -0700100 # TODO: check this worked
101 time.sleep( main.onosCfgSleep ) # wait for apps to activate
102 else:
103 main.log.warn( "No configurations were specified to be changed after startup" )
104 utilities.assert_equals( expect=main.TRUE,
Jon Hallca319892017-06-15 15:25:22 -0700105 actual=activateResult,
106 onpass="Successfully set config",
107 onfail="Failed to set config" )
suibin zhang116647a2016-05-06 16:30:09 -0700108
109 main.step( "Set ONOS configurations" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700110 config = main.params[ 'CASE10' ].get( 'ONOS_Configuration' )
suibin zhang116647a2016-05-06 16:30:09 -0700111 if config:
112 main.log.debug( config )
113 checkResult = main.TRUE
114 for component in config:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700115 for setting in config[ component ]:
116 value = config[ component ][ setting ]
117 check = main.Cluster.runningNodes[ 0 ].setCfg( component, setting, value )
suibin zhang116647a2016-05-06 16:30:09 -0700118 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
119 checkResult = check and checkResult
120 utilities.assert_equals( expect=main.TRUE,
121 actual=checkResult,
122 onpass="Successfully set config",
123 onfail="Failed to set config" )
124 else:
125 main.log.warn( "No configurations were specified to be changed after startup" )
126
127 def CASE11( self, main ):
128 """
129 Start mininet and assign controllers
130 """
131 import time
132
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700133 topology = main.params[ 'CASE11' ][ 'topo' ]
suibin zhang116647a2016-05-06 16:30:09 -0700134 main.log.report( "Start Mininet topology" )
Jon Hall6509dbf2016-06-21 17:01:17 -0700135 main.case( "Start Mininet topology" )
suibin zhang116647a2016-05-06 16:30:09 -0700136
137 main.step( "Starting Mininet Topology" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700138 topoResult = main.Mininet1.startNet( mnCmd=topology )
suibin zhang116647a2016-05-06 16:30:09 -0700139 stepResult = topoResult
140 utilities.assert_equals( expect=main.TRUE,
141 actual=stepResult,
142 onpass="Successfully loaded topology",
143 onfail="Failed to load topology" )
144 # Exit if topology did not load properly
145 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700146 main.cleanAndExit()
suibin zhang116647a2016-05-06 16:30:09 -0700147
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700148 main.step( "Assign switches to controllers." )
suibin zhang116647a2016-05-06 16:30:09 -0700149 assignResult = main.TRUE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700150 for i in range( 1, 8 ):
suibin zhang116647a2016-05-06 16:30:09 -0700151 assignResult = assignResult & main.Mininet1.assignSwController( sw="s" + str( i ),
Jon Hallca319892017-06-15 15:25:22 -0700152 ip=main.Cluster.getIps(),
153 port='6653' )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700154 time.sleep( main.mnCfgSleep )
suibin zhang116647a2016-05-06 16:30:09 -0700155 utilities.assert_equals( expect=main.TRUE,
156 actual=stepResult,
157 onpass="Successfully assign switches to controllers",
158 onfail="Failed to assign switches to controllers" )
159
suibin zhang116647a2016-05-06 16:30:09 -0700160 def CASE12( self, main ):
161 """
162 Tests using through ONOS CLI handles
163 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700164 main.case( "Test some onos commands through CLI. " )
Devin Lim142b5342017-07-20 15:22:39 -0700165 main.log.debug( main.Cluster.active( 0 ).CLI.sendline( "summary" ) )
166 main.log.debug( main.Cluster.active( 1 ).CLI.sendline( "devices" ) )
suibin zhang116647a2016-05-06 16:30:09 -0700167
168 def CASE22( self, main ):
169 """
170 Tests using ONOS REST API handles
171 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700172 main.case( " Sample tests using ONOS REST API handles. " )
Devin Lim142b5342017-07-20 15:22:39 -0700173 main.log.debug( main.Cluster.active( 0 ).REST.send( "/devices" ) )
174 main.log.debug( main.Cluster.active( 2 ).REST.apps() )
alison12f34c32016-06-10 14:39:21 -0700175
176 def CASE32( self, main ):
177 """
178 Configure fwd app from .params json string with parameter configured
179 Check if configuration successful
180 Run pingall to check connectivity
181 Check ONOS log for warning/error/exceptions
182 """
183 main.case( "Configure onos-app-fwd and check if configuration successful. " )
184 main.step( "Install reactive forwarding app." )
Devin Lim142b5342017-07-20 15:22:39 -0700185 installResults = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
186 utilities.assert_equals( expect=main.TRUE,
187 actual=installResults,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700188 onpass="Configure fwd successful",
189 onfail="Configure fwd failed" )
alison12f34c32016-06-10 14:39:21 -0700190 main.step( "Run pingall to check connectivity. " )
191 pingResult = main.FALSE
192 passMsg = "Reactive Pingall test passed"
193 pingResult = main.Mininet1.pingall()
194 if not pingResult:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700195 main.log.warn( "First pingall failed. Trying again..." )
196 pingResult = main.Mininet1.pingall()
197 passMsg += "on the second try"
Devin Lim142b5342017-07-20 15:22:39 -0700198 utilities.assert_equals( expect=main.TRUE,
199 actual=pingResult,
200 onpass=passMsg,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700201 onfail="Reactive Pingall failed, " + "one or more ping pairs failed" )