blob: 58ba9297c21cbd559494f465f0419fba6240db97 [file] [log] [blame]
Jon Hall05b2b432014-10-08 19:53:25 -04001#!/usr/bin/env python
andrewonlabe8e56fd2014-10-09 17:12:44 -04002
kelvin8ec71442015-01-15 16:57:00 -08003"""
4This driver interacts with ONOS bench, the OSGi platform
5that configures the ONOS nodes. ( aka ONOS-next )
andrewonlabe8e56fd2014-10-09 17:12:44 -04006
kelvin8ec71442015-01-15 16:57:00 -08007Please follow the coding style demonstrated by existing
andrewonlabe8e56fd2014-10-09 17:12:44 -04008functions and document properly.
9
10If you are a contributor to the driver, please
11list your email here for future contact:
12
13jhall@onlab.us
14andrew@onlab.us
15
16OCT 9 2014
17
kelvin8ec71442015-01-15 16:57:00 -080018"""
andrewonlab7735d852014-10-09 13:02:47 -040019import sys
Jon Hall05b2b432014-10-08 19:53:25 -040020import time
21import pexpect
Jon Hall05b2b432014-10-08 19:53:25 -040022import traceback
andrewonlab7735d852014-10-09 13:02:47 -040023import os.path
kelvin8ec71442015-01-15 16:57:00 -080024sys.path.append( "../" )
Jon Hall05b2b432014-10-08 19:53:25 -040025from drivers.common.clidriver import CLI
26
Jon Hall05b2b432014-10-08 19:53:25 -040027
kelvin8ec71442015-01-15 16:57:00 -080028class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040029
kelvin8ec71442015-01-15 16:57:00 -080030 def __init__( self ):
31 """
32 Initialize client
33 """
34 super( CLI, self ).__init__()
35
36 def connect( self, **connectargs ):
37 """
Jon Hall05b2b432014-10-08 19:53:25 -040038 Creates ssh handle for ONOS "bench".
kelvin8ec71442015-01-15 16:57:00 -080039 """
Jon Hall05b2b432014-10-08 19:53:25 -040040 try:
41 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080042 vars( self )[ key ] = connectargs[ key ]
Jon Hall05b2b432014-10-08 19:53:25 -040043 self.home = "~/ONOS"
44 for key in self.options:
45 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080046 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040047 break
48
kelvin8ec71442015-01-15 16:57:00 -080049 self.name = self.options[ 'name' ]
50 self.handle = super( OnosDriver, self ).connect(
51 user_name=self.user_name,
52 ip_address=self.ip_address,
53 port=self.port,
54 pwd=self.pwd,
55 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -040056
kelvin8ec71442015-01-15 16:57:00 -080057 self.handle.sendline( "cd " + self.home )
58 self.handle.expect( "\$" )
Jon Hall05b2b432014-10-08 19:53:25 -040059 if self.handle:
60 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080061 else:
62 main.log.info( "NO ONOS HANDLE" )
Jon Hall05b2b432014-10-08 19:53:25 -040063 return main.FALSE
64 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080065 main.log.error( self.name + ": EOF exception found" )
66 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040067 main.cleanup()
68 main.exit()
69 except:
kelvin8ec71442015-01-15 16:57:00 -080070 main.log.info(
71 self.name +
72 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hall05b2b432014-10-08 19:53:25 -040073 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -080074 main.log.info(
75 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hall05b2b432014-10-08 19:53:25 -040076 main.cleanup()
77 main.exit()
78
kelvin8ec71442015-01-15 16:57:00 -080079 def disconnect( self ):
80 """
Jon Hall05b2b432014-10-08 19:53:25 -040081 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080082 """
Jon Hall05b2b432014-10-08 19:53:25 -040083 response = ''
84 try:
kelvin8ec71442015-01-15 16:57:00 -080085 self.handle.sendline( "" )
86 self.handle.expect( "\$" )
87 self.handle.sendline( "exit" )
88 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -040089 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080090 main.log.error( self.name + ": EOF exception found" )
91 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040092 except:
kelvin8ec71442015-01-15 16:57:00 -080093 main.log.error( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -040094 response = main.FALSE
95 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040096
kelvin8ec71442015-01-15 16:57:00 -080097 def onos_package( self ):
98 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040099 Produce a self-contained tar.gz file that can be deployed
kelvin8ec71442015-01-15 16:57:00 -0800100 and executed on any platform with Java 7 JRE.
101 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400102 try:
kelvin8ec71442015-01-15 16:57:00 -0800103 self.handle.sendline( "onos-package" )
104 self.handle.expect( "onos-package" )
105 self.handle.expect( "tar.gz", timeout=30 )
106 handle = str( self.handle.before )
107 main.log.info( "onos-package command returned: " +
108 handle )
109 # As long as the sendline does not time out,
110 # return true. However, be careful to interpret
111 # the results of the onos-package command return
andrewonlab0748d2a2014-10-09 13:24:17 -0400112 return main.TRUE
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400113
andrewonlab7735d852014-10-09 13:02:47 -0400114 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800115 main.log.error( self.name + ": EOF exception found" )
116 main.log.error( self.name + ": " + self.handle.before )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400117 except:
kelvin8ec71442015-01-15 16:57:00 -0800118 main.log.error( "Failed to package ONOS" )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400119 main.cleanup()
120 main.exit()
121
kelvin8ec71442015-01-15 16:57:00 -0800122 def onos_build( self ):
123 """
andrewonlab8790abb2014-11-06 13:51:54 -0500124 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800125 """
andrewonlab8790abb2014-11-06 13:51:54 -0500126 try:
kelvin8ec71442015-01-15 16:57:00 -0800127 self.handle.sendline( "onos-build" )
128 self.handle.expect( "onos-build" )
129 i = self.handle.expect( [
130 "BUILD SUCCESS",
131 "ERROR",
132 "BUILD FAILED" ],
133 timeout=120 )
134 handle = str( self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500135
kelvin8ec71442015-01-15 16:57:00 -0800136 main.log.info( "onos-build command returned: " +
137 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500138
139 if i == 0:
140 return main.TRUE
141 else:
142 return handle
143
144 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800145 main.log.error( self.name + ": EOF exception found" )
146 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500147 except:
kelvin8ec71442015-01-15 16:57:00 -0800148 main.log.error( "Failed to build ONOS" )
andrewonlab8790abb2014-11-06 13:51:54 -0500149 main.cleanup()
150 main.exit()
151
kelvin8ec71442015-01-15 16:57:00 -0800152 def clean_install( self ):
153 """
154 Runs mvn clean install in the root of the ONOS directory.
155 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400156
kelvin8ec71442015-01-15 16:57:00 -0800157 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400158 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800159 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400160 try:
kelvin8ec71442015-01-15 16:57:00 -0800161 main.log.info( "Running 'mvn clean install' on " + str( self.name ) +
162 ". This may take some time." )
163 self.handle.sendline( "cd " + self.home )
164 self.handle.expect( "\$" )
Jon Hallea7818b2014-10-09 14:30:59 -0400165
kelvin8ec71442015-01-15 16:57:00 -0800166 self.handle.sendline( "" )
167 self.handle.expect( "\$" )
168 self.handle.sendline( "mvn clean install" )
169 self.handle.expect( "mvn clean install" )
170 while True:
171 i = self.handle.expect( [
Jon Hallde9d9aa2014-10-08 20:36:02 -0400172 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\
173 Runtime\sEnvironment\sto\scontinue',
174 'BUILD\sFAILURE',
175 'BUILD\sSUCCESS',
176 'ONOS\$',
kelvin8ec71442015-01-15 16:57:00 -0800177 pexpect.TIMEOUT ], timeout=600 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400178 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800179 main.log.error( self.name + ":There is insufficient memory \
180 for the Java Runtime Environment to continue." )
181 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400182 main.cleanup()
183 main.exit()
184 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800185 main.log.error( self.name + ": Build failure!" )
186 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400187 main.cleanup()
188 main.exit()
189 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800190 main.log.info( self.name + ": Build success!" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400191 elif i == 3:
kelvin8ec71442015-01-15 16:57:00 -0800192 main.log.info( self.name + ": Build complete" )
193 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400194 for line in self.handle.before.splitlines():
195 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800196 main.log.info( line )
197 self.handle.sendline( "" )
198 self.handle.expect( "\$", timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400199 return main.TRUE
200 elif i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800201 main.log.error(
202 self.name +
203 ": mvn clean install TIMEOUT!" )
204 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400205 main.cleanup()
206 main.exit()
207 else:
kelvin8ec71442015-01-15 16:57:00 -0800208 main.log.error( self.name + ": unexpected response from \
209 mvn clean install" )
210 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400211 main.cleanup()
212 main.exit()
213 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800214 main.log.error( self.name + ": EOF exception found" )
215 main.log.error( self.name + ": " + self.handle.before )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400216 main.cleanup()
217 main.exit()
218 except:
kelvin8ec71442015-01-15 16:57:00 -0800219 main.log.info(
220 self.name +
221 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400222 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800223 main.log.info(
224 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400225 main.cleanup()
226 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400227
kelvin8ec71442015-01-15 16:57:00 -0800228 def git_pull( self, comp1="" ):
229 """
Jon Hallacabffd2014-10-09 12:36:53 -0400230 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800231
Jon Hallacabffd2014-10-09 12:36:53 -0400232 This function will perform a git pull on the ONOS instance.
kelvin8ec71442015-01-15 16:57:00 -0800233 If used as git_pull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400234 for the purpose of pulling from other nodes if necessary.
235
Jon Hall47a93fb2015-01-06 16:46:06 -0800236 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400237 ONOS repository. If it has any problems, it will return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800238 If it successfully does a git_pull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400239 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400240
kelvin8ec71442015-01-15 16:57:00 -0800241 """
Jon Hallacabffd2014-10-09 12:36:53 -0400242 try:
kelvin8ec71442015-01-15 16:57:00 -0800243 # main.log.info( self.name + ": Stopping ONOS" )
244 # self.stop()
245 self.handle.sendline( "cd " + self.home )
246 self.handle.expect( "ONOS\$" )
247 if comp1 == "":
248 self.handle.sendline( "git pull" )
Jon Hallacabffd2014-10-09 12:36:53 -0400249 else:
kelvin8ec71442015-01-15 16:57:00 -0800250 self.handle.sendline( "git pull " + comp1 )
Jon Hall47a93fb2015-01-06 16:46:06 -0800251
kelvin8ec71442015-01-15 16:57:00 -0800252 i = self.handle.expect( [ 'fatal',
253 'Username\sfor\s(.*):\s',
254 '\sfile(s*) changed,\s',
255 'Already up-to-date',
256 'Aborting',
257 'You\sare\snot\scurrently\son\sa\sbranch',
258 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\sbranch\syou',
259 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\sfiles',
260 pexpect.TIMEOUT ],
261 timeout=300 )
262 # debug
263 # main.log.report( self.name +": DEBUG: \n"+"git pull response: " +
264 # str( self.handle.before ) + str( self.handle.after ) )
265 if i == 0:
266 main.log.error( self.name + ": Git pull had some issue..." )
Jon Hallacabffd2014-10-09 12:36:53 -0400267 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800268 elif i == 1:
269 main.log.error(
270 self.name +
271 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400272 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800273 elif i == 2:
274 main.log.info(
275 self.name +
276 ": Git Pull - pulling repository now" )
277 self.handle.expect( "ONOS\$", 120 )
278 return main.TRUE # So that only when git pull is done, we do mvn clean compile
279 elif i == 3:
280 main.log.info( self.name + ": Git Pull - Already up to date" )
Jon Hall47a93fb2015-01-06 16:46:06 -0800281 return i
kelvin8ec71442015-01-15 16:57:00 -0800282 elif i == 4:
283 main.log.info(
284 self.name +
285 ": Git Pull - Aborting... Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400286 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800287 elif i == 5:
288 main.log.info(
289 self.name +
290 ": Git Pull - You are not currently on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400291 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800292 elif i == 6:
293 main.log.info(
294 self.name +
295 ": Git Pull - You have not configured an upstream branch to pull from. Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400296 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800297 elif i == 7:
298 main.log.info(
299 self.name +
300 ": Git Pull - Pull is not possible because you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400301 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800302 elif i == 8:
303 main.log.error( self.name + ": Git Pull - TIMEOUT" )
304 main.log.error(
305 self.name + " Response was: " + str(
306 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400307 return main.ERROR
308 else:
kelvin8ec71442015-01-15 16:57:00 -0800309 main.log.error(
310 self.name +
311 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400312 return main.ERROR
313 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800314 main.log.error( self.name + ": EOF exception found" )
315 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400316 main.cleanup()
317 main.exit()
318 except:
kelvin8ec71442015-01-15 16:57:00 -0800319 main.log.info(
320 self.name +
321 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hallacabffd2014-10-09 12:36:53 -0400322 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800323 main.log.info(
324 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hallacabffd2014-10-09 12:36:53 -0400325 main.cleanup()
326 main.exit()
327
kelvin8ec71442015-01-15 16:57:00 -0800328 def git_checkout( self, branch="master" ):
329 """
Jon Hallacabffd2014-10-09 12:36:53 -0400330 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800331
Jon Hallacabffd2014-10-09 12:36:53 -0400332 This function will perform a git git checkout on the ONOS instance.
kelvin8ec71442015-01-15 16:57:00 -0800333 If used as git_checkout( "branch" ) it will do git checkout of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400334
335 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800336 branch of the ONOS repository. If it has any problems, it will return
337 main.ERROR.
338 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400339 successful then the function will return main.TRUE.
340
kelvin8ec71442015-01-15 16:57:00 -0800341 """
Jon Hallacabffd2014-10-09 12:36:53 -0400342 try:
kelvin8ec71442015-01-15 16:57:00 -0800343 self.handle.sendline( "cd " + self.home )
344 self.handle.expect( "ONOS\$" )
345 main.log.info(
346 self.name +
347 ": Checking out git branch: " +
348 branch +
349 "..." )
350 cmd = "git checkout " + branch
351 self.handle.sendline( cmd )
352 self.handle.expect( cmd )
353 i = self.handle.expect( [ 'fatal',
354 'Username\sfor\s(.*):\s',
355 'Already\son\s\'',
356 'Switched\sto\sbranch\s\'' +
357 str( branch ),
358 pexpect.TIMEOUT,
359 'error: Your local changes to the following files would be overwritten by checkout:',
360 'error: you need to resolve your current index first' ], timeout=60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400361
kelvin8ec71442015-01-15 16:57:00 -0800362 if i == 0:
363 main.log.error(
364 self.name +
365 ": Git checkout had some issue..." )
366 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400367 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800368 elif i == 1:
369 main.log.error( self.name + ": Git checkout asking for username."
370 + " Please configure your local git repository to be able "
371 + "to access your remote repository passwordlessly" )
Jon Hallacabffd2014-10-09 12:36:53 -0400372 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800373 elif i == 2:
374 main.log.info(
375 self.name +
376 ": Git Checkout %s : Already on this branch" %
377 branch )
378 self.handle.expect( "ONOS\$" )
379 # main.log.info( "DEBUG: after checkout cmd = "+
380 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400381 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800382 elif i == 3:
383 main.log.info(
384 self.name +
385 ": Git checkout %s - Switched to this branch" %
386 branch )
387 self.handle.expect( "ONOS\$" )
388 # main.log.info( "DEBUG: after checkout cmd = "+
389 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400390 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800391 elif i == 4:
392 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
393 main.log.error(
394 self.name + " Response was: " + str(
395 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400396 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800397 elif i == 5:
398 self.handle.expect( "Aborting" )
399 main.log.error( self.name + ": Git checkout error: \n" +
400 "Your local changes to the following files would be overwritten by checkout:" +
401 str( self.handle.before ) )
402 self.handle.expect( "ONOS\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500403 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800404 elif i == 6:
405 main.log.error( self.name + ": Git checkout error: \n" +
406 "You need to resolve your current index first:" +
407 str( self.handle.before ) )
408 self.handle.expect( "ONOS\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500409 return main.ERROR
Jon Hallacabffd2014-10-09 12:36:53 -0400410 else:
kelvin8ec71442015-01-15 16:57:00 -0800411 main.log.error(
412 self.name +
413 ": Git Checkout - Unexpected response, check for pull errors" )
414 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400415 return main.ERROR
416
417 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800418 main.log.error( self.name + ": EOF exception found" )
419 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400420 main.cleanup()
421 main.exit()
422 except:
kelvin8ec71442015-01-15 16:57:00 -0800423 main.log.info(
424 self.name +
425 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hallacabffd2014-10-09 12:36:53 -0400426 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800427 main.log.info(
428 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hallacabffd2014-10-09 12:36:53 -0400429 main.cleanup()
430 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400431
kelvin8ec71442015-01-15 16:57:00 -0800432 def get_version( self, report=False ):
433 """
Jon Hall45ec0922014-10-10 19:33:49 -0400434 Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
kelvin8ec71442015-01-15 16:57:00 -0800435 """
Jon Hall45ec0922014-10-10 19:33:49 -0400436 try:
kelvin8ec71442015-01-15 16:57:00 -0800437 self.handle.sendline( "" )
438 self.handle.expect( "\$" )
439 self.handle.sendline(
440 "cd " +
441 self.home +
442 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 \"commit\" --color=never" )
443 # NOTE: for some reason there are backspaces inserted in this
444 # phrase when run from Jenkins on some tests
445 self.handle.expect( "never" )
446 self.handle.expect( "\$" )
447 response = ( self.name + ": \n" + str(
448 self.handle.before + self.handle.after ) )
449 self.handle.sendline( "cd " + self.home )
450 self.handle.expect( "\$" )
451 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400452 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500453 print line
454 if report:
kelvin8ec71442015-01-15 16:57:00 -0800455 for line in lines[ 2:-1 ]:
456 # Bracket replacement is for Wiki-compliant
457 # formatting. '<' or '>' are interpreted
458 # as xml specific tags that cause errors
459 line = line.replace( "<", "[" )
460 line = line.replace( ">", "]" )
461 main.log.report( "\t" + line )
462 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400463 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800464 main.log.error( self.name + ": EOF exception found" )
465 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400466 main.cleanup()
467 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800468 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800469 main.log.error( self.name + ": TIMEOUT exception found" )
470 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800471 main.cleanup()
472 main.exit()
Jon Hall45ec0922014-10-10 19:33:49 -0400473 except:
kelvin8ec71442015-01-15 16:57:00 -0800474 main.log.info(
475 self.name +
476 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hall45ec0922014-10-10 19:33:49 -0400477 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800478 main.log.info(
479 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hall45ec0922014-10-10 19:33:49 -0400480 main.cleanup()
481 main.exit()
482
kelvin8ec71442015-01-15 16:57:00 -0800483 def create_cell_file( self, bench_ip, file_name, mn_ip_addrs,
484 extra_feature_string, *onos_ip_addrs ):
485 """
andrewonlab94282092014-10-10 13:00:11 -0400486 Creates a cell file based on arguments
487 Required:
kelvin8ec71442015-01-15 16:57:00 -0800488 * Bench IP address ( bench_ip )
andrewonlab94282092014-10-10 13:00:11 -0400489 - Needed to copy the cell file over
kelvin8ec71442015-01-15 16:57:00 -0800490 * File name of the cell file ( file_name )
491 * Mininet IP address ( mn_ip_addrs )
492 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400493 supported currently
kelvin8ec71442015-01-15 16:57:00 -0800494 * ONOS IP addresses ( onos_ip_addrs )
andrewonlab94282092014-10-10 13:00:11 -0400495 - Must be passed in as last arguments
kelvin8ec71442015-01-15 16:57:00 -0800496
andrewonlab94282092014-10-10 13:00:11 -0400497 NOTE: Assumes cells are located at:
498 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800499 """
500 # Variable initialization
andrewonlab94282092014-10-10 13:00:11 -0400501 cell_directory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800502 # We want to create the cell file in the dependencies directory
503 # of TestON first, then copy over to ONOS bench
andrewonlab94282092014-10-10 13:00:11 -0400504 temp_directory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800505 # Create the cell file in the directory for writing ( w+ )
506 cell_file = open( temp_directory + file_name, 'w+' )
507
508 # Feature string is hardcoded environment variables
509 # That you may wish to use by default on startup.
510 # Note that you may not want certain features listed
511 # on here.
512 core_feature_string = "export ONOS_FEATURES=webconsole,onos-api," +\
513 "onos-cli,onos-openflow," + extra_feature_string
andrewonlab94282092014-10-10 13:00:11 -0400514 mn_string = "export OCN="
515 onos_string = "export OC"
516 temp_count = 1
kelvin8ec71442015-01-15 16:57:00 -0800517
518 # Create ONOS_NIC ip address prefix
519 temp_onos_ip = onos_ip_addrs[ 0 ]
andrewonlab94282092014-10-10 13:00:11 -0400520 temp_list = []
kelvin8ec71442015-01-15 16:57:00 -0800521 temp_list = temp_onos_ip.split( "." )
522 # Omit last element of list to format for NIC
523 temp_list = temp_list[ :-1 ]
524 # Structure the nic string ip
525 nic_addr = ".".join( temp_list ) + ".*"
526 onos_nic_string = "export ONOS_NIC=" + nic_addr
andrewonlab94282092014-10-10 13:00:11 -0400527
528 try:
kelvin8ec71442015-01-15 16:57:00 -0800529 # Start writing to file
530 cell_file.write( onos_nic_string + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400531
532 for arg in onos_ip_addrs:
kelvin8ec71442015-01-15 16:57:00 -0800533 # For each argument in onos_ip_addrs, write to file
534 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400535 # export OC1="10.128.20.11"
536 # export OC2="10.128.20.12"
kelvin8ec71442015-01-15 16:57:00 -0800537 cell_file.write( onos_string + str( temp_count ) +
538 "=" + "\"" + arg + "\"" + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400539 temp_count = temp_count + 1
kelvin8ec71442015-01-15 16:57:00 -0800540
541 cell_file.write( mn_string + "\"" + mn_ip_addrs + "\"" + "\n" )
542 cell_file.write( core_feature_string + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400543 cell_file.close()
544
kelvin8ec71442015-01-15 16:57:00 -0800545 # We use os.system to send the command to TestON cluster
546 # to account for the case in which TestON is not located
547 # on the same cluster as the ONOS bench
548 # Note that even if TestON is located on the same cluster
549 # as ONOS bench, you must setup passwordless ssh
550 # between TestON and ONOS bench in order to automate the test.
551 os.system( "scp " + temp_directory + file_name +
552 " admin@" + bench_ip + ":" + cell_directory )
andrewonlab94282092014-10-10 13:00:11 -0400553
andrewonlab2a6c9342014-10-16 13:40:15 -0400554 return main.TRUE
555
andrewonlab94282092014-10-10 13:00:11 -0400556 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800557 main.log.error( self.name + ": EOF exception found" )
558 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -0400559 main.cleanup()
560 main.exit()
561 except:
kelvin8ec71442015-01-15 16:57:00 -0800562 main.log.info( self.name + ":::::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400563 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800564 main.log.info( ":::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400565 main.cleanup()
566 main.exit()
567
kelvin8ec71442015-01-15 16:57:00 -0800568 def set_cell( self, cellname ):
569 """
andrewonlab95ca1462014-10-09 14:04:24 -0400570 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800571 """
andrewonlab95ca1462014-10-09 14:04:24 -0400572 try:
573 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800574 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400575 main.cleanup()
576 main.exit()
577 else:
kelvin8ec71442015-01-15 16:57:00 -0800578 self.handle.sendline( "cell " + str( cellname ) )
579 # Expect the cellname in the ONOS_CELL variable.
580 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400581 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800582 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
andrewonlab95ca1462014-10-09 14:04:24 -0400583 handle_before = self.handle.before
584 handle_after = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800585 # Get the rest of the handle
586 self.handle.sendline( "" )
587 self.handle.expect( "\$" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400588 handle_more = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400589
kelvin8ec71442015-01-15 16:57:00 -0800590 main.log.info( "Cell call returned: " + handle_before +
591 handle_after + handle_more )
andrewonlab95ca1462014-10-09 14:04:24 -0400592
593 return main.TRUE
594
595 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800596 main.log.error( self.name + ": EOF exception found" )
597 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400598 main.cleanup()
599 main.exit()
600 except:
kelvin8ec71442015-01-15 16:57:00 -0800601 main.log.info( self.name + " ::::::" )
602 main.log.error( traceback.print_exc() )
603 main.log.info( self.name + " ::::::" )
andrewonlab95ca1462014-10-09 14:04:24 -0400604 main.cleanup()
605 main.exit()
606
kelvin8ec71442015-01-15 16:57:00 -0800607 def verify_cell( self ):
608 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400609 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800610 """
611 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400612
andrewonlabc03bf6c2014-10-09 14:56:18 -0400613 try:
kelvin8ec71442015-01-15 16:57:00 -0800614 # Clean handle by sending empty and expecting $
615 self.handle.sendline( "" )
616 self.handle.expect( "\$" )
617 self.handle.sendline( "onos-verify-cell" )
618 self.handle.expect( "\$" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400619 handle_before = self.handle.before
620 handle_after = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800621 # Get the rest of the handle
622 self.handle.sendline( "" )
623 self.handle.expect( "\$" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400624 handle_more = self.handle.before
625
kelvin8ec71442015-01-15 16:57:00 -0800626 main.log.info( "Verify cell returned: " + handle_before +
627 handle_after + handle_more )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400628
629 return main.TRUE
Jon Hall7993bfc2014-10-09 16:30:14 -0400630 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800631 main.log.error( self.name + ": EOF exception found" )
632 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400633 main.cleanup()
634 main.exit()
635 except:
kelvin8ec71442015-01-15 16:57:00 -0800636 main.log.info( self.name + " ::::::" )
637 main.log.error( traceback.print_exc() )
638 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400639 main.cleanup()
640 main.exit()
641
kelvin8ec71442015-01-15 16:57:00 -0800642 def onos_cli( self, ONOS_ip, cmdstr ):
643 """
andrewonlab05e362f2014-10-10 00:40:57 -0400644 Uses 'onos' command to send various ONOS CLI arguments.
645 Required:
646 * ONOS_ip: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400647 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800648
649 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400650 CLI commands for ONOS. Try to use this function first
651 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800652 function.
653 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400654 by starting onos, and typing in 'onos' to enter the
655 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800656 available commands.
657 """
andrewonlab05e362f2014-10-10 00:40:57 -0400658 try:
659 if not ONOS_ip:
kelvin8ec71442015-01-15 16:57:00 -0800660 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400661 return main.FALSE
662 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800663 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400664 return main.FALSE
665
kelvin8ec71442015-01-15 16:57:00 -0800666 cmdstr = str( cmdstr )
667 self.handle.sendline( "" )
668 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400669
kelvin8ec71442015-01-15 16:57:00 -0800670 self.handle.sendline( "onos -w " + ONOS_ip + " " + cmdstr )
671 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400672
Shreya Shaha73aaad2014-10-27 18:03:09 -0400673 handle_before = self.handle.before
674 print "handle_before = ", self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800675 # handle_after = str( self.handle.after )
Jon Hall47a93fb2015-01-06 16:46:06 -0800676
kelvin8ec71442015-01-15 16:57:00 -0800677 # self.handle.sendline( "" )
678 # self.handle.expect( "\$" )
679 # handle_more = str( self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400680
kelvin8ec71442015-01-15 16:57:00 -0800681 main.log.info( "Command sent successfully" )
andrewonlab05e362f2014-10-10 00:40:57 -0400682
kelvin8ec71442015-01-15 16:57:00 -0800683 # Obtain return handle that consists of result from
684 # the onos command. The string may need to be
685 # configured further.
686 # return_string = handle_before + handle_after
Shreya Shaha73aaad2014-10-27 18:03:09 -0400687 return_string = handle_before
688 print "return_string = ", return_string
andrewonlab05e362f2014-10-10 00:40:57 -0400689 return return_string
690
691 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800692 main.log.error( self.name + ": EOF exception found" )
693 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400694 main.cleanup()
695 main.exit()
696 except:
kelvin8ec71442015-01-15 16:57:00 -0800697 main.log.info( self.name + " ::::::" )
698 main.log.error( traceback.print_exc() )
699 main.log.info( self.name + " ::::::" )
andrewonlab05e362f2014-10-10 00:40:57 -0400700 main.cleanup()
701 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400702
kelvin8ec71442015-01-15 16:57:00 -0800703 def onos_install( self, options="-f", node="" ):
704 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400705 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800706 If -f option is provided, it also forces an uninstall.
707 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400708 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800709 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400710 files to certain onos nodes
711
712 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800713 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400714 try:
andrewonlab114768a2014-11-14 12:44:44 -0500715 if options:
kelvin8ec71442015-01-15 16:57:00 -0800716 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500717 else:
kelvin8ec71442015-01-15 16:57:00 -0800718 self.handle.sendline( "onos-install " + node )
719 self.handle.expect( "onos-install " )
720 # NOTE: this timeout may need to change depending on the network
721 # and size of ONOS
722 i = self.handle.expect( [ "Network\sis\sunreachable",
723 "onos\sstart/running,\sprocess",
724 "ONOS\sis\salready\sinstalled",
725 pexpect.TIMEOUT ], timeout=60 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400726
Jon Hall7993bfc2014-10-09 16:30:14 -0400727 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800728 main.log.warn( "Network is unreachable" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400729 return main.FALSE
730 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800731 main.log.info(
732 "ONOS was installed on " +
733 node +
734 " and started" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400735 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500736 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800737 main.log.info( "ONOS is already installed on " + node )
andrewonlabd9a73a72014-11-14 17:28:21 -0500738 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800739 elif i == 3:
740 main.log.info(
741 "Installation of ONOS on " +
742 node +
743 " timed out" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400744 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400745
746 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800747 main.log.error( self.name + ": EOF exception found" )
748 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400749 main.cleanup()
750 main.exit()
751 except:
kelvin8ec71442015-01-15 16:57:00 -0800752 main.log.info( self.name + " ::::::" )
753 main.log.error( traceback.print_exc() )
754 main.log.info( self.name + " ::::::" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400755 main.cleanup()
756 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400757
kelvin8ec71442015-01-15 16:57:00 -0800758 def onos_start( self, node_ip ):
759 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400760 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400761 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800762 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400763 try:
kelvin8ec71442015-01-15 16:57:00 -0800764 self.handle.sendline( "" )
765 self.handle.expect( "\$" )
766 self.handle.sendline( "onos-service " + str( node_ip ) +
767 " start" )
768 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -0400769 "Job\sis\salready\srunning",
770 "start/running",
771 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800772 pexpect.TIMEOUT ], timeout=120 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400773
774 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800775 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400776 return main.TRUE
777 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800778 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400779 return main.TRUE
780 else:
kelvin8ec71442015-01-15 16:57:00 -0800781 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400782 main.cleanup()
783 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400784 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800785 main.log.error( self.name + ": EOF exception found" )
786 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400787 main.cleanup()
788 main.exit()
789 except:
kelvin8ec71442015-01-15 16:57:00 -0800790 main.log.info( self.name + " ::::::" )
791 main.log.error( traceback.print_exc() )
792 main.log.info( self.name + " ::::::" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400793 main.cleanup()
794 main.exit()
795
kelvin8ec71442015-01-15 16:57:00 -0800796 def onos_stop( self, node_ip ):
797 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400798 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400799 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800800 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400801 try:
kelvin8ec71442015-01-15 16:57:00 -0800802 self.handle.sendline( "" )
803 self.handle.expect( "\$" )
804 self.handle.sendline( "onos-service " + str( node_ip ) +
805 " stop" )
806 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -0400807 "stop/waiting",
808 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800809 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2b30bd32014-10-09 16:48:55 -0400810
811 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800812 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400813 return main.TRUE
814 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800815 main.log.info( "Unknown ONOS instance specified: " +
816 str( node_ip ) )
andrewonlab2b30bd32014-10-09 16:48:55 -0400817 return main.FALSE
818 else:
kelvin8ec71442015-01-15 16:57:00 -0800819 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400820 return main.FALSE
821
822 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800823 main.log.error( self.name + ": EOF exception found" )
824 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -0400825 main.cleanup()
826 main.exit()
827 except:
kelvin8ec71442015-01-15 16:57:00 -0800828 main.log.info( self.name + " ::::::" )
829 main.log.error( traceback.print_exc() )
830 main.log.info( self.name + " ::::::" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400831 main.cleanup()
832 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800833
834 def onos_uninstall( self, node_ip="" ):
835 """
andrewonlabc8d47972014-10-09 16:52:36 -0400836 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -0800837 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -0400838 if needed
kelvin8ec71442015-01-15 16:57:00 -0800839 """
andrewonlabc8d47972014-10-09 16:52:36 -0400840 try:
kelvin8ec71442015-01-15 16:57:00 -0800841 self.handle.sendline( "" )
842 self.handle.expect( "\$" )
843 self.handle.sendline( "onos-uninstall " + str( node_ip ) )
844 self.handle.expect( "\$" )
andrewonlabc8d47972014-10-09 16:52:36 -0400845
kelvin8ec71442015-01-15 16:57:00 -0800846 main.log.info( "ONOS " + node_ip + " was uninstalled" )
andrewonlab9dfd2082014-11-13 17:44:03 -0500847
kelvin8ec71442015-01-15 16:57:00 -0800848 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -0400849 return main.TRUE
850
851 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800852 main.log.error( self.name + ": EOF exception found" )
853 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -0400854 main.cleanup()
855 main.exit()
856 except:
kelvin8ec71442015-01-15 16:57:00 -0800857 main.log.info( self.name + " ::::::" )
858 main.log.error( traceback.print_exc() )
859 main.log.info( self.name + " ::::::" )
andrewonlabc8d47972014-10-09 16:52:36 -0400860 main.cleanup()
861 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400862
kelvin8ec71442015-01-15 16:57:00 -0800863 def onos_die( self, node_ip ):
864 """
andrewonlabaedc8332014-12-04 12:43:03 -0500865 Issues the command 'onos-die <node-ip>'
866 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -0800867 """
andrewonlabaedc8332014-12-04 12:43:03 -0500868 try:
kelvin8ec71442015-01-15 16:57:00 -0800869 self.handle.sendline( "" )
870 self.handle.expect( "\$" )
871 cmd_str = "onos-kill " + str( node_ip )
872 self.handle.sendline( cmd_str )
873 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -0500874 "Killing\sONOS",
875 "ONOS\sprocess\sis\snot\srunning",
kelvin8ec71442015-01-15 16:57:00 -0800876 pexpect.TIMEOUT ], timeout=20 )
andrewonlabaedc8332014-12-04 12:43:03 -0500877 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800878 main.log.info( "ONOS instance " + str( node_ip ) +
879 " was killed and stopped" )
andrewonlabaedc8332014-12-04 12:43:03 -0500880 return main.TRUE
881 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800882 main.log.info( "ONOS process was not running" )
andrewonlabaedc8332014-12-04 12:43:03 -0500883 return main.FALSE
884 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800885 main.log.error( self.name + ": EOF exception found" )
886 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -0500887 main.cleanup()
888 main.exit()
889 except:
kelvin8ec71442015-01-15 16:57:00 -0800890 main.log.info( self.name + " ::::::" )
891 main.log.error( traceback.print_exc() )
892 main.log.info( self.name + " ::::::" )
andrewonlabaedc8332014-12-04 12:43:03 -0500893 main.cleanup()
894 main.exit()
895
kelvin8ec71442015-01-15 16:57:00 -0800896 def onos_kill( self, node_ip ):
897 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400898 Calls the command: 'onos-kill [<node-ip>]'
899 "Remotely, and unceremoniously kills the ONOS instance running on
900 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -0800901 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400902 try:
kelvin8ec71442015-01-15 16:57:00 -0800903 self.handle.sendline( "" )
904 self.handle.expect( "\$" )
905 self.handle.sendline( "onos-kill " + str( node_ip ) )
906 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -0400907 "\$",
908 "No\sroute\sto\shost",
909 "password:",
kelvin8ec71442015-01-15 16:57:00 -0800910 pexpect.TIMEOUT ], timeout=20 )
911
andrewonlabe8e56fd2014-10-09 17:12:44 -0400912 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800913 main.log.info(
914 "ONOS instance " + str(
915 node_ip ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400916 return main.TRUE
917 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800918 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400919 return main.FALSE
920 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800921 main.log.info( "Passwordless login for host: " + str( node_ip ) +
922 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400923 return main.FALSE
924 else:
kelvin8ec71442015-01-15 16:57:00 -0800925 main.log.info( "ONOS instasnce was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400926 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800927
andrewonlabe8e56fd2014-10-09 17:12:44 -0400928 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800929 main.log.error( self.name + ": EOF exception found" )
930 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400931 main.cleanup()
932 main.exit()
933 except:
kelvin8ec71442015-01-15 16:57:00 -0800934 main.log.info( self.name + " ::::::" )
935 main.log.error( traceback.print_exc() )
936 main.log.info( self.name + " ::::::" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400937 main.cleanup()
938 main.exit()
939
kelvin8ec71442015-01-15 16:57:00 -0800940 def onos_remove_raft_logs( self ):
941 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500942 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -0500943 a cleaner environment.
944
andrewonlab19fbdca2014-11-14 12:55:59 -0500945 Description:
Jon Hallfcc88622014-11-25 13:09:54 -0500946 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -0500947 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -0800948 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500949 try:
kelvin8ec71442015-01-15 16:57:00 -0800950 self.handle.sendline( "" )
951 self.handle.expect( "\$" )
952 self.handle.sendline( "onos-remove-raft-logs" )
953 # Sometimes this command hangs
954 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
955 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500956 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800957 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
958 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500959 if i == 1:
960 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800961 self.handle.sendline( "" )
962 self.handle.expect( "\$" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500963 return main.TRUE
964
965 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800966 main.log.error( self.name + ": EOF exception found" )
967 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -0500968 main.cleanup()
969 main.exit()
970 except:
kelvin8ec71442015-01-15 16:57:00 -0800971 main.log.info( self.name + " ::::::" )
972 main.log.error( traceback.print_exc() )
973 main.log.info( self.name + " ::::::" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500974 main.cleanup()
975 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -0500976
kelvin8ec71442015-01-15 16:57:00 -0800977 def onos_start_network( self, mntopo ):
978 """
979 Calls the command 'onos-start-network [ <mininet-topo> ]
980 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -0400981 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -0800982 cell."
andrewonlab94282092014-10-10 13:00:11 -0400983 * Specify mininet topology file name for mntopo
984 * Topo files should be placed at:
985 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -0800986
andrewonlab94282092014-10-10 13:00:11 -0400987 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -0800988 """
andrewonlab94282092014-10-10 13:00:11 -0400989 try:
990 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -0800991 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -0400992 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -0400993
kelvin8ec71442015-01-15 16:57:00 -0800994 mntopo = str( mntopo )
995 self.handle.sendline( "" )
996 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -0400997
kelvin8ec71442015-01-15 16:57:00 -0800998 self.handle.sendline( "onos-start-network " + mntopo )
999 self.handle.expect( "mininet>" )
1000 main.log.info( "Network started, entered mininet prompt" )
1001
1002 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001003
1004 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001005 main.log.error( self.name + ": EOF exception found" )
1006 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001007 main.cleanup()
1008 main.exit()
1009 except:
kelvin8ec71442015-01-15 16:57:00 -08001010 main.log.info( self.name + " ::::::" )
1011 main.log.error( traceback.print_exc() )
1012 main.log.info( self.name + " ::::::" )
andrewonlab94282092014-10-10 13:00:11 -04001013 main.cleanup()
1014 main.exit()
1015
kelvin8ec71442015-01-15 16:57:00 -08001016 def isup( self, node="" ):
1017 """
1018 Run's onos-wait-for-start which only returns once ONOS is at run
1019 level 100( ready for use )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001020
Jon Hall7993bfc2014-10-09 16:30:14 -04001021 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001022 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001023 try:
kelvin8ec71442015-01-15 16:57:00 -08001024 self.handle.sendline( "onos-wait-for-start " + node )
1025 self.handle.expect( "onos-wait-for-start" )
1026 # NOTE: this timeout is arbitrary"
1027 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], timeout=120 )
Jon Hall7993bfc2014-10-09 16:30:14 -04001028 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001029 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001030 return main.TRUE
1031 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001032 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001033 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001034 main.log.error( "ONOS has not started yet" )
1035 self.handle.send( "\x03" ) # Control-C
1036 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001037 return main.FALSE
1038 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001039 main.log.error( self.name + ": EOF exception found" )
1040 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001041 main.cleanup()
1042 main.exit()
1043 except:
kelvin8ec71442015-01-15 16:57:00 -08001044 main.log.info( self.name + " ::::::" )
1045 main.log.error( traceback.print_exc() )
1046 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001047 main.cleanup()
1048 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001049
kelvin8ec71442015-01-15 16:57:00 -08001050 def push_test_intents_shell( self, dpid_src, dpid_dst, num_intents,
1051 dir_file, onos_ip, num_mult="", app_id="", report=True,
1052 options="" ):
1053 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001054 Description:
kelvin8ec71442015-01-15 16:57:00 -08001055 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001056 better parallelize the results than the CLI
1057 Required:
1058 * dpid_src: specify source dpid
1059 * dpid_dst: specify destination dpid
1060 * num_intents: specify number of intents to push
1061 * dir_file: specify directory and file name to save
1062 results
1063 * onos_ip: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001064 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001065 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001066 """
1067 try:
1068 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001069 if options:
kelvin8ec71442015-01-15 16:57:00 -08001070 base_cmd = "onos " + str( onos_ip ) + " push-test-intents " +\
1071 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001072 else:
kelvin8ec71442015-01-15 16:57:00 -08001073 base_cmd = "onos " + str( onos_ip ) + " push-test-intents "
1074
1075 add_dpid = base_cmd + str( dpid_src ) + " " + str( dpid_dst )
andrewonlabb66dfa12014-12-02 15:51:10 -05001076 if not num_mult:
kelvin8ec71442015-01-15 16:57:00 -08001077 add_intents = add_dpid + " " + str( num_intents )
andrewonlabb66dfa12014-12-02 15:51:10 -05001078 elif num_mult:
kelvin8ec71442015-01-15 16:57:00 -08001079 add_intents = add_dpid + " " + str( num_intents ) + " " +\
1080 str( num_mult )
andrewonlabb66dfa12014-12-02 15:51:10 -05001081 if app_id:
kelvin8ec71442015-01-15 16:57:00 -08001082 add_app = add_intents + " " + str( app_id )
andrewonlabb66dfa12014-12-02 15:51:10 -05001083 else:
1084 add_app = add_intents
1085
andrewonlabaedc8332014-12-04 12:43:03 -05001086 if report:
kelvin8ec71442015-01-15 16:57:00 -08001087 send_cmd = add_app + " > " + str( dir_file ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001088 else:
1089 send_cmd = add_app + " &"
kelvin8ec71442015-01-15 16:57:00 -08001090 main.log.info( "Send cmd: " + send_cmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001091
kelvin8ec71442015-01-15 16:57:00 -08001092 self.handle.sendline( send_cmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001093
1094 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001095 main.log.error( self.name + ": EOF exception found" )
1096 main.log.error( self.name + ": " + self.handle.before )
andrewonlabb66dfa12014-12-02 15:51:10 -05001097 main.cleanup()
1098 main.exit()
1099 except:
kelvin8ec71442015-01-15 16:57:00 -08001100 main.log.info( self.name + " ::::::" )
1101 main.log.error( traceback.print_exc() )
1102 main.log.info( self.name + " ::::::" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001103 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001104 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001105
kelvin8ec71442015-01-15 16:57:00 -08001106 def get_topology( self, topology_output ):
1107 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001108 parses the onos:topology output
kelvin8ec71442015-01-15 16:57:00 -08001109 Returns: a topology dict populated by the key values found in
Jon Hall77f53ce2014-10-13 18:02:06 -04001110 the cli command.
kelvin8ec71442015-01-15 16:57:00 -08001111 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001112 try:
kelvin8ec71442015-01-15 16:57:00 -08001113 # call the cli to get the topology summary
1114 # cmdstr = "onos:topology"
1115 # cli_result = self.onos_cli( ip, cmdstr )
1116 # print "cli_result = ", cli_result
Jon Hall77f53ce2014-10-13 18:02:06 -04001117
kelvin8ec71442015-01-15 16:57:00 -08001118 # Parse the output
Jon Hall77f53ce2014-10-13 18:02:06 -04001119 topology = {}
kelvin8ec71442015-01-15 16:57:00 -08001120 # for line in cli_result.split( "\n" ):
Shreya Shaha73aaad2014-10-27 18:03:09 -04001121 for line in topology_output.splitlines():
kelvin8ec71442015-01-15 16:57:00 -08001122 if not line.startswith( "time=" ):
Jon Hall77f53ce2014-10-13 18:02:06 -04001123 continue
kelvin8ec71442015-01-15 16:57:00 -08001124 # else
1125 # print line
1126 for var in line.split( "," ):
1127 # print "'"+var+"'"
1128 # print "'"+var.strip()+"'"
1129 key, value = var.strip().split( "=" )
1130 topology[ key ] = value
1131 # print "topology = ", topology
1132 # devices = topology.get( 'devices', False )
1133 # print "devices = ", devices
1134 # links = topology.get( 'links', False )
1135 # print "links = ", links
1136 # SCCs = topology.get( 'SCC(s)', False )
1137 # print "SCCs = ", SCCs
1138 # paths = topology.get( 'paths', False )
1139 # print "paths = ", paths
Jon Hall77f53ce2014-10-13 18:02:06 -04001140
1141 return topology
1142 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001143 main.log.error( self.name + ": EOF exception found" )
1144 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001145 main.cleanup()
1146 main.exit()
1147 except:
kelvin8ec71442015-01-15 16:57:00 -08001148 main.log.info( self.name + " ::::::" )
1149 main.log.error( traceback.print_exc() )
1150 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001151 main.cleanup()
1152 main.exit()
1153
kelvin8ec71442015-01-15 16:57:00 -08001154 def check_status(
1155 self,
1156 topology_result,
1157 numoswitch,
1158 numolink,
1159 log_level="info" ):
1160 """
1161 Checks the number of swithes & links that ONOS sees against the
1162 supplied values. By default this will report to main.log, but the
Jon Hall77f53ce2014-10-13 18:02:06 -04001163 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001164
Jon Hall77f53ce2014-10-13 18:02:06 -04001165 Params: ip = ip used for the onos cli
1166 numoswitch = expected number of switches
1167 numlink = expected number of links
1168 log_level = level to log to. Currently accepts 'info', 'warn' and 'report'
1169
1170
1171 log_level can
1172
kelvin8ec71442015-01-15 16:57:00 -08001173 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall77f53ce2014-10-13 18:02:06 -04001174 main.FALSE if the numer of switches and links is incorrect,
1175 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001176 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001177 try:
kelvin8ec71442015-01-15 16:57:00 -08001178 topology = self.get_topology( topology_result )
Jon Hall77f53ce2014-10-13 18:02:06 -04001179 if topology == {}:
1180 return main.ERROR
1181 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001182 # Is the number of switches is what we expected
1183 devices = topology.get( 'devices', False )
1184 links = topology.get( 'links', False )
Jon Hall77f53ce2014-10-13 18:02:06 -04001185 if devices == False or links == False:
1186 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001187 switch_check = ( int( devices ) == int( numoswitch ) )
1188 # Is the number of links is what we expected
1189 link_check = ( int( links ) == int( numolink ) )
1190 if ( switch_check and link_check ):
1191 # We expected the correct numbers
Jon Hall77f53ce2014-10-13 18:02:06 -04001192 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001193 + "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001194 result = main.TRUE
1195 else:
1196 output = output + \
kelvin8ec71442015-01-15 16:57:00 -08001197 "The number of links and switches does not match what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001198 result = main.FALSE
1199 output = output + "\n ONOS sees %i devices (%i expected) and %i links (%i expected)"\
kelvin8ec71442015-01-15 16:57:00 -08001200 % ( int( devices ), int( numoswitch ), int( links ), int( numolink ) )
Jon Hall77f53ce2014-10-13 18:02:06 -04001201 if log_level == "report":
kelvin8ec71442015-01-15 16:57:00 -08001202 main.log.report( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001203 elif log_level == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001204 main.log.warn( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001205 else:
kelvin8ec71442015-01-15 16:57:00 -08001206 main.log.info( output )
1207 return result
Jon Hall77f53ce2014-10-13 18:02:06 -04001208 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001209 main.log.error( self.name + ": EOF exception found" )
1210 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001211 main.cleanup()
1212 main.exit()
1213 except:
kelvin8ec71442015-01-15 16:57:00 -08001214 main.log.info( self.name + " ::::::" )
1215 main.log.error( traceback.print_exc() )
1216 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001217 main.cleanup()
1218 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001219
kelvin8ec71442015-01-15 16:57:00 -08001220 def tshark_pcap( self, interface, dir_file ):
1221 """
andrewonlab970399c2014-11-07 13:09:32 -05001222 Capture all packet activity and store in specified
1223 directory/file
1224
1225 Required:
1226 * interface: interface to capture
1227 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001228 """
1229 self.handle.sendline( "" )
1230 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001231
kelvin8ec71442015-01-15 16:57:00 -08001232 self.handle.sendline( "tshark -i " + str( interface ) +
1233 " -t e -w " + str( dir_file ) + " &" )
1234 self.handle.sendline( "\r" )
1235 self.handle.expect( "Capturing on" )
1236 self.handle.sendline( "\r" )
1237 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001238
kelvin8ec71442015-01-15 16:57:00 -08001239 main.log.info( "Tshark started capturing files on " +
1240 str( interface ) + " and saving to directory: " +
1241 str( dir_file ) )
Shreya Shaha73aaad2014-10-27 18:03:09 -04001242
kelvin8ec71442015-01-15 16:57:00 -08001243 def run_onos_topo_cfg( self, instance_name, json_file ):
1244 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001245 On ONOS bench, run this command: ./~/ONOS/tools/test/bin/onos-topo-cfg $OC1 filename
shahshreya4d79aab2014-11-07 15:20:41 -08001246 which starts the rest and copies the json file to the onos instance
kelvin8ec71442015-01-15 16:57:00 -08001247 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001248 try:
kelvin8ec71442015-01-15 16:57:00 -08001249 self.handle.sendline( "" )
1250 self.handle.expect( "\$" )
1251 self.handle.sendline( "cd ~/ONOS/tools/test/bin" )
1252 self.handle.expect( "/bin$" )
1253 cmd = "./onos-topo-cfg " + instance_name + " " + json_file
shahshreyae6c7cf42014-11-26 16:39:01 -08001254 print "cmd = ", cmd
kelvin8ec71442015-01-15 16:57:00 -08001255 self.handle.sendline( cmd )
1256 self.handle.expect( "\$" )
1257 self.handle.sendline( "cd ~" )
1258 self.handle.expect( "\$" )
shahshreyae6c7cf42014-11-26 16:39:01 -08001259 return main.TRUE
1260 except:
1261 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001262
1263 def tshark_grep( self, grep, directory, interface='eth0' ):
1264 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001265 Required:
kelvin8ec71442015-01-15 16:57:00 -08001266 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001267 * directory to store results
1268 Optional:
1269 * interface - default: eth0
1270 Description:
1271 Uses tshark command to grep specific group of packets
1272 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001273 The timestamp is hardcoded to be in epoch
1274 """
1275 self.handle.sendline( "" )
1276 self.handle.expect( "\$" )
1277 self.handle.sendline( "" )
1278 self.handle.sendline( "tshark -i " + str( interface ) +
1279 " -t e | grep --line-buffered \"" + str(grep) + "\" >" + directory + " &" )
1280 self.handle.sendline( "\r" )
1281 self.handle.expect( "Capturing on" )
1282 self.handle.sendline( "\r" )
1283 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001284
kelvin8ec71442015-01-15 16:57:00 -08001285 def tshark_stop( self ):
1286 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001287 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001288 """
1289 # Remove all pcap from previous captures
1290 self.execute( cmd="sudo rm /tmp/wireshark*" )
1291 self.handle.sendline( "" )
1292 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\" |" +
1293 " grep -v grep | awk '{print $2}'`" )
1294 self.handle.sendline( "" )
1295 main.log.info( "Tshark stopped" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001296
kelvin8ec71442015-01-15 16:57:00 -08001297 def ptpd( self, args ):
1298 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001299 Initiate ptp with user-specified args.
1300 Required:
1301 * args: specify string of args after command
1302 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001303 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001304 try:
kelvin8ec71442015-01-15 16:57:00 -08001305 self.handle.sendline( "sudo ptpd " + str( args ) )
1306 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001307 "Multiple",
1308 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001309 "\$" ] )
1310 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001311
andrewonlab0c38a4a2014-10-28 18:35:35 -04001312 if i == 0:
1313 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001314 main.log.info( "ptpd returned an error: " +
1315 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001316 return handle
1317 elif i == 1:
1318 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001319 main.log.error( "ptpd returned an error: " +
1320 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001321 return handle
1322 else:
1323 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001324
andrewonlab0c38a4a2014-10-28 18:35:35 -04001325 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001326 main.log.error( self.name + ": EOF exception found" )
1327 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001328 main.cleanup()
1329 main.exit()
1330 except:
kelvin8ec71442015-01-15 16:57:00 -08001331 main.log.info( self.name + " ::::::" )
1332 main.log.error( traceback.print_exc() )
1333 main.log.info( self.name + " ::::::" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001334 main.cleanup()
1335 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001336
kelvin8ec71442015-01-15 16:57:00 -08001337 def cp_logs_to_dir( self, log_to_copy,
1338 dest_dir, copy_file_name="" ):
1339 """
1340 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001341 Current implementation of ONOS deletes its karaf
1342 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001343 you may want to use this function to capture
1344 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001345 Localtime will be attached to the filename
1346
1347 Required:
1348 * log_to_copy: specify directory and log name to
1349 copy.
kelvin8ec71442015-01-15 16:57:00 -08001350 ex ) /opt/onos/log/karaf.log.1
andrewonlab5d7a8f32014-11-10 13:07:56 -05001351 For copying multiple files, leave copy_file_name
kelvin8ec71442015-01-15 16:57:00 -08001352 empty and only specify dest_dir -
1353 ex ) /opt/onos/log/karaf*
andrewonlab5d7a8f32014-11-10 13:07:56 -05001354 * dest_dir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001355 ex ) /tmp/
1356 Optional:
andrewonlab5d7a8f32014-11-10 13:07:56 -05001357 * copy_file_name: If you want to rename the log
1358 file, specify copy_file_name. This will not work
1359 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001360 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001361 try:
kelvin8ec71442015-01-15 16:57:00 -08001362 localtime = time.strftime( '%x %X' )
1363 localtime = localtime.replace( "/", "" )
1364 localtime = localtime.replace( " ", "_" )
1365 localtime = localtime.replace( ":", "" )
1366 if dest_dir[ -1: ] != "/":
andrewonlab5d7a8f32014-11-10 13:07:56 -05001367 dest_dir += "/"
1368
1369 if copy_file_name:
kelvin8ec71442015-01-15 16:57:00 -08001370 self.handle.sendline( "cp " + str( log_to_copy ) +
1371 " " + str( dest_dir ) + str( copy_file_name ) +
1372 localtime )
1373 self.handle.expect( "cp" )
1374 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001375 else:
kelvin8ec71442015-01-15 16:57:00 -08001376 self.handle.sendline( "cp " + str( log_to_copy ) +
1377 " " + str( dest_dir ) )
1378 self.handle.expect( "cp" )
1379 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001380
kelvin8ec71442015-01-15 16:57:00 -08001381 return self.handle.before
1382
1383 except pexpect.EOF:
1384 main.log.error( "Copying files failed" )
1385 main.log.error( self.name + ": EOF exception found" )
1386 main.log.error( self.name + ": " + self.handle.before )
1387 except:
1388 main.log.error( "Copying files failed" )
1389 main.log.info( self.name + " ::::::" )
1390 main.log.error( traceback.print_exc() )
1391 main.log.info( self.name + " ::::::" )
1392
1393 def check_logs( self, onos_ip ):
1394 """
Jon Hall94fd0472014-12-08 11:52:42 -08001395 runs onos-check-logs on the given onos node
1396 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001397 """
Jon Hall94fd0472014-12-08 11:52:42 -08001398 try:
kelvin8ec71442015-01-15 16:57:00 -08001399 cmd = "onos-check-logs " + str( onos_ip )
1400 self.handle.sendline( cmd )
1401 self.handle.expect( cmd )
1402 self.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -08001403 response = self.handle.before
1404 return response
1405 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001406 main.log.error( "Lost ssh connection" )
1407 main.log.error( self.name + ": EOF exception found" )
1408 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001409 except:
kelvin8ec71442015-01-15 16:57:00 -08001410 main.log.error( "Some error in check_logs:" )
1411 main.log.info( self.name + " ::::::" )
1412 main.log.error( traceback.print_exc() )
1413 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001414
kelvin8ec71442015-01-15 16:57:00 -08001415 def onos_status( self, node="" ):
1416 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001417 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001418 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001419 try:
kelvin8ec71442015-01-15 16:57:00 -08001420 self.handle.sendline( "" )
1421 self.handle.expect( "\$" )
1422 self.handle.sendline( "onos-service " + str( node ) +
1423 " status" )
1424 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001425 "start/running",
1426 "stop/waiting",
kelvin8ec71442015-01-15 16:57:00 -08001427 pexpect.TIMEOUT ], timeout=120 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001428
1429 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001430 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001431 return main.TRUE
1432 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001433 main.log.info( "ONOS is stopped" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001434 return main.FALSE
1435 else:
kelvin8ec71442015-01-15 16:57:00 -08001436 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001437 main.cleanup()
1438 main.exit()
1439 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001440 main.log.error( self.name + ": EOF exception found" )
1441 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001442 main.cleanup()
1443 main.exit()
1444 except:
kelvin8ec71442015-01-15 16:57:00 -08001445 main.log.info( self.name + " ::::::" )
1446 main.log.error( traceback.print_exc() )
1447 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001448 main.cleanup()
1449 main.exit()