blob: f60e004a3b0d8af5ffd3134baab847034f217cf2 [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
Jon Hall2c8959e2016-12-16 12:17:34 -080032
Devin Lim58046fa2017-07-05 16:55:00 -070033 try:
34 from tests.dependencies.ONOSSetup import ONOSSetup
35 main.testSetUp = ONOSSetup()
36 except ImportError:
37 main.log.error( "ONOSSetup not found. exiting the test" )
38 main.exit()
39 main.testSetUp.envSetupDescription()
40 stepResult = main.FALSE
41 try:
42 # load some variables from the params file
43 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall2c8959e2016-12-16 12:17:34 -080044
Devin Lim58046fa2017-07-05 16:55:00 -070045 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
46 main.numCtrls = int( main.params[ 'num_controllers' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -080047
Devin Lim58046fa2017-07-05 16:55:00 -070048 ofPort = main.params[ 'CTRL' ][ 'port' ]
49 stepResult = main.testSetUp.envSetup( hasRest=True, hasNode=True )
50 except Exception as e:
51 main.testSetUp.envSetupException( e )
52 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall2c8959e2016-12-16 12:17:34 -080053
Devin Lim58046fa2017-07-05 16:55:00 -070054 main.testSetUp.ONOSSetUp( main.Mininet1, cellName=cellName )
Jon Hall2c8959e2016-12-16 12:17:34 -080055
Jon Hall2c8959e2016-12-16 12:17:34 -080056 main.step( "Starting Mininet" )
57 # scp topo file to mininet
58 # TODO: move to params?
59 topoName = "vpls"
60 topoFile = "vpls.py"
61 filePath = main.ONOSbench.home + "/tools/test/topos/"
62 main.ONOSbench.scp( main.Mininet1,
63 filePath + topoFile,
64 main.Mininet1.home,
65 direction="to" )
66 topo = " --custom " + main.Mininet1.home + topoFile + " --topo " + topoName
67 args = " --switch ovs,protocols=OpenFlow13 --controller=remote"
68 for node in main.nodes:
69 args += ",ip=" + node.ip_address
70 mnCmd = "sudo mn" + topo + args
71 mnResult = main.Mininet1.startNet( mnCmd=mnCmd )
72 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
73 onpass="Mininet Started",
74 onfail="Error starting Mininet" )
75
Jon Hall2c8959e2016-12-16 12:17:34 -080076 main.activeNodes = [ i for i in range( 0, len( main.CLIs ) ) ]
77
78 main.step( "Activate apps defined in the params file" )
79 # get data from the params
80 apps = main.params.get( 'apps' )
81 if apps:
Jon Halled258232017-05-24 17:30:18 -070082 apps = apps.split( ',' )
Jon Hall2c8959e2016-12-16 12:17:34 -080083 main.log.warn( apps )
84 activateResult = True
85 for app in apps:
86 main.CLIs[ 0 ].app( app, "Activate" )
87 # TODO: check this worked
88 time.sleep( SLEEP ) # wait for apps to activate
89 for app in apps:
90 state = main.CLIs[ 0 ].appStatus( app )
91 if state == "ACTIVE":
Jon Hall937bc812017-01-31 16:44:10 -080092 activateResult = activateResult and True
Jon Hall2c8959e2016-12-16 12:17:34 -080093 else:
94 main.log.error( "{} is in {} state".format( app, state ) )
Jon Hall937bc812017-01-31 16:44:10 -080095 activateResult = False
Jon Hall2c8959e2016-12-16 12:17:34 -080096 utilities.assert_equals( expect=True,
97 actual=activateResult,
98 onpass="Successfully activated apps",
99 onfail="Failed to activate apps" )
100 else:
101 main.log.warn( "No apps were specified to be loaded after startup" )
102
103 main.step( "Set ONOS configurations" )
104 config = main.params.get( 'ONOS_Configuration' )
105 if config:
106 main.log.debug( config )
107 checkResult = main.TRUE
108 for component in config:
Jon Halled258232017-05-24 17:30:18 -0700109 for setting in config[ component ]:
110 value = config[ component ][ setting ]
Jon Hall2c8959e2016-12-16 12:17:34 -0800111 check = main.CLIs[ 0 ].setCfg( component, setting, value )
112 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
113 checkResult = check and checkResult
114 utilities.assert_equals( expect=main.TRUE,
115 actual=checkResult,
116 onpass="Successfully set config",
117 onfail="Failed to set config" )
118 else:
119 main.log.warn( "No configurations were specified to be changed after startup" )
120
121 main.step( "App Ids check" )
122 appCheck = main.TRUE
123 threads = []
124 for i in main.activeNodes:
Jon Halled258232017-05-24 17:30:18 -0700125 t = main.Thread( target=main.CLIs[ i ].appToIDCheck,
Jon Hall2c8959e2016-12-16 12:17:34 -0800126 name="appToIDCheck-" + str( i ),
127 args=[] )
128 threads.append( t )
129 t.start()
130
131 for t in threads:
132 t.join()
133 appCheck = appCheck and t.result
134 if appCheck != main.TRUE:
Jon Halled258232017-05-24 17:30:18 -0700135 main.log.warn( main.CLIs[ 0 ].apps() )
136 main.log.warn( main.CLIs[ 0 ].appIDs() )
Jon Hall2c8959e2016-12-16 12:17:34 -0800137 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
138 onpass="App Ids seem to be correct",
139 onfail="Something is wrong with app Ids" )
140
141 def CASE2( self, main ):
142 """
143 Load and test vpls configurations from json configuration file
144 """
145 import os.path
146 from tests.USECASE.VPLS.dependencies import vpls
147
148 pprint = main.ONOSrest1.pprint
Jon Halled258232017-05-24 17:30:18 -0700149 hosts = int( main.params[ 'vpls' ][ 'hosts' ] )
150 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800151
152 main.step( "Discover hosts using pings" )
153 for i in range( 1, hosts + 1 ):
154 src = "h" + str( i )
155 for j in range( 1, hosts + 1 ):
156 if j == i:
157 continue
158 dst = "h" + str( j )
159 pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst )
160
161 main.step( "Load VPLS configurations" )
162 # TODO: load from params
Jon Halled258232017-05-24 17:30:18 -0700163 fileName = main.params[ 'DEPENDENCY' ][ 'topology' ]
164 app = main.params[ 'vpls' ][ 'name' ]
Jon Hall2c8959e2016-12-16 12:17:34 -0800165 # TODO make this a function?
166 main.ONOSbench.handle.sendline( "onos-netcfg $OC1 " + fileName )
167 # Time for netcfg to load data
168 time.sleep( SLEEP )
169 # 'Master' copy of test configuration
170 try:
171 with open( os.path.expanduser( fileName ) ) as dataFile:
172 originalCfg = json.load( dataFile )
Jon Halled258232017-05-24 17:30:18 -0700173 main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800174 except Exception as e:
175 main.log.error( "Error loading config file: {}".format( e ) )
176 if main.vplsConfig:
177 result = True
178 else:
179 result = False
180 utilities.assert_equals( expect=True,
181 actual=result,
182 onpass="Loaded vpls configuration",
183 onfail="Failed to load vpls configuration" )
184
185 main.step( "Check interface configurations" )
186 result = False
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700187 getPorts = utilities.retry( f=main.ONOSrest1.getNetCfg,
188 retValue=False,
189 kwargs={"subjectClass":"ports"},
190 sleep=SLEEP )
Jon Hall2c8959e2016-12-16 12:17:34 -0800191 onosCfg = pprint( getPorts )
192 sentCfg = pprint( originalCfg.get( "ports" ) )
193
194 if onosCfg == sentCfg:
195 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
196 result = True
197 else:
198 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
199 main.log.debug( "ONOS config: {}".format( onosCfg ) )
200 main.log.debug( "Sent config: {}".format( sentCfg ) )
201 utilities.assert_equals( expect=True,
202 actual=result,
203 onpass="Net Cfg added for interfaces",
204 onfail="Net Cfg not added for interfaces" )
205
206 # Run a bunch of checks to verify functionality based on configs
207 vpls.verify( main )
208
209 def CASE3( self, main ):
210 """
211 Test VPLS cli commands
212 High level steps:
213 remove interface from a network
214 Clean configs
215 create vpls network
216 add interfaces to a network
217 add encap
218 change encap
219 remove encap
220 list?
221 """
222 from tests.USECASE.VPLS.dependencies import vpls
Jon Halled258232017-05-24 17:30:18 -0700223 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800224 pprint = main.ONOSrest1.pprint
225
226 main.step( "Remove an interface from a vpls network" )
Jon Halled258232017-05-24 17:30:18 -0700227 main.CLIs[ 0 ].vplsRemIface( 'VPLS1', 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800228 time.sleep( SLEEP )
229 #update master config json
230 for network in main.vplsConfig:
231 if network.get( 'name' ) == 'VPLS1':
232 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700233 ifaces.remove( 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800234 vpls.verify( main )
235
236 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700237 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800238 time.sleep( SLEEP )
239 main.vplsConfig = []
240 vpls.verify( main )
241
242 main.step( "Create a new vpls network" )
243 name = "Network1"
Jon Halled258232017-05-24 17:30:18 -0700244 main.CLIs[ 0 ].vplsCreate( name )
Jon Hall2c8959e2016-12-16 12:17:34 -0800245 time.sleep( SLEEP )
246 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
247 main.vplsConfig.append( network1 )
248 vpls.verify( main )
249
250 main.step( "Add interfaces to the network" )
Jon Halled258232017-05-24 17:30:18 -0700251 main.CLIs[ 0 ].vplsAddIface( name, "h1" )
252 main.CLIs[ 0 ].vplsAddIface( name, "h5" )
253 main.CLIs[ 0 ].vplsAddIface( name, "h4" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800254 time.sleep( SLEEP )
255 for network in main.vplsConfig:
256 if network.get( 'name' ) == name:
257 ifaces = network.get( 'interfaces' )
258 ifaces.append( 'h1' )
259 ifaces.append( 'h4' )
260 ifaces.append( 'h5' )
261 network[ 'interfaces' ] = ifaces
262 vpls.verify( main )
263
264 main.step( "Add MPLS encapsulation to a vpls network" )
265 encapType = "MPLS"
Jon Halled258232017-05-24 17:30:18 -0700266 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800267 for network in main.vplsConfig:
268 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700269 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800270 time.sleep( SLEEP )
271 vpls.verify( main )
272
273 main.step( "Change an encapsulation type" )
274 encapType = "VLAN"
Jon Halled258232017-05-24 17:30:18 -0700275 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800276 for network in main.vplsConfig:
277 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700278 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800279 time.sleep( SLEEP )
280 vpls.verify( main )
281
282 main.step( "Remove encapsulation" )
283 encapType = "NONE"
Jon Halled258232017-05-24 17:30:18 -0700284 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800285 for network in main.vplsConfig:
286 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700287 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800288 time.sleep( SLEEP )
289 vpls.verify( main )
290
291 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700292 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800293 time.sleep( SLEEP )
294 main.vplsConfig = []
295 vpls.verify( main )