blob: f16adb86971a5f3add2d54496af63c9c7bcc36a4 [file] [log] [blame]
zhanghaoyu451c1392015-08-07 19:21:16 +08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2015 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
22"""
zhanghaoyu451c1392015-08-07 19:21:16 +080023Description: This test is to check onos set configuration and flows with ovsdb connection.
24
25List of test cases:
26CASE1: Compile ONOS and push it to the test machines
27CASE2: Test ovsdb connection and tearDown
28CASE3: Test default br-int configuration and vxlan port
29CASE4: Test default openflow configuration
30CASE5: Test default flows
zhanghaoyu7474d8c62015-08-26 14:53:28 +080031CASE6: Configure Network Subnet Port
zhanghaoyu451c1392015-08-07 19:21:16 +080032CASE7: Test host go online and ping each other
zhanghaoyu7474d8c62015-08-26 14:53:28 +080033CASE8: Clear ovs configuration and host configuration
zhanghaoyu451c1392015-08-07 19:21:16 +080034zhanghaoyu7@huawei.com
35"""
36import os
37
Jon Hall8638b562017-05-24 16:39:59 -070038
zhanghaoyu451c1392015-08-07 19:21:16 +080039class FUNCovsdbtest:
40
41 def __init__( self ):
42 self.default = ''
43
44 def CASE1( self, main ):
45 """
46 CASE1 is to compile ONOS and push it to the test machines
47
48 Startup sequence:
alison6acef9f2016-09-28 12:29:08 -070049 Construct test variables
50 Safety check, kill all ONOS processes before setup
zhanghaoyu451c1392015-08-07 19:21:16 +080051 NOTE: temporary - onos-remove-raft-logs
alison6acef9f2016-09-28 12:29:08 -070052 Create ONOS package
53 Install ONOS package
zhanghaoyu451c1392015-08-07 19:21:16 +080054 start cli sessions
55 start ovsdb
56 start vtn apps
57 """
58 import os
alison6acef9f2016-09-28 12:29:08 -070059 import time
60 main.log.info( "ONOS Single node start ovsdb test - initialization" )
Devin Lim58046fa2017-07-05 16:55:00 -070061 try:
62 from tests.dependencies.ONOSSetup import ONOSSetup
63 main.testSetUp = ONOSSetup()
64 except ImportError:
65 main.log.error( "ONOSSetup not found. exiting the test" )
66 main.exit()
67 main.testSetUp.envSetupDescription()
68 stepResult = main.FALSE
zhanghaoyu451c1392015-08-07 19:21:16 +080069
Devin Lim58046fa2017-07-05 16:55:00 -070070 try:
71 # load some variables from the params file
72 main.step( "Constructing test variables" )
73 cellName = main.params[ 'ENV' ][ 'cellName' ]
74 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
75 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Devin Lim142b5342017-07-20 15:22:39 -070076 stepResult = main.testSetUp.envSetup()
zhanghaoyu451c1392015-08-07 19:21:16 +080077
Devin Lim58046fa2017-07-05 16:55:00 -070078 except Exception as e:
79 main.testSetUp.envSetupException( e )
80 main.testSetUp.evnSetupConclusion( stepResult )
zhanghaoyu451c1392015-08-07 19:21:16 +080081
zhanghaoyu451c1392015-08-07 19:21:16 +080082
Devin Lim142b5342017-07-20 15:22:39 -070083 cliResults = main.testSetUp.ONOSSetUp( main.OVSDB1, main.Cluster,
84 cellName=cellName, removeLog=True )
alison6acef9f2016-09-28 12:29:08 -070085
86 if cliResults == main.FALSE:
87 main.log.error( "Failed to start ONOS, stopping test" )
88 main.cleanup()
89 main.exit()
zhanghaoyu451c1392015-08-07 19:21:16 +080090
91 main.step( "App Ids check" )
Devin Lim142b5342017-07-20 15:22:39 -070092 appCheck = main.Cluster.active( 0 ).CLI.appToIDCheck()
zhanghaoyu451c1392015-08-07 19:21:16 +080093
alison6acef9f2016-09-28 12:29:08 -070094 if appCheck != main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -070095 main.log.warn( main.Cluster.active( 0 ).CLI.apps() )
96 main.log.warn( main.Cluster.active( 0 ).CLI.appIDs() )
alison6acef9f2016-09-28 12:29:08 -070097
98 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
zhanghaoyu451c1392015-08-07 19:21:16 +080099 onpass="App Ids seem to be correct",
100 onfail="Something is wrong with app Ids" )
zhanghaoyu451c1392015-08-07 19:21:16 +0800101
alisond9915ea2016-08-12 10:16:26 -0700102 main.step( "Install onos-ovsdb" )
Devin Lim142b5342017-07-20 15:22:39 -0700103 installResults = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.ovsdb" )
zhanghaoyu451c1392015-08-07 19:21:16 +0800104 utilities.assert_equals( expect=main.TRUE, actual=installResults,
105 onpass="Install onos-ovsdatabase successful",
106 onfail="Install onos-ovsdatabase failed" )
107
zhanghaoyu451c1392015-08-07 19:21:16 +0800108 main.step( "Install onos-app-vtn" )
Devin Lim142b5342017-07-20 15:22:39 -0700109 installResults = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.vtn" )
zhanghaoyu451c1392015-08-07 19:21:16 +0800110 utilities.assert_equals( expect=main.TRUE, actual=installResults,
111 onpass="Install onos-app-vtn successful",
112 onfail="Install onos-app-vtn failed" )
113
zhanghaoyu451c1392015-08-07 19:21:16 +0800114 def CASE2( self, main ):
zhanghaoyu451c1392015-08-07 19:21:16 +0800115 """
116 Test ovsdb connection and teardown
117 """
alison6acef9f2016-09-28 12:29:08 -0700118 import os
zhanghaoyu451c1392015-08-07 19:21:16 +0800119 import re
zhanghaoyu451c1392015-08-07 19:21:16 +0800120
121 main.case( "Test ovsdb connection and teardown" )
122 main.caseExplanation = "Test ovsdb connection create and delete" +\
123 " over ovsdb node and onos node "
124
125 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
126 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
127 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
128
129 main.step( "Set ovsdb node manager" )
130 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
131 stepResult = assignResult
132 utilities.assert_equals( expect=main.TRUE,
133 actual=stepResult,
134 onpass="Set ovsdb node manager sucess",
135 onfail="Set ovsdb node manager failed" )
136
137 main.step( "Check ovsdb node manager is " + str( ctrlip ) )
138 response = main.OVSDB1.getManager()
139 if re.search( ctrlip, response ):
140 stepResult = main.TRUE
141 else:
142 stepResult = main.FALSE
143 utilities.assert_equals( expect=main.TRUE,
144 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700145 onpass="Check ovsdb node manager is " + str( response ),
zhanghaoyu451c1392015-08-07 19:21:16 +0800146 onfail="Check ovsdb node manager failed" )
147
148 main.step( "Delete ovsdb node manager" )
149 deleteResult = main.OVSDB1.delManager( delaytime=delaytime )
150 stepResult = deleteResult
151 utilities.assert_equals( expect=main.TRUE,
152 actual=stepResult,
153 onpass="ovsdb node delete manager sucess",
154 onfail="ovsdb node delete manager failed" )
155
156 main.step( "Check ovsdb node delete manager " + str( ctrlip ) )
157 response = main.OVSDB1.getManager()
158 if not re.search( ctrlip, response ):
159 stepResult = main.TRUE
160 else:
161 stepResult = main.FALSE
162 utilities.assert_equals( expect=main.TRUE,
163 actual=stepResult,
164 onpass="Check ovsdb node delete manager sucess",
165 onfail="Check ovsdb node delete manager failed" )
166
167 def CASE3( self, main ):
zhanghaoyu451c1392015-08-07 19:21:16 +0800168 """
169 Test default br-int configuration and vxlan port
170 """
171 import re
alison6acef9f2016-09-28 12:29:08 -0700172 import os
zhanghaoyu451c1392015-08-07 19:21:16 +0800173
174 main.case( "Test default br-int configuration and vxlan port" )
175 main.caseExplanation = "onos create default br-int bridge and" +\
176 " vxlan port on the ovsdb node"
177
178 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
179 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
180 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
Jon Hall8638b562017-05-24 16:39:59 -0700181 OVSDB1Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip1' ] )
182 OVSDB2Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip2' ] )
zhanghaoyu451c1392015-08-07 19:21:16 +0800183
184 main.step( "ovsdb node 1 set ovs manager to " + str( ctrlip ) )
185 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
186 stepResult = assignResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700189 onpass="ovsdb node 1 set ovs manager to to " +
zhanghaoyu451c1392015-08-07 19:21:16 +0800190 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700191 onfail="ovsdb node 1 set ovs manager to to " +
zhanghaoyu451c1392015-08-07 19:21:16 +0800192 str( ctrlip ) + " failed" )
193
194 main.step( "ovsdb node 2 set ovs manager to " + str( ctrlip ) )
195 assignResult = main.OVSDB2.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
196 stepResult = assignResult
197 utilities.assert_equals( expect=main.TRUE,
198 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700199 onpass="ovsdb node 2 set ovs manager to to " +
zhanghaoyu451c1392015-08-07 19:21:16 +0800200 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700201 onfail="ovsdb node 2 set ovs manager to to " +
zhanghaoyu451c1392015-08-07 19:21:16 +0800202 str( ctrlip ) + " failed" )
203
204 main.step( "Check ovsdb node 1 manager is " + str( ctrlip ) )
205 response = main.OVSDB1.getManager()
206 if re.search( ctrlip, response ):
207 stepResult = main.TRUE
208 else:
209 stepResult = main.FALSE
210 utilities.assert_equals( expect=main.TRUE,
211 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700212 onpass="ovsdb node 1 manager is " + str( response ),
zhanghaoyu451c1392015-08-07 19:21:16 +0800213 onfail="ovsdb node 1 manager check failed" )
214
215 main.step( "Check ovsdb node 2 manager is " + str( ctrlip ) )
216 response = main.OVSDB2.getManager()
217 if re.search( ctrlip, response ):
218 stepResult = main.TRUE
219 else:
220 stepResult = main.FALSE
221 utilities.assert_equals( expect=main.TRUE,
222 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700223 onpass="ovsdb node 2 manager is " + str( response ),
zhanghaoyu451c1392015-08-07 19:21:16 +0800224 onfail="ovsdb node 2 manager check failed" )
225
226 main.step( "Check default br-int bridge on ovsdb node " + str( OVSDB1Ip ) )
227 response = main.OVSDB1.listBr()
228 if re.search( "br-int", response ):
229 stepResult = main.TRUE
230 else:
231 stepResult = main.FALSE
232 utilities.assert_equals( expect=main.TRUE,
233 actual=stepResult,
234 onpass="onos add default bridge on the node 1 sucess",
235 onfail="onos add default bridge on the node 1 failed" )
236
237 main.step( "Check default br-int bridge on ovsdb node " + str( OVSDB2Ip ) )
238 response = main.OVSDB2.listBr()
239 if re.search( "br-int", response ):
240 stepResult = main.TRUE
241 else:
242 stepResult = main.FALSE
243 utilities.assert_equals( expect=main.TRUE,
244 actual=stepResult,
245 onpass="onos add default bridge on the node 2 sucess",
246 onfail="onos add default bridge on the node 2 failed" )
247
248 main.step( "Check default vxlan port on ovsdb node " + str( OVSDB1Ip ) )
249 response = main.OVSDB1.listPorts( "br-int" )
250 if re.search( "vxlan", response ) and re.search( str( OVSDB2Ip ), response ):
251 stepResult = main.TRUE
252 else:
253 stepResult = main.FALSE
254 utilities.assert_equals( expect=main.TRUE,
255 actual=stepResult,
256 onpass="onos add default vxlan port on the node 1 sucess",
257 onfail="onos add default vxlan port on the node 1 failed" )
258
259 main.step( "Check default vxlan port on ovsdb node " + str( OVSDB2Ip ) )
260 response = main.OVSDB2.listPorts( "br-int" )
261 if re.search( "vxlan", response ) and re.search( str( OVSDB1Ip ), response ):
262 stepResult = main.TRUE
263 else:
264 stepResult = main.FALSE
265 utilities.assert_equals( expect=main.TRUE,
266 actual=stepResult,
267 onpass="onos add default vxlan port on the node 2 sucess",
268 onfail="onos add default vxlan port on the node 2 failed" )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800269
270 def CASE4( self, main ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800271 """
272 Test default openflow configuration
273 """
274 import re
alison6acef9f2016-09-28 12:29:08 -0700275 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800276
277 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
278 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
279 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
280
281 main.step( "ovsdb node 1 set ovs manager to " + str( ctrlip ) )
282 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
283 stepResult = assignResult
284 utilities.assert_equals( expect=main.TRUE,
285 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700286 onpass="ovsdb node 1 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800287 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700288 onfail="ovsdb node 1 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800289 str( ctrlip ) + " failed" )
290
291 main.step( "ovsdb node 2 set ovs manager to " + str( ctrlip ) )
292 assignResult = main.OVSDB2.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
293 stepResult = assignResult
294 utilities.assert_equals( expect=main.TRUE,
295 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700296 onpass="ovsdb node 2 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800297 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700298 onfail="ovsdb node 2 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800299 str( ctrlip ) + " failed" )
300
301 main.step( "Check ovsdb node 1 manager is " + str( ctrlip ) )
302 response = main.OVSDB1.getManager()
303 if re.search( ctrlip, response ):
304 stepResult = main.TRUE
305 else:
306 stepResult = main.FALSE
307 utilities.assert_equals( expect=main.TRUE,
308 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700309 onpass="ovsdb node 1 manager is " + str( response ),
310 onfail="ovsdb node 1 manager check failed\n" +
sunyulin916e13e2015-10-15 20:27:23 +0800311 str( main.OVSDB1.show() ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800312
313 main.step( "Check ovsdb node 2 manager is " + str( ctrlip ) )
314 response = main.OVSDB2.getManager()
315 if re.search( ctrlip, response ):
316 stepResult = main.TRUE
317 else:
318 stepResult = main.FALSE
319 utilities.assert_equals( expect=main.TRUE,
320 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700321 onpass="ovsdb node 2 manager is " + str( response ),
322 onfail="ovsdb node 2 manager check failed\n" +
sunyulin916e13e2015-10-15 20:27:23 +0800323 str( main.OVSDB2.show() ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800324
325 main.step( "Check ovsdb node 1 bridge br-int controller set to " + str( ctrlip ) )
326 response = main.OVSDB1.getController( "br-int" )
327 if re.search( ctrlip, response ):
328 stepResult = main.TRUE
329 else:
330 stepResult = main.FALSE
331 utilities.assert_equals( expect=main.TRUE,
332 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700333 onpass="Check ovsdb node 1 bridge br-int controller set to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800334 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700335 onfail="Check ovsdb node 1 bridge br-int controller set to " +
sunyulin916e13e2015-10-15 20:27:23 +0800336 str( ctrlip ) + " failed\n" + str( main.OVSDB1.show() ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800337
338 main.step( "Check ovsdb node 2 bridge br-int controller set to " + str( ctrlip ) )
339 response = main.OVSDB2.getController( "br-int" )
340 if re.search( ctrlip, response ):
341 stepResult = main.TRUE
342 else:
343 stepResult = main.FALSE
344 utilities.assert_equals( expect=main.TRUE,
345 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700346 onpass="Check ovsdb node 2 bridge br-int controller set to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800347 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700348 onfail="Check ovsdb node 2 bridge br-int controller set to " +
349 str( ctrlip ) + " failed\n" + str( main.OVSDB2.show() ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800350
351 main.step( "Check onoscli devices have ovs " + str( OVSDB1Ip ) )
Devin Lim142b5342017-07-20 15:22:39 -0700352 response = main.Cluster.active( 0 ).CLI.devices()
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800353 if re.search( OVSDB1Ip, response ) and not re.search( "false", response ):
354 stepResult = main.TRUE
355 else:
356 stepResult = main.FALSE
357 utilities.assert_equals( expect=main.TRUE,
358 actual=stepResult,
359 onpass="Check onoscli devices have ovs " + str( OVSDB1Ip ) + " sucess",
360 onfail="Check onoscli devices have ovs " + str( OVSDB1Ip ) + " failed" )
361
362 main.step( "Check onoscli devices have ovs " + str( OVSDB2Ip ) )
Devin Lim142b5342017-07-20 15:22:39 -0700363 response = main.Cluster.active( 0 ).CLI.devices()
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800364 if re.search( OVSDB2Ip, response ) and not re.search( "false", response ):
365 stepResult = main.TRUE
366 else:
367 stepResult = main.FALSE
368 utilities.assert_equals( expect=main.TRUE,
369 actual=stepResult,
370 onpass="Check onoscli devices have ovs " + str( OVSDB2Ip ) + " sucess",
371 onfail="Check onoscli devices have ovs " + str( OVSDB2Ip ) + " failed" )
372
373 def CASE5( self, main ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800374 """
375 Test default flows
376 """
377 import re
alison6acef9f2016-09-28 12:29:08 -0700378 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800379
380 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
381 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
382 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
383
384 main.step( "ovsdb node 1 set ovs manager to onos" )
385 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
386 stepResult = assignResult
387 utilities.assert_equals( expect=main.TRUE,
388 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700389 onpass="ovsdb node 1 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800390 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700391 onfail="ovsdb node 1 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800392 str( ctrlip ) + " failed" )
393
394 main.step( "Check ovsdb node 1 manager is " + str( ctrlip ) )
395 response = main.OVSDB1.getManager()
396 if re.search( ctrlip, response ):
397 stepResult = main.TRUE
398 else:
399 stepResult = main.FALSE
400 utilities.assert_equals( expect=main.TRUE,
401 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700402 onpass="ovsdb node 1 manager is " + str( response ),
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800403 onfail="ovsdb node 1 manager check failed" )
404
405 main.step( "Check ovsdb node 1 bridge br-int default flows on " + str( OVSDB1Ip ) )
406 response = main.OVSDB1.dumpFlows( sw="br-int", protocols="OpenFlow13" )
407 if re.search( "actions=CONTROLLER", response ):
408 stepResult = main.TRUE
409 else:
410 stepResult = main.FALSE
411 utilities.assert_equals( expect=main.TRUE,
412 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700413 onpass="Successfully set default flows " + str( ctrlip ),
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800414 onfail="Failed to set default flows " + str( ctrlip ) )
415
416 def CASE6( self, main ):
417 """
418 Configure Network Subnet Port
419 """
420 import os
421
422 try:
Jon Hall53c5e662016-04-13 16:06:56 -0700423 from tests.FUNC.FUNCovsdbtest.dependencies.Nbdata import NetworkData
424 from tests.FUNC.FUNCovsdbtest.dependencies.Nbdata import SubnetData
425 from tests.FUNC.FUNCovsdbtest.dependencies.Nbdata import VirtualPortData
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800426 except ImportError:
427 main.log.exception( "Something wrong with import file or code error." )
428 main.log.info( "Import Error, please check!" )
429 main.cleanup()
430 main.exit()
431
432 main.log.info( "Configure Network Subnet Port Start" )
433 main.case( "Configure Network Subnet Port" )
434 main.caseExplanation = "Configure Network Subnet Port " +\
435 "Verify post is OK"
436
Jon Hall8638b562017-05-24 16:39:59 -0700437 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
438 httpport = main.params[ 'HTTP' ][ 'port' ]
439 path = main.params[ 'HTTP' ][ 'path' ]
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800440
441 main.step( "Generate Post Data" )
442 network = NetworkData()
443 network.id = '030d6d3d-fa36-45bf-ae2b-4f4bc43a54dc'
444 network.tenant_id = '26cd996094344a0598b0a1af1d525cdc'
445 subnet = SubnetData()
446 subnet.id = "e44bd655-e22c-4aeb-b1e9-ea1606875178"
447 subnet.tenant_id = network.tenant_id
448 subnet.network_id = network.id
449 subnet.start = "10.0.0.1"
450 subnet.end = "10.0.0.254"
451 subnet.cidr = "10.0.0.0/24"
452 port1 = VirtualPortData()
453 port1.id = "00000000-0000-0000-0000-000000000001"
454 port1.subnet_id = subnet.id
455 port1.tenant_id = network.tenant_id
456 port1.network_id = network.id
457 port1.macAddress = "00:00:00:00:00:01"
458 port1.ip_address = "10.0.0.1"
459 port2 = VirtualPortData()
460 port2.id = "00000000-0000-0000-0000-000000000002"
461 port2.subnet_id = subnet.id
462 port2.tenant_id = network.tenant_id
463 port2.network_id = network.id
464 port2.macAddress = "00:00:00:00:00:02"
465 port2.ip_address = "10.0.0.2"
466
467 networkpostdata = network.DictoJson()
468 subnetpostdata = subnet.DictoJson()
469 port1postdata = port1.DictoJson()
470 port2postdata = port2.DictoJson()
471
472 main.step( "Post Network Data via HTTP(Post port need post network)" )
Devin Lim142b5342017-07-20 15:22:39 -0700473 Poststatus, result = main.Cluster.active( 0 ).REST.send( ctrlip, httpport, '', path + 'networks/',
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800474 'POST', None, networkpostdata )
475 utilities.assert_equals(
476 expect='200',
477 actual=Poststatus,
478 onpass="Post Network Success",
479 onfail="Post Network Failed " + str( Poststatus ) + "," + str( result ) )
480
481 main.step( "Post Subnet Data via HTTP(Post port need post subnet)" )
Devin Lim142b5342017-07-20 15:22:39 -0700482 Poststatus, result = main.Cluster.active( 0 ).REST.send( ctrlip, httpport, '', path + 'subnets/',
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800483 'POST', None, subnetpostdata )
484 utilities.assert_equals(
485 expect='202',
486 actual=Poststatus,
487 onpass="Post Subnet Success",
488 onfail="Post Subnet Failed " + str( Poststatus ) + "," + str( result ) )
489
490 main.step( "Post Port1 Data via HTTP" )
Devin Lim142b5342017-07-20 15:22:39 -0700491 Poststatus, result = main.Cluster.active( 0 ).REST.send( ctrlip, httpport, '', path + 'ports/',
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800492 'POST', None, port1postdata )
493 utilities.assert_equals(
494 expect='200',
495 actual=Poststatus,
496 onpass="Post Port Success",
497 onfail="Post Port Failed " + str( Poststatus ) + "," + str( result ) )
498
499 main.step( "Post Port2 Data via HTTP" )
Devin Lim142b5342017-07-20 15:22:39 -0700500 Poststatus, result = main.Cluster.active( 0 ).REST.send( ctrlip, httpport, '', path + 'ports/',
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800501 'POST', None, port2postdata )
502 utilities.assert_equals(
503 expect='200',
504 actual=Poststatus,
505 onpass="Post Port Success",
506 onfail="Post Port Failed " + str( Poststatus ) + "," + str( result ) )
507
508 def CASE7( self, main ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800509 """
510 Test host go online and ping each other
511 """
512 import re
alison6acef9f2016-09-28 12:29:08 -0700513 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800514
515 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
516 ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ]
517 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
518
519 main.step( "ovsdb node 1 set ovs manager to " + str( ctrlip ) )
520 assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
521 stepResult = assignResult
522 utilities.assert_equals( expect=main.TRUE,
523 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700524 onpass="ovsdb node 1 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800525 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700526 onfail="ovsdb node 1 set ovs manager to to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800527 str( ctrlip ) + " failed" )
528
529 main.step( "ovsdb node 2 set ovs manager to " + str( ctrlip ) )
530 assignResult = main.OVSDB2.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime )
531 stepResult = assignResult
532 utilities.assert_equals( expect=main.TRUE,
533 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700534 onpass="ovsdb node 2 set ovs manager to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800535 str( ctrlip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700536 onfail="ovsdb node 2 set ovs manager to " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800537 str( ctrlip ) + " failed" )
538
539 main.step( "Create host1 on node 1 " + str( OVSDB1Ip ) )
540 stepResult = main.OVSDB1.createHost( hostname="host1" )
541 utilities.assert_equals( expect=main.TRUE,
542 actual=stepResult,
543 onpass="Create host1 on node 1 " + str( OVSDB1Ip ) + " sucess",
544 onfail="Create host1 on node 1 " + str( OVSDB1Ip ) + " failed" )
545
546 main.step( "Create host2 on node 2 " + str( OVSDB2Ip ) )
547 stepResult = main.OVSDB2.createHost( hostname="host2" )
548 utilities.assert_equals( expect=main.TRUE,
549 actual=stepResult,
550 onpass="Create host2 on node 2 " + str( OVSDB2Ip ) + " sucess",
551 onfail="Create host2 on node 2 " + str( OVSDB2Ip ) + " failed" )
552
Jon Hall8638b562017-05-24 16:39:59 -0700553 main.step( "Create port on host1 on the node " + str( OVSDB1Ip ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800554 stepResult = main.OVSDB1.createHostport( hostname="host1", hostport="host1-eth0", hostportmac="000000000001" )
555 utilities.assert_equals( expect=main.TRUE,
556 actual=stepResult,
557 onpass="Create port on host1 on the node " + str( OVSDB1Ip ) + " sucess",
558 onfail="Create port on host1 on the node " + str( OVSDB1Ip ) + " failed" )
559
Jon Hall8638b562017-05-24 16:39:59 -0700560 main.step( "Create port on host2 on the node " + str( OVSDB2Ip ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800561 stepResult = main.OVSDB2.createHostport( hostname="host2", hostport="host2-eth0", hostportmac="000000000002" )
562 utilities.assert_equals( expect=main.TRUE,
563 actual=stepResult,
564 onpass="Create port on host1 on the node " + str( OVSDB2Ip ) + " sucess",
565 onfail="Create port on host1 on the node " + str( OVSDB2Ip ) + " failed" )
566
Jon Hall8638b562017-05-24 16:39:59 -0700567 main.step( "Add port to ovs br-int and host go-online on the node " + str( OVSDB1Ip ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800568 stepResult = main.OVSDB1.addPortToOvs( ovsname="br-int", ifaceId="00000000-0000-0000-0000-000000000001",
569 attachedMac="00:00:00:00:00:01", vmuuid="10000000-0000-0000-0000-000000000001" )
570 utilities.assert_equals( expect=main.TRUE,
571 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700572 onpass="Add port to ovs br-int and host go-online on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800573 str( OVSDB1Ip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700574 onfail="Add port to ovs br-int and host go-online on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800575 str( OVSDB1Ip ) + " failed" )
576
Jon Hall8638b562017-05-24 16:39:59 -0700577 main.step( "Add port to ovs br-int and host go-online on the node " + str( OVSDB2Ip ) )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800578 stepResult = main.OVSDB2.addPortToOvs( ovsname="br-int", ifaceId="00000000-0000-0000-0000-000000000002",
579 attachedMac="00:00:00:00:00:02", vmuuid="10000000-0000-0000-0000-000000000001" )
580 utilities.assert_equals( expect=main.TRUE,
581 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700582 onpass="Add port to ovs br-int and host go-online on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800583 str( OVSDB2Ip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700584 onfail="Add port to ovs br-int and host go-online on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800585 str( OVSDB2Ip ) + " failed" )
586
587 main.step( "Check onos set host flows on the node " + str( OVSDB1Ip ) )
588 response = main.OVSDB1.dumpFlows( sw="br-int", protocols="OpenFlow13" )
589 if re.search( "00:00:00:00:00:01", response ):
590 stepResult = main.TRUE
591 else:
592 stepResult = main.FALSE
593 utilities.assert_equals( expect=main.TRUE,
594 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700595 onpass="Check onos set host flows on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800596 str( OVSDB1Ip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700597 onfail="Check onos set host flows on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800598 str( OVSDB1Ip ) + " failed" )
599
600 main.step( "Check onos set host flows on the node " + str( OVSDB2Ip ) )
601 response = main.OVSDB2.dumpFlows( sw="br-int", protocols="OpenFlow13" )
602 if re.search( "00:00:00:00:00:02", response ):
603 stepResult = main.TRUE
604 else:
605 stepResult = main.FALSE
606 utilities.assert_equals( expect=main.TRUE,
607 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700608 onpass="Check onos set host flows on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800609 str( OVSDB2Ip ) + " sucess",
Jon Hall8638b562017-05-24 16:39:59 -0700610 onfail="Check onos set host flows on the node " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800611 str( OVSDB2Ip ) + " failed" )
612
613 main.step( "Check hosts can ping each other" )
614 main.OVSDB1.setHostportIp( hostname="host1", hostport1="host1-eth0", ip="10.0.0.1" )
615 main.OVSDB2.setHostportIp( hostname="host2", hostport1="host2-eth0", ip="10.0.0.2" )
616 pingResult1 = main.OVSDB1.hostPing( src="10.0.0.1", hostname="host1", target="10.0.0.2" )
617 pingResult2 = main.OVSDB2.hostPing( src="10.0.0.2", hostname="host2", target="10.0.0.1" )
618 stepResult = pingResult1 and pingResult2
619 utilities.assert_equals( expect=main.TRUE,
620 actual=stepResult,
Jon Hall8638b562017-05-24 16:39:59 -0700621 onpass="Successfully host go online and ping each other,controller is " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800622 str( ctrlip ),
Jon Hall8638b562017-05-24 16:39:59 -0700623 onfail="Failed to host go online and ping each other,controller is " +
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800624 str( ctrlip ) )
625
626 def CASE8( self, main ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800627 """
628 Clear ovs configuration and host configuration
629 """
630 import re
alison6acef9f2016-09-28 12:29:08 -0700631 import os
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800632
633 ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
634 OVSDB1Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip1' ] )
635 OVSDB2Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip2' ] )
636 delaytime = main.params[ 'TIMER' ][ 'delaytime' ]
637
638 main.step( "Delete ovsdb node 1 manager" )
639 deleteResult = main.OVSDB1.delManager( delaytime=delaytime )
640 stepResult = deleteResult
641 utilities.assert_equals( expect=main.TRUE,
642 actual=stepResult,
643 onpass="ovsdb node 1 delete manager sucess",
644 onfail="ovsdb node 1 delete manager failed" )
645
646 main.step( "Delete ovsdb node 2 manager" )
647 deleteResult = main.OVSDB2.delManager( delaytime=delaytime )
648 stepResult = deleteResult
649 utilities.assert_equals( expect=main.TRUE,
650 actual=stepResult,
651 onpass="ovsdb node 2 delete manager sucess",
652 onfail="ovsdb node 2 delete manager failed" )
653
654 main.step( "Delete ovsdb node 1 bridge br-int" )
655 deleteResult = main.OVSDB1.delBr( sw="br-int" )
656 stepResult = deleteResult
657 utilities.assert_equals( expect=main.TRUE,
658 actual=stepResult,
659 onpass="Delete ovsdb node 1 bridge br-int sucess",
660 onfail="Delete ovsdb node 1 bridge br-int failed" )
661
662 main.step( "Delete ovsdb node 2 bridge br-int" )
663 deleteResult = main.OVSDB2.delBr( sw="br-int" )
664 stepResult = deleteResult
665 utilities.assert_equals( expect=main.TRUE,
666 actual=stepResult,
667 onpass="Delete ovsdb node 2 bridge br-int sucess",
668 onfail="Delete ovsdb node 2 bridge br-int failed" )
669
670 main.step( "Delete ip netns host on the ovsdb node 1" )
671 deleteResult = main.OVSDB1.delHost( hostname="host1" )
672 stepResult = deleteResult
673 utilities.assert_equals( expect=main.TRUE,
674 actual=stepResult,
675 onpass="Delete ip netns host on the ovsdb node 1 sucess",
676 onfail="Delete ip netns host on the ovsdb node 1 failed" )
677
678 main.step( "Delete ip netns host on the ovsdb node 2" )
679 deleteResult = main.OVSDB2.delHost( hostname="host2" )
680 stepResult = deleteResult
681 utilities.assert_equals( expect=main.TRUE,
682 actual=stepResult,
683 onpass="Delete ip netns host on the ovsdb node 2 sucess",
684 onfail="Delete ip netns host on the ovsdb node 2 failed" )
685
686 main.step( "Check onoscli devices openflow session is false " + str( OVSDB1Ip ) )
Devin Lim142b5342017-07-20 15:22:39 -0700687 response = main.Cluster.active( 0 ).CLI.devices()
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800688 if re.search( OVSDB1Ip, response ) and not re.search( "true", response ):
689 stepResult = main.TRUE
690 else:
691 stepResult = main.FALSE
692 utilities.assert_equals( expect=main.TRUE,
693 actual=stepResult,
694 onpass="Check openflow session is false " + str( OVSDB1Ip ) + " sucess",
695 onfail="Check openflow session is false " + str( OVSDB1Ip ) + " failed" )
696
697 main.step( "Check onoscli devices have ovs " + str( OVSDB2Ip ) )
Devin Lim142b5342017-07-20 15:22:39 -0700698 response = main.Cluster.active( 0 ).CLI.devices()
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800699 if re.search( OVSDB2Ip, response ) and not re.search( "true", response ):
700 stepResult = main.TRUE
701 else:
702 stepResult = main.FALSE
703 utilities.assert_equals( expect=main.TRUE,
704 actual=stepResult,
705 onpass="Check openflow session is false " + str( OVSDB2Ip ) + " sucess",
Jon Hall53c5e662016-04-13 16:06:56 -0700706 onfail="Check openflow session is false " + str( OVSDB2Ip ) + " failed" )