blob: 62e033749ea1e3b7fb056540913414f2dd6df5d4 [file] [log] [blame]
AntonySilvestera1080f22016-04-26 13:05:57 +05301"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002
3Copyright 2016 Open Networking Foundation (ONF)
4
5Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8
9 TestON is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 2 of the License, or
12 (at your option) any later version.
13
14 TestON is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with TestON. If not, see <http://www.gnu.org/licenses/>.
21
AntonySilvestera1080f22016-04-26 13:05:57 +053022**** Scripted by Antony Silvester - antony.silvester@huawei.com ******
23
24
25This Test check the bgp_ls functionality
26
27List of test cases:
28CASE1: Compile ONOS and push it to the test machines
29CASE2: Discovery the topology using BGPLS
30CASE3: Addition of new Node to existing topology
AntonySilvester02652382016-07-13 16:44:45 +053031CASE4: Verification of Links thats is discovered"
32CASE5: Deletion of Links
33Case6: Uninstalling the app
AntonySilvestera1080f22016-04-26 13:05:57 +053034
35
36"""
AntonySilvestera1080f22016-04-26 13:05:57 +053037class FUNCbgpls:
38
39 def __init__( self ):
40 self.default = ''
41
42 def CASE1( self, main ):
43 """
44 CASE1 is to compile ONOS and push it to the test machines
45
46 Startup sequence:
47 cell <name>
48 onos-verify-cell
49 NOTE: temporary - onos-remove-raft-logs
50 onos-uninstall
51 git pull
AntonySilvestera1080f22016-04-26 13:05:57 +053052 onos-package
53 onos-install -f
54 onos-wait-for-start
55 start cli sessions
56 start BGPLS apps
57
58 """
AntonySilvestera1080f22016-04-26 13:05:57 +053059 import os
Pratik Parab3b2ab5a2017-02-14 13:15:14 -080060
AntonySilvestera1080f22016-04-26 13:05:57 +053061 main.log.info( "ONOS Single node start " +
62 "Scapy Tool - initialization" )
63 main.case( "Setting up test environment" )
64 main.caseExplanation = "Setup the test environment including " +\
65 "installing ONOS, start ONOS."
66
AntonySilvestera1080f22016-04-26 13:05:57 +053067 PULLCODE = False
68 if main.params[ 'GIT' ][ 'pull' ] == 'True':
69 PULLCODE = True
70 gitBranch = main.params[ 'GIT' ][ 'branch' ]
71 cellName = main.params[ 'ENV' ][ 'cellName' ]
72 ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
Jon Hall46fdea12017-05-24 15:48:57 -070073 scapy_ip = os.getenv( main.params[ 'SCAPY' ][ 'HOSTNAMES' ] )
AntonySilvestera1080f22016-04-26 13:05:57 +053074
75 main.log.info( "Removing raft logs" )
76 main.ONOSbench.onosRemoveRaftLogs()
77
78 main.CLIs = []
79 main.nodes = []
Jon Hall46fdea12017-05-24 15:48:57 -070080 main.numCtrls = 1
AntonySilvestera1080f22016-04-26 13:05:57 +053081
82 for i in range( 1, main.numCtrls + 1 ):
83 try:
84 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
85 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
86 ipList.append( main.nodes[ -1 ].ip_address )
87 except AttributeError:
88 break
89
90 main.log.info( "Uninstalling ONOS" )
91 for node in main.nodes:
92 main.ONOSbench.onosUninstall( node.ip_address )
93
94 main.step( "Create cell file" )
95 cellAppString = main.params[ 'ENV' ][ 'cellApps' ]
96
97 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
98 scapy_ip,
Devin Limdc78e202017-06-09 18:30:07 -070099 cellAppString, ipList, main.ONOScli1.karafUser )
AntonySilvestera1080f22016-04-26 13:05:57 +0530100
101 main.step( "Applying cell variable to environment" )
102 cellResult = main.ONOSbench.setCell( cellName )
103
104 verifyResult = main.ONOSbench.verifyCell()
105
106 # Make sure ONOS process is not running
107 main.log.info( "Killing any ONOS processes" )
108 killResults = main.TRUE
109 for node in main.nodes:
110 killed = main.ONOSbench.onosKill( node.ip_address )
111 killResults = killResults and killed
112
AntonySilvestera1080f22016-04-26 13:05:57 +0530113 gitPullResult = main.FALSE
114 main.step( "Git checkout and pull" + gitBranch )
115 if PULLCODE:
116 main.ONOSbench.gitCheckout( gitBranch )
117 gitPullResult = main.ONOSbench.gitPull()
118 # values of 1 or 3 are good
119 utilities.assert_lesser( expect=0, actual=gitPullResult,
120 onpass="Git pull successful",
121 onfail="Git pull failed" )
122
Devin Lim8d7c7782017-06-07 16:21:20 -0700123 main.ONOSbench.getVersion( report=True )
AntonySilvestera1080f22016-04-26 13:05:57 +0530124
125 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700126 packageResult = main.ONOSbench.buckBuild()
AntonySilvestera1080f22016-04-26 13:05:57 +0530127 utilities.assert_equals( expect=main.TRUE,
128 actual=packageResult,
129 onpass="Successfully created ONOS package",
130 onfail="Failed to create ONOS package" )
131
132 main.step( "Installing ONOS package" )
133 onosInstallResult = main.ONOSbench.onosInstall(
alisonb1a26522016-11-22 17:27:17 -0800134 options="-f", node=main.nodes[ 0 ].ip_address )
AntonySilvestera1080f22016-04-26 13:05:57 +0530135 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
136 onpass="ONOS install successful",
137 onfail="ONOS install failed" )
138
You Wangf5de25b2017-01-06 15:13:01 -0800139 main.step( "Set up ONOS secure SSH" )
140 secureSshResult = main.ONOSbench.onosSecureSSH( node=main.nodes[ 0 ].ip_address )
141 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
142 onpass="Test step PASS",
143 onfail="Test step FAIL" )
144
AntonySilvestera1080f22016-04-26 13:05:57 +0530145 main.step( "Checking if ONOS is up yet" )
Jon Hall46fdea12017-05-24 15:48:57 -0700146 print main.nodes[ 0 ].ip_address
AntonySilvestera1080f22016-04-26 13:05:57 +0530147 for i in range( 2 ):
alisonb1a26522016-11-22 17:27:17 -0800148 onos1Isup = main.ONOSbench.isup( main.nodes[ 0 ].ip_address )
AntonySilvestera1080f22016-04-26 13:05:57 +0530149 if onos1Isup:
150 break
151 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
152 onpass="ONOS startup successful",
153 onfail="ONOS startup failed" )
Chiyu Chengef109502016-11-21 15:51:38 -0800154
Jon Hall6509dbf2016-06-21 17:01:17 -0700155 main.step( "Starting ONOS CLI sessions" )
alisonb1a26522016-11-22 17:27:17 -0800156 print main.nodes[ 0 ].ip_address
157 cliResults = main.ONOScli1.startOnosCli( main.nodes[ 0 ].ip_address )
AntonySilvestera1080f22016-04-26 13:05:57 +0530158 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
159 onpass="ONOS cli startup successful",
160 onfail="ONOS cli startup failed" )
161
162 main.step( "App Ids check" )
163 appCheck = main.ONOScli1.appToIDCheck()
164
Jon Hall46fdea12017-05-24 15:48:57 -0700165 if appCheck != main.TRUE:
alisonb1a26522016-11-22 17:27:17 -0800166 main.log.warn( main.CLIs[ 0 ].apps() )
167 main.log.warn( main.CLIs[ 0 ].appIDs() )
AntonySilvestera1080f22016-04-26 13:05:57 +0530168 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
Jon Hall46fdea12017-05-24 15:48:57 -0700169 onpass="App Ids seem to be correct",
170 onfail="Something is wrong with app Ids" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530171 if cliResults == main.FALSE:
172 main.log.error( "Failed to start ONOS,stopping test" )
173 main.cleanup()
174 main.exit()
175
AntonySilvestera1080f22016-04-26 13:05:57 +0530176 def CASE2( self, main ):
177 """
178 Discovery the topology using BGPLS
179 """
Jon Hall46fdea12017-05-24 15:48:57 -0700180 import os
181 import sys
AntonySilvestera1080f22016-04-26 13:05:57 +0530182 import re
183 import time
184
185 main.case( "Testcase 2 : Discovery the Network Topology using BGPLS" )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800186 main.ONOScli1.log( "\"testcase2 start\"" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530187
188 try:
189 from tests.FUNC.FUNCbgpls.dependencies.Nbdata import BgpLs
190 except ImportError:
191 main.log.exception( "Something wrong with import file or code error." )
192 main.log.info( "Import Error, please check!" )
193 main.cleanup()
194 main.exit()
195
196 bgplsConfig = BgpLs()
197 Ne_id = bgplsConfig.Constants()
198 app = bgplsConfig.apps()
199 main.CLIs = []
200 main.nodes = []
Jon Hall46fdea12017-05-24 15:48:57 -0700201 main.numCtrls = 1
AntonySilvestera1080f22016-04-26 13:05:57 +0530202
203 ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
Jon Hall46fdea12017-05-24 15:48:57 -0700204 scapy_ip = os.getenv( main.params[ 'SCAPY' ][ 'HOSTNAMES' ] )
205 httpport = main.params[ 'HTTP' ][ 'port' ]
206 path = main.params[ 'HTTP' ][ 'path' ]
207 bgplsConfig.ipValue( ipList, scapy_ip )
AntonySilvestera1080f22016-04-26 13:05:57 +0530208
209 for i in range( 1, main.numCtrls + 1 ):
210 try:
211 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
212 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
213 ipList.append( main.nodes[ -1 ].ip_address )
214 except AttributeError:
215 break
216
217 main.step( "Apply cell to environment" )
218 bgplsConfig.Comments()
219
220 bgplsConfig.Comments()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800221 main.log.info( "Sending BGPLS information" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530222 bgplsConfig.Comments()
223
AntonySilvestera1080f22016-04-26 13:05:57 +0530224 main.Scapy1.handle.sendline( "sudo python OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/\
225 dependencies/Scapyfiles/Topo_discovery.py" )
226 bgplsConfig.Comments()
227 main.log.info( "Enable BGPlS plugin in ONOS" )
228 bgplsConfig.Comments()
229
Jon Hall46fdea12017-05-24 15:48:57 -0700230 cliResults = main.ONOScli1.startOnosCli( main.nodes[ 0 ].ip_address )
AntonySilvestera1080f22016-04-26 13:05:57 +0530231
232 main.step( "Getting connected to ONOS" )
233 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
234 onpass="ONOS cli startup successful",
235 onfail="ONOS cli startup failed" )
Jon Hall46fdea12017-05-24 15:48:57 -0700236 installResults = main.ONOScli1.activateApp( app[ 0 ] )
AntonySilvestera1080f22016-04-26 13:05:57 +0530237
238 main.step( "Install onos-app-bgp" )
239 utilities.assert_equals( expect=main.TRUE, actual=installResults,
240 onpass="Install onos-app-bgp successful",
241 onfail="Install onos-app-bgp failed" )
242
243 bgpls_post = bgplsConfig.DictoJson()
244
245 bgplsConfig.Comments()
246 main.log.info( "BGPLS RestConf input" )
247 bgplsConfig.Comments()
248
Jon Hall46fdea12017-05-24 15:48:57 -0700249 print ( bgpls_post )
alisonb1a26522016-11-22 17:27:17 -0800250 main.ONOSrest.user_name = "onos"
251 main.ONOSrest.pwd = "rocks"
Jon Hall46fdea12017-05-24 15:48:57 -0700252 Poststatus, result = main.ONOSrest.send( '/network/configuration/', method="POST", data=bgpls_post )
AntonySilvestera1080f22016-04-26 13:05:57 +0530253 main.step( "Configure BGP through RESTCONF" )
254
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800255 utilities.assert_equals( expect='200',
256 actual=Poststatus,
257 onpass="Post Port Success",
258 onfail="Post Port Failed " + str( Poststatus ) + "," + str( result ) )
AntonySilvestera1080f22016-04-26 13:05:57 +0530259
AntonySilvestera1080f22016-04-26 13:05:57 +0530260 bgplsConfig.Comments()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800261 main.step( "Check Network devices are Updated in ONOS " )
AntonySilvestera1080f22016-04-26 13:05:57 +0530262 bgplsConfig.Comments()
Jon Hall46fdea12017-05-24 15:48:57 -0700263 time.sleep( 15 )
AntonySilvestera1080f22016-04-26 13:05:57 +0530264 response = main.ONOScli1.devices()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800265 responseCheck = main.FALSE
266 if response:
267 responseCheck = main.TRUE
268 utilities.assert_equals( expect=main.TRUE,
269 actual=responseCheck,
270 onpass="Network Devices update in ONOS successful",
271 onfail="Network Devices update in ONOS failed" )
272
AntonySilvestera1080f22016-04-26 13:05:57 +0530273 main.step( "Check the nodes are discovered" )
Jon Hall46fdea12017-05-24 15:48:57 -0700274 if response.find( Ne_id[ 1 ][ 0 ] ) and response.find( Ne_id[ 1 ][ 1 ] ) and response.find( Ne_id[ 1 ][ 2 ] ) != -1:
AntonySilvestera1080f22016-04-26 13:05:57 +0530275 stepResult = main.TRUE
276 else:
277 stepResult = main.FALSE
278 utilities.assert_equals( expect=main.TRUE,
279 actual=stepResult,
Jon Hall46fdea12017-05-24 15:48:57 -0700280 onpass="Node " + str( Ne_id[ 1 ][ 0 ] ) + ( Ne_id[ 1 ][ 1 ] ) + ( Ne_id[ 1 ][ 2 ] ) + " sucess",
281 onfail="Node " + str( Ne_id[ 1 ][ 0 ] ) + ( Ne_id[ 1 ][ 1 ] ) + ( Ne_id[ 1 ][ 2 ] ) + " failed" )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800282 main.ONOScli1.log( "\"testcase2 end\"" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530283
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800284 main.step( "Check for Errors or Exception in testcase2" )
285 startStr = "testcase2 start"
286 endStr = "testcase2 end"
Jon Hall46fdea12017-05-24 15:48:57 -0700287 errorLog = main.ONOSbench.logReport( main.nodes[ 0 ].ip_address,
288 [ "ERROR", "EXCEPT" ], "s",
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800289 startStr, endStr )
290 utilities.assert_equals( expect=0, actual=errorLog,
291 onpass="No Exception or Error occured in testcase2",
292 onfail="Exception or Error occured in testcase2" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530293 bgplsConfig.Comments()
294 main.log.info( "Kill Scapy process" )
295 bgplsConfig.Comments()
296
297 main.Scapy1.handle.sendline( "\x03" )
Jon Hall46fdea12017-05-24 15:48:57 -0700298 time.sleep( 90 ) # This Sleep time gives time for the socket to close.
AntonySilvestera1080f22016-04-26 13:05:57 +0530299
AntonySilvestera1080f22016-04-26 13:05:57 +0530300 def CASE3( self, main ):
301 """
302 Addition of new Node to existing topology
303 """
Jon Hall46fdea12017-05-24 15:48:57 -0700304 import os
305 import sys
AntonySilvestera1080f22016-04-26 13:05:57 +0530306 import re
307 import time
308
309 main.case( "Testcase 3: Addition of New Node to existing topology" )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800310 main.ONOScli1.log( "\"testcase3 start\"" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530311 try:
312 from tests.FUNC.FUNCbgpls.dependencies.Nbdata import BgpLs
313 except ImportError:
314 main.log.exception( "Something wrong with import file or code error." )
315 main.log.info( "Import Error, please check!" )
316 main.cleanup()
317 main.exit()
318
319 bgplsConfig = BgpLs()
320 Ne_id = bgplsConfig.Constants()
321 app = bgplsConfig.apps()
322 main.CLIs = []
323 main.nodes = []
Jon Hall46fdea12017-05-24 15:48:57 -0700324 main.numCtrls = 1
AntonySilvestera1080f22016-04-26 13:05:57 +0530325
326 ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
Jon Hall46fdea12017-05-24 15:48:57 -0700327 scapy_ip = os.getenv( main.params[ 'SCAPY' ][ 'HOSTNAMES' ] )
AntonySilvestera1080f22016-04-26 13:05:57 +0530328 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall46fdea12017-05-24 15:48:57 -0700329 cellAppString = main.params[ 'ENV' ][ 'cellApps' ]
330 httpport = main.params[ 'HTTP' ][ 'port' ]
331 path = main.params[ 'HTTP' ][ 'path' ]
AntonySilvestera1080f22016-04-26 13:05:57 +0530332
Jon Hall46fdea12017-05-24 15:48:57 -0700333 bgplsConfig.ipValue( ipList, scapy_ip )
AntonySilvestera1080f22016-04-26 13:05:57 +0530334
335 for i in range( 1, main.numCtrls + 1 ):
336 try:
337 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
338 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
339 ipList.append( main.nodes[ -1 ].ip_address )
340 except AttributeError:
341 break
342
343 bgplsConfig.Comments()
344 main.log.info( "Sending BGPLS Packet " )
345 bgplsConfig.Comments()
346
347 main.Scapy1.handle.sendline( "sudo python OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/\
348 dependencies/Scapyfiles/Update_Node.py" )
349 bgplsConfig.Comments()
350 main.log.info( "Enable BGPlS plugin in ONOS" )
351 bgplsConfig.Comments()
352
353 main.step( "UnInstall onos-app-bgp" )
Jon Hall46fdea12017-05-24 15:48:57 -0700354 installResults = main.ONOScli1.deactivateApp( app[ 0 ] )
AntonySilvestera1080f22016-04-26 13:05:57 +0530355 utilities.assert_equals( expect=main.TRUE, actual=installResults,
356 onpass="Uninstall onos-app-bgp successful",
357 onfail="Uninstall onos-app-bgp failed" )
358
Jon Hall46fdea12017-05-24 15:48:57 -0700359 installResults = main.ONOScli1.activateApp( app[ 0 ] )
AntonySilvestera1080f22016-04-26 13:05:57 +0530360 main.step( "Install onos-app-bgp" )
361 utilities.assert_equals( expect=main.TRUE, actual=installResults,
362 onpass="Install onos-app-bgp successful",
363 onfail="Install onos-app-bgp failed" )
364
AntonySilvestera1080f22016-04-26 13:05:57 +0530365 bgpls_post = bgplsConfig.DictoJson()
366
367 bgplsConfig.Comments()
368 main.log.info( "BGPLS RestConf input" )
369 bgplsConfig.Comments()
370
371 bgplsConfig.Comments()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800372 main.step( "Check Network devices are Updated in ONOS" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530373 bgplsConfig.Comments()
Jon Hall46fdea12017-05-24 15:48:57 -0700374 time.sleep( 120 )
AntonySilvestera1080f22016-04-26 13:05:57 +0530375 response = main.ONOScli1.devices()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800376 responseCheck = main.FALSE
377 if response:
378 responseCheck = main.TRUE
379 utilities.assert_equals( expect=main.TRUE,
380 actual=responseCheck,
381 onpass="Network Devices update in ONOS successful",
382 onfail="Network Devices update in ONOS failed" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530383 main.step( "Check Newly added Node is getting updated" )
384
Jon Hall46fdea12017-05-24 15:48:57 -0700385 if response.find( Ne_id[ 1 ][ 3 ] ) != -1:
AntonySilvestera1080f22016-04-26 13:05:57 +0530386 stepResult = main.TRUE
387 else:
388 stepResult = main.FALSE
389 utilities.assert_equals( expect=main.TRUE,
390 actual=stepResult,
AntonySilvester02652382016-07-13 16:44:45 +0530391 onpass="Node " + str( Ne_id[ 1 ][ 3 ] ) + " update sucess",
392 onfail="Node " + str( Ne_id[ 1 ][ 3 ] ) + " update failed" )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800393 main.ONOScli1.log( "\"testcase3 end\"" )
394
395 main.step( "Check for Errors or Exception in testcase3" )
396 startStr = "testcase3 start"
397 endStr = "testcase3 end"
Jon Hall46fdea12017-05-24 15:48:57 -0700398 errorLog = main.ONOSbench.logReport( main.nodes[ 0 ].ip_address,
399 [ "ERROR", "EXCEPT" ], "s",
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800400 startStr, endStr )
401 utilities.assert_equals( expect=0, actual=errorLog,
402 onpass="No Exception or Error occured in testcase3",
403 onfail="Exception or Error occured in testcase3" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530404 bgplsConfig.Comments()
405 main.log.info( "Kill Scapy process" )
406 bgplsConfig.Comments()
407 main.Scapy1.handle.sendline( "\x03" )
Jon Hall46fdea12017-05-24 15:48:57 -0700408 time.sleep( 90 ) # This Sleep time gives time for the socket to close.
AntonySilvestera1080f22016-04-26 13:05:57 +0530409
AntonySilvestera1080f22016-04-26 13:05:57 +0530410 def CASE4( self, main ):
411 """
AntonySilvester02652382016-07-13 16:44:45 +0530412 Verification of Links in existing topology
AntonySilvestera1080f22016-04-26 13:05:57 +0530413 """
AntonySilvester02652382016-07-13 16:44:45 +0530414 import json
AntonySilvestera1080f22016-04-26 13:05:57 +0530415 import time
AntonySilvester02652382016-07-13 16:44:45 +0530416 import os
417 main.case( "Testcase 4: Verification of Links thats is discovered" )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800418 main.ONOScli1.log( "\"testcase4 start\"" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530419 try:
420 from tests.FUNC.FUNCbgpls.dependencies.Nbdata import BgpLs
421 except ImportError:
422 main.log.exception( "Something wrong with import file or code error." )
423 main.log.info( "Import Error, please check!" )
424 main.cleanup()
425 main.exit()
426
427 bgplsConfig = BgpLs()
AntonySilvestera1080f22016-04-26 13:05:57 +0530428 app = bgplsConfig.apps()
429 main.CLIs = []
430 main.nodes = []
Jon Hall46fdea12017-05-24 15:48:57 -0700431 main.numCtrls = 1
AntonySilvestera1080f22016-04-26 13:05:57 +0530432 ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
Jon Hall46fdea12017-05-24 15:48:57 -0700433 scapy_ip = os.getenv( main.params[ 'SCAPY' ][ 'HOSTNAMES' ] )
434 bgplsConfig.ipValue( ipList, scapy_ip )
AntonySilvestera1080f22016-04-26 13:05:57 +0530435
AntonySilvestera1080f22016-04-26 13:05:57 +0530436 for i in range( 1, main.numCtrls + 1 ):
437 try:
438 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
439 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
440 ipList.append( main.nodes[ -1 ].ip_address )
441 except AttributeError:
442 break
443
AntonySilvestera1080f22016-04-26 13:05:57 +0530444 bgplsConfig.Comments()
AntonySilvester02652382016-07-13 16:44:45 +0530445 main.log.info( "Sending BGPLS Link information Packet " )
AntonySilvestera1080f22016-04-26 13:05:57 +0530446 bgplsConfig.Comments()
447
AntonySilvester02652382016-07-13 16:44:45 +0530448 main.Scapy1.handle.sendline( "sudo python OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies/Scapyfiles/Link_Update_Node.py" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530449 bgplsConfig.Comments()
450 main.log.info( "Enable BGPlS plugin in ONOS" )
451 bgplsConfig.Comments()
452
AntonySilvester02652382016-07-13 16:44:45 +0530453 main.step( "UnInstall onos-app-bgp" )
454 installResults = main.ONOScli1.deactivateApp( app[ 0 ] )
455 utilities.assert_equals( expect=main.TRUE, actual=installResults,
456 onpass="Uninstall onos-app-bgp successful",
457 onfail="Uninstall onos-app-bgp failed" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530458
Jon Hall46fdea12017-05-24 15:48:57 -0700459 installResults = main.ONOScli1.activateApp( app[ 0 ] )
AntonySilvestera1080f22016-04-26 13:05:57 +0530460 main.step( "Install onos-app-bgp" )
461 utilities.assert_equals( expect=main.TRUE, actual=installResults,
462 onpass="Install onos-app-bgp successful",
463 onfail="Install onos-app-bgp failed" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530464 bgplsConfig.Comments()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800465 main.step( "Checking the Link Discovery Status" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530466 bgplsConfig.Comments()
AntonySilvester02652382016-07-13 16:44:45 +0530467 time.sleep( 120 ) # Time taken to discovery the links
468 response = main.ONOScli1.links()
469 linksResp = json.loads( response )
470 check_link = bgplsConfig.checkLinks( linksResp )
AntonySilvestera1080f22016-04-26 13:05:57 +0530471
Jon Hall46fdea12017-05-24 15:48:57 -0700472 if check_link:
AntonySilvester02652382016-07-13 16:44:45 +0530473 reply_Check_Link = main.TRUE
Jon Hall46fdea12017-05-24 15:48:57 -0700474 utilities.assert_equals( expect=main.TRUE, actual=reply_Check_Link,
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800475 onpass="Link Discovery Success.",
476 onfail="Link Discovery Failed." )
477 main.ONOScli1.log( "\"testcase4 end\"" )
478
479 main.step( "Check for Errors or Exception in testcase4 " )
480 startStr = "testcase4 start"
481 endStr = "testcase4 end"
Jon Hall46fdea12017-05-24 15:48:57 -0700482 errorLog = main.ONOSbench.logReport( main.nodes[ 0 ].ip_address,
483 [ "ERROR", "EXCEPT" ], "s",
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800484 startStr, endStr )
Jon Hall46fdea12017-05-24 15:48:57 -0700485 utilities.assert_equals( expect=0, actual=errorLog,
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800486 onpass="No Exception or Error occured in testcase4",
487 onfail="Exception or Error occured in testcase4" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530488 bgplsConfig.Comments()
489 main.log.info( "Kill Scapy process" )
490 bgplsConfig.Comments()
AntonySilvestera1080f22016-04-26 13:05:57 +0530491 main.Scapy1.handle.sendline( "\x03" )
AntonySilvester02652382016-07-13 16:44:45 +0530492 time.sleep( 90 )
AntonySilvestera1080f22016-04-26 13:05:57 +0530493
494 def CASE5( self, main ):
495 """
AntonySilvester02652382016-07-13 16:44:45 +0530496 Deletion of links
497 """
498 import json
499 import time
500 import os
501 main.case( "Testcase 5: Deletion of Link in existing topology" )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800502
503 main.ONOScli1.log( "\"testcase5 start\"" )
AntonySilvester02652382016-07-13 16:44:45 +0530504 try:
505 from tests.FUNC.FUNCbgpls.dependencies.Nbdata import BgpLs
506 except ImportError:
507 main.log.exception( "Something wrong with import file or code error." )
508 main.log.info( "Import Error, please check!" )
509 main.cleanup()
510 main.exit()
511
512 bgplsConfig = BgpLs()
513 app = bgplsConfig.apps()
514 main.CLIs = []
515 main.nodes = []
Jon Hall46fdea12017-05-24 15:48:57 -0700516 main.numCtrls = 1
AntonySilvester02652382016-07-13 16:44:45 +0530517 ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
Jon Hall46fdea12017-05-24 15:48:57 -0700518 scapy_ip = os.getenv( main.params[ 'SCAPY' ][ 'HOSTNAMES' ] )
519 bgplsConfig.ipValue( ipList, scapy_ip )
AntonySilvester02652382016-07-13 16:44:45 +0530520
521 for i in range( 1, main.numCtrls + 1 ):
522 try:
523 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
524 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
525 ipList.append( main.nodes[ -1 ].ip_address )
526 except AttributeError:
527 break
528
529 bgplsConfig.Comments()
530 main.log.info( "Sending BGPLS Delete Link Packet " )
531 bgplsConfig.Comments()
532
533 main.Scapy1.handle.sendline( "sudo python OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies/Scapyfiles/Deletion_Node.py" )
534 bgplsConfig.Comments()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800535 main.log.info( "Enable BGPlS plugin in ONOS " )
AntonySilvester02652382016-07-13 16:44:45 +0530536 bgplsConfig.Comments()
537
538 main.step( "UnInstall onos-app-bgp" )
539 installResults = main.ONOScli1.deactivateApp( app[ 0 ] )
540 utilities.assert_equals( expect=main.TRUE, actual=installResults,
541 onpass="Uninstall onos-app-bgp successful",
542 onfail="Uninstall onos-app-bgp failed" )
543
Jon Hall46fdea12017-05-24 15:48:57 -0700544 installResults = main.ONOScli1.activateApp( app[ 0 ] )
AntonySilvester02652382016-07-13 16:44:45 +0530545 main.step( "Install onos-app-bgp" )
546 utilities.assert_equals( expect=main.TRUE, actual=installResults,
547 onpass="Install onos-app-bgp successful",
548 onfail="Install onos-app-bgp failed" )
549 bgplsConfig.Comments()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800550 main.step( "Checking whether the links is deleted" )
AntonySilvester02652382016-07-13 16:44:45 +0530551 bgplsConfig.Comments()
552 time.sleep( 120 ) # Time taken to discovery the links
553 response = main.ONOScli1.links()
554 linksResp = json.loads( response )
555 check_link = bgplsConfig.checkLinks( linksResp )
Jon Hall46fdea12017-05-24 15:48:57 -0700556 if not check_link:
AntonySilvester02652382016-07-13 16:44:45 +0530557 reply_Check_Link = main.TRUE
Jon Hall46fdea12017-05-24 15:48:57 -0700558 utilities.assert_equals( expect=main.TRUE, actual=reply_Check_Link,
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800559 onpass="Link is Deleted Successfully.",
560 onfail="Link is Deletion Failed." )
561 main.ONOScli1.log( "\"testcase5 end\"" )
562
563 main.step( "Check for Errors or Exception in testcase5" )
564 startStr = "testcase5 start"
565 endStr = "testcase5 end"
Jon Hall46fdea12017-05-24 15:48:57 -0700566 errorLog = main.ONOSbench.logReport( main.nodes[ 0 ].ip_address,
567 [ "ERROR", "EXCEPT" ], "s",
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800568 startStr, endStr )
569 utilities.assert_equals( expect=0, actual=errorLog,
570 onpass="No Exception or Error occured in testcase5",
571 onfail="Exception or Error occured in testcase5" )
AntonySilvester02652382016-07-13 16:44:45 +0530572 bgplsConfig.Comments()
573 main.log.info( "Kill Scapy process" )
574 bgplsConfig.Comments()
575 main.Scapy1.handle.sendline( "\x03" )
576 time.sleep( 90 )
577
578 def CASE6( self, main ):
579 """
AntonySilvestera1080f22016-04-26 13:05:57 +0530580 Uninstalling the app
581 """
Jon Hall46fdea12017-05-24 15:48:57 -0700582 import os
583 import sys
AntonySilvestera1080f22016-04-26 13:05:57 +0530584 import re
585 import time
586
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800587 main.case( "TestCase 6: UnInstalling of app" )
588 main.ONOScli1.log( "\"testcase6 start\"" )
AntonySilvestera1080f22016-04-26 13:05:57 +0530589 try:
590 from tests.FUNC.FUNCbgpls.dependencies.Nbdata import BgpLs
591 except ImportError:
592 main.log.exception( "Something wrong with import file or code error." )
593 main.log.info( "Import Error, please check!" )
594 main.cleanup()
595 main.exit()
596
597 bgplsConfig = BgpLs()
598 app = bgplsConfig.apps()
599 main.CLIs = []
600 main.nodes = []
Jon Hall46fdea12017-05-24 15:48:57 -0700601 main.numCtrls = 1
AntonySilvestera1080f22016-04-26 13:05:57 +0530602
603 ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] )
Jon Hall46fdea12017-05-24 15:48:57 -0700604 scapy_ip = os.getenv( main.params[ 'SCAPY' ][ 'HOSTNAMES' ] )
AntonySilvestera1080f22016-04-26 13:05:57 +0530605 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall46fdea12017-05-24 15:48:57 -0700606 cellAppString = main.params[ 'ENV' ][ 'cellApps' ]
AntonySilvestera1080f22016-04-26 13:05:57 +0530607
608 bgplsConfig = BgpLs()
Jon Hall46fdea12017-05-24 15:48:57 -0700609 bgplsConfig.ipValue( ipList, scapy_ip )
AntonySilvestera1080f22016-04-26 13:05:57 +0530610 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
611 scapy_ip,
Devin Limdc78e202017-06-09 18:30:07 -0700612 cellAppString, ipList, main.ONOScli1.karafUser )
AntonySilvestera1080f22016-04-26 13:05:57 +0530613
614 for i in range( 1, main.numCtrls + 1 ):
615 try:
616 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
617 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
618 ipList.append( main.nodes[ -1 ].ip_address )
619 except AttributeError:
620 break
621
622 main.step( "Apply cell to environment" )
623 bgplsConfig.Comments()
624 cellResult = main.ONOSbench.setCell( cellName )
625
626 bgplsConfig.Comments()
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800627 main.step( "Logging into ONOS CLI " )
AntonySilvestera1080f22016-04-26 13:05:57 +0530628 bgplsConfig.Comments()
629
Jon Hall46fdea12017-05-24 15:48:57 -0700630 cliResults = main.ONOScli1.startOnosCli( main.nodes[ 0 ].ip_address )
AntonySilvestera1080f22016-04-26 13:05:57 +0530631 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
632 onpass="ONOS cli startup successful",
633 onfail="ONOS cli startup failed" )
634
635 bgplsConfig.Comments()
636 main.log.info( "Uninstall onos-app-bgp" )
637 bgplsConfig.Comments()
638 main.step( "UnInstall onos-app-bgp" )
Jon Hall46fdea12017-05-24 15:48:57 -0700639 installResults = main.ONOScli1.deactivateApp( app[ 0 ] )
AntonySilvestera1080f22016-04-26 13:05:57 +0530640 utilities.assert_equals( expect=main.TRUE, actual=installResults,
641 onpass="Uninstall onos-app-bgp successful",
642 onfail="Uninstall onos-app-bgp failed" )
643
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800644 main.ONOScli1.log( "\"testcase6 end\"" )
645 main.step( "Check for Errors or Exception in testcase6" )
646 startStr = "testcase6 start"
647 endStr = "testcase6 end"
Jon Hall46fdea12017-05-24 15:48:57 -0700648 errorLog = main.ONOSbench.logReport( main.nodes[ 0 ].ip_address,
649 [ "ERROR", "EXCEPT" ], "s",
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800650 startStr, endStr )
651 utilities.assert_equals( expect=0, actual=errorLog,
652 onpass="No Exception or Error occured in testcase6",
653 onfail="Exception or Error occured in testcase6" )
654
655 main.step( "Check for Errors or Exception End of the Script" )
Jon Hall46fdea12017-05-24 15:48:57 -0700656 errorLog = main.ONOSbench.logReport( main.nodes[ 0 ].ip_address,
657 [ "ERROR", "EXCEPT" ] )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800658 utilities.assert_equals( expect=0, actual=errorLog,
AntonySilvester02652382016-07-13 16:44:45 +0530659 onpass="No Exception or Error occured",
Chiyu Chengef109502016-11-21 15:51:38 -0800660 onfail="Exception or Error occured" )