blob: 7c9905e86cb287e660a6753f3993510d6a21f48a [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"""
21
Jon Hall2c8959e2016-12-16 12:17:34 -080022# CASE1: Startup
23# CASE2: Load vpls topology and configurations from demo script
24# CASE3: Test CLI commands
25
Jon Halled258232017-05-24 17:30:18 -070026
Jon Hall2c8959e2016-12-16 12:17:34 -080027class VPLSBasic:
Jon Halled258232017-05-24 17:30:18 -070028
Jon Hall2c8959e2016-12-16 12:17:34 -080029 def __init__( self ):
30 self.default = ''
31
32 def CASE1( self, main ):
33 """
34 CASE1 is to compile ONOS and push it to the test machines
35
36 Startup sequence:
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-uninstall
41 start mininet
42 git pull
43 mvn clean install
44 onos-package
45 onos-install -f
46 onos-wait-for-start
47 start cli sessions
48 start tcpdump
49 """
50 import imp
51 import time
52 import json
Jon Hall2c8959e2016-12-16 12:17:34 -080053
Devin Lim58046fa2017-07-05 16:55:00 -070054 try:
55 from tests.dependencies.ONOSSetup import ONOSSetup
56 main.testSetUp = ONOSSetup()
57 except ImportError:
58 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070059 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070060 main.testSetUp.envSetupDescription()
61 stepResult = main.FALSE
62 try:
63 # load some variables from the params file
Jeremy Ronquillod7791d82017-08-14 16:23:08 +000064 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
65 main.sleep = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070066 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Jon Hall2c8959e2016-12-16 12:17:34 -080067
Devin Lim58046fa2017-07-05 16:55:00 -070068 ofPort = main.params[ 'CTRL' ][ 'port' ]
Devin Lim142b5342017-07-20 15:22:39 -070069 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070070 except Exception as e:
71 main.testSetUp.envSetupException( e )
72 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall2c8959e2016-12-16 12:17:34 -080073
Devin Lim142b5342017-07-20 15:22:39 -070074 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster,
Jeremy Ronquillod7791d82017-08-14 16:23:08 +000075 cellName=main.cellName )
Jon Hall2c8959e2016-12-16 12:17:34 -080076
Jon Hall2c8959e2016-12-16 12:17:34 -080077 main.step( "Starting Mininet" )
78 # scp topo file to mininet
79 # TODO: move to params?
80 topoName = "vpls"
81 topoFile = "vpls.py"
82 filePath = main.ONOSbench.home + "/tools/test/topos/"
83 main.ONOSbench.scp( main.Mininet1,
84 filePath + topoFile,
85 main.Mininet1.home,
86 direction="to" )
87 topo = " --custom " + main.Mininet1.home + topoFile + " --topo " + topoName
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -070088 args = " --switch ovs,protocols=OpenFlow13"
Devin Lim142b5342017-07-20 15:22:39 -070089 for ctrl in main.Cluster.active():
90 args += " --controller=remote,ip=" + ctrl.ipAddress
Jon Hall2c8959e2016-12-16 12:17:34 -080091 mnCmd = "sudo mn" + topo + args
92 mnResult = main.Mininet1.startNet( mnCmd=mnCmd )
93 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
94 onpass="Mininet Started",
95 onfail="Error starting Mininet" )
96
Jon Hall2c8959e2016-12-16 12:17:34 -080097
98 main.step( "Activate apps defined in the params file" )
99 # get data from the params
100 apps = main.params.get( 'apps' )
101 if apps:
Jon Halled258232017-05-24 17:30:18 -0700102 apps = apps.split( ',' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800103 main.log.warn( apps )
104 activateResult = True
105 for app in apps:
Devin Lim142b5342017-07-20 15:22:39 -0700106 main.Cluster.active( 0 ).CLI.app( app, "Activate" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800107 # TODO: check this worked
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000108 time.sleep( main.sleep ) # wait for apps to activate
Jon Hall2c8959e2016-12-16 12:17:34 -0800109 for app in apps:
Devin Lim142b5342017-07-20 15:22:39 -0700110 state = main.Cluster.active( 0 ).CLI.appStatus( app )
Jon Hall2c8959e2016-12-16 12:17:34 -0800111 if state == "ACTIVE":
Jon Hall937bc812017-01-31 16:44:10 -0800112 activateResult = activateResult and True
Jon Hall2c8959e2016-12-16 12:17:34 -0800113 else:
114 main.log.error( "{} is in {} state".format( app, state ) )
Jon Hall937bc812017-01-31 16:44:10 -0800115 activateResult = False
Jon Hall2c8959e2016-12-16 12:17:34 -0800116 utilities.assert_equals( expect=True,
117 actual=activateResult,
118 onpass="Successfully activated apps",
119 onfail="Failed to activate apps" )
120 else:
121 main.log.warn( "No apps were specified to be loaded after startup" )
122
123 main.step( "Set ONOS configurations" )
124 config = main.params.get( 'ONOS_Configuration' )
125 if config:
126 main.log.debug( config )
127 checkResult = main.TRUE
128 for component in config:
Jon Halled258232017-05-24 17:30:18 -0700129 for setting in config[ component ]:
130 value = config[ component ][ setting ]
Devin Lim142b5342017-07-20 15:22:39 -0700131 check = main.Cluster.active( 0 ).CLI.setCfg( component, setting, value )
Jon Hall2c8959e2016-12-16 12:17:34 -0800132 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
133 checkResult = check and checkResult
134 utilities.assert_equals( expect=main.TRUE,
135 actual=checkResult,
136 onpass="Successfully set config",
137 onfail="Failed to set config" )
138 else:
139 main.log.warn( "No configurations were specified to be changed after startup" )
140
141 main.step( "App Ids check" )
Devin Lim142b5342017-07-20 15:22:39 -0700142 appCheck = main.Cluster.command( "appToIDCheck", returnBool=True )
143 if appCheck != True:
144 main.log.warn( main.Cluster.active( 0 ).CLI.apps() )
145 main.log.warn( main.Cluster.active( 0 ).CLI.appIDs() )
146 utilities.assert_equals( expect=True, actual=appCheck,
Jon Hall2c8959e2016-12-16 12:17:34 -0800147 onpass="App Ids seem to be correct",
148 onfail="Something is wrong with app Ids" )
149
150 def CASE2( self, main ):
151 """
152 Load and test vpls configurations from json configuration file
153 """
154 import os.path
155 from tests.USECASE.VPLS.dependencies import vpls
156
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700157 main.vpls = vpls
Devin Lim142b5342017-07-20 15:22:39 -0700158 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Halled258232017-05-24 17:30:18 -0700159 hosts = int( main.params[ 'vpls' ][ 'hosts' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800160 main.step( "Discover hosts using pings" )
161 for i in range( 1, hosts + 1 ):
162 src = "h" + str( i )
163 for j in range( 1, hosts + 1 ):
164 if j == i:
165 continue
166 dst = "h" + str( j )
167 pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst )
168
169 main.step( "Load VPLS configurations" )
Jon Halled258232017-05-24 17:30:18 -0700170 fileName = main.params[ 'DEPENDENCY' ][ 'topology' ]
171 app = main.params[ 'vpls' ][ 'name' ]
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700172
Devin Lim142b5342017-07-20 15:22:39 -0700173 loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700174 utilities.assert_equals( expect=main.TRUE,
175 actual=loadVPLSResult,
176 onpass="Loaded vpls configuration.",
177 onfail="Failed to load vpls configuration." )
178
Jon Hall2c8959e2016-12-16 12:17:34 -0800179 # Time for netcfg to load data
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000180 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800181 # 'Master' copy of test configuration
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700182
Jon Hall2c8959e2016-12-16 12:17:34 -0800183 try:
184 with open( os.path.expanduser( fileName ) ) as dataFile:
185 originalCfg = json.load( dataFile )
Jon Halled258232017-05-24 17:30:18 -0700186 main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800187 except Exception as e:
188 main.log.error( "Error loading config file: {}".format( e ) )
189 if main.vplsConfig:
190 result = True
191 else:
192 result = False
193 utilities.assert_equals( expect=True,
194 actual=result,
195 onpass="Loaded vpls configuration",
196 onfail="Failed to load vpls configuration" )
197
198 main.step( "Check interface configurations" )
199 result = False
Devin Lim142b5342017-07-20 15:22:39 -0700200 getPorts = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700201 retValue=False,
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000202 kwargs={ "subjectClass" :"ports" },
203 sleep=main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800204 onosCfg = pprint( getPorts )
205 sentCfg = pprint( originalCfg.get( "ports" ) )
206
207 if onosCfg == sentCfg:
208 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
209 result = True
210 else:
211 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
212 main.log.debug( "ONOS config: {}".format( onosCfg ) )
213 main.log.debug( "Sent config: {}".format( sentCfg ) )
214 utilities.assert_equals( expect=True,
215 actual=result,
216 onpass="Net Cfg added for interfaces",
217 onfail="Net Cfg not added for interfaces" )
218
219 # Run a bunch of checks to verify functionality based on configs
220 vpls.verify( main )
221
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700222 main.step( "Loading vpls configuration in case any configuration was missed." )
Devin Lim142b5342017-07-20 15:22:39 -0700223 loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700224 utilities.assert_equals( expect=main.TRUE,
225 actual=loadVPLSResult,
226 onpass="Loaded vpls configuration.",
227 onfail="Failed to load vpls configuration." )
228
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000229 def CASE10( self, main ):
Jon Hall2c8959e2016-12-16 12:17:34 -0800230 """
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000231 Remove an interface from a vpls network
Jon Hall2c8959e2016-12-16 12:17:34 -0800232 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800233 main.step( "Remove an interface from a vpls network" )
Devin Lim142b5342017-07-20 15:22:39 -0700234 main.Cluster.active( 0 ).CLI.vplsRemIface( 'VPLS1', 'h1' )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000235 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800236 #update master config json
237 for network in main.vplsConfig:
238 if network.get( 'name' ) == 'VPLS1':
239 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700240 ifaces.remove( 'h1' )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000241 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800242
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000243
244 def CASE11( self, main ):
245 """
246 Clean all VPLS configurations
247 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800248 main.step( "Clean all vpls configurations" )
Devin Lim142b5342017-07-20 15:22:39 -0700249 main.Cluster.active( 0 ).CLI.vplsClean()
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000250 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800251 main.vplsConfig = []
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000252 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800253
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000254
255 def CASE12( self, main ):
256 """
257 Create a new VPLS network.
258 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800259 main.step( "Create a new vpls network" )
260 name = "Network1"
Devin Lim142b5342017-07-20 15:22:39 -0700261 main.Cluster.active( 0 ).CLI.vplsCreate( name )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000262 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800263 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
264 main.vplsConfig.append( network1 )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000265 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800266
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000267
268 def CASE13( self, main ):
269 """
270 Add interfaces to the new VPLS network.
271 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800272 main.step( "Add interfaces to the network" )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000273 utilities.retry( f=main.Cluster.active( 0 ).CLI.vplsAddIface,
274 retValue=main.FALSE,
275 args=( name, "h1" ),
276 sleep=main.sleep )
277 utilities.retry( f=main.Cluster.active( 0 ).CLI.vplsAddIface,
278 retValue=main.FALSE,
279 args=( name, "h5" ),
280 sleep=main.sleep )
281 utilities.retry( f=main.Cluster.active( 0 ).CLI.vplsAddIface,
282 retValue=main.FALSE,
283 args=( name, "h4" ),
284 sleep=main.sleep )
285 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800286 for network in main.vplsConfig:
287 if network.get( 'name' ) == name:
288 ifaces = network.get( 'interfaces' )
289 ifaces.append( 'h1' )
290 ifaces.append( 'h4' )
291 ifaces.append( 'h5' )
292 network[ 'interfaces' ] = ifaces
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000293 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800294
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000295
296 def CASE14( self, main ):
297 """
298 Add MPLS encapsulation.
299 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800300 main.step( "Add MPLS encapsulation to a vpls network" )
301 encapType = "MPLS"
Devin Lim142b5342017-07-20 15:22:39 -0700302 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800303 for network in main.vplsConfig:
304 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700305 network[ 'encapsulation' ] = encapType
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000306 time.sleep( main.sleep )
307 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800308
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000309
310 def CASE15( self, main ):
311 """
312 Change an encapsulation type.
313 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800314 main.step( "Change an encapsulation type" )
315 encapType = "VLAN"
Devin Lim142b5342017-07-20 15:22:39 -0700316 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800317 for network in main.vplsConfig:
318 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700319 network[ 'encapsulation' ] = encapType
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000320 time.sleep( main.sleep )
321 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800322
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000323
324 def CASE16( self, main ):
325 """
326 Remove encapsulation.
327 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800328 main.step( "Remove encapsulation" )
329 encapType = "NONE"
Devin Lim142b5342017-07-20 15:22:39 -0700330 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800331 for network in main.vplsConfig:
332 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700333 network[ 'encapsulation' ] = encapType
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000334 time.sleep( main.sleep )
335 main.vpls.verify( main )