blob: 8b145ab73657d13ef586ea8f5ff48e28edc97d53 [file] [log] [blame]
Jeremyfc567ca2016-02-16 15:08:25 -08001# Testing the NETCONF protocol within ONOS
2
3class FUNCnetconf:
4
5 def __init__( self ):
6 self.default = ''
7
8 def CASE1( self, main ):
9 import time
10 import imp
11 import re
12
13 """
14 - Construct tests variables
15 - GIT ( optional )
16 - Checkout ONOS master branch
17 - Pull latest ONOS code
18 - Building ONOS ( optional )
19 - Install ONOS package
20 - Build ONOS package
21 """
22
23 main.case( "Constructing test variables and building ONOS package" )
24 main.step( "Constructing test variables" )
25 main.caseExplanation = "This test case is mainly for loading " +\
26 "from params file, and pull and build the " +\
27 " latest ONOS package"
28 stepResult = main.FALSE
29
30 # Test variables
31 try:
32 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
33 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
34 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 main.dependencyPath = main.testOnDirectory + \
36 main.params[ 'DEPENDENCY' ][ 'path' ]
37 # main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
38 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
39 if main.ONOSbench.maxNodes:
40 main.maxNodes = int( main.ONOSbench.maxNodes )
41 else:
42 main.maxNodes = 0
43 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
44 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
45 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
46 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
47 main.switchSleep = int( main.params[ 'SLEEP' ][ 'upSwitch' ] )
48 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
49 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
50
51 # Config file parameters
52 main.configDevicePort = main.params[ 'CONFIGURE' ][ 'cfgDevicePort' ]
53 main.configDriver = main.params[ 'CONFIGURE' ][ 'cfgDriver' ]
54 main.configApps = main.params[ 'CONFIGURE' ][ 'cfgApps' ]
55 main.configName = main.params[ 'CONFIGURE' ][ 'cfgName' ]
56 main.configPass = main.params[ 'CONFIGURE' ][ 'cfgPass' ]
57 main.configPort = main.params[ 'CONFIGURE' ][ 'cfgAppPort' ]
Jeremy Songster17147f22016-05-31 18:30:52 -070058 main.cycle = 0 # How many times FUNCintent has run through its tests
Jeremyfc567ca2016-02-16 15:08:25 -080059
60 gitPull = main.params[ 'GIT' ][ 'pull' ]
61 main.cellData = {} # for creating cell file
62 main.hostsData = {}
63 main.CLIs = []
64 main.CLIs2 = []
65 main.ONOSip = []
66 main.assertReturnString = '' # Assembled assert return string
67
68 main.ONOSip = main.ONOSbench.getOnosIps()
69 print main.ONOSip
70
71 # Assigning ONOS cli handles to a list
72 for i in range( 1, main.maxNodes + 1 ):
73 main.CLIs.append( getattr( main, 'ONOSrest' + str( i ) ) )
74 main.CLIs2.append( getattr( main, 'ONOScli' + str( i ) ) )
75
76 # -- INIT SECTION, ONLY RUNS ONCE -- #
77 main.startUp = imp.load_source( wrapperFile1,
78 main.dependencyPath +
79 wrapperFile1 +
80 ".py" )
81
82 main.netconfFunction = imp.load_source( wrapperFile2,
83 main.dependencyPath +
84 wrapperFile2 +
85 ".py" )
86
87 main.topo = imp.load_source( wrapperFile3,
88 main.dependencyPath +
89 wrapperFile3 +
90 ".py" )
91
92 # Uncomment out the following if a mininet topology is added
93 # copyResult1 = main.ONOSbench.scp( main.Mininet1,
94 # main.dependencyPath +
95 # main.topology,
96 # main.Mininet1.home + "custom/",
97 # direction="to" )
98
99 if main.CLIs and main.CLIs2:
100 stepResult = main.TRUE
101 else:
102 main.log.error( "Did not properly created list of ONOS CLI handle" )
103 stepResult = main.FALSE
104 except Exception as e:
105 main.log.exception(e)
106 main.cleanup()
107 main.exit()
108
109 utilities.assert_equals( expect=main.TRUE,
110 actual=stepResult,
111 onpass="Successfully construct " +
112 "test variables ",
113 onfail="Failed to construct test variables" )
114
115 if gitPull == 'True':
116 main.step( "Building ONOS in " + gitBranch + " branch" )
117 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
118 stepResult = onosBuildResult
119 utilities.assert_equals( expect=main.TRUE,
120 actual=stepResult,
121 onpass="Successfully compiled " +
122 "latest ONOS",
123 onfail="Failed to compile " +
124 "latest ONOS" )
125 else:
126 main.log.warn( "Did not pull new code so skipping mvn " +
127 "clean install" )
128 main.ONOSbench.getVersion( report=True )
129
130 def CASE2( self, main ):
131 """
132 - Set up cell
133 - Create cell file
134 - Set cell file
135 - Verify cell file
136 - Kill ONOS process
137 - Uninstall ONOS cluster
138 - Verify ONOS start up
139 - Install ONOS cluster
140 - Connect to cli
141 """
142
Jeremy Songster17147f22016-05-31 18:30:52 -0700143 main.cycle += 1
144
Jeremyfc567ca2016-02-16 15:08:25 -0800145 # main.scale[ 0 ] determines the current number of ONOS controller
146 main.numCtrls = int( main.scale[ 0 ] )
147
148 main.case( "Starting up " + str( main.numCtrls ) +
149 " node(s) ONOS cluster" )
150 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
151 " node(s) ONOS cluster"
152
153
154
155 #kill off all onos processes
156 main.log.info( "Safety check, killing all ONOS processes" +
157 " before initiating environment setup" )
158
159
160
161 time.sleep( main.startUpSleep )
162 main.step( "Uninstalling ONOS package" )
163 onosUninstallResult = main.TRUE
164 for ip in main.ONOSip:
165 onosUninstallResult = onosUninstallResult and \
166 main.ONOSbench.onosUninstall( nodeIp=ip )
167 stepResult = onosUninstallResult
168 utilities.assert_equals( expect=main.TRUE,
169 actual=stepResult,
170 onpass="Successfully uninstalled ONOS package",
171 onfail="Failed to uninstall ONOS package" )
172
173 for i in range( main.maxNodes ):
174 main.ONOSbench.onosDie( main.ONOSip[ i ] )
175
176 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
177
178 tempOnosIp = []
179 for i in range( main.numCtrls ):
180 tempOnosIp.append( main.ONOSip[i] )
181
182 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
183 "temp", main.Mininet1.ip_address,
184 main.apps, tempOnosIp )
185
186 main.step( "Apply cell to environment" )
187 cellResult = main.ONOSbench.setCell( "temp" )
188 verifyResult = main.ONOSbench.verifyCell()
189 stepResult = cellResult and verifyResult
190 utilities.assert_equals( expect=main.TRUE,
191 actual=stepResult,
192 onpass="Successfully applied cell to " + \
193 "environment",
194 onfail="Failed to apply cell to environment " )
195
196 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700197 packageResult = main.ONOSbench.buckBuild()
Jeremyfc567ca2016-02-16 15:08:25 -0800198 stepResult = packageResult
199 utilities.assert_equals( expect=main.TRUE,
200 actual=stepResult,
201 onpass="Successfully created ONOS package",
202 onfail="Failed to create ONOS package" )
203
204 time.sleep( main.startUpSleep )
205 main.step( "Installing ONOS package" )
206 onosInstallResult = main.TRUE
207 for i in range( main.numCtrls ):
208 onosInstallResult = onosInstallResult and \
209 main.ONOSbench.onosInstall( node=main.ONOSip[ i ], options="" )
210 stepResult = onosInstallResult
211
212 utilities.assert_equals( expect=main.TRUE,
213 actual=stepResult,
214 onpass="Successfully installed ONOS package",
215 onfail="Failed to install ONOS package" )
216
217 time.sleep( main.startUpSleep )
218 main.step( "Starting ONOS service" )
219 stopResult = main.TRUE
220 startResult = main.TRUE
221 onosIsUp = main.TRUE
222
223 for i in range( main.numCtrls ):
224 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
225 if onosIsUp == main.TRUE:
226 main.log.report( "ONOS instance is up and ready" )
227 else:
228 main.log.report( "ONOS instance may not be up, stop and " +
229 "start ONOS again " )
230 for i in range( main.numCtrls ):
231 stopResult = stopResult and \
232 main.ONOSbench.onosStop( main.ONOSip[ i ] )
233 for i in range( main.numCtrls ):
234 startResult = startResult and \
235 main.ONOSbench.onosStart( main.ONOSip[ i ] )
236 stepResult = onosIsUp and stopResult and startResult
237 utilities.assert_equals( expect=main.TRUE,
238 actual=stepResult,
239 onpass="ONOS service is ready",
240 onfail="ONOS service did not start properly" )
241
242 # Start an ONOS cli to provide functionality that is not currently
243 # supported by the Rest API remove this when Leader Checking is supported
244 # by the REST API
245
Chiyu Chengef109502016-11-21 15:51:38 -0800246 main.step( "Set up ONOS secure SSH" )
247 secureSshResult = main.TRUE
248 for i in range( int( main.numCtrls ) ):
249 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
250 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
251 onpass="Test step PASS",
252 onfail="Test step FAIL" )
253
Jeremyfc567ca2016-02-16 15:08:25 -0800254 main.step( "Start ONOS cli" )
255 cliResult = main.TRUE
256 for i in range( main.numCtrls ):
257 cliResult = cliResult and \
258 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
259 stepResult = cliResult
260 utilities.assert_equals( expect=main.TRUE,
261 actual=stepResult,
262 onpass="Successfully start ONOS cli",
263 onfail="Failed to start ONOS cli" )
264
265 # Remove the first element in main.scale list
266 main.scale.remove( main.scale[ 0 ] )
267
Jeremy Songster17147f22016-05-31 18:30:52 -0700268 def CASE19( self, main ):
269 """
270 Copy the karaf.log files after each testcase cycle
271 """
272 main.log.report( "Copy karaf logs" )
273 main.case( "Copy karaf logs" )
274 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
275 "reinstalling ONOS"
276 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700277 stepResult = main.TRUE
278 scpResult = main.TRUE
279 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700280 for i in range( main.numCtrls ):
Jeremy Songsterd2d687e2016-07-19 11:20:48 -0700281 main.node = main.CLIs2[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700282 ip = main.ONOSip[ i ]
283 main.node.ip_address = ip
Jeremy Songster31aad312016-06-13 16:32:11 -0700284 scpResult = scpResult and main.ONOSbench.scp( main.node ,
285 "/opt/onos/log/karaf.log",
286 "/tmp/karaf.log",
287 direction="from" )
288 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
289 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
290 if scpResult and copyResult:
291 stepResult = main.TRUE and stepResult
292 else:
293 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700294 utilities.assert_equals( expect=main.TRUE,
295 actual=stepResult,
296 onpass="Successfully copied remote ONOS logs",
297 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700298
Jeremyfc567ca2016-02-16 15:08:25 -0800299 def CASE100( self, main ):
300 """
301 Start NETCONF app and OFC-Server or make sure that they are already running
302 """
303 assert main, "There is no main"
304 assert main.CLIs, "There is no main.CLIs"
305 assert main.numCtrls, "Placed the total number of switch topology in \
306 main.numCtrls"
307
308 testResult = main.FALSE
309 main.testName = "Start up NETCONF app in all nodes"
310 main.case( main.testName + " Test - " + str( main.numCtrls ) +
311 " NODE(S)" )
312 main.step( "Starting NETCONF app" )
313 main.assertReturnString = "Assertion result for starting NETCONF app"
314 testResult = main.netconfFunction.startApp( main )
315
316 utilities.assert_equals( expect=main.TRUE,
317 actual=testResult,
318 onpass=main.assertReturnString,
319 onfail=main.assertReturnString )
320
321 main.step( "Starting OFC-Server" )
322 main.assertReturnString = "Assertion result for starting OFC-Server"
323 testResult = main.netconfFunction.startOFC( main )
324
325 utilities.assert_equals( expect=main.TRUE,
326 actual=testResult,
327 onpass=main.assertReturnString,
328 onfail=main.assertReturnString )
329 time.sleep( main.startUpSleep )
330
331 def CASE200( self, main ):
332 """
333 Create or modify a Configuration file
334 -The file is built from information loaded from the .params file
335 """
336 assert main, "There is no main"
337 assert main.CLIs, "There is no main.CLIs"
338 assert main.numCtrls, "Placed the total number of switch topology in \
339 main.numCtrls"
340
341 main.testName = "Assemble the configuration"
342 main.case( main.testName + " Test - " + str( main.numCtrls ) +
343 " NODES(S)" )
344 main.step( "Assembling configuration file" )
345 main.assertReturnString = "Assertion result for assembling configuration file"
346 testResult = main.FALSE
347 testResult = main.netconfFunction.createConfig( main )
348
349 utilities.assert_equals( expect=main.TRUE,
350 actual=testResult,
351 onpass=main.assertReturnString,
352 onfail=main.assertReturnString )
353 time.sleep( main.startUpSleep )
354
355 def CASE300( self, main ):
356 """
357 Push a configuration and bring up a switch
358 """
359 assert main, "There is no main"
360 assert main.CLIs, "There is no main.CLIs"
361 assert main.numCtrls, "Placed the total number of switch topology in \
362 main.numCtrls"
363
364 main.testName = "Uploading the configuration"
365 main.case( main.testName + " Test - " + str( main.numCtrls ) +
366 " NODES(S)" )
367 main.step( "Sending the configuration file")
368 main.assertReturnString = "Assertion result for sending the configuration file"
369 testResult = main.FALSE
370
371 testResult = main.netconfFunction.sendConfig( main )
372
373 utilities.assert_equals( expect=main.TRUE,
374 actual=testResult,
375 onpass=main.assertReturnString,
376 onfail=main.assertReturnString )
377
378 time.sleep( main.switchSleep )
379
380 main.step( "Confirming the device was configured" )
381 main.assertReturnString = "Assertion result for confirming a configuration."
382 testResult = main.FALSE
383
384 testResult = main.netconfFunction.devices( main )
385
386 utilities.assert_equals( expect=main.TRUE,
387 actual=testResult,
388 onpass=main.assertReturnString,
389 onfail=main.assertReturnString )
390
391 def CASE400( self, main ):
392 """
393 Bring down a switch
394 This test case is not yet possible, but the functionality needed to
395 perform it is planned to be added
396 There is a message that is sent "Device () has closed session"
397 when the device disconnects from onos for some reason.
398 Because of the triggers for this message are not practical
399 to activate this will likely not be used to implement the test
400 case at this time
401 Possible ways to do this may include bringing down mininet then checking
402 ONOS to see if it was recongnized the device being disconnected
403 """