blob: 894b96b04637ab7219558515d1966dbc29cbae2b [file] [log] [blame]
zhanghaoyu451c1392015-08-07 19:21:16 +08001"""
2Description: This test is to check onos set configuration and flows with ovsdb connection.
3
4List of test cases:
5CASE1: Compile ONOS and push it to the test machines
6CASE2: Test ovsdb connection and tearDown
7CASE3: Test default br-int configuration and vxlan port
8CASE4: Test default openflow configuration
9CASE5: Test default flows
zhanghaoyu7474d8c62015-08-26 14:53:28 +080010CASE6: Configure Network Subnet Port
zhanghaoyu451c1392015-08-07 19:21:16 +080011CASE7: Test host go online and ping each other
zhanghaoyu7474d8c62015-08-26 14:53:28 +080012CASE8: Clear ovs configuration and host configuration
zhanghaoyu451c1392015-08-07 19:21:16 +080013zhanghaoyu7@huawei.com
14"""
15import os
16
17class FUNCovsdbtest:
18
19 def __init__( self ):
20 self.default = ''
21
22 def CASE1( self, main ):
23 """
24 CASE1 is to compile ONOS and push it to the test machines
25
26 Startup sequence:
alison6acef9f2016-09-28 12:29:08 -070027 Construct test variables
28 Safety check, kill all ONOS processes before setup
zhanghaoyu451c1392015-08-07 19:21:16 +080029 NOTE: temporary - onos-remove-raft-logs
alison6acef9f2016-09-28 12:29:08 -070030 Create ONOS package
31 Install ONOS package
zhanghaoyu451c1392015-08-07 19:21:16 +080032 start cli sessions
33 start ovsdb
34 start vtn apps
35 """
36 import os
alison6acef9f2016-09-28 12:29:08 -070037 import time
38 main.log.info( "ONOS Single node start ovsdb test - initialization" )
zhanghaoyu451c1392015-08-07 19:21:16 +080039 main.case( "Setting up test environment" )
40 main.caseExplanation = "Setup the test environment including " +\
41 "installing ONOS, start ONOS."
42
43 # load some variables from the params file
alison6acef9f2016-09-28 12:29:08 -070044 main.step( "Constructing test variables" )
45 gitPull = main.params[ 'GIT' ][ 'pull' ]
zhanghaoyu451c1392015-08-07 19:21:16 +080046 gitBranch = main.params[ 'GIT' ][ 'branch' ]
47 cellName = main.params[ 'ENV' ][ 'cellName' ]
48 ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
alison6acef9f2016-09-28 12:29:08 -070049 main.startUpSleep = int( main.params['SLEEP']['startup'] )
50 cellAppString = main.params['ENV']['cellApps']
zhanghaoyu451c1392015-08-07 19:21:16 +080051
alison6acef9f2016-09-28 12:29:08 -070052 if gitPull == 'True':
53 main.step( "Building ONOS in " + gitBranch + "branch" )
54 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
55 stepResult = onosBuildResult
56 utilities.assert_equals( expect=main.TRUE,
57 actual=stepResult,
58 onpass="Successfully compiled latest ONOS",
59 onfail="Failed to compile latest ONOS")
60 else:
61 main.log.warn( "Did not pull new code so skipping mvn " +
62 "clean install" )
63 main.ONOSbench.getVersion( report=True )
zhanghaoyu451c1392015-08-07 19:21:16 +080064
alison6acef9f2016-09-28 12:29:08 -070065 main.log.info( "Safety check, killing all ONOS processes" +
66 " before initiating environment setup" )
zhanghaoyu451c1392015-08-07 19:21:16 +080067
68 main.log.info( "Removing raft logs" )
69 main.ONOSbench.onosRemoveRaftLogs()
70
71 main.CLIs = []
72 main.nodes = []
73 main.numCtrls= 1
74
75 for i in range( 1, main.numCtrls + 1 ):
76 try:
77 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
78 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
79 ipList.append( main.nodes[ -1 ].ip_address )
80 except AttributeError:
81 break
82
alison6acef9f2016-09-28 12:29:08 -070083 main.step( "Uninstalling ONOS package" )
84 onosUninstallResult = main.TRUE
zhanghaoyu451c1392015-08-07 19:21:16 +080085 for node in main.nodes:
alison6acef9f2016-09-28 12:29:08 -070086 onosUninstallResult = onosUninstallResult and main.ONOSbench.onosUninstall( node.ip_address )
87 utilities.assert_equals( expect=main.TRUE,
88 actual=onosUninstallResult,
89 onpass="Successfully uninstalled ONOS package",
90 onfail="Failed to uninstall ONOS package" )
91 time.sleep( main.startUpSleep )
zhanghaoyu451c1392015-08-07 19:21:16 +080092
93 # Make sure ONOS process is not running
94 main.log.info( "Killing any ONOS processes" )
95 killResults = main.TRUE
96 for node in main.nodes:
97 killed = main.ONOSbench.onosKill( node.ip_address )
98 killResults = killResults and killed
zhanghaoyu451c1392015-08-07 19:21:16 +080099 utilities.assert_equals( expect=main.TRUE,
alison6acef9f2016-09-28 12:29:08 -0700100 actual=onosUninstallResult,
101 onpass="Successfully kill all ONOS processes",
102 onfail="Failed to kill all ONOS processes" )
103
104 main.step( "Create cell file" )
105 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
106 main.OVSDB1.ip_address,
107 cellAppString, ipList )
108
109 main.step( "Apply cell to environment" )
110 cellResult = main.ONOSbench.setCell( cellName )
111 verifyResult = main.ONOSbench.verifyCell()
112 stepResult = cellResult and verifyResult
113 utilities.assert_equals( expect=main.TRUE,
114 actual=stepResult,
115 onpass="Successfully applied cell to environment",
116 onfail="Failed to apply cell to environment" )
117
zhanghaoyu451c1392015-08-07 19:21:16 +0800118
119 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700120 packageResult = main.ONOSbench.buckBuild()
zhanghaoyu451c1392015-08-07 19:21:16 +0800121 utilities.assert_equals( expect=main.TRUE,
alison6acef9f2016-09-28 12:29:08 -0700122 actual=packageResult,
123 onpass="Successfully created ONOS package",
124 onfail="Failed to create ONOS package" )
zhanghaoyu451c1392015-08-07 19:21:16 +0800125
alison6acef9f2016-09-28 12:29:08 -0700126 time.sleep( main.startUpSleep )
zhanghaoyu451c1392015-08-07 19:21:16 +0800127 main.step( "Installing ONOS package" )
alison6acef9f2016-09-28 12:29:08 -0700128 onosInstallResult = main.ONOSbench.onosInstall( options="-f", node=main.nodes[0].ip_address )
zhanghaoyu451c1392015-08-07 19:21:16 +0800129 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
alison6acef9f2016-09-28 12:29:08 -0700130 onpass="Successfully installed ONOS package",
131 onfail="Failed to install ONOS package" )
zhanghaoyu451c1392015-08-07 19:21:16 +0800132
alison6acef9f2016-09-28 12:29:08 -0700133 time.sleep( main.startUpSleep )
134 main.step("Starting ONOS service")
135 stopResult = main.TRUE
136 startResult = main.TRUE
137 onos1Isup = main.TRUE
zhanghaoyu451c1392015-08-07 19:21:16 +0800138 for i in range( 2 ):
alison6acef9f2016-09-28 12:29:08 -0700139 Isup = main.ONOSbench.isup( main.nodes[ 0 ].ip_address )
140 onos1Isup = onos1Isup and Isup
zhanghaoyu451c1392015-08-07 19:21:16 +0800141 if onos1Isup:
alison6acef9f2016-09-28 12:29:08 -0700142 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
143 else:
144 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
145 "start ONOS again" )
146 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
147 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
148 if not startResult or stopResult:
149 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1 ) )
150 stepResult = onos1Isup and stopResult and startResult
151 utilities.assert_equals( expect=main.TRUE, actual=stepResult,
152 onpass="ONOS service is ready on all nodes",
153 onfail="ONOS service did not start properly on all nodes" )
154
Chiyu Chengef109502016-11-21 15:51:38 -0800155 main.step( "Set up ONOS secure SSH" )
156 secureSshResult = main.TRUE
157 for i in range( int( main.numCtrls ) ):
alisonb1a26522016-11-22 17:27:17 -0800158 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.nodes[ i ].ip_address )
Chiyu Chengef109502016-11-21 15:51:38 -0800159 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
160 onpass="Test step PASS",
161 onfail="Test step FAIL" )
162
Jon Hall6509dbf2016-06-21 17:01:17 -0700163 main.step( "Starting ONOS CLI sessions" )
alison6acef9f2016-09-28 12:29:08 -0700164 cliResults = main.ONOScli1.startOnosCli( main.nodes[ 0 ].ip_address )
zhanghaoyu451c1392015-08-07 19:21:16 +0800165 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
alison6acef9f2016-09-28 12:29:08 -0700166 onpass="Successfully start ONOS cli",
167 onfail="Failed to start ONOS cli" )
168
169 if cliResults == main.FALSE:
170 main.log.error( "Failed to start ONOS, stopping test" )
171 main.cleanup()
172 main.exit()
zhanghaoyu451c1392015-08-07 19:21:16 +0800173
174 main.step( "App Ids check" )
175 appCheck = main.ONOScli1.appToIDCheck()
176
alison6acef9f2016-09-28 12:29:08 -0700177 if appCheck != main.TRUE:
178 main.log.warn( main.CLIs[ 0 ].apps() )
179 main.log.warn( main.CLIs[ 0 ].appIDs() )
180
181 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
zhanghaoyu451c1392015-08-07 19:21:16 +0800182 onpass="App Ids seem to be correct",
183 onfail="Something is wrong with app Ids" )
zhanghaoyu451c1392015-08-07 19:21:16 +0800184
alisond9915ea2016-08-12 10:16:26 -0700185 main.step( "Install onos-ovsdb" )
zhanghaoyu451c1392015-08-07 19:21:16 +0800186 installResults = main.ONOScli1.activateApp( "org.onosproject.ovsdb" )
187 utilities.assert_equals( expect=main.TRUE, actual=installResults,
188 onpass="Install onos-ovsdatabase successful",
189 onfail="Install onos-ovsdatabase failed" )
190
zhanghaoyu451c1392015-08-07 19:21:16 +0800191 main.step( "Install onos-app-vtn" )
192 installResults = main.ONOScli1.activateApp( "org.onosproject.vtn" )
193 utilities.assert_equals( expect=main.TRUE, actual=installResults,
194 onpass="Install onos-app-vtn successful",
195 onfail="Install onos-app-vtn failed" )
196
zhanghaoyu451c1392015-08-07 19:21:16 +0800197 def CASE2( self, main ):
198
199 """
200 Test ovsdb connection and teardown
201 """
alison6acef9f2016-09-28 12:29:08 -0700202 import os
zhanghaoyu451c1392015-08-07 19:21:16 +0800203 import re
zhanghaoyu451c1392015-08-07 19:21:16 +0800204
205 main.case( "Test ovsdb connection and teardown" )
206 main.caseExplanation = "Test ovsdb connection create and delete" +\
207 " over ovsdb node and onos node "
208
209 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
210 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
211 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
212
213 main.step( "Set ovsdb node manager" )
214 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
215 stepResult = assignResult
216 utilities.assert_equals( expect=main.TRUE,
217 actual=stepResult,
218 onpass="Set ovsdb node manager sucess",
219 onfail="Set ovsdb node manager failed" )
220
221 main.step( "Check ovsdb node manager is " + str( ctrlip ) )
222 response = main.OVSDB1.getManager()
223 if re.search( ctrlip, response ):
224 stepResult = main.TRUE
225 else:
226 stepResult = main.FALSE
227 utilities.assert_equals( expect=main.TRUE,
228 actual=stepResult,
229 onpass="Check ovsdb node manager is " + str( response ) ,
230 onfail="Check ovsdb node manager failed" )
231
232 main.step( "Delete ovsdb node manager" )
233 deleteResult = main.OVSDB1.delManager( delaytime=delaytime )
234 stepResult = deleteResult
235 utilities.assert_equals( expect=main.TRUE,
236 actual=stepResult,
237 onpass="ovsdb node delete manager sucess",
238 onfail="ovsdb node delete manager failed" )
239
240 main.step( "Check ovsdb node delete manager " + str( ctrlip ) )
241 response = main.OVSDB1.getManager()
242 if not re.search( ctrlip, response ):
243 stepResult = main.TRUE
244 else:
245 stepResult = main.FALSE
246 utilities.assert_equals( expect=main.TRUE,
247 actual=stepResult,
248 onpass="Check ovsdb node delete manager sucess",
249 onfail="Check ovsdb node delete manager failed" )
250
251 def CASE3( self, main ):
252
253 """
254 Test default br-int configuration and vxlan port
255 """
256 import re
alison6acef9f2016-09-28 12:29:08 -0700257 import os
zhanghaoyu451c1392015-08-07 19:21:16 +0800258
259 main.case( "Test default br-int configuration and vxlan port" )
260 main.caseExplanation = "onos create default br-int bridge and" +\
261 " vxlan port on the ovsdb node"
262
263 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
264 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
265 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
alison6acef9f2016-09-28 12:29:08 -0700266 OVSDB1Ip = os.getenv( main.params['OVSDB']['ip1'] )
267 OVSDB2Ip = os.getenv( main.params['OVSDB']['ip2'] )
zhanghaoyu451c1392015-08-07 19:21:16 +0800268
269 main.step( "ovsdb node 1 set ovs manager to " + str( ctrlip ) )
270 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
271 stepResult = assignResult
272 utilities.assert_equals( expect=main.TRUE,
273 actual=stepResult,
274 onpass="ovsdb node 1 set ovs manager to to " +\
275 str( ctrlip ) + " sucess",
276 onfail="ovsdb node 1 set ovs manager to to " +\
277 str( ctrlip ) + " failed" )
278
279 main.step( "ovsdb node 2 set ovs manager to " + str( ctrlip ) )
280 assignResult = main.OVSDB2.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
281 stepResult = assignResult
282 utilities.assert_equals( expect=main.TRUE,
283 actual=stepResult,
284 onpass="ovsdb node 2 set ovs manager to to " +\
285 str( ctrlip ) + " sucess",
286 onfail="ovsdb node 2 set ovs manager to to " +\
287 str( ctrlip ) + " failed" )
288
289 main.step( "Check ovsdb node 1 manager is " + str( ctrlip ) )
290 response = main.OVSDB1.getManager()
291 if re.search( ctrlip, response ):
292 stepResult = main.TRUE
293 else:
294 stepResult = main.FALSE
295 utilities.assert_equals( expect=main.TRUE,
296 actual=stepResult,
297 onpass="ovsdb node 1 manager is " + str( response ) ,
298 onfail="ovsdb node 1 manager check failed" )
299
300 main.step( "Check ovsdb node 2 manager is " + str( ctrlip ) )
301 response = main.OVSDB2.getManager()
302 if re.search( ctrlip, response ):
303 stepResult = main.TRUE
304 else:
305 stepResult = main.FALSE
306 utilities.assert_equals( expect=main.TRUE,
307 actual=stepResult,
308 onpass="ovsdb node 2 manager is " + str( response ) ,
309 onfail="ovsdb node 2 manager check failed" )
310
311 main.step( "Check default br-int bridge on ovsdb node " + str( OVSDB1Ip ) )
312 response = main.OVSDB1.listBr()
313 if re.search( "br-int", response ):
314 stepResult = main.TRUE
315 else:
316 stepResult = main.FALSE
317 utilities.assert_equals( expect=main.TRUE,
318 actual=stepResult,
319 onpass="onos add default bridge on the node 1 sucess",
320 onfail="onos add default bridge on the node 1 failed" )
321
322 main.step( "Check default br-int bridge on ovsdb node " + str( OVSDB2Ip ) )
323 response = main.OVSDB2.listBr()
324 if re.search( "br-int", response ):
325 stepResult = main.TRUE
326 else:
327 stepResult = main.FALSE
328 utilities.assert_equals( expect=main.TRUE,
329 actual=stepResult,
330 onpass="onos add default bridge on the node 2 sucess",
331 onfail="onos add default bridge on the node 2 failed" )
332
333 main.step( "Check default vxlan port on ovsdb node " + str( OVSDB1Ip ) )
334 response = main.OVSDB1.listPorts( "br-int" )
335 if re.search( "vxlan", response ) and re.search( str( OVSDB2Ip ), response ):
336 stepResult = main.TRUE
337 else:
338 stepResult = main.FALSE
339 utilities.assert_equals( expect=main.TRUE,
340 actual=stepResult,
341 onpass="onos add default vxlan port on the node 1 sucess",
342 onfail="onos add default vxlan port on the node 1 failed" )
343
344 main.step( "Check default vxlan port on ovsdb node " + str( OVSDB2Ip ) )
345 response = main.OVSDB2.listPorts( "br-int" )
346 if re.search( "vxlan", response ) and re.search( str( OVSDB1Ip ), response ):
347 stepResult = main.TRUE
348 else:
349 stepResult = main.FALSE
350 utilities.assert_equals( expect=main.TRUE,
351 actual=stepResult,
352 onpass="onos add default vxlan port on the node 2 sucess",
353 onfail="onos add default vxlan port on the node 2 failed" )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800354
355 def CASE4( self, main ):
356
357 """
358 Test default openflow configuration
359 """
360 import re
alison6acef9f2016-09-28 12:29:08 -0700361 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800362
363 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
364 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
365 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
366
367 main.step( "ovsdb node 1 set ovs manager to " + str( ctrlip ) )
368 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
369 stepResult = assignResult
370 utilities.assert_equals( expect=main.TRUE,
371 actual=stepResult,
372 onpass="ovsdb node 1 set ovs manager to to " +\
373 str( ctrlip ) + " sucess",
374 onfail="ovsdb node 1 set ovs manager to to " +\
375 str( ctrlip ) + " failed" )
376
377 main.step( "ovsdb node 2 set ovs manager to " + str( ctrlip ) )
378 assignResult = main.OVSDB2.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
379 stepResult = assignResult
380 utilities.assert_equals( expect=main.TRUE,
381 actual=stepResult,
382 onpass="ovsdb node 2 set ovs manager to to " +\
383 str( ctrlip ) + " sucess",
384 onfail="ovsdb node 2 set ovs manager to to " +\
385 str( ctrlip ) + " failed" )
386
387 main.step( "Check ovsdb node 1 manager is " + str( ctrlip ) )
388 response = main.OVSDB1.getManager()
389 if re.search( ctrlip, response ):
390 stepResult = main.TRUE
391 else:
392 stepResult = main.FALSE
393 utilities.assert_equals( expect=main.TRUE,
394 actual=stepResult,
395 onpass="ovsdb node 1 manager is " + str( response ) ,
sunyulin916e13e2015-10-15 20:27:23 +0800396 onfail="ovsdb node 1 manager check failed\n" +\
397 str( main.OVSDB1.show() ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800398
399 main.step( "Check ovsdb node 2 manager is " + str( ctrlip ) )
400 response = main.OVSDB2.getManager()
401 if re.search( ctrlip, response ):
402 stepResult = main.TRUE
403 else:
404 stepResult = main.FALSE
405 utilities.assert_equals( expect=main.TRUE,
406 actual=stepResult,
407 onpass="ovsdb node 2 manager is " + str( response ) ,
sunyulin916e13e2015-10-15 20:27:23 +0800408 onfail="ovsdb node 2 manager check failed\n" +\
409 str( main.OVSDB2.show() ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800410
411 main.step( "Check ovsdb node 1 bridge br-int controller set to " + str( ctrlip ) )
412 response = main.OVSDB1.getController( "br-int" )
413 if re.search( ctrlip, response ):
414 stepResult = main.TRUE
415 else:
416 stepResult = main.FALSE
417 utilities.assert_equals( expect=main.TRUE,
418 actual=stepResult,
419 onpass="Check ovsdb node 1 bridge br-int controller set to " +\
420 str( ctrlip ) + " sucess",
421 onfail="Check ovsdb node 1 bridge br-int controller set to " +\
sunyulin916e13e2015-10-15 20:27:23 +0800422 str( ctrlip ) + " failed\n" + str( main.OVSDB1.show() ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800423
424 main.step( "Check ovsdb node 2 bridge br-int controller set to " + str( ctrlip ) )
425 response = main.OVSDB2.getController( "br-int" )
426 if re.search( ctrlip, response ):
427 stepResult = main.TRUE
428 else:
429 stepResult = main.FALSE
430 utilities.assert_equals( expect=main.TRUE,
431 actual=stepResult,
432 onpass="Check ovsdb node 2 bridge br-int controller set to " +\
433 str( ctrlip ) + " sucess",
434 onfail="Check ovsdb node 2 bridge br-int controller set to " +\
sunyulin916e13e2015-10-15 20:27:23 +0800435 str( ctrlip ) + " failed\n" + str( main.OVSDB2.show()) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800436
437 main.step( "Check onoscli devices have ovs " + str( OVSDB1Ip ) )
438 response = main.ONOScli1.devices()
439 if re.search( OVSDB1Ip, response ) and not re.search( "false", response ):
440 stepResult = main.TRUE
441 else:
442 stepResult = main.FALSE
443 utilities.assert_equals( expect=main.TRUE,
444 actual=stepResult,
445 onpass="Check onoscli devices have ovs " + str( OVSDB1Ip ) + " sucess",
446 onfail="Check onoscli devices have ovs " + str( OVSDB1Ip ) + " failed" )
447
448 main.step( "Check onoscli devices have ovs " + str( OVSDB2Ip ) )
449 response = main.ONOScli1.devices()
450 if re.search( OVSDB2Ip, response ) and not re.search( "false", response ):
451 stepResult = main.TRUE
452 else:
453 stepResult = main.FALSE
454 utilities.assert_equals( expect=main.TRUE,
455 actual=stepResult,
456 onpass="Check onoscli devices have ovs " + str( OVSDB2Ip ) + " sucess",
457 onfail="Check onoscli devices have ovs " + str( OVSDB2Ip ) + " failed" )
458
459 def CASE5( self, main ):
460
461 """
462 Test default flows
463 """
464 import re
alison6acef9f2016-09-28 12:29:08 -0700465 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800466
467 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
468 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
469 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
470
471 main.step( "ovsdb node 1 set ovs manager to onos" )
472 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
473 stepResult = assignResult
474 utilities.assert_equals( expect=main.TRUE,
475 actual=stepResult,
476 onpass="ovsdb node 1 set ovs manager to to " +\
477 str( ctrlip ) + " sucess",
478 onfail="ovsdb node 1 set ovs manager to to " +\
479 str( ctrlip ) + " failed" )
480
481 main.step( "Check ovsdb node 1 manager is " + str( ctrlip ) )
482 response = main.OVSDB1.getManager()
483 if re.search( ctrlip, response ):
484 stepResult = main.TRUE
485 else:
486 stepResult = main.FALSE
487 utilities.assert_equals( expect=main.TRUE,
488 actual=stepResult,
489 onpass="ovsdb node 1 manager is " + str( response ) ,
490 onfail="ovsdb node 1 manager check failed" )
491
492 main.step( "Check ovsdb node 1 bridge br-int default flows on " + str( OVSDB1Ip ) )
493 response = main.OVSDB1.dumpFlows( sw="br-int", protocols="OpenFlow13" )
494 if re.search( "actions=CONTROLLER", response ):
495 stepResult = main.TRUE
496 else:
497 stepResult = main.FALSE
498 utilities.assert_equals( expect=main.TRUE,
499 actual=stepResult,
500 onpass="Successfully set default flows " + str( ctrlip ) ,
501 onfail="Failed to set default flows " + str( ctrlip ) )
502
503 def CASE6( self, main ):
504 """
505 Configure Network Subnet Port
506 """
507 import os
508
509 try:
Jon Hall53c5e662016-04-13 16:06:56 -0700510 from tests.FUNC.FUNCovsdbtest.dependencies.Nbdata import NetworkData
511 from tests.FUNC.FUNCovsdbtest.dependencies.Nbdata import SubnetData
512 from tests.FUNC.FUNCovsdbtest.dependencies.Nbdata import VirtualPortData
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800513 except ImportError:
514 main.log.exception( "Something wrong with import file or code error." )
515 main.log.info( "Import Error, please check!" )
516 main.cleanup()
517 main.exit()
518
519 main.log.info( "Configure Network Subnet Port Start" )
520 main.case( "Configure Network Subnet Port" )
521 main.caseExplanation = "Configure Network Subnet Port " +\
522 "Verify post is OK"
523
524 ctrlip = os.getenv( main.params['CTRL']['ip1'] )
525 httpport = main.params['HTTP']['port']
526 path = main.params['HTTP']['path']
527
528 main.step( "Generate Post Data" )
529 network = NetworkData()
530 network.id = '030d6d3d-fa36-45bf-ae2b-4f4bc43a54dc'
531 network.tenant_id = '26cd996094344a0598b0a1af1d525cdc'
532 subnet = SubnetData()
533 subnet.id = "e44bd655-e22c-4aeb-b1e9-ea1606875178"
534 subnet.tenant_id = network.tenant_id
535 subnet.network_id = network.id
536 subnet.start = "10.0.0.1"
537 subnet.end = "10.0.0.254"
538 subnet.cidr = "10.0.0.0/24"
539 port1 = VirtualPortData()
540 port1.id = "00000000-0000-0000-0000-000000000001"
541 port1.subnet_id = subnet.id
542 port1.tenant_id = network.tenant_id
543 port1.network_id = network.id
544 port1.macAddress = "00:00:00:00:00:01"
545 port1.ip_address = "10.0.0.1"
546 port2 = VirtualPortData()
547 port2.id = "00000000-0000-0000-0000-000000000002"
548 port2.subnet_id = subnet.id
549 port2.tenant_id = network.tenant_id
550 port2.network_id = network.id
551 port2.macAddress = "00:00:00:00:00:02"
552 port2.ip_address = "10.0.0.2"
553
554 networkpostdata = network.DictoJson()
555 subnetpostdata = subnet.DictoJson()
556 port1postdata = port1.DictoJson()
557 port2postdata = port2.DictoJson()
558
559 main.step( "Post Network Data via HTTP(Post port need post network)" )
560 Poststatus, result = main.ONOSrest.send( ctrlip, httpport, '', path + 'networks/',
561 'POST', None, networkpostdata )
562 utilities.assert_equals(
563 expect='200',
564 actual=Poststatus,
565 onpass="Post Network Success",
566 onfail="Post Network Failed " + str( Poststatus ) + "," + str( result ) )
567
568 main.step( "Post Subnet Data via HTTP(Post port need post subnet)" )
569 Poststatus, result = main.ONOSrest.send( ctrlip, httpport, '', path + 'subnets/',
570 'POST', None, subnetpostdata )
571 utilities.assert_equals(
572 expect='202',
573 actual=Poststatus,
574 onpass="Post Subnet Success",
575 onfail="Post Subnet Failed " + str( Poststatus ) + "," + str( result ) )
576
577 main.step( "Post Port1 Data via HTTP" )
578 Poststatus, result = main.ONOSrest.send( ctrlip, httpport, '', path + 'ports/',
579 'POST', None, port1postdata )
580 utilities.assert_equals(
581 expect='200',
582 actual=Poststatus,
583 onpass="Post Port Success",
584 onfail="Post Port Failed " + str( Poststatus ) + "," + str( result ) )
585
586 main.step( "Post Port2 Data via HTTP" )
587 Poststatus, result = main.ONOSrest.send( ctrlip, httpport, '', path + 'ports/',
588 'POST', None, port2postdata )
589 utilities.assert_equals(
590 expect='200',
591 actual=Poststatus,
592 onpass="Post Port Success",
593 onfail="Post Port Failed " + str( Poststatus ) + "," + str( result ) )
594
595 def CASE7( self, main ):
596
597 """
598 Test host go online and ping each other
599 """
600 import re
alison6acef9f2016-09-28 12:29:08 -0700601 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800602
603 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
604 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
605 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
606
607 main.step( "ovsdb node 1 set ovs manager to " + str( ctrlip ) )
608 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
609 stepResult = assignResult
610 utilities.assert_equals( expect=main.TRUE,
611 actual=stepResult,
612 onpass="ovsdb node 1 set ovs manager to to " +\
613 str( ctrlip ) + " sucess",
614 onfail="ovsdb node 1 set ovs manager to to " +\
615 str( ctrlip ) + " failed" )
616
617 main.step( "ovsdb node 2 set ovs manager to " + str( ctrlip ) )
618 assignResult = main.OVSDB2.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
619 stepResult = assignResult
620 utilities.assert_equals( expect=main.TRUE,
621 actual=stepResult,
622 onpass="ovsdb node 2 set ovs manager to " +\
623 str( ctrlip ) + " sucess",
624 onfail="ovsdb node 2 set ovs manager to " +\
625 str( ctrlip ) + " failed" )
626
627 main.step( "Create host1 on node 1 " + str( OVSDB1Ip ) )
628 stepResult = main.OVSDB1.createHost( hostname="host1" )
629 utilities.assert_equals( expect=main.TRUE,
630 actual=stepResult,
631 onpass="Create host1 on node 1 " + str( OVSDB1Ip ) + " sucess",
632 onfail="Create host1 on node 1 " + str( OVSDB1Ip ) + " failed" )
633
634 main.step( "Create host2 on node 2 " + str( OVSDB2Ip ) )
635 stepResult = main.OVSDB2.createHost( hostname="host2" )
636 utilities.assert_equals( expect=main.TRUE,
637 actual=stepResult,
638 onpass="Create host2 on node 2 " + str( OVSDB2Ip ) + " sucess",
639 onfail="Create host2 on node 2 " + str( OVSDB2Ip ) + " failed" )
640
641 main.step( "Create port on host1 on the node " + str ( OVSDB1Ip ) )
642 stepResult = main.OVSDB1.createHostport( hostname="host1", hostport="host1-eth0", hostportmac="000000000001" )
643 utilities.assert_equals( expect=main.TRUE,
644 actual=stepResult,
645 onpass="Create port on host1 on the node " + str( OVSDB1Ip ) + " sucess",
646 onfail="Create port on host1 on the node " + str( OVSDB1Ip ) + " failed" )
647
648 main.step( "Create port on host2 on the node " + str ( OVSDB2Ip ) )
649 stepResult = main.OVSDB2.createHostport( hostname="host2", hostport="host2-eth0", hostportmac="000000000002" )
650 utilities.assert_equals( expect=main.TRUE,
651 actual=stepResult,
652 onpass="Create port on host1 on the node " + str( OVSDB2Ip ) + " sucess",
653 onfail="Create port on host1 on the node " + str( OVSDB2Ip ) + " failed" )
654
655 main.step( "Add port to ovs br-int and host go-online on the node " + str ( OVSDB1Ip ) )
656 stepResult = main.OVSDB1.addPortToOvs( ovsname="br-int", ifaceId="00000000-0000-0000-0000-000000000001",
657 attachedMac="00:00:00:00:00:01", vmuuid="10000000-0000-0000-0000-000000000001" )
658 utilities.assert_equals( expect=main.TRUE,
659 actual=stepResult,
660 onpass="Add port to ovs br-int and host go-online on the node " +\
661 str( OVSDB1Ip ) + " sucess",
662 onfail="Add port to ovs br-int and host go-online on the node " +\
663 str( OVSDB1Ip ) + " failed" )
664
665 main.step( "Add port to ovs br-int and host go-online on the node " + str ( OVSDB2Ip ) )
666 stepResult = main.OVSDB2.addPortToOvs( ovsname="br-int", ifaceId="00000000-0000-0000-0000-000000000002",
667 attachedMac="00:00:00:00:00:02", vmuuid="10000000-0000-0000-0000-000000000001" )
668 utilities.assert_equals( expect=main.TRUE,
669 actual=stepResult,
670 onpass="Add port to ovs br-int and host go-online on the node " +\
671 str( OVSDB2Ip ) + " sucess",
672 onfail="Add port to ovs br-int and host go-online on the node " +\
673 str( OVSDB2Ip ) + " failed" )
674
675 main.step( "Check onos set host flows on the node " + str( OVSDB1Ip ) )
676 response = main.OVSDB1.dumpFlows( sw="br-int", protocols="OpenFlow13" )
677 if re.search( "00:00:00:00:00:01", response ):
678 stepResult = main.TRUE
679 else:
680 stepResult = main.FALSE
681 utilities.assert_equals( expect=main.TRUE,
682 actual=stepResult,
683 onpass="Check onos set host flows on the node " +\
684 str( OVSDB1Ip ) + " sucess",
685 onfail="Check onos set host flows on the node " +\
686 str( OVSDB1Ip ) + " failed" )
687
688 main.step( "Check onos set host flows on the node " + str( OVSDB2Ip ) )
689 response = main.OVSDB2.dumpFlows( sw="br-int", protocols="OpenFlow13" )
690 if re.search( "00:00:00:00:00:02", response ):
691 stepResult = main.TRUE
692 else:
693 stepResult = main.FALSE
694 utilities.assert_equals( expect=main.TRUE,
695 actual=stepResult,
696 onpass="Check onos set host flows on the node " +\
697 str( OVSDB2Ip ) + " sucess",
698 onfail="Check onos set host flows on the node " +\
699 str( OVSDB2Ip ) + " failed" )
700
701 main.step( "Check hosts can ping each other" )
702 main.OVSDB1.setHostportIp( hostname="host1", hostport1="host1-eth0", ip="10.0.0.1" )
703 main.OVSDB2.setHostportIp( hostname="host2", hostport1="host2-eth0", ip="10.0.0.2" )
704 pingResult1 = main.OVSDB1.hostPing( src="10.0.0.1", hostname="host1", target="10.0.0.2" )
705 pingResult2 = main.OVSDB2.hostPing( src="10.0.0.2", hostname="host2", target="10.0.0.1" )
706 stepResult = pingResult1 and pingResult2
707 utilities.assert_equals( expect=main.TRUE,
708 actual=stepResult,
709 onpass="Successfully host go online and ping each other,controller is " +\
710 str( ctrlip ),
711 onfail="Failed to host go online and ping each other,controller is " +\
712 str( ctrlip ) )
713
714 def CASE8( self, main ):
715
716 """
717 Clear ovs configuration and host configuration
718 """
719 import re
alison6acef9f2016-09-28 12:29:08 -0700720 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800721
722 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
723 OVSDB1Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip1' ] )
724 OVSDB2Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip2' ] )
725 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
726
727 main.step( "Delete ovsdb node 1 manager" )
728 deleteResult = main.OVSDB1.delManager( delaytime=delaytime )
729 stepResult = deleteResult
730 utilities.assert_equals( expect=main.TRUE,
731 actual=stepResult,
732 onpass="ovsdb node 1 delete manager sucess",
733 onfail="ovsdb node 1 delete manager failed" )
734
735 main.step( "Delete ovsdb node 2 manager" )
736 deleteResult = main.OVSDB2.delManager( delaytime=delaytime )
737 stepResult = deleteResult
738 utilities.assert_equals( expect=main.TRUE,
739 actual=stepResult,
740 onpass="ovsdb node 2 delete manager sucess",
741 onfail="ovsdb node 2 delete manager failed" )
742
743 main.step( "Delete ovsdb node 1 bridge br-int" )
744 deleteResult = main.OVSDB1.delBr( sw="br-int" )
745 stepResult = deleteResult
746 utilities.assert_equals( expect=main.TRUE,
747 actual=stepResult,
748 onpass="Delete ovsdb node 1 bridge br-int sucess",
749 onfail="Delete ovsdb node 1 bridge br-int failed" )
750
751 main.step( "Delete ovsdb node 2 bridge br-int" )
752 deleteResult = main.OVSDB2.delBr( sw="br-int" )
753 stepResult = deleteResult
754 utilities.assert_equals( expect=main.TRUE,
755 actual=stepResult,
756 onpass="Delete ovsdb node 2 bridge br-int sucess",
757 onfail="Delete ovsdb node 2 bridge br-int failed" )
758
759 main.step( "Delete ip netns host on the ovsdb node 1" )
760 deleteResult = main.OVSDB1.delHost( hostname="host1" )
761 stepResult = deleteResult
762 utilities.assert_equals( expect=main.TRUE,
763 actual=stepResult,
764 onpass="Delete ip netns host on the ovsdb node 1 sucess",
765 onfail="Delete ip netns host on the ovsdb node 1 failed" )
766
767 main.step( "Delete ip netns host on the ovsdb node 2" )
768 deleteResult = main.OVSDB2.delHost( hostname="host2" )
769 stepResult = deleteResult
770 utilities.assert_equals( expect=main.TRUE,
771 actual=stepResult,
772 onpass="Delete ip netns host on the ovsdb node 2 sucess",
773 onfail="Delete ip netns host on the ovsdb node 2 failed" )
774
775 main.step( "Check onoscli devices openflow session is false " + str( OVSDB1Ip ) )
776 response = main.ONOScli1.devices()
777 if re.search( OVSDB1Ip, response ) and not re.search( "true", response ):
778 stepResult = main.TRUE
779 else:
780 stepResult = main.FALSE
781 utilities.assert_equals( expect=main.TRUE,
782 actual=stepResult,
783 onpass="Check openflow session is false " + str( OVSDB1Ip ) + " sucess",
784 onfail="Check openflow session is false " + str( OVSDB1Ip ) + " failed" )
785
786 main.step( "Check onoscli devices have ovs " + str( OVSDB2Ip ) )
787 response = main.ONOScli1.devices()
788 if re.search( OVSDB2Ip, response ) and not re.search( "true", response ):
789 stepResult = main.TRUE
790 else:
791 stepResult = main.FALSE
792 utilities.assert_equals( expect=main.TRUE,
793 actual=stepResult,
794 onpass="Check openflow session is false " + str( OVSDB2Ip ) + " sucess",
Jon Hall53c5e662016-04-13 16:06:56 -0700795 onfail="Check openflow session is false " + str( OVSDB2Ip ) + " failed" )