blob: a0a061ac0ffd5fd84ad7d7681ab0660414901a77 [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' ]
67 main.numCtrls = int( main.params[ 'num_controllers' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -080068
Devin Lim58046fa2017-07-05 16:55:00 -070069 ofPort = main.params[ 'CTRL' ][ 'port' ]
70 stepResult = main.testSetUp.envSetup( hasRest=True, hasNode=True )
71 except Exception as e:
72 main.testSetUp.envSetupException( e )
73 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall2c8959e2016-12-16 12:17:34 -080074
Devin Lim58046fa2017-07-05 16:55:00 -070075 main.testSetUp.ONOSSetUp( main.Mininet1, 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"
Jon Hall2c8959e2016-12-16 12:17:34 -080089 for node in main.nodes:
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -070090 args += " --controller=remote,ip=" + node.ip_address
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 main.activeNodes = [ i for i in range( 0, len( main.CLIs ) ) ]
98
99 main.step( "Activate apps defined in the params file" )
100 # get data from the params
101 apps = main.params.get( 'apps' )
102 if apps:
Jon Halled258232017-05-24 17:30:18 -0700103 apps = apps.split( ',' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800104 main.log.warn( apps )
105 activateResult = True
106 for app in apps:
107 main.CLIs[ 0 ].app( app, "Activate" )
108 # TODO: check this worked
109 time.sleep( SLEEP ) # wait for apps to activate
110 for app in apps:
111 state = main.CLIs[ 0 ].appStatus( app )
112 if state == "ACTIVE":
Jon Hall937bc812017-01-31 16:44:10 -0800113 activateResult = activateResult and True
Jon Hall2c8959e2016-12-16 12:17:34 -0800114 else:
115 main.log.error( "{} is in {} state".format( app, state ) )
Jon Hall937bc812017-01-31 16:44:10 -0800116 activateResult = False
Jon Hall2c8959e2016-12-16 12:17:34 -0800117 utilities.assert_equals( expect=True,
118 actual=activateResult,
119 onpass="Successfully activated apps",
120 onfail="Failed to activate apps" )
121 else:
122 main.log.warn( "No apps were specified to be loaded after startup" )
123
124 main.step( "Set ONOS configurations" )
125 config = main.params.get( 'ONOS_Configuration' )
126 if config:
127 main.log.debug( config )
128 checkResult = main.TRUE
129 for component in config:
Jon Halled258232017-05-24 17:30:18 -0700130 for setting in config[ component ]:
131 value = config[ component ][ setting ]
Jon Hall2c8959e2016-12-16 12:17:34 -0800132 check = main.CLIs[ 0 ].setCfg( component, setting, value )
133 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
134 checkResult = check and checkResult
135 utilities.assert_equals( expect=main.TRUE,
136 actual=checkResult,
137 onpass="Successfully set config",
138 onfail="Failed to set config" )
139 else:
140 main.log.warn( "No configurations were specified to be changed after startup" )
141
142 main.step( "App Ids check" )
143 appCheck = main.TRUE
144 threads = []
145 for i in main.activeNodes:
Jon Halled258232017-05-24 17:30:18 -0700146 t = main.Thread( target=main.CLIs[ i ].appToIDCheck,
Jon Hall2c8959e2016-12-16 12:17:34 -0800147 name="appToIDCheck-" + str( i ),
148 args=[] )
149 threads.append( t )
150 t.start()
151
152 for t in threads:
153 t.join()
154 appCheck = appCheck and t.result
155 if appCheck != main.TRUE:
Jon Halled258232017-05-24 17:30:18 -0700156 main.log.warn( main.CLIs[ 0 ].apps() )
157 main.log.warn( main.CLIs[ 0 ].appIDs() )
Jon Hall2c8959e2016-12-16 12:17:34 -0800158 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
159 onpass="App Ids seem to be correct",
160 onfail="Something is wrong with app Ids" )
161
162 def CASE2( self, main ):
163 """
164 Load and test vpls configurations from json configuration file
165 """
166 import os.path
167 from tests.USECASE.VPLS.dependencies import vpls
168
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700169 main.vpls = vpls
Jon Hall2c8959e2016-12-16 12:17:34 -0800170 pprint = main.ONOSrest1.pprint
Jon Halled258232017-05-24 17:30:18 -0700171 hosts = int( main.params[ 'vpls' ][ 'hosts' ] )
172 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800173
174 main.step( "Discover hosts using pings" )
175 for i in range( 1, hosts + 1 ):
176 src = "h" + str( i )
177 for j in range( 1, hosts + 1 ):
178 if j == i:
179 continue
180 dst = "h" + str( j )
181 pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst )
182
183 main.step( "Load VPLS configurations" )
Jon Halled258232017-05-24 17:30:18 -0700184 fileName = main.params[ 'DEPENDENCY' ][ 'topology' ]
185 app = main.params[ 'vpls' ][ 'name' ]
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700186
187 loadVPLSResult = main.ONOSbench.onosNetCfg( main.nodes[ 0 ].ip_address, "", fileName )
188 utilities.assert_equals( expect=main.TRUE,
189 actual=loadVPLSResult,
190 onpass="Loaded vpls configuration.",
191 onfail="Failed to load vpls configuration." )
192
Jon Hall2c8959e2016-12-16 12:17:34 -0800193 # Time for netcfg to load data
194 time.sleep( SLEEP )
195 # 'Master' copy of test configuration
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700196
Jon Hall2c8959e2016-12-16 12:17:34 -0800197 try:
198 with open( os.path.expanduser( fileName ) ) as dataFile:
199 originalCfg = json.load( dataFile )
Jon Halled258232017-05-24 17:30:18 -0700200 main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800201 except Exception as e:
202 main.log.error( "Error loading config file: {}".format( e ) )
203 if main.vplsConfig:
204 result = True
205 else:
206 result = False
207 utilities.assert_equals( expect=True,
208 actual=result,
209 onpass="Loaded vpls configuration",
210 onfail="Failed to load vpls configuration" )
211
212 main.step( "Check interface configurations" )
213 result = False
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700214 getPorts = utilities.retry( f=main.ONOSrest1.getNetCfg,
215 retValue=False,
216 kwargs={"subjectClass":"ports"},
217 sleep=SLEEP )
Jon Hall2c8959e2016-12-16 12:17:34 -0800218 onosCfg = pprint( getPorts )
219 sentCfg = pprint( originalCfg.get( "ports" ) )
220
221 if onosCfg == sentCfg:
222 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
223 result = True
224 else:
225 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
226 main.log.debug( "ONOS config: {}".format( onosCfg ) )
227 main.log.debug( "Sent config: {}".format( sentCfg ) )
228 utilities.assert_equals( expect=True,
229 actual=result,
230 onpass="Net Cfg added for interfaces",
231 onfail="Net Cfg not added for interfaces" )
232
233 # Run a bunch of checks to verify functionality based on configs
234 vpls.verify( main )
235
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700236 main.step( "Loading vpls configuration in case any configuration was missed." )
237 loadVPLSResult = main.ONOSbench.onosNetCfg( main.nodes[ 0 ].ip_address, "", fileName )
238 utilities.assert_equals( expect=main.TRUE,
239 actual=loadVPLSResult,
240 onpass="Loaded vpls configuration.",
241 onfail="Failed to load vpls configuration." )
242
Jon Hall2c8959e2016-12-16 12:17:34 -0800243 def CASE3( self, main ):
244 """
245 Test VPLS cli commands
246 High level steps:
247 remove interface from a network
248 Clean configs
249 create vpls network
250 add interfaces to a network
251 add encap
252 change encap
253 remove encap
254 list?
255 """
256 from tests.USECASE.VPLS.dependencies import vpls
Jon Halled258232017-05-24 17:30:18 -0700257 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800258 pprint = main.ONOSrest1.pprint
259
260 main.step( "Remove an interface from a vpls network" )
Jon Halled258232017-05-24 17:30:18 -0700261 main.CLIs[ 0 ].vplsRemIface( 'VPLS1', 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800262 time.sleep( SLEEP )
263 #update master config json
264 for network in main.vplsConfig:
265 if network.get( 'name' ) == 'VPLS1':
266 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700267 ifaces.remove( 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800268 vpls.verify( main )
269
270 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700271 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800272 time.sleep( SLEEP )
273 main.vplsConfig = []
274 vpls.verify( main )
275
276 main.step( "Create a new vpls network" )
277 name = "Network1"
Jon Halled258232017-05-24 17:30:18 -0700278 main.CLIs[ 0 ].vplsCreate( name )
Jon Hall2c8959e2016-12-16 12:17:34 -0800279 time.sleep( SLEEP )
280 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
281 main.vplsConfig.append( network1 )
282 vpls.verify( main )
283
284 main.step( "Add interfaces to the network" )
Jon Halled258232017-05-24 17:30:18 -0700285 main.CLIs[ 0 ].vplsAddIface( name, "h1" )
286 main.CLIs[ 0 ].vplsAddIface( name, "h5" )
287 main.CLIs[ 0 ].vplsAddIface( name, "h4" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800288 time.sleep( SLEEP )
289 for network in main.vplsConfig:
290 if network.get( 'name' ) == name:
291 ifaces = network.get( 'interfaces' )
292 ifaces.append( 'h1' )
293 ifaces.append( 'h4' )
294 ifaces.append( 'h5' )
295 network[ 'interfaces' ] = ifaces
296 vpls.verify( main )
297
298 main.step( "Add MPLS encapsulation to a vpls network" )
299 encapType = "MPLS"
Jon Halled258232017-05-24 17:30:18 -0700300 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800301 for network in main.vplsConfig:
302 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700303 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800304 time.sleep( SLEEP )
305 vpls.verify( main )
306
307 main.step( "Change an encapsulation type" )
308 encapType = "VLAN"
Jon Halled258232017-05-24 17:30:18 -0700309 main.CLIs[ 0 ].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
Jon Hall2c8959e2016-12-16 12:17:34 -0800313 time.sleep( SLEEP )
314 vpls.verify( main )
315
316 main.step( "Remove encapsulation" )
317 encapType = "NONE"
Jon Halled258232017-05-24 17:30:18 -0700318 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800319 for network in main.vplsConfig:
320 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700321 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800322 time.sleep( SLEEP )
323 vpls.verify( main )
324
325 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700326 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800327 time.sleep( SLEEP )
328 main.vplsConfig = []
329 vpls.verify( main )