blob: 3003c829bc8e6ed3017b628dcdcbaf09000aa42a [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
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -070067 args = " --switch ovs,protocols=OpenFlow13"
Jon Hall2c8959e2016-12-16 12:17:34 -080068 for node in main.nodes:
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -070069 args += " --controller=remote,ip=" + node.ip_address
Jon Hall2c8959e2016-12-16 12:17:34 -080070 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
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700148 main.vpls = vpls
Jon Hall2c8959e2016-12-16 12:17:34 -0800149 pprint = main.ONOSrest1.pprint
Jon Halled258232017-05-24 17:30:18 -0700150 hosts = int( main.params[ 'vpls' ][ 'hosts' ] )
151 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800152
153 main.step( "Discover hosts using pings" )
154 for i in range( 1, hosts + 1 ):
155 src = "h" + str( i )
156 for j in range( 1, hosts + 1 ):
157 if j == i:
158 continue
159 dst = "h" + str( j )
160 pingResult = main.Mininet1.pingHost( SRC=src, TARGET=dst )
161
162 main.step( "Load VPLS configurations" )
Jon Halled258232017-05-24 17:30:18 -0700163 fileName = main.params[ 'DEPENDENCY' ][ 'topology' ]
164 app = main.params[ 'vpls' ][ 'name' ]
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700165
166 loadVPLSResult = main.ONOSbench.onosNetCfg( main.nodes[ 0 ].ip_address, "", fileName )
167 utilities.assert_equals( expect=main.TRUE,
168 actual=loadVPLSResult,
169 onpass="Loaded vpls configuration.",
170 onfail="Failed to load vpls configuration." )
171
Jon Hall2c8959e2016-12-16 12:17:34 -0800172 # Time for netcfg to load data
173 time.sleep( SLEEP )
174 # 'Master' copy of test configuration
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700175
Jon Hall2c8959e2016-12-16 12:17:34 -0800176 try:
177 with open( os.path.expanduser( fileName ) ) as dataFile:
178 originalCfg = json.load( dataFile )
Jon Halled258232017-05-24 17:30:18 -0700179 main.vplsConfig = originalCfg[ 'apps' ].get( app ).get( 'vpls' ).get( 'vplsList' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800180 except Exception as e:
181 main.log.error( "Error loading config file: {}".format( e ) )
182 if main.vplsConfig:
183 result = True
184 else:
185 result = False
186 utilities.assert_equals( expect=True,
187 actual=result,
188 onpass="Loaded vpls configuration",
189 onfail="Failed to load vpls configuration" )
190
191 main.step( "Check interface configurations" )
192 result = False
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700193 getPorts = utilities.retry( f=main.ONOSrest1.getNetCfg,
194 retValue=False,
195 kwargs={"subjectClass":"ports"},
196 sleep=SLEEP )
Jon Hall2c8959e2016-12-16 12:17:34 -0800197 onosCfg = pprint( getPorts )
198 sentCfg = pprint( originalCfg.get( "ports" ) )
199
200 if onosCfg == sentCfg:
201 main.log.info( "ONOS interfaces NetCfg matches what was sent" )
202 result = True
203 else:
204 main.log.error( "ONOS interfaces NetCfg doesn't match what was sent" )
205 main.log.debug( "ONOS config: {}".format( onosCfg ) )
206 main.log.debug( "Sent config: {}".format( sentCfg ) )
207 utilities.assert_equals( expect=True,
208 actual=result,
209 onpass="Net Cfg added for interfaces",
210 onfail="Net Cfg not added for interfaces" )
211
212 # Run a bunch of checks to verify functionality based on configs
213 vpls.verify( main )
214
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -0700215 main.step( "Loading vpls configuration in case any configuration was missed." )
216 loadVPLSResult = main.ONOSbench.onosNetCfg( main.nodes[ 0 ].ip_address, "", fileName )
217 utilities.assert_equals( expect=main.TRUE,
218 actual=loadVPLSResult,
219 onpass="Loaded vpls configuration.",
220 onfail="Failed to load vpls configuration." )
221
Jon Hall2c8959e2016-12-16 12:17:34 -0800222 def CASE3( self, main ):
223 """
224 Test VPLS cli commands
225 High level steps:
226 remove interface from a network
227 Clean configs
228 create vpls network
229 add interfaces to a network
230 add encap
231 change encap
232 remove encap
233 list?
234 """
235 from tests.USECASE.VPLS.dependencies import vpls
Jon Halled258232017-05-24 17:30:18 -0700236 SLEEP = int( main.params[ 'SLEEP' ][ 'netcfg' ] )
Jon Hall2c8959e2016-12-16 12:17:34 -0800237 pprint = main.ONOSrest1.pprint
238
239 main.step( "Remove an interface from a vpls network" )
Jon Halled258232017-05-24 17:30:18 -0700240 main.CLIs[ 0 ].vplsRemIface( 'VPLS1', 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800241 time.sleep( SLEEP )
242 #update master config json
243 for network in main.vplsConfig:
244 if network.get( 'name' ) == 'VPLS1':
245 ifaces = network.get( 'interfaces' )
Jon Halled258232017-05-24 17:30:18 -0700246 ifaces.remove( 'h1' )
Jon Hall2c8959e2016-12-16 12:17:34 -0800247 vpls.verify( main )
248
249 main.step( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700250 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800251 time.sleep( SLEEP )
252 main.vplsConfig = []
253 vpls.verify( main )
254
255 main.step( "Create a new vpls network" )
256 name = "Network1"
Jon Halled258232017-05-24 17:30:18 -0700257 main.CLIs[ 0 ].vplsCreate( name )
Jon Hall2c8959e2016-12-16 12:17:34 -0800258 time.sleep( SLEEP )
259 network1 = { 'name': name, 'interfaces': [], 'encapsulation': 'NONE' }
260 main.vplsConfig.append( network1 )
261 vpls.verify( main )
262
263 main.step( "Add interfaces to the network" )
Jon Halled258232017-05-24 17:30:18 -0700264 main.CLIs[ 0 ].vplsAddIface( name, "h1" )
265 main.CLIs[ 0 ].vplsAddIface( name, "h5" )
266 main.CLIs[ 0 ].vplsAddIface( name, "h4" )
Jon Hall2c8959e2016-12-16 12:17:34 -0800267 time.sleep( SLEEP )
268 for network in main.vplsConfig:
269 if network.get( 'name' ) == name:
270 ifaces = network.get( 'interfaces' )
271 ifaces.append( 'h1' )
272 ifaces.append( 'h4' )
273 ifaces.append( 'h5' )
274 network[ 'interfaces' ] = ifaces
275 vpls.verify( main )
276
277 main.step( "Add MPLS encapsulation to a vpls network" )
278 encapType = "MPLS"
Jon Halled258232017-05-24 17:30:18 -0700279 main.CLIs[ 0 ].vplsSetEncap( name, encapType )
Jon Hall2c8959e2016-12-16 12:17:34 -0800280 for network in main.vplsConfig:
281 if network.get( 'name' ) == name:
Jon Halled258232017-05-24 17:30:18 -0700282 network[ 'encapsulation' ] = encapType
Jon Hall2c8959e2016-12-16 12:17:34 -0800283 time.sleep( SLEEP )
284 vpls.verify( main )
285
286 main.step( "Change an encapsulation type" )
287 encapType = "VLAN"
Jon Halled258232017-05-24 17:30:18 -0700288 main.CLIs[ 0 ].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( "Remove encapsulation" )
296 encapType = "NONE"
Jon Halled258232017-05-24 17:30:18 -0700297 main.CLIs[ 0 ].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( "Clean all vpls configurations" )
Jon Halled258232017-05-24 17:30:18 -0700305 main.CLIs[ 0 ].vplsClean()
Jon Hall2c8959e2016-12-16 12:17:34 -0800306 time.sleep( SLEEP )
307 main.vplsConfig = []
308 vpls.verify( main )