blob: 9135daf74dd73f2c18db76fa6524ab2853489e9b [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" )
197 packageResult = main.ONOSbench.onosPackage()
198 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
246 main.step( "Start ONOS cli" )
247 cliResult = main.TRUE
248 for i in range( main.numCtrls ):
249 cliResult = cliResult and \
250 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
251 stepResult = cliResult
252 utilities.assert_equals( expect=main.TRUE,
253 actual=stepResult,
254 onpass="Successfully start ONOS cli",
255 onfail="Failed to start ONOS cli" )
256
257 # Remove the first element in main.scale list
258 main.scale.remove( main.scale[ 0 ] )
259
Jeremy Songster17147f22016-05-31 18:30:52 -0700260 def CASE19( self, main ):
261 """
262 Copy the karaf.log files after each testcase cycle
263 """
264 main.log.report( "Copy karaf logs" )
265 main.case( "Copy karaf logs" )
266 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
267 "reinstalling ONOS"
268 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700269 stepResult = main.TRUE
270 scpResult = main.TRUE
271 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700272 for i in range( main.numCtrls ):
Jeremy Songsterd2d687e2016-07-19 11:20:48 -0700273 main.node = main.CLIs2[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700274 ip = main.ONOSip[ i ]
275 main.node.ip_address = ip
Jeremy Songster31aad312016-06-13 16:32:11 -0700276 scpResult = scpResult and main.ONOSbench.scp( main.node ,
277 "/opt/onos/log/karaf.log",
278 "/tmp/karaf.log",
279 direction="from" )
280 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
281 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
282 if scpResult and copyResult:
283 stepResult = main.TRUE and stepResult
284 else:
285 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700286 utilities.assert_equals( expect=main.TRUE,
287 actual=stepResult,
288 onpass="Successfully copied remote ONOS logs",
289 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700290
Jeremyfc567ca2016-02-16 15:08:25 -0800291 def CASE100( self, main ):
292 """
293 Start NETCONF app and OFC-Server or make sure that they are already running
294 """
295 assert main, "There is no main"
296 assert main.CLIs, "There is no main.CLIs"
297 assert main.numCtrls, "Placed the total number of switch topology in \
298 main.numCtrls"
299
300 testResult = main.FALSE
301 main.testName = "Start up NETCONF app in all nodes"
302 main.case( main.testName + " Test - " + str( main.numCtrls ) +
303 " NODE(S)" )
304 main.step( "Starting NETCONF app" )
305 main.assertReturnString = "Assertion result for starting NETCONF app"
306 testResult = main.netconfFunction.startApp( main )
307
308 utilities.assert_equals( expect=main.TRUE,
309 actual=testResult,
310 onpass=main.assertReturnString,
311 onfail=main.assertReturnString )
312
313 main.step( "Starting OFC-Server" )
314 main.assertReturnString = "Assertion result for starting OFC-Server"
315 testResult = main.netconfFunction.startOFC( main )
316
317 utilities.assert_equals( expect=main.TRUE,
318 actual=testResult,
319 onpass=main.assertReturnString,
320 onfail=main.assertReturnString )
321 time.sleep( main.startUpSleep )
322
323 def CASE200( self, main ):
324 """
325 Create or modify a Configuration file
326 -The file is built from information loaded from the .params file
327 """
328 assert main, "There is no main"
329 assert main.CLIs, "There is no main.CLIs"
330 assert main.numCtrls, "Placed the total number of switch topology in \
331 main.numCtrls"
332
333 main.testName = "Assemble the configuration"
334 main.case( main.testName + " Test - " + str( main.numCtrls ) +
335 " NODES(S)" )
336 main.step( "Assembling configuration file" )
337 main.assertReturnString = "Assertion result for assembling configuration file"
338 testResult = main.FALSE
339 testResult = main.netconfFunction.createConfig( main )
340
341 utilities.assert_equals( expect=main.TRUE,
342 actual=testResult,
343 onpass=main.assertReturnString,
344 onfail=main.assertReturnString )
345 time.sleep( main.startUpSleep )
346
347 def CASE300( self, main ):
348 """
349 Push a configuration and bring up a switch
350 """
351 assert main, "There is no main"
352 assert main.CLIs, "There is no main.CLIs"
353 assert main.numCtrls, "Placed the total number of switch topology in \
354 main.numCtrls"
355
356 main.testName = "Uploading the configuration"
357 main.case( main.testName + " Test - " + str( main.numCtrls ) +
358 " NODES(S)" )
359 main.step( "Sending the configuration file")
360 main.assertReturnString = "Assertion result for sending the configuration file"
361 testResult = main.FALSE
362
363 testResult = main.netconfFunction.sendConfig( main )
364
365 utilities.assert_equals( expect=main.TRUE,
366 actual=testResult,
367 onpass=main.assertReturnString,
368 onfail=main.assertReturnString )
369
370 time.sleep( main.switchSleep )
371
372 main.step( "Confirming the device was configured" )
373 main.assertReturnString = "Assertion result for confirming a configuration."
374 testResult = main.FALSE
375
376 testResult = main.netconfFunction.devices( main )
377
378 utilities.assert_equals( expect=main.TRUE,
379 actual=testResult,
380 onpass=main.assertReturnString,
381 onfail=main.assertReturnString )
382
383 def CASE400( self, main ):
384 """
385 Bring down a switch
386 This test case is not yet possible, but the functionality needed to
387 perform it is planned to be added
388 There is a message that is sent "Device () has closed session"
389 when the device disconnects from onos for some reason.
390 Because of the triggers for this message are not practical
391 to activate this will likely not be used to implement the test
392 case at this time
393 Possible ways to do this may include bringing down mininet then checking
394 ONOS to see if it was recongnized the device being disconnected
395 """