blob: 0b8c85d548cc94453536194a948caa460fc75255 [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" )
59 main.exit()
60 main.testSetUp.envSetupDescription()
61 stepResult = main.FALSE
62 try:
63 # load some variables from the params file
64 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall2c8959e2016-12-16 12:17:34 -080065
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,
75 cellName=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
108 time.sleep( SLEEP ) # wait for apps to activate
109 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' ] )
160 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800161
162 main.step( "Discover hosts using pings" )
163 for i in range( 1, hosts + 1 ):
164 src = "h" + str( i )
165 for j in range( 1, hosts + 1 ):
166 if j == i:
167 continue
168 dst = "h" + str( j )
169 pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst )
170
171 main.step( "Load VPLS configurations" )
Jon Halled258232017-05-24 17:30:18 -0700172 fileName = main.params[ 'DEPENDENCY' ][ 'topology' ]
173 app = main.params[ 'vpls' ][ 'name' ]
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700174
Devin Lim142b5342017-07-20 15:22:39 -0700175 loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700176 utilities.assert_equals( expect=main.TRUE,
177 actual=loadVPLSResult,
178 onpass="Loaded vpls configuration.",
179 onfail="Failed to load vpls configuration." )
180
Jon Hall2c8959e2016-12-16 12:17:34 -0800181 # Time for netcfg to load data
182 time.sleep( SLEEP )
183 # 'Master' copy of test configuration
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700184
Jon Hall2c8959e2016-12-16 12:17:34 -0800185 try:
186 with open( os.path.expanduser( fileName ) ) as dataFile:
187 originalCfg = json.load( dataFile )
Jon Halled258232017-05-24 17:30:18 -0700188 main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800189 except Exception as e:
190 main.log.error( "Error loading config file: {}".format( e ) )
191 if main.vplsConfig:
192 result = True
193 else:
194 result = False
195 utilities.assert_equals( expect=True,
196 actual=result,
197 onpass="Loaded vpls configuration",
198 onfail="Failed to load vpls configuration" )
199
200 main.step( "Check interface configurations" )
201 result = False
Devin Lim142b5342017-07-20 15:22:39 -0700202 getPorts = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700203 retValue=False,
204 kwargs={"subjectClass":"ports"},
205 sleep=SLEEP )
Jon Hall2c8959e2016-12-16 12:17:34 -0800206 onosCfg = pprint( getPorts )
207 sentCfg = pprint( originalCfg.get( "ports" ) )
208
209 if onosCfg == sentCfg:
210 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
211 result = True
212 else:
213 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
214 main.log.debug( "ONOS config: {}".format( onosCfg ) )
215 main.log.debug( "Sent config: {}".format( sentCfg ) )
216 utilities.assert_equals( expect=True,
217 actual=result,
218 onpass="Net Cfg added for interfaces",
219 onfail="Net Cfg not added for interfaces" )
220
221 # Run a bunch of checks to verify functionality based on configs
222 vpls.verify( main )
223
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700224 main.step( "Loading vpls configuration in case any configuration was missed." )
Devin Lim142b5342017-07-20 15:22:39 -0700225 loadVPLSResult = main.ONOSbench.onosNetCfg( main.Cluster.active( 0 ).ipAddress, "", fileName )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700226 utilities.assert_equals( expect=main.TRUE,
227 actual=loadVPLSResult,
228 onpass="Loaded vpls configuration.",
229 onfail="Failed to load vpls configuration." )
230
Jon Hall2c8959e2016-12-16 12:17:34 -0800231 def CASE3( self, main ):
232 """
233 Test VPLS cli commands
234 High level steps:
235 remove interface from a network
236 Clean configs
237 create vpls network
238 add interfaces to a network
239 add encap
240 change encap
241 remove encap
242 list?
243 """
244 from tests.USECASE.VPLS.dependencies import vpls
Jon Halled258232017-05-24 17:30:18 -0700245 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Devin Lim142b5342017-07-20 15:22:39 -0700246 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Hall2c8959e2016-12-16 12:17:34 -0800247
248 main.step( "Remove an interface from a vpls network" )
Devin Lim142b5342017-07-20 15:22:39 -0700249 main.Cluster.active( 0 ).CLI.vplsRemIface( 'VPLS1', 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800250 time.sleep( SLEEP )
251 #update master config json
252 for network in main.vplsConfig:
253 if network.get( 'name' ) == 'VPLS1':
254 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700255 ifaces.remove( 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800256 vpls.verify( main )
257
258 main.step( "Clean all vpls configurations" )
Devin Lim142b5342017-07-20 15:22:39 -0700259 main.Cluster.active( 0 ).CLI.vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800260 time.sleep( SLEEP )
261 main.vplsConfig = []
262 vpls.verify( main )
263
264 main.step( "Create a new vpls network" )
265 name = "Network1"
Devin Lim142b5342017-07-20 15:22:39 -0700266 main.Cluster.active( 0 ).CLI.vplsCreate( name )
Jon Hall2c8959e2016-12-16 12:17:34 -0800267 time.sleep( SLEEP )
268 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
269 main.vplsConfig.append( network1 )
270 vpls.verify( main )
271
272 main.step( "Add interfaces to the network" )
Devin Lim142b5342017-07-20 15:22:39 -0700273 main.Cluster.active( 0 ).CLI.vplsAddIface( name, "h1" )
274 main.Cluster.active( 0 ).CLI.vplsAddIface( name, "h5" )
275 main.Cluster.active( 0 ).CLI.vplsAddIface( name, "h4" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800276 time.sleep( SLEEP )
277 for network in main.vplsConfig:
278 if network.get( 'name' ) == name:
279 ifaces = network.get( 'interfaces' )
280 ifaces.append( 'h1' )
281 ifaces.append( 'h4' )
282 ifaces.append( 'h5' )
283 network[ 'interfaces' ] = ifaces
284 vpls.verify( main )
285
286 main.step( "Add MPLS encapsulation to a vpls network" )
287 encapType = "MPLS"
Devin Lim142b5342017-07-20 15:22:39 -0700288 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800289 for network in main.vplsConfig:
290 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700291 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800292 time.sleep( SLEEP )
293 vpls.verify( main )
294
295 main.step( "Change an encapsulation type" )
296 encapType = "VLAN"
Devin Lim142b5342017-07-20 15:22:39 -0700297 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800298 for network in main.vplsConfig:
299 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700300 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800301 time.sleep( SLEEP )
302 vpls.verify( main )
303
304 main.step( "Remove encapsulation" )
305 encapType = "NONE"
Devin Lim142b5342017-07-20 15:22:39 -0700306 main.Cluster.active( 0 ).CLI.vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800307 for network in main.vplsConfig:
308 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700309 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800310 time.sleep( SLEEP )
311 vpls.verify( main )
312
313 main.step( "Clean all vpls configurations" )
Devin Lim142b5342017-07-20 15:22:39 -0700314 main.Cluster.active( 0 ).CLI.vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800315 time.sleep( SLEEP )
316 main.vplsConfig = []
317 vpls.verify( main )