blob: 76f7ccdbb8882c071de236ef93e7b783d3ebd6a0 [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,
Devin Lim461f0872017-06-05 16:49:33 -070061 cellAppString, ipList, main.ONOScli1.user_name )
Jon Hall2c8959e2016-12-16 12:17:34 -080062 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
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700267 getPorts = utilities.retry( f=main.ONOSrest1.getNetCfg,
268 retValue=False,
269 kwargs={"subjectClass":"ports"},
270 sleep=SLEEP )
Jon Hall2c8959e2016-12-16 12:17:34 -0800271 onosCfg = pprint( getPorts )
272 sentCfg = pprint( originalCfg.get( "ports" ) )
273
274 if onosCfg == sentCfg:
275 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
276 result = True
277 else:
278 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
279 main.log.debug( "ONOS config: {}".format( onosCfg ) )
280 main.log.debug( "Sent config: {}".format( sentCfg ) )
281 utilities.assert_equals( expect=True,
282 actual=result,
283 onpass="Net Cfg added for interfaces",
284 onfail="Net Cfg not added for interfaces" )
285
286 # Run a bunch of checks to verify functionality based on configs
287 vpls.verify( main )
288
289 def CASE3( self, main ):
290 """
291 Test VPLS cli commands
292 High level steps:
293 remove interface from a network
294 Clean configs
295 create vpls network
296 add interfaces to a network
297 add encap
298 change encap
299 remove encap
300 list?
301 """
302 from tests.USECASE.VPLS.dependencies import vpls
Jon Halled258232017-05-24 17:30:18 -0700303 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800304 pprint = main.ONOSrest1.pprint
305
306 main.step( "Remove an interface from a vpls network" )
Jon Halled258232017-05-24 17:30:18 -0700307 main.CLIs[ 0 ].vplsRemIface( 'VPLS1', 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800308 time.sleep( SLEEP )
309 #update master config json
310 for network in main.vplsConfig:
311 if network.get( 'name' ) == 'VPLS1':
312 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700313 ifaces.remove( 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800314 vpls.verify( main )
315
316 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700317 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800318 time.sleep( SLEEP )
319 main.vplsConfig = []
320 vpls.verify( main )
321
322 main.step( "Create a new vpls network" )
323 name = "Network1"
Jon Halled258232017-05-24 17:30:18 -0700324 main.CLIs[ 0 ].vplsCreate( name )
Jon Hall2c8959e2016-12-16 12:17:34 -0800325 time.sleep( SLEEP )
326 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
327 main.vplsConfig.append( network1 )
328 vpls.verify( main )
329
330 main.step( "Add interfaces to the network" )
Jon Halled258232017-05-24 17:30:18 -0700331 main.CLIs[ 0 ].vplsAddIface( name, "h1" )
332 main.CLIs[ 0 ].vplsAddIface( name, "h5" )
333 main.CLIs[ 0 ].vplsAddIface( name, "h4" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800334 time.sleep( SLEEP )
335 for network in main.vplsConfig:
336 if network.get( 'name' ) == name:
337 ifaces = network.get( 'interfaces' )
338 ifaces.append( 'h1' )
339 ifaces.append( 'h4' )
340 ifaces.append( 'h5' )
341 network[ 'interfaces' ] = ifaces
342 vpls.verify( main )
343
344 main.step( "Add MPLS encapsulation to a vpls network" )
345 encapType = "MPLS"
Jon Halled258232017-05-24 17:30:18 -0700346 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800347 for network in main.vplsConfig:
348 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700349 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800350 time.sleep( SLEEP )
351 vpls.verify( main )
352
353 main.step( "Change an encapsulation type" )
354 encapType = "VLAN"
Jon Halled258232017-05-24 17:30:18 -0700355 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800356 for network in main.vplsConfig:
357 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700358 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800359 time.sleep( SLEEP )
360 vpls.verify( main )
361
362 main.step( "Remove encapsulation" )
363 encapType = "NONE"
Jon Halled258232017-05-24 17:30:18 -0700364 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800365 for network in main.vplsConfig:
366 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700367 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800368 time.sleep( SLEEP )
369 vpls.verify( main )
370
371 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700372 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800373 time.sleep( SLEEP )
374 main.vplsConfig = []
375 vpls.verify( main )