blob: 048ec8198147390c7dbd62bbdac9b47ed2acd39a [file] [log] [blame]
Jon Hall2c8959e2016-12-16 12:17:34 -08001# CASE1: Startup
2# CASE2: Load vpls topology and configurations from demo script
3# CASE3: Test CLI commands
4
Jon Halled258232017-05-24 17:30:18 -07005
Jon Hall2c8959e2016-12-16 12:17:34 -08006class VPLSBasic:
Jon Halled258232017-05-24 17:30:18 -07007
Jon Hall2c8959e2016-12-16 12:17:34 -08008 def __init__( self ):
9 self.default = ''
10
11 def CASE1( self, main ):
12 """
13 CASE1 is to compile ONOS and push it to the test machines
14
15 Startup sequence:
16 cell <name>
17 onos-verify-cell
18 NOTE: temporary - onos-remove-raft-logs
19 onos-uninstall
20 start mininet
21 git pull
22 mvn clean install
23 onos-package
24 onos-install -f
25 onos-wait-for-start
26 start cli sessions
27 start tcpdump
28 """
29 import imp
30 import time
31 import json
32 main.case( "Setting up test environment" )
33 main.caseExplanation = "Setup the test environment including " +\
34 "installing ONOS, starting Mininet and ONOS" +\
35 "cli sessions."
36
37 # load some variables from the params file
38 cellName = main.params[ 'ENV' ][ 'cellName' ]
39
40 main.numCtrls = int( main.params[ 'num_controllers' ] )
41
42 ofPort = main.params[ 'CTRL' ][ 'port' ]
43
44 main.CLIs = []
45 main.RESTs = []
46 main.nodes = []
47 ipList = []
48 for i in range( 1, main.numCtrls + 1 ):
49 try:
50 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
51 main.RESTs.append( getattr( main, 'ONOSrest' + str( i ) ) )
52 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
53 ipList.append( main.nodes[ -1 ].ip_address )
54 except AttributeError:
55 break
56
57 main.step( "Create cell file" )
58 cellAppString = main.params[ 'ENV' ][ 'cellApps' ]
59 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
60 main.Mininet1.ip_address,
61 cellAppString, ipList )
62 main.step( "Applying cell variable to environment" )
63 cellResult = main.ONOSbench.setCell( cellName )
64 verifyResult = main.ONOSbench.verifyCell()
65
66 main.log.info( "Uninstalling ONOS" )
67 for node in main.nodes:
68 main.ONOSbench.onosUninstall( node.ip_address )
69
70 # Make sure ONOS is DEAD
71 main.log.info( "Killing any ONOS processes" )
72 killResults = main.TRUE
73 for node in main.nodes:
74 killed = main.ONOSbench.onosKill( node.ip_address )
75 killResults = killResults and killed
76
77 cleanInstallResult = main.TRUE
78
79 main.step( "Starting Mininet" )
80 # scp topo file to mininet
81 # TODO: move to params?
82 topoName = "vpls"
83 topoFile = "vpls.py"
84 filePath = main.ONOSbench.home + "/tools/test/topos/"
85 main.ONOSbench.scp( main.Mininet1,
86 filePath + topoFile,
87 main.Mininet1.home,
88 direction="to" )
89 topo = " --custom " + main.Mininet1.home + topoFile + " --topo " + topoName
90 args = " --switch ovs,protocols=OpenFlow13 --controller=remote"
91 for node in main.nodes:
92 args += ",ip=" + node.ip_address
93 mnCmd = "sudo mn" + topo + args
94 mnResult = main.Mininet1.startNet( mnCmd=mnCmd )
95 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
96 onpass="Mininet Started",
97 onfail="Error starting Mininet" )
98
99 main.ONOSbench.getVersion( report=True )
100
101 main.step( "Creating ONOS package" )
102 packageResult = main.ONOSbench.buckBuild()
103 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
104 onpass="ONOS package successful",
105 onfail="ONOS package failed" )
106
107 main.step( "Installing ONOS package" )
108 onosInstallResult = main.TRUE
109 for node in main.nodes:
110 tmpResult = main.ONOSbench.onosInstall( options="-f",
111 node=node.ip_address )
112 onosInstallResult = onosInstallResult and tmpResult
113 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
114 onpass="ONOS install successful",
115 onfail="ONOS install failed" )
116
You Wangf5de25b2017-01-06 15:13:01 -0800117 main.step( "Set up ONOS secure SSH" )
118 secureSshResult = main.TRUE
119 for node in main.nodes:
120 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=node.ip_address )
121 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
122 onpass="Test step PASS",
123 onfail="Test step FAIL" )
124
Jon Hall2c8959e2016-12-16 12:17:34 -0800125 main.step( "Checking if ONOS is up yet" )
126 for i in range( 2 ):
127 onosIsupResult = main.TRUE
128 for node in main.nodes:
129 started = main.ONOSbench.isup( node.ip_address )
130 if not started:
131 main.log.error( node.name + " hasn't started" )
132 onosIsupResult = onosIsupResult and started
133 if onosIsupResult == main.TRUE:
134 break
135 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
136 onpass="ONOS startup successful",
137 onfail="ONOS startup failed" )
138
Jon Hall2c8959e2016-12-16 12:17:34 -0800139 main.step( "Starting ONOS CLI sessions" )
140 cliResults = main.TRUE
141 threads = []
142 for i in range( main.numCtrls ):
Jon Halled258232017-05-24 17:30:18 -0700143 t = main.Thread( target=main.CLIs[ i ].startOnosCli,
Jon Hall2c8959e2016-12-16 12:17:34 -0800144 name="startOnosCli-" + str( i ),
Jon Halled258232017-05-24 17:30:18 -0700145 args=[ main.nodes[ i ].ip_address ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800146 threads.append( t )
147 t.start()
148
149 for t in threads:
150 t.join()
151 cliResults = cliResults and t.result
152 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
153 onpass="ONOS cli startup successful",
154 onfail="ONOS cli startup failed" )
155
156 main.activeNodes = [ i for i in range( 0, len( main.CLIs ) ) ]
157
158 main.step( "Activate apps defined in the params file" )
159 # get data from the params
160 apps = main.params.get( 'apps' )
161 if apps:
Jon Halled258232017-05-24 17:30:18 -0700162 apps = apps.split( ',' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800163 main.log.warn( apps )
164 activateResult = True
165 for app in apps:
166 main.CLIs[ 0 ].app( app, "Activate" )
167 # TODO: check this worked
168 time.sleep( SLEEP ) # wait for apps to activate
169 for app in apps:
170 state = main.CLIs[ 0 ].appStatus( app )
171 if state == "ACTIVE":
Jon Hall937bc812017-01-31 16:44:10 -0800172 activateResult = activateResult and True
Jon Hall2c8959e2016-12-16 12:17:34 -0800173 else:
174 main.log.error( "{} is in {} state".format( app, state ) )
Jon Hall937bc812017-01-31 16:44:10 -0800175 activateResult = False
Jon Hall2c8959e2016-12-16 12:17:34 -0800176 utilities.assert_equals( expect=True,
177 actual=activateResult,
178 onpass="Successfully activated apps",
179 onfail="Failed to activate apps" )
180 else:
181 main.log.warn( "No apps were specified to be loaded after startup" )
182
183 main.step( "Set ONOS configurations" )
184 config = main.params.get( 'ONOS_Configuration' )
185 if config:
186 main.log.debug( config )
187 checkResult = main.TRUE
188 for component in config:
Jon Halled258232017-05-24 17:30:18 -0700189 for setting in config[ component ]:
190 value = config[ component ][ setting ]
Jon Hall2c8959e2016-12-16 12:17:34 -0800191 check = main.CLIs[ 0 ].setCfg( component, setting, value )
192 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
193 checkResult = check and checkResult
194 utilities.assert_equals( expect=main.TRUE,
195 actual=checkResult,
196 onpass="Successfully set config",
197 onfail="Failed to set config" )
198 else:
199 main.log.warn( "No configurations were specified to be changed after startup" )
200
201 main.step( "App Ids check" )
202 appCheck = main.TRUE
203 threads = []
204 for i in main.activeNodes:
Jon Halled258232017-05-24 17:30:18 -0700205 t = main.Thread( target=main.CLIs[ i ].appToIDCheck,
Jon Hall2c8959e2016-12-16 12:17:34 -0800206 name="appToIDCheck-" + str( i ),
207 args=[] )
208 threads.append( t )
209 t.start()
210
211 for t in threads:
212 t.join()
213 appCheck = appCheck and t.result
214 if appCheck != main.TRUE:
Jon Halled258232017-05-24 17:30:18 -0700215 main.log.warn( main.CLIs[ 0 ].apps() )
216 main.log.warn( main.CLIs[ 0 ].appIDs() )
Jon Hall2c8959e2016-12-16 12:17:34 -0800217 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
218 onpass="App Ids seem to be correct",
219 onfail="Something is wrong with app Ids" )
220
221 def CASE2( self, main ):
222 """
223 Load and test vpls configurations from json configuration file
224 """
225 import os.path
226 from tests.USECASE.VPLS.dependencies import vpls
227
228 pprint = main.ONOSrest1.pprint
Jon Halled258232017-05-24 17:30:18 -0700229 hosts = int( main.params[ 'vpls' ][ 'hosts' ] )
230 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800231
232 main.step( "Discover hosts using pings" )
233 for i in range( 1, hosts + 1 ):
234 src = "h" + str( i )
235 for j in range( 1, hosts + 1 ):
236 if j == i:
237 continue
238 dst = "h" + str( j )
239 pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst )
240
241 main.step( "Load VPLS configurations" )
242 # TODO: load from params
Jon Halled258232017-05-24 17:30:18 -0700243 fileName = main.params[ 'DEPENDENCY' ][ 'topology' ]
244 app = main.params[ 'vpls' ][ 'name' ]
Jon Hall2c8959e2016-12-16 12:17:34 -0800245 # TODO make this a function?
246 main.ONOSbench.handle.sendline( "onos-netcfg $OC1 " + fileName )
247 # Time for netcfg to load data
248 time.sleep( SLEEP )
249 # 'Master' copy of test configuration
250 try:
251 with open( os.path.expanduser( fileName ) ) as dataFile:
252 originalCfg = json.load( dataFile )
Jon Halled258232017-05-24 17:30:18 -0700253 main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800254 except Exception as e:
255 main.log.error( "Error loading config file: {}".format( e ) )
256 if main.vplsConfig:
257 result = True
258 else:
259 result = False
260 utilities.assert_equals( expect=True,
261 actual=result,
262 onpass="Loaded vpls configuration",
263 onfail="Failed to load vpls configuration" )
264
265 main.step( "Check interface configurations" )
266 result = False
267 getPorts = main.ONOSrest1.getNetCfg( subjectClass="ports" )
268 onosCfg = pprint( getPorts )
269 sentCfg = pprint( originalCfg.get( "ports" ) )
270
271 if onosCfg == sentCfg:
272 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
273 result = True
274 else:
275 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
276 main.log.debug( "ONOS config: {}".format( onosCfg ) )
277 main.log.debug( "Sent config: {}".format( sentCfg ) )
278 utilities.assert_equals( expect=True,
279 actual=result,
280 onpass="Net Cfg added for interfaces",
281 onfail="Net Cfg not added for interfaces" )
282
283 # Run a bunch of checks to verify functionality based on configs
284 vpls.verify( main )
285
286 def CASE3( self, main ):
287 """
288 Test VPLS cli commands
289 High level steps:
290 remove interface from a network
291 Clean configs
292 create vpls network
293 add interfaces to a network
294 add encap
295 change encap
296 remove encap
297 list?
298 """
299 from tests.USECASE.VPLS.dependencies import vpls
Jon Halled258232017-05-24 17:30:18 -0700300 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800301 pprint = main.ONOSrest1.pprint
302
303 main.step( "Remove an interface from a vpls network" )
Jon Halled258232017-05-24 17:30:18 -0700304 main.CLIs[ 0 ].vplsRemIface( 'VPLS1', 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800305 time.sleep( SLEEP )
306 #update master config json
307 for network in main.vplsConfig:
308 if network.get( 'name' ) == 'VPLS1':
309 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700310 ifaces.remove( 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800311 vpls.verify( main )
312
313 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700314 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800315 time.sleep( SLEEP )
316 main.vplsConfig = []
317 vpls.verify( main )
318
319 main.step( "Create a new vpls network" )
320 name = "Network1"
Jon Halled258232017-05-24 17:30:18 -0700321 main.CLIs[ 0 ].vplsCreate( name )
Jon Hall2c8959e2016-12-16 12:17:34 -0800322 time.sleep( SLEEP )
323 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
324 main.vplsConfig.append( network1 )
325 vpls.verify( main )
326
327 main.step( "Add interfaces to the network" )
Jon Halled258232017-05-24 17:30:18 -0700328 main.CLIs[ 0 ].vplsAddIface( name, "h1" )
329 main.CLIs[ 0 ].vplsAddIface( name, "h5" )
330 main.CLIs[ 0 ].vplsAddIface( name, "h4" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800331 time.sleep( SLEEP )
332 for network in main.vplsConfig:
333 if network.get( 'name' ) == name:
334 ifaces = network.get( 'interfaces' )
335 ifaces.append( 'h1' )
336 ifaces.append( 'h4' )
337 ifaces.append( 'h5' )
338 network[ 'interfaces' ] = ifaces
339 vpls.verify( main )
340
341 main.step( "Add MPLS encapsulation to a vpls network" )
342 encapType = "MPLS"
Jon Halled258232017-05-24 17:30:18 -0700343 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800344 for network in main.vplsConfig:
345 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700346 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800347 time.sleep( SLEEP )
348 vpls.verify( main )
349
350 main.step( "Change an encapsulation type" )
351 encapType = "VLAN"
Jon Halled258232017-05-24 17:30:18 -0700352 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800353 for network in main.vplsConfig:
354 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700355 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800356 time.sleep( SLEEP )
357 vpls.verify( main )
358
359 main.step( "Remove encapsulation" )
360 encapType = "NONE"
Jon Halled258232017-05-24 17:30:18 -0700361 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800362 for network in main.vplsConfig:
363 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700364 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800365 time.sleep( SLEEP )
366 vpls.verify( main )
367
368 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700369 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800370 time.sleep( SLEEP )
371 main.vplsConfig = []
372 vpls.verify( main )