blob: 757487f12f00f8849dcd52cf98becf65660e1fd4 [file] [log] [blame]
Jeremyfc567ca2016-02-16 15:08:25 -08001# Testing the NETCONF protocol within ONOS
2
Jon Hall0c3f46f2017-05-24 16:34:46 -07003
Jeremyfc567ca2016-02-16 15:08:25 -08004class FUNCnetconf:
5
6 def __init__( self ):
7 self.default = ''
8
9 def CASE1( self, main ):
10 import time
11 import imp
12 import re
13
14 """
15 - Construct tests variables
16 - GIT ( optional )
17 - Checkout ONOS master branch
18 - Pull latest ONOS code
19 - Building ONOS ( optional )
20 - Install ONOS package
21 - Build ONOS package
22 """
Jeremyfc567ca2016-02-16 15:08:25 -080023 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' ]
Jon Hall0c3f46f2017-05-24 16:34:46 -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' ]
Jon Hall0c3f46f2017-05-24 16:34:46 -070061 main.cellData = {} # for creating cell file
Jeremyfc567ca2016-02-16 15:08:25 -080062 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
Jon Hall0c3f46f2017-05-24 16:34:46 -070072 for i in range( 1, main.maxNodes + 1 ):
Jeremyfc567ca2016-02-16 15:08:25 -080073 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,
Jon Hall0c3f46f2017-05-24 16:34:46 -070083 main.dependencyPath +
84 wrapperFile2 +
85 ".py" )
Jeremyfc567ca2016-02-16 15:08:25 -080086
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:
Jon Hall0c3f46f2017-05-24 16:34:46 -0700105 main.log.exception( e )
Jeremyfc567ca2016-02-16 15:08:25 -0800106 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 """
Jeremy Songster17147f22016-05-31 18:30:52 -0700142 main.cycle += 1
143
Jeremyfc567ca2016-02-16 15:08:25 -0800144 # main.scale[ 0 ] determines the current number of ONOS controller
145 main.numCtrls = int( main.scale[ 0 ] )
146
147 main.case( "Starting up " + str( main.numCtrls ) +
148 " node(s) ONOS cluster" )
149 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
150 " node(s) ONOS cluster"
151
Jeremyfc567ca2016-02-16 15:08:25 -0800152 #kill off all onos processes
153 main.log.info( "Safety check, killing all ONOS processes" +
154 " before initiating environment setup" )
155
Jeremyfc567ca2016-02-16 15:08:25 -0800156 time.sleep( main.startUpSleep )
157 main.step( "Uninstalling ONOS package" )
158 onosUninstallResult = main.TRUE
159 for ip in main.ONOSip:
160 onosUninstallResult = onosUninstallResult and \
161 main.ONOSbench.onosUninstall( nodeIp=ip )
162 stepResult = onosUninstallResult
163 utilities.assert_equals( expect=main.TRUE,
164 actual=stepResult,
165 onpass="Successfully uninstalled ONOS package",
166 onfail="Failed to uninstall ONOS package" )
167
168 for i in range( main.maxNodes ):
169 main.ONOSbench.onosDie( main.ONOSip[ i ] )
170
171 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
172
173 tempOnosIp = []
174 for i in range( main.numCtrls ):
Jon Hall0c3f46f2017-05-24 16:34:46 -0700175 tempOnosIp.append( main.ONOSip[ i ] )
Jeremyfc567ca2016-02-16 15:08:25 -0800176
177 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
178 "temp", main.Mininet1.ip_address,
179 main.apps, tempOnosIp )
180
181 main.step( "Apply cell to environment" )
182 cellResult = main.ONOSbench.setCell( "temp" )
183 verifyResult = main.ONOSbench.verifyCell()
184 stepResult = cellResult and verifyResult
185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
Jon Hall0c3f46f2017-05-24 16:34:46 -0700187 onpass="Successfully applied cell to " +
Jeremyfc567ca2016-02-16 15:08:25 -0800188 "environment",
189 onfail="Failed to apply cell to environment " )
190
191 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700192 packageResult = main.ONOSbench.buckBuild()
Jeremyfc567ca2016-02-16 15:08:25 -0800193 stepResult = packageResult
194 utilities.assert_equals( expect=main.TRUE,
195 actual=stepResult,
196 onpass="Successfully created ONOS package",
197 onfail="Failed to create ONOS package" )
198
199 time.sleep( main.startUpSleep )
200 main.step( "Installing ONOS package" )
201 onosInstallResult = main.TRUE
202 for i in range( main.numCtrls ):
203 onosInstallResult = onosInstallResult and \
204 main.ONOSbench.onosInstall( node=main.ONOSip[ i ], options="" )
205 stepResult = onosInstallResult
206
207 utilities.assert_equals( expect=main.TRUE,
208 actual=stepResult,
209 onpass="Successfully installed ONOS package",
210 onfail="Failed to install ONOS package" )
211
You Wangf5de25b2017-01-06 15:13:01 -0800212 main.step( "Set up ONOS secure SSH" )
213 secureSshResult = main.TRUE
214 for i in range( int( main.numCtrls ) ):
Jon Hall0c3f46f2017-05-24 16:34:46 -0700215 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
You Wangf5de25b2017-01-06 15:13:01 -0800216 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
217 onpass="Test step PASS",
218 onfail="Test step FAIL" )
219
Jeremyfc567ca2016-02-16 15:08:25 -0800220 time.sleep( main.startUpSleep )
221 main.step( "Starting ONOS service" )
222 stopResult = main.TRUE
223 startResult = main.TRUE
224 onosIsUp = main.TRUE
225
226 for i in range( main.numCtrls ):
227 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
228 if onosIsUp == main.TRUE:
229 main.log.report( "ONOS instance is up and ready" )
230 else:
231 main.log.report( "ONOS instance may not be up, stop and " +
232 "start ONOS again " )
233 for i in range( main.numCtrls ):
234 stopResult = stopResult and \
235 main.ONOSbench.onosStop( main.ONOSip[ i ] )
236 for i in range( main.numCtrls ):
237 startResult = startResult and \
238 main.ONOSbench.onosStart( main.ONOSip[ i ] )
239 stepResult = onosIsUp and stopResult and startResult
240 utilities.assert_equals( expect=main.TRUE,
241 actual=stepResult,
242 onpass="ONOS service is ready",
243 onfail="ONOS service did not start properly" )
244
245 # Start an ONOS cli to provide functionality that is not currently
246 # supported by the Rest API remove this when Leader Checking is supported
247 # by the REST API
248
249 main.step( "Start ONOS cli" )
250 cliResult = main.TRUE
251 for i in range( main.numCtrls ):
252 cliResult = cliResult and \
253 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
254 stepResult = cliResult
255 utilities.assert_equals( expect=main.TRUE,
256 actual=stepResult,
257 onpass="Successfully start ONOS cli",
258 onfail="Failed to start ONOS cli" )
259
260 # Remove the first element in main.scale list
261 main.scale.remove( main.scale[ 0 ] )
262
Jeremy Songster17147f22016-05-31 18:30:52 -0700263 def CASE19( self, main ):
264 """
265 Copy the karaf.log files after each testcase cycle
266 """
267 main.log.report( "Copy karaf logs" )
268 main.case( "Copy karaf logs" )
269 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
270 "reinstalling ONOS"
271 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700272 stepResult = main.TRUE
273 scpResult = main.TRUE
274 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700275 for i in range( main.numCtrls ):
Jeremy Songsterd2d687e2016-07-19 11:20:48 -0700276 main.node = main.CLIs2[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700277 ip = main.ONOSip[ i ]
278 main.node.ip_address = ip
Jon Hall0c3f46f2017-05-24 16:34:46 -0700279 scpResult = scpResult and main.ONOSbench.scp( main.node,
280 "/opt/onos/log/karaf.log",
281 "/tmp/karaf.log",
282 direction="from" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700283 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
284 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
285 if scpResult and copyResult:
Jon Hall0c3f46f2017-05-24 16:34:46 -0700286 stepResult = main.TRUE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700287 else:
288 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700289 utilities.assert_equals( expect=main.TRUE,
290 actual=stepResult,
291 onpass="Successfully copied remote ONOS logs",
292 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700293
Jeremyfc567ca2016-02-16 15:08:25 -0800294 def CASE100( self, main ):
295 """
296 Start NETCONF app and OFC-Server or make sure that they are already running
297 """
298 assert main, "There is no main"
299 assert main.CLIs, "There is no main.CLIs"
300 assert main.numCtrls, "Placed the total number of switch topology in \
301 main.numCtrls"
302
303 testResult = main.FALSE
304 main.testName = "Start up NETCONF app in all nodes"
305 main.case( main.testName + " Test - " + str( main.numCtrls ) +
306 " NODE(S)" )
307 main.step( "Starting NETCONF app" )
308 main.assertReturnString = "Assertion result for starting NETCONF app"
309 testResult = main.netconfFunction.startApp( main )
310
311 utilities.assert_equals( expect=main.TRUE,
312 actual=testResult,
313 onpass=main.assertReturnString,
314 onfail=main.assertReturnString )
315
316 main.step( "Starting OFC-Server" )
317 main.assertReturnString = "Assertion result for starting OFC-Server"
318 testResult = main.netconfFunction.startOFC( main )
319
320 utilities.assert_equals( expect=main.TRUE,
321 actual=testResult,
322 onpass=main.assertReturnString,
323 onfail=main.assertReturnString )
324 time.sleep( main.startUpSleep )
325
326 def CASE200( self, main ):
327 """
328 Create or modify a Configuration file
329 -The file is built from information loaded from the .params file
330 """
331 assert main, "There is no main"
332 assert main.CLIs, "There is no main.CLIs"
333 assert main.numCtrls, "Placed the total number of switch topology in \
334 main.numCtrls"
335
336 main.testName = "Assemble the configuration"
337 main.case( main.testName + " Test - " + str( main.numCtrls ) +
338 " NODES(S)" )
339 main.step( "Assembling configuration file" )
340 main.assertReturnString = "Assertion result for assembling configuration file"
341 testResult = main.FALSE
342 testResult = main.netconfFunction.createConfig( main )
343
344 utilities.assert_equals( expect=main.TRUE,
345 actual=testResult,
346 onpass=main.assertReturnString,
347 onfail=main.assertReturnString )
348 time.sleep( main.startUpSleep )
349
350 def CASE300( self, main ):
351 """
352 Push a configuration and bring up a switch
353 """
354 assert main, "There is no main"
355 assert main.CLIs, "There is no main.CLIs"
356 assert main.numCtrls, "Placed the total number of switch topology in \
357 main.numCtrls"
358
359 main.testName = "Uploading the configuration"
360 main.case( main.testName + " Test - " + str( main.numCtrls ) +
361 " NODES(S)" )
Jon Hall0c3f46f2017-05-24 16:34:46 -0700362 main.step( "Sending the configuration file" )
Jeremyfc567ca2016-02-16 15:08:25 -0800363 main.assertReturnString = "Assertion result for sending the configuration file"
364 testResult = main.FALSE
365
366 testResult = main.netconfFunction.sendConfig( main )
367
368 utilities.assert_equals( expect=main.TRUE,
369 actual=testResult,
370 onpass=main.assertReturnString,
371 onfail=main.assertReturnString )
372
373 time.sleep( main.switchSleep )
374
375 main.step( "Confirming the device was configured" )
376 main.assertReturnString = "Assertion result for confirming a configuration."
377 testResult = main.FALSE
378
379 testResult = main.netconfFunction.devices( main )
380
381 utilities.assert_equals( expect=main.TRUE,
382 actual=testResult,
383 onpass=main.assertReturnString,
384 onfail=main.assertReturnString )
385
386 def CASE400( self, main ):
387 """
388 Bring down a switch
389 This test case is not yet possible, but the functionality needed to
390 perform it is planned to be added
391 There is a message that is sent "Device () has closed session"
392 when the device disconnects from onos for some reason.
393 Because of the triggers for this message are not practical
394 to activate this will likely not be used to implement the test
395 case at this time
396 Possible ways to do this may include bringing down mininet then checking
397 ONOS to see if it was recongnized the device being disconnected
398 """