blob: 4f8d159f61681e1821d86aefdb0306ef8dda41e7 [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"""
Jon Hall2c8959e2016-12-16 12:17:34 -080021# CASE1: Startup
22# CASE2: Load vpls topology and configurations from demo script
23# CASE3: Test CLI commands
24
Jon Halled258232017-05-24 17:30:18 -070025
Jon Hall2c8959e2016-12-16 12:17:34 -080026class VPLSBasic:
Jon Halled258232017-05-24 17:30:18 -070027
Jon Hall2c8959e2016-12-16 12:17:34 -080028 def __init__( self ):
29 self.default = ''
30
31 def CASE1( self, main ):
32 """
33 CASE1 is to compile ONOS and push it to the test machines
34
35 Startup sequence:
36 cell <name>
37 onos-verify-cell
38 NOTE: temporary - onos-remove-raft-logs
39 onos-uninstall
40 start mininet
41 git pull
42 mvn clean install
43 onos-package
44 onos-install -f
45 onos-wait-for-start
46 start cli sessions
47 start tcpdump
48 """
49 import imp
50 import time
51 import json
Jon Hall2c8959e2016-12-16 12:17:34 -080052
Devin Lim58046fa2017-07-05 16:55:00 -070053 try:
54 from tests.dependencies.ONOSSetup import ONOSSetup
55 main.testSetUp = 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 main.testSetUp.envSetupDescription()
60 stepResult = main.FALSE
61 try:
62 # load some variables from the params file
Jeremy Ronquillod7791d82017-08-14 16:23:08 +000063 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
64 main.sleep = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070065 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Jon Hall2c8959e2016-12-16 12:17:34 -080066
Devin Lim58046fa2017-07-05 16:55:00 -070067 ofPort = main.params[ 'CTRL' ][ 'port' ]
Devin Lim142b5342017-07-20 15:22:39 -070068 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070069 except Exception as e:
70 main.testSetUp.envSetupException( e )
71 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall2c8959e2016-12-16 12:17:34 -080072
Devin Lim142b5342017-07-20 15:22:39 -070073 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster,
Jeremy Ronquillod7791d82017-08-14 16:23:08 +000074 cellName=main.cellName )
Jon Hall2c8959e2016-12-16 12:17:34 -080075
Jon Hall2c8959e2016-12-16 12:17:34 -080076 main.step( "Starting Mininet" )
77 # scp topo file to mininet
78 # TODO: move to params?
79 topoName = "vpls"
80 topoFile = "vpls.py"
81 filePath = main.ONOSbench.home + "/tools/test/topos/"
82 main.ONOSbench.scp( main.Mininet1,
83 filePath + topoFile,
84 main.Mininet1.home,
85 direction="to" )
86 topo = " --custom " + main.Mininet1.home + topoFile + " --topo " + topoName
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -070087 args = " --switch ovs,protocols=OpenFlow13"
Devin Lim142b5342017-07-20 15:22:39 -070088 for ctrl in main.Cluster.active():
89 args += " --controller=remote,ip=" + ctrl.ipAddress
Jon Hall2c8959e2016-12-16 12:17:34 -080090 mnCmd = "sudo mn" + topo + args
91 mnResult = main.Mininet1.startNet( mnCmd=mnCmd )
92 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
93 onpass="Mininet Started",
94 onfail="Error starting Mininet" )
95
Jon Hall2c8959e2016-12-16 12:17:34 -080096 main.step( "Activate apps defined in the params file" )
97 # get data from the params
98 apps = main.params.get( 'apps' )
99 if apps:
Jon Halled258232017-05-24 17:30:18 -0700100 apps = apps.split( ',' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800101 main.log.warn( apps )
102 activateResult = True
103 for app in apps:
Devin Lim142b5342017-07-20 15:22:39 -0700104 main.Cluster.active( 0 ).CLI.app( app, "Activate" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800105 # TODO: check this worked
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000106 time.sleep( main.sleep ) # wait for apps to activate
Jon Hall2c8959e2016-12-16 12:17:34 -0800107 for app in apps:
Devin Lim142b5342017-07-20 15:22:39 -0700108 state = main.Cluster.active( 0 ).CLI.appStatus( app )
Jon Hall2c8959e2016-12-16 12:17:34 -0800109 if state == "ACTIVE":
Jon Hall937bc812017-01-31 16:44:10 -0800110 activateResult = activateResult and True
Jon Hall2c8959e2016-12-16 12:17:34 -0800111 else:
112 main.log.error( "{} is in {} state".format( app, state ) )
Jon Hall937bc812017-01-31 16:44:10 -0800113 activateResult = False
Jon Hall2c8959e2016-12-16 12:17:34 -0800114 utilities.assert_equals( expect=True,
115 actual=activateResult,
116 onpass="Successfully activated apps",
117 onfail="Failed to activate apps" )
118 else:
119 main.log.warn( "No apps were specified to be loaded after startup" )
120
121 main.step( "Set ONOS configurations" )
122 config = main.params.get( 'ONOS_Configuration' )
123 if config:
124 main.log.debug( config )
125 checkResult = main.TRUE
126 for component in config:
Jon Halled258232017-05-24 17:30:18 -0700127 for setting in config[ component ]:
128 value = config[ component ][ setting ]
Devin Lim142b5342017-07-20 15:22:39 -0700129 check = main.Cluster.active( 0 ).CLI.setCfg( component, setting, value )
Jon Hall2c8959e2016-12-16 12:17:34 -0800130 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
131 checkResult = check and checkResult
132 utilities.assert_equals( expect=main.TRUE,
133 actual=checkResult,
134 onpass="Successfully set config",
135 onfail="Failed to set config" )
136 else:
137 main.log.warn( "No configurations were specified to be changed after startup" )
138
139 main.step( "App Ids check" )
Devin Lim142b5342017-07-20 15:22:39 -0700140 appCheck = main.Cluster.command( "appToIDCheck", returnBool=True )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700141 if not appCheck:
Devin Lim142b5342017-07-20 15:22:39 -0700142 main.log.warn( main.Cluster.active( 0 ).CLI.apps() )
143 main.log.warn( main.Cluster.active( 0 ).CLI.appIDs() )
144 utilities.assert_equals( expect=True, actual=appCheck,
Jon Hall2c8959e2016-12-16 12:17:34 -0800145 onpass="App Ids seem to be correct",
146 onfail="Something is wrong with app Ids" )
147
148 def CASE2( self, main ):
149 """
150 Load and test vpls configurations from json configuration file
151 """
152 import os.path
153 from tests.USECASE.VPLS.dependencies import vpls
154
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700155 main.vpls = vpls
Devin Lim142b5342017-07-20 15:22:39 -0700156 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Halled258232017-05-24 17:30:18 -0700157 hosts = int( main.params[ 'vpls' ][ 'hosts' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800158 main.step( "Discover hosts using pings" )
159 for i in range( 1, hosts + 1 ):
160 src = "h" + str( i )
161 for j in range( 1, hosts + 1 ):
162 if j == i:
163 continue
164 dst = "h" + str( j )
165 pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst )
166
167 main.step( "Load VPLS configurations" )
Jon Halled258232017-05-24 17:30:18 -0700168 fileName = main.params[ 'DEPENDENCY' ][ 'topology' ]
169 app = main.params[ 'vpls' ][ 'name' ]
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700170
Devin Lim142b5342017-07-20 15:22:39 -0700171 loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700172 utilities.assert_equals( expect=main.TRUE,
173 actual=loadVPLSResult,
174 onpass="Loaded vpls configuration.",
175 onfail="Failed to load vpls configuration." )
176
Jon Hall2c8959e2016-12-16 12:17:34 -0800177 # Time for netcfg to load data
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000178 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800179 # 'Master' copy of test configuration
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700180
Jon Hall2c8959e2016-12-16 12:17:34 -0800181 try:
182 with open( os.path.expanduser( fileName ) ) as dataFile:
183 originalCfg = json.load( dataFile )
Jon Halled258232017-05-24 17:30:18 -0700184 main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800185 except Exception as e:
186 main.log.error( "Error loading config file: {}".format( e ) )
187 if main.vplsConfig:
188 result = True
189 else:
190 result = False
191 utilities.assert_equals( expect=True,
192 actual=result,
193 onpass="Loaded vpls configuration",
194 onfail="Failed to load vpls configuration" )
195
196 main.step( "Check interface configurations" )
197 result = False
Devin Lim142b5342017-07-20 15:22:39 -0700198 getPorts = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700199 retValue=False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700200 kwargs={ "subjectClass": "ports" },
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000201 sleep=main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800202 onosCfg = pprint( getPorts )
203 sentCfg = pprint( originalCfg.get( "ports" ) )
204
205 if onosCfg == sentCfg:
206 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
207 result = True
208 else:
209 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
210 main.log.debug( "ONOS config: {}".format( onosCfg ) )
211 main.log.debug( "Sent config: {}".format( sentCfg ) )
212 utilities.assert_equals( expect=True,
213 actual=result,
214 onpass="Net Cfg added for interfaces",
215 onfail="Net Cfg not added for interfaces" )
216
217 # Run a bunch of checks to verify functionality based on configs
218 vpls.verify( main )
219
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700220 main.step( "Loading vpls configuration in case any configuration was missed." )
Devin Lim142b5342017-07-20 15:22:39 -0700221 loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700222 utilities.assert_equals( expect=main.TRUE,
223 actual=loadVPLSResult,
224 onpass="Loaded vpls configuration.",
225 onfail="Failed to load vpls configuration." )
226
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000227 def CASE10( self, main ):
Jon Hall2c8959e2016-12-16 12:17:34 -0800228 """
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000229 Remove an interface from a vpls network
Jon Hall2c8959e2016-12-16 12:17:34 -0800230 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800231 main.step( "Remove an interface from a vpls network" )
Devin Lim142b5342017-07-20 15:22:39 -0700232 main.Cluster.active( 0 ).CLI.vplsRemIface( 'VPLS1', 'h1' )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000233 time.sleep( main.sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700234 # update master config json
Jon Hall2c8959e2016-12-16 12:17:34 -0800235 for network in main.vplsConfig:
236 if network.get( 'name' ) == 'VPLS1':
237 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700238 ifaces.remove( 'h1' )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000239 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800240
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000241 def CASE11( self, main ):
242 """
243 Clean all VPLS configurations
244 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800245 main.step( "Clean all vpls configurations" )
Devin Lim142b5342017-07-20 15:22:39 -0700246 main.Cluster.active( 0 ).CLI.vplsClean()
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000247 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800248 main.vplsConfig = []
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000249 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800250
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000251 def CASE12( self, main ):
252 """
253 Create a new VPLS network.
254 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800255 main.step( "Create a new vpls network" )
256 name = "Network1"
Devin Lim142b5342017-07-20 15:22:39 -0700257 main.Cluster.active( 0 ).CLI.vplsCreate( name )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000258 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800259 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
260 main.vplsConfig.append( network1 )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000261 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800262
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000263 def CASE13( self, main ):
264 """
265 Add interfaces to the new VPLS network.
266 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800267 main.step( "Add interfaces to the network" )
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000268 utilities.retry( f=main.Cluster.active( 0 ).CLI.vplsAddIface,
269 retValue=main.FALSE,
270 args=( name, "h1" ),
271 sleep=main.sleep )
272 utilities.retry( f=main.Cluster.active( 0 ).CLI.vplsAddIface,
273 retValue=main.FALSE,
274 args=( name, "h5" ),
275 sleep=main.sleep )
276 utilities.retry( f=main.Cluster.active( 0 ).CLI.vplsAddIface,
277 retValue=main.FALSE,
278 args=( name, "h4" ),
279 sleep=main.sleep )
280 time.sleep( main.sleep )
Jon Hall2c8959e2016-12-16 12:17:34 -0800281 for network in main.vplsConfig:
282 if network.get( 'name' ) == name:
283 ifaces = network.get( 'interfaces' )
284 ifaces.append( 'h1' )
285 ifaces.append( 'h4' )
286 ifaces.append( 'h5' )
287 network[ 'interfaces' ] = ifaces
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000288 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800289
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000290 def CASE14( self, main ):
291 """
292 Add MPLS encapsulation.
293 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800294 main.step( "Add MPLS encapsulation to a vpls network" )
295 encapType = "MPLS"
Devin Lim142b5342017-07-20 15:22:39 -0700296 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800297 for network in main.vplsConfig:
298 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700299 network[ 'encapsulation' ] = encapType
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000300 time.sleep( main.sleep )
301 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800302
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000303 def CASE15( self, main ):
304 """
305 Change an encapsulation type.
306 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800307 main.step( "Change an encapsulation type" )
308 encapType = "VLAN"
Devin Lim142b5342017-07-20 15:22:39 -0700309 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800310 for network in main.vplsConfig:
311 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700312 network[ 'encapsulation' ] = encapType
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000313 time.sleep( main.sleep )
314 main.vpls.verify( main )
Jon Hall2c8959e2016-12-16 12:17:34 -0800315
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000316 def CASE16( self, main ):
317 """
318 Remove encapsulation.
319 """
Jon Hall2c8959e2016-12-16 12:17:34 -0800320 main.step( "Remove encapsulation" )
321 encapType = "NONE"
Devin Lim142b5342017-07-20 15:22:39 -0700322 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800323 for network in main.vplsConfig:
324 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700325 network[ 'encapsulation' ] = encapType
Jeremy Ronquillod7791d82017-08-14 16:23:08 +0000326 time.sleep( main.sleep )
327 main.vpls.verify( main )