blob: e3c3cc4be1bef726a39163a52eae8f2ddc158ffd [file] [log] [blame]
lanqinglong77124b02015-08-06 11:47:38 +08001"""
2Description: This test is to determine if North bound
3 can handle the request
4
5List of test cases:
6CASE1 - Variable initialization and optional pull and build ONOS package
7CASE2 - Create Network northbound test
8CASE3 - Update Network northbound test
9CASE4 - Delete Network northbound test
10CASE5 - Create Subnet northbound test
11CASE6 - Update Subnet northbound test
12CASE7 - Delete Subnet northbound test
13CASE8 - Create Virtualport northbound test
14CASE9 - Update Virtualport northbound test
15CASE10 - Delete Virtualport northbound test
16
17lanqinglong@huawei.com
18"""
19import os
20
21class FUNCvirNetNB:
22
23 def __init__( self ):
24 self.default = ''
25
26 def CASE1( self, main ):
27 """
28 CASE1 is to compile ONOS and push it to the test machines
29
30 Startup sequence:
31 cell<name>
32 onos-verify-cell
33 NOTE:temporary - onos-remove-raft-logs
34 onos-uninstall
35 git pull
36 mvn clean install
37 onos-package
38 onos-install -f
39 onos-wait-for-start
40 start cli sessions
41 start vtnrsc
42 """
43
44 import time
45 import os
46 main.log.info( "ONOS Single node Start "+
47 "VirtualNet Northbound test - initialization" )
48 main.case( "Setting up test environment" )
49 main.caseExplanation = "Setup the test environment including "+\
50 "installing ONOS,start ONOS."
51
52 # load some variables from the params file
53 PULLCODE = False
54 if main.params['GIT']['pull'] =='True':
55 PULLCODE = True
56 gitBranch = main.params['GIT']['branch']
57 cellName = main.params['ENV']['cellName']
58 ipList = os.getenv( main.params['CTRL']['ip1'] )
59
60 main.step("Create cell file")
61 cellAppString = main.params['ENV']['cellApps']
62 main.ONOSbench.createCellFile(main.ONOSbench.ip_address,cellName,
63 main.Mininet1.ip_address,
64 cellAppString,ipList )
65
66 main.step( "Applying cell variable to environment" )
67 cellResult = main.ONOSbench.setCell(cellName)
68 verifyResult = main.ONOSbench.verifyCell()
69
70 #FIXME:this is short term fix
71 main.log.info( "Removing raft logs" )
72 main.ONOSbench.onosRemoveRaftlogs()
73
74 main.CLIs = []
75 main.nodes = []
76 main.numCtrls=1
77 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
78
79 for i in range ( 1, main.numCtrls +1):
80 try:
81 main.CLIs.append( getattr( main, 'ONOScli' + str(i) ) )
82 main.nodes.append( getattr( main, 'ONOS' + str(i) ) )
83 ipList.append( main.nodes[ -1 ].ip_address )
84 except AttributeError:
85 break
86
87 main.log.info( "Uninstalling ONOS" )
88 for node in main.nodes:
89 main.ONOSbench.onosUninstall( node.ip_address )
90
91 #Make sure ONOS is DEAD
92 main.log.info( "Killing any ONOS processes" )
93 killResults = main.TRUE
94 for node in main.nodes:
95 killed = main.ONOSbench.onosKill( node.ip_address )
96 killResults = killResults and killed
97
98 cleanInstallResult = main.TRUE
99 gitPullResult = main.TRUE
100 main.step( "Git checkout and pull " + gitBranch )
101 if PULLCODE:
102 main.ONOSbench.gitCheckout ( gitBranch )
103 gitPullResult = main.ONOSbench.gitPull()
104 # values of 1 or 3 are good
105 utilities.assert_lesser ( expect=0, actual=gitPullResult,
106 onpass="Git pull successful",
107 onfail ="Git pull failed" )
108 main.ONOSbench.getVersion( report =True )
109 main.step( "Using mvn clean install" )
110 cleanInstallResult= main.TRUE
111 if PULLCODE and gitPullResult == main.TRUE:
112 cleanInstallResult = main.ONOSbench.cleanInstall()
113 else:
114 main.log.warn("Did not pull new code so skipping mvn "+
115 "clean install")
116
117 utilities.assert_equals( expect=main.TRUE,
118 actual=cleanInstallResult,
119 onpass="MCI successful",
120 onfail="MCI failed" )
121
122 main.step( "Creating ONOS package" )
123 packageResult = main.ONOSbench.onosPackage()
124 utilities.assert_equals( expect=main.TRUE,
125 actual=packageResult,
126 onpass="Successfully created ONOS package",
127 onfail="Failed to create ONOS package " )
128 time.sleep( main.startUpSleep )
129
130 main.step( "Installing ONOS package" )
131 onosInstallResult = main.ONOSbench.onosInstall(
132 options="-f",node=main.nodes[0].ip_address )
133 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
134 onpass="ONOS install successful",
135 onfail="ONOS install failed" )
136 time.sleep( main.startUpSleep )
137
138 main.step( "Checking if ONOS is up yet" )
139
140 for i in range( 2 ):
141 onos1Isup = main.ONOSbench.isup( main.nodes[0].ip_address )
142 if onos1Isup:
143 break
144 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
145 onpass="ONOS startup successful",
146 onfail="ONOS startup failed" )
147 time.sleep( main.startUpSleep )
148
149 main.log.step( "Starting ONOS CLI sessions" )
150
151 print main.nodes[0].ip_address
152 cliResults = main.ONOScli1.startOnosCli(main.nodes[0].ip_address)
153 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
154 onpass="ONOS cli startup successful",
155 onfail="ONOS cli startup failed" )
156 time.sleep( main.startUpSleep )
157
158 main.step( "App Ids check" )
159 appCheck = main.ONOScli1.appToIDCheck()
160 if appCheck != main.TRUE:
161 main.log.warn( main.CLIs[0].apps() )
162 main.log.warn( main.CLIs[0].appIDs() )
163 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
164 onpass="App Ids seem to be correct",
165 onfail="Something is wrong with app Ids" )
166
167 if cliResults == main.FALSE:
168 main.log.error( "Failed to start ONOS, stopping test" )
169 main.cleanup()
170 main.exit()
171
172 main.step( "Install onos-app-vtnrsc app" )
173 installResults = main.ONOScli1.featureInstall( "onos-app-vtnrsc" )
174 utilities.assert_equals( expect=main.TRUE, actual=installResults,
175 onpass="Install onos-app-vtnrsc successful",
176 onfail="Install onos-app-vtnrsc app failed" )
177
178 time.sleep( main.startUpSleep )
179
180 main.step( "Install onos-app-vtnweb app" )
181 installResults = main.ONOScli1.featureInstall( "onos-app-vtnweb" )
182 utilities.assert_equals( expect=main.TRUE, actual=installResults,
183 onpass="Install onos-app-vtnweb successful",
184 onfail="Install onos-app-vtnweb app failed" )
185
186 time.sleep( main.startUpSleep )
187
188 def CASE2 ( self,main ):
189
190 """
191 Test Post Network
192 """
193 import os,sys
194 sys.path.append("..")
195 try:
196 from tests.FUNCvirNetNB.dependencies.Nbdata import NetworkData
197 except ImportError:
198 main.log.exception( "Something wrong with import file or code error." )
199 main.log.info( "Import Error,please check!" )
200
201 main.log.info( "ONOS Network Post test Start" )
202 main.case( "Virtual Network NBI Test - Network" )
203 main.caseExplanation = "Test Network Post NBI " +\
204 "Verify Post Data same with Stored Data"
205
206 ctrlip = os.getenv( main.params['CTRL']['ip1'] )
207 port = main.params['HTTP']['port']
208 path = main.params['HTTP']['path']
209
210 main.step( "Generate Post Data" )
211 network = NetworkData()
212 network.id = '030d6d3d-fa36-45bf-ae2b-4f4bc43a54dc'
213 network.tenant_id = '26cd996094344a0598b0a1af1d525cdc'
214 postdata = network.DictoJson()
215
216 main.step( "Post Data via HTTP" )
217 Poststatus, result = main.ONOSrest.send( ctrlip, port, '', path+'networks/',
218 'POST', None, postdata)
219
220 utilities.assert_equals(
221 expect='200',
222 actual=Poststatus,
223 onpass="Post Success",
224 onfail="Post Failed " + str( Poststatus ) + str( result ) )
225
226 main.step( "Get Data via HTTP" )
227 Getstatus, result = main.ONOSrest.send( ctrlip, port, network.id, path+'networks/',
228 'GET', None, None)
229 utilities.assert_equals(
230 expect='200',
231 actual=Getstatus,
232 onpass="Get Success",
233 onfail="Get Failed " + str( Getstatus ) + str( result ) )
234
235 main.log.info("Post Network Data is :%s\nGet Network Data is:%s"%(postdata,result))
236
237 main.step( "Compare Send Id and Get Id" )
238 IDcmpresult = network.JsonCompare( postdata, result, 'network', 'id' )
239 TanantIDcmpresult = network.JsonCompare( postdata, result, 'network', 'tenant_id' )
240 Cmpresult = IDcmpresult and TanantIDcmpresult
241
242 utilities.assert_equals(
243 expect=True,
244 actual=Cmpresult,
245 onpass="Compare Success",
246 onfail="Compare Failed:ID compare: " + str( IDcmpresult ) + \
247 ",Tenant id compare :" + str( TanantIDcmpresult ) )
248
249 deletestatus,result = main.ONOSrest.send( ctrlip, port, network.id, path+'networks/',
250 'DELETE', None, None )
251 utilities.assert_equals(
252 expect='200',
253 actual=deletestatus,
254 onpass="Delete Network Success",
255 onfail="Delete Network Failed")
256
257 if Cmpresult !=True:
258 main.log.error( "Post Network compare failed" )
259
260 def CASE3( self,main ):
261
262 """
263 Test Update Network
264 """
265 import os,sys
266 sys.path.append("..")
267 try:
268 from tests.FUNCvirNetNB.dependencies.Nbdata import NetworkData
269 except ImportError:
270 main.log.exception( "Something wrong with import file or code error." )
271 main.log.info( "Import Error,please check!" )
272
273 main.log.info( "ONOS Network Update test Start" )
274 main.case( "Virtual Network NBI Test - Network" )
275 main.caseExplanation = "Test Network Update NBI " +\
276 "Verify Update Data same with Stored Data"
277
278 ctrlip = os.getenv( main.params['CTRL']['ip1'] )
279 port = main.params['HTTP']['port']
280 path = main.params['HTTP']['path']
281
282 main.step( "Generate Post Data" )
283 network = NetworkData()
284 network.id = '030d6d3d-fa36-45bf-ae2b-4f4bc43a54dc'
285 network.tenant_id = '26cd996094344a0598b0a1af1d525cdc'
286 network.shared = 'false'
287 postdata = network.DictoJson()
288
289 network.shared = 'true'
290 postdatanew = network.DictoJson()
291
292 main.step( "Post Data via HTTP" )
293 Poststatus, result = main.ONOSrest.send( ctrlip, port, '', path+'networks',
294 'POST', None, postdata )
295 utilities.assert_equals(
296 expect='200',
297 actual=Poststatus,
298 onpass="Post Success",
299 onfail="Post Failed " + str( Poststatus ) + str( result ) )
300
301 main.step( "Update Data via HTTP" )
302 Updatestatus, result = main.ONOSrest.send( ctrlip, port, network.id, path+'networks/',
303 'PUT', None, postdatanew)
304 utilities.assert_equals(
305 expect='200',
306 actual=Updatestatus,
307 onpass="Update Success",
308 onfail="Update Failed " + str( Updatestatus ) + str( result ) )
309
310 main.step( "Get Data via HTTP" )
311 Getstatus, result = main.ONOSrest.send( ctrlip, port, network.id, path+'networks/',
312 'GET', None, None )
313 utilities.assert_equals(
314 expect='200',
315 actual=Getstatus,
316 onpass="Get Success",
317 onfail="Get Failed " + str( Getstatus ) + str( result ) )
318
319 main.step( "Compare Update data." )
320 IDcmpresult = network.JsonCompare( postdatanew, result, 'network', 'id' )
321 TanantIDcmpresult = network.JsonCompare( postdatanew, result, 'network', 'tenant_id' )
322 Shareresult = network.JsonCompare( postdatanew, result, 'network', 'shared' )
323
324 Cmpresult = IDcmpresult and TanantIDcmpresult and Shareresult
325 utilities.assert_equals(
326 expect=True,
327 actual=Cmpresult,
328 onpass="Compare Success",
329 onfail="Compare Failed:ID compare:" + str( IDcmpresult ) + \
330 ",Tenant id compare:"+ str( TanantIDcmpresult ) + \
331 ",Name compare:" + str( Shareresult ) )
332
333 deletestatus,result = main.ONOSrest.send( ctrlip, port, network.id, path+'networks/',
334 'DELETE', None, None )
335
336 utilities.assert_equals(
337 expect='200',
338 actual=deletestatus,
339 onpass="Delete Network Success",
340 onfail="Delete Network Failed" )
341
342 if Cmpresult!=True:
343 main.log.error( "Update Network compare failed" )
344
345 def CASE4( self,main ):
346
347 """
348 Test Delete Network
349 """
350 import os,sys
351 sys.path.append("..")
352 try:
353 from tests.FUNCvirNetNB.dependencies.Nbdata import NetworkData
354 except ImportError:
355 main.log.exception( "Something wrong with import file or code error." )
356 main.log.info( "Import Error,please check!" )
357
358 main.log.info( "ONOS Network Delete test Start" )
359 main.case( "Virtual Network NBI Test - Network" )
360 main.caseExplanation = "Test Network Delete NBI " +\
361 "Verify Stored Data is NULL after Delete"
362
363 ctrlip = os.getenv( main.params['CTRL']['ip1'] )
364 port = main.params['HTTP']['port']
365 path = main.params['HTTP']['path']
366
367 main.step( "Generate Post Data" )
368 network = NetworkData()
369 network.id = '030d6d3d-fa36-45bf-ae2b-4f4bc43a54dc'
370 network.tenant_id = '26cd996094344a0598b0a1af1d525cdc'
371 postdata = network.DictoJson()
372
373 main.step( "Post Data via HTTP" )
374 Poststatus, result = main.ONOSrest.send( ctrlip, port , '' , path + 'networks/',
375 'POST', None , postdata )
376
377 utilities.assert_equals(
378 expect='200',
379 actual=Poststatus,
380 onpass="Post Success",
381 onfail="Post Failed " + str( Poststatus ) + str( result ) )
382
383 main.step( "Delete Data via HTTP" )
384 Deletestatus, result = main.ONOSrest.send( ctrlip,port,network.id,path+'networks/',
385 'DELETE', None, None )
386 utilities.assert_equals(
387 expect='200',
388 actual=Deletestatus,
389 onpass="Delete Success",
390 onfail="Delete Failed " + str( Getstatus ) + str( result ) )
391
392 main.step( "Get Data is NULL" )
393 Getstatus, result = main.ONOSrest.send( ctrlip, port, network.id, path+'networks/',
394 'GET', None, None )
395 utilities.assert_equals(
396 expect='The tenantNetwork does not exists',
397 actual=result,
398 onpass="Get Success",
399 onfail="Get Failed " + str( Getstatus ) + str( result ) )
400
401 if result != 'The tenantNetwork does not exists':
402 main.log.error( "Delete Network failed" )