blob: d671f48ede9d0e3e85232c3e182784f6483a409f [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( "export TERM=xterm-256color" )
438 self.handle.expect( "xterm-256color" )
439 self.handle.expect( "\$" )
440 self.handle.sendline( "" )
441 self.handle.expect( "\$" )
442 self.handle.sendline(
443 "cd " +
444 self.home +
445 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 \"commit\" --color=never" )
446 # NOTE: for some reason there are backspaces inserted in this
447 # phrase when run from Jenkins on some tests
448 self.handle.expect( "never" )
449 self.handle.expect( "\$" )
450 response = ( self.name + ": \n" + str(
451 self.handle.before + self.handle.after ) )
452 self.handle.sendline( "cd " + self.home )
453 self.handle.expect( "\$" )
454 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400455 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500456 print line
457 if report:
kelvin8ec71442015-01-15 16:57:00 -0800458 for line in lines[ 2:-1 ]:
459 # Bracket replacement is for Wiki-compliant
460 # formatting. '<' or '>' are interpreted
461 # as xml specific tags that cause errors
462 line = line.replace( "<", "[" )
463 line = line.replace( ">", "]" )
464 main.log.report( "\t" + line )
465 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400466 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800467 main.log.error( self.name + ": EOF exception found" )
468 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400469 main.cleanup()
470 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800471 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800472 main.log.error( self.name + ": TIMEOUT exception found" )
473 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800474 main.cleanup()
475 main.exit()
Jon Hall45ec0922014-10-10 19:33:49 -0400476 except:
kelvin8ec71442015-01-15 16:57:00 -0800477 main.log.info(
478 self.name +
479 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hall45ec0922014-10-10 19:33:49 -0400480 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800481 main.log.info(
482 ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
Jon Hall45ec0922014-10-10 19:33:49 -0400483 main.cleanup()
484 main.exit()
485
kelvin8ec71442015-01-15 16:57:00 -0800486 def create_cell_file( self, bench_ip, file_name, mn_ip_addrs,
487 extra_feature_string, *onos_ip_addrs ):
488 """
andrewonlab94282092014-10-10 13:00:11 -0400489 Creates a cell file based on arguments
490 Required:
kelvin8ec71442015-01-15 16:57:00 -0800491 * Bench IP address ( bench_ip )
andrewonlab94282092014-10-10 13:00:11 -0400492 - Needed to copy the cell file over
kelvin8ec71442015-01-15 16:57:00 -0800493 * File name of the cell file ( file_name )
494 * Mininet IP address ( mn_ip_addrs )
495 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400496 supported currently
kelvin8ec71442015-01-15 16:57:00 -0800497 * ONOS IP addresses ( onos_ip_addrs )
andrewonlab94282092014-10-10 13:00:11 -0400498 - Must be passed in as last arguments
kelvin8ec71442015-01-15 16:57:00 -0800499
andrewonlab94282092014-10-10 13:00:11 -0400500 NOTE: Assumes cells are located at:
501 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800502 """
503 # Variable initialization
andrewonlab94282092014-10-10 13:00:11 -0400504 cell_directory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800505 # We want to create the cell file in the dependencies directory
506 # of TestON first, then copy over to ONOS bench
andrewonlab94282092014-10-10 13:00:11 -0400507 temp_directory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800508 # Create the cell file in the directory for writing ( w+ )
509 cell_file = open( temp_directory + file_name, 'w+' )
510
511 # Feature string is hardcoded environment variables
512 # That you may wish to use by default on startup.
513 # Note that you may not want certain features listed
514 # on here.
515 core_feature_string = "export ONOS_FEATURES=webconsole,onos-api," +\
516 "onos-cli,onos-openflow," + extra_feature_string
andrewonlab94282092014-10-10 13:00:11 -0400517 mn_string = "export OCN="
518 onos_string = "export OC"
519 temp_count = 1
kelvin8ec71442015-01-15 16:57:00 -0800520
521 # Create ONOS_NIC ip address prefix
522 temp_onos_ip = onos_ip_addrs[ 0 ]
andrewonlab94282092014-10-10 13:00:11 -0400523 temp_list = []
kelvin8ec71442015-01-15 16:57:00 -0800524 temp_list = temp_onos_ip.split( "." )
525 # Omit last element of list to format for NIC
526 temp_list = temp_list[ :-1 ]
527 # Structure the nic string ip
528 nic_addr = ".".join( temp_list ) + ".*"
529 onos_nic_string = "export ONOS_NIC=" + nic_addr
andrewonlab94282092014-10-10 13:00:11 -0400530
531 try:
kelvin8ec71442015-01-15 16:57:00 -0800532 # Start writing to file
533 cell_file.write( onos_nic_string + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400534
535 for arg in onos_ip_addrs:
kelvin8ec71442015-01-15 16:57:00 -0800536 # For each argument in onos_ip_addrs, write to file
537 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400538 # export OC1="10.128.20.11"
539 # export OC2="10.128.20.12"
kelvin8ec71442015-01-15 16:57:00 -0800540 cell_file.write( onos_string + str( temp_count ) +
541 "=" + "\"" + arg + "\"" + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400542 temp_count = temp_count + 1
kelvin8ec71442015-01-15 16:57:00 -0800543
544 cell_file.write( mn_string + "\"" + mn_ip_addrs + "\"" + "\n" )
545 cell_file.write( core_feature_string + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400546 cell_file.close()
547
kelvin8ec71442015-01-15 16:57:00 -0800548 # We use os.system to send the command to TestON cluster
549 # to account for the case in which TestON is not located
550 # on the same cluster as the ONOS bench
551 # Note that even if TestON is located on the same cluster
552 # as ONOS bench, you must setup passwordless ssh
553 # between TestON and ONOS bench in order to automate the test.
554 os.system( "scp " + temp_directory + file_name +
555 " admin@" + bench_ip + ":" + cell_directory )
andrewonlab94282092014-10-10 13:00:11 -0400556
andrewonlab2a6c9342014-10-16 13:40:15 -0400557 return main.TRUE
558
andrewonlab94282092014-10-10 13:00:11 -0400559 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800560 main.log.error( self.name + ": EOF exception found" )
561 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -0400562 main.cleanup()
563 main.exit()
564 except:
kelvin8ec71442015-01-15 16:57:00 -0800565 main.log.info( self.name + ":::::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400566 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800567 main.log.info( ":::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400568 main.cleanup()
569 main.exit()
570
kelvin8ec71442015-01-15 16:57:00 -0800571 def set_cell( self, cellname ):
572 """
andrewonlab95ca1462014-10-09 14:04:24 -0400573 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800574 """
andrewonlab95ca1462014-10-09 14:04:24 -0400575 try:
576 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800577 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400578 main.cleanup()
579 main.exit()
580 else:
kelvin8ec71442015-01-15 16:57:00 -0800581 self.handle.sendline( "cell " + str( cellname ) )
582 # Expect the cellname in the ONOS_CELL variable.
583 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400584 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800585 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
andrewonlab95ca1462014-10-09 14:04:24 -0400586 handle_before = self.handle.before
587 handle_after = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800588 # Get the rest of the handle
589 self.handle.sendline( "" )
590 self.handle.expect( "\$" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400591 handle_more = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400592
kelvin8ec71442015-01-15 16:57:00 -0800593 main.log.info( "Cell call returned: " + handle_before +
594 handle_after + handle_more )
andrewonlab95ca1462014-10-09 14:04:24 -0400595
596 return main.TRUE
597
598 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800599 main.log.error( self.name + ": EOF exception found" )
600 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400601 main.cleanup()
602 main.exit()
603 except:
kelvin8ec71442015-01-15 16:57:00 -0800604 main.log.info( self.name + " ::::::" )
605 main.log.error( traceback.print_exc() )
606 main.log.info( self.name + " ::::::" )
andrewonlab95ca1462014-10-09 14:04:24 -0400607 main.cleanup()
608 main.exit()
609
kelvin8ec71442015-01-15 16:57:00 -0800610 def verify_cell( self ):
611 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400612 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800613 """
614 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400615
andrewonlabc03bf6c2014-10-09 14:56:18 -0400616 try:
kelvin8ec71442015-01-15 16:57:00 -0800617 # Clean handle by sending empty and expecting $
618 self.handle.sendline( "" )
619 self.handle.expect( "\$" )
620 self.handle.sendline( "onos-verify-cell" )
621 self.handle.expect( "\$" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400622 handle_before = self.handle.before
623 handle_after = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800624 # Get the rest of the handle
625 self.handle.sendline( "" )
626 self.handle.expect( "\$" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400627 handle_more = self.handle.before
628
kelvin8ec71442015-01-15 16:57:00 -0800629 main.log.info( "Verify cell returned: " + handle_before +
630 handle_after + handle_more )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400631
632 return main.TRUE
Jon Hall7993bfc2014-10-09 16:30:14 -0400633 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800634 main.log.error( self.name + ": EOF exception found" )
635 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400636 main.cleanup()
637 main.exit()
638 except:
kelvin8ec71442015-01-15 16:57:00 -0800639 main.log.info( self.name + " ::::::" )
640 main.log.error( traceback.print_exc() )
641 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400642 main.cleanup()
643 main.exit()
644
kelvin8ec71442015-01-15 16:57:00 -0800645 def onos_cli( self, ONOS_ip, cmdstr ):
646 """
andrewonlab05e362f2014-10-10 00:40:57 -0400647 Uses 'onos' command to send various ONOS CLI arguments.
648 Required:
649 * ONOS_ip: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400650 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800651
652 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400653 CLI commands for ONOS. Try to use this function first
654 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800655 function.
656 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400657 by starting onos, and typing in 'onos' to enter the
658 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800659 available commands.
660 """
andrewonlab05e362f2014-10-10 00:40:57 -0400661 try:
662 if not ONOS_ip:
kelvin8ec71442015-01-15 16:57:00 -0800663 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400664 return main.FALSE
665 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800666 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400667 return main.FALSE
668
kelvin8ec71442015-01-15 16:57:00 -0800669 cmdstr = str( cmdstr )
670 self.handle.sendline( "" )
671 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400672
kelvin8ec71442015-01-15 16:57:00 -0800673 self.handle.sendline( "onos -w " + ONOS_ip + " " + cmdstr )
674 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400675
Shreya Shaha73aaad2014-10-27 18:03:09 -0400676 handle_before = self.handle.before
677 print "handle_before = ", self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800678 # handle_after = str( self.handle.after )
Jon Hall47a93fb2015-01-06 16:46:06 -0800679
kelvin8ec71442015-01-15 16:57:00 -0800680 # self.handle.sendline( "" )
681 # self.handle.expect( "\$" )
682 # handle_more = str( self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400683
kelvin8ec71442015-01-15 16:57:00 -0800684 main.log.info( "Command sent successfully" )
andrewonlab05e362f2014-10-10 00:40:57 -0400685
kelvin8ec71442015-01-15 16:57:00 -0800686 # Obtain return handle that consists of result from
687 # the onos command. The string may need to be
688 # configured further.
689 # return_string = handle_before + handle_after
Shreya Shaha73aaad2014-10-27 18:03:09 -0400690 return_string = handle_before
691 print "return_string = ", return_string
andrewonlab05e362f2014-10-10 00:40:57 -0400692 return return_string
693
694 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800695 main.log.error( self.name + ": EOF exception found" )
696 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400697 main.cleanup()
698 main.exit()
699 except:
kelvin8ec71442015-01-15 16:57:00 -0800700 main.log.info( self.name + " ::::::" )
701 main.log.error( traceback.print_exc() )
702 main.log.info( self.name + " ::::::" )
andrewonlab05e362f2014-10-10 00:40:57 -0400703 main.cleanup()
704 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400705
kelvin8ec71442015-01-15 16:57:00 -0800706 def onos_install( self, options="-f", node="" ):
707 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400708 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800709 If -f option is provided, it also forces an uninstall.
710 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400711 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800712 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400713 files to certain onos nodes
714
715 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800716 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400717 try:
andrewonlab114768a2014-11-14 12:44:44 -0500718 if options:
kelvin8ec71442015-01-15 16:57:00 -0800719 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500720 else:
kelvin8ec71442015-01-15 16:57:00 -0800721 self.handle.sendline( "onos-install " + node )
722 self.handle.expect( "onos-install " )
723 # NOTE: this timeout may need to change depending on the network
724 # and size of ONOS
725 i = self.handle.expect( [ "Network\sis\sunreachable",
726 "onos\sstart/running,\sprocess",
727 "ONOS\sis\salready\sinstalled",
728 pexpect.TIMEOUT ], timeout=60 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400729
Jon Hall7993bfc2014-10-09 16:30:14 -0400730 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800731 main.log.warn( "Network is unreachable" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400732 return main.FALSE
733 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800734 main.log.info(
735 "ONOS was installed on " +
736 node +
737 " and started" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400738 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500739 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800740 main.log.info( "ONOS is already installed on " + node )
andrewonlabd9a73a72014-11-14 17:28:21 -0500741 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800742 elif i == 3:
743 main.log.info(
744 "Installation of ONOS on " +
745 node +
746 " timed out" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400747 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400748
749 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800750 main.log.error( self.name + ": EOF exception found" )
751 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400752 main.cleanup()
753 main.exit()
754 except:
kelvin8ec71442015-01-15 16:57:00 -0800755 main.log.info( self.name + " ::::::" )
756 main.log.error( traceback.print_exc() )
757 main.log.info( self.name + " ::::::" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400758 main.cleanup()
759 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400760
kelvin8ec71442015-01-15 16:57:00 -0800761 def onos_start( self, node_ip ):
762 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400763 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400764 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800765 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400766 try:
kelvin8ec71442015-01-15 16:57:00 -0800767 self.handle.sendline( "" )
768 self.handle.expect( "\$" )
769 self.handle.sendline( "onos-service " + str( node_ip ) +
770 " start" )
771 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -0400772 "Job\sis\salready\srunning",
773 "start/running",
774 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800775 pexpect.TIMEOUT ], timeout=120 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400776
777 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800778 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400779 return main.TRUE
780 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800781 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400782 return main.TRUE
783 else:
kelvin8ec71442015-01-15 16:57:00 -0800784 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400785 main.cleanup()
786 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400787 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800788 main.log.error( self.name + ": EOF exception found" )
789 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400790 main.cleanup()
791 main.exit()
792 except:
kelvin8ec71442015-01-15 16:57:00 -0800793 main.log.info( self.name + " ::::::" )
794 main.log.error( traceback.print_exc() )
795 main.log.info( self.name + " ::::::" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400796 main.cleanup()
797 main.exit()
798
kelvin8ec71442015-01-15 16:57:00 -0800799 def onos_stop( self, node_ip ):
800 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400801 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400802 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800803 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400804 try:
kelvin8ec71442015-01-15 16:57:00 -0800805 self.handle.sendline( "" )
806 self.handle.expect( "\$" )
807 self.handle.sendline( "onos-service " + str( node_ip ) +
808 " stop" )
809 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -0400810 "stop/waiting",
811 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800812 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2b30bd32014-10-09 16:48:55 -0400813
814 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800815 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400816 return main.TRUE
817 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800818 main.log.info( "Unknown ONOS instance specified: " +
819 str( node_ip ) )
andrewonlab2b30bd32014-10-09 16:48:55 -0400820 return main.FALSE
821 else:
kelvin8ec71442015-01-15 16:57:00 -0800822 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400823 return main.FALSE
824
825 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800826 main.log.error( self.name + ": EOF exception found" )
827 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -0400828 main.cleanup()
829 main.exit()
830 except:
kelvin8ec71442015-01-15 16:57:00 -0800831 main.log.info( self.name + " ::::::" )
832 main.log.error( traceback.print_exc() )
833 main.log.info( self.name + " ::::::" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400834 main.cleanup()
835 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800836
837 def onos_uninstall( self, node_ip="" ):
838 """
andrewonlabc8d47972014-10-09 16:52:36 -0400839 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -0800840 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -0400841 if needed
kelvin8ec71442015-01-15 16:57:00 -0800842 """
andrewonlabc8d47972014-10-09 16:52:36 -0400843 try:
kelvin8ec71442015-01-15 16:57:00 -0800844 self.handle.sendline( "" )
845 self.handle.expect( "\$" )
846 self.handle.sendline( "onos-uninstall " + str( node_ip ) )
847 self.handle.expect( "\$" )
andrewonlabc8d47972014-10-09 16:52:36 -0400848
kelvin8ec71442015-01-15 16:57:00 -0800849 main.log.info( "ONOS " + node_ip + " was uninstalled" )
andrewonlab9dfd2082014-11-13 17:44:03 -0500850
kelvin8ec71442015-01-15 16:57:00 -0800851 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -0400852 return main.TRUE
853
854 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800855 main.log.error( self.name + ": EOF exception found" )
856 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -0400857 main.cleanup()
858 main.exit()
859 except:
kelvin8ec71442015-01-15 16:57:00 -0800860 main.log.info( self.name + " ::::::" )
861 main.log.error( traceback.print_exc() )
862 main.log.info( self.name + " ::::::" )
andrewonlabc8d47972014-10-09 16:52:36 -0400863 main.cleanup()
864 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400865
kelvin8ec71442015-01-15 16:57:00 -0800866 def onos_die( self, node_ip ):
867 """
andrewonlabaedc8332014-12-04 12:43:03 -0500868 Issues the command 'onos-die <node-ip>'
869 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -0800870 """
andrewonlabaedc8332014-12-04 12:43:03 -0500871 try:
kelvin8ec71442015-01-15 16:57:00 -0800872 self.handle.sendline( "" )
873 self.handle.expect( "\$" )
874 cmd_str = "onos-kill " + str( node_ip )
875 self.handle.sendline( cmd_str )
876 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -0500877 "Killing\sONOS",
878 "ONOS\sprocess\sis\snot\srunning",
kelvin8ec71442015-01-15 16:57:00 -0800879 pexpect.TIMEOUT ], timeout=20 )
andrewonlabaedc8332014-12-04 12:43:03 -0500880 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800881 main.log.info( "ONOS instance " + str( node_ip ) +
882 " was killed and stopped" )
andrewonlabaedc8332014-12-04 12:43:03 -0500883 return main.TRUE
884 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800885 main.log.info( "ONOS process was not running" )
andrewonlabaedc8332014-12-04 12:43:03 -0500886 return main.FALSE
887 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800888 main.log.error( self.name + ": EOF exception found" )
889 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -0500890 main.cleanup()
891 main.exit()
892 except:
kelvin8ec71442015-01-15 16:57:00 -0800893 main.log.info( self.name + " ::::::" )
894 main.log.error( traceback.print_exc() )
895 main.log.info( self.name + " ::::::" )
andrewonlabaedc8332014-12-04 12:43:03 -0500896 main.cleanup()
897 main.exit()
898
kelvin8ec71442015-01-15 16:57:00 -0800899 def onos_kill( self, node_ip ):
900 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400901 Calls the command: 'onos-kill [<node-ip>]'
902 "Remotely, and unceremoniously kills the ONOS instance running on
903 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -0800904 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400905 try:
kelvin8ec71442015-01-15 16:57:00 -0800906 self.handle.sendline( "" )
907 self.handle.expect( "\$" )
908 self.handle.sendline( "onos-kill " + str( node_ip ) )
909 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -0400910 "\$",
911 "No\sroute\sto\shost",
912 "password:",
kelvin8ec71442015-01-15 16:57:00 -0800913 pexpect.TIMEOUT ], timeout=20 )
914
andrewonlabe8e56fd2014-10-09 17:12:44 -0400915 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800916 main.log.info(
917 "ONOS instance " + str(
918 node_ip ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400919 return main.TRUE
920 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800921 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400922 return main.FALSE
923 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800924 main.log.info( "Passwordless login for host: " + str( node_ip ) +
925 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400926 return main.FALSE
927 else:
kelvin8ec71442015-01-15 16:57:00 -0800928 main.log.info( "ONOS instasnce was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400929 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800930
andrewonlabe8e56fd2014-10-09 17:12:44 -0400931 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800932 main.log.error( self.name + ": EOF exception found" )
933 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400934 main.cleanup()
935 main.exit()
936 except:
kelvin8ec71442015-01-15 16:57:00 -0800937 main.log.info( self.name + " ::::::" )
938 main.log.error( traceback.print_exc() )
939 main.log.info( self.name + " ::::::" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400940 main.cleanup()
941 main.exit()
942
kelvin8ec71442015-01-15 16:57:00 -0800943 def onos_remove_raft_logs( self ):
944 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500945 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -0500946 a cleaner environment.
947
andrewonlab19fbdca2014-11-14 12:55:59 -0500948 Description:
Jon Hallfcc88622014-11-25 13:09:54 -0500949 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -0500950 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -0800951 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500952 try:
kelvin8ec71442015-01-15 16:57:00 -0800953 self.handle.sendline( "" )
954 self.handle.expect( "\$" )
955 self.handle.sendline( "onos-remove-raft-logs" )
956 # Sometimes this command hangs
957 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
958 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500959 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800960 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
961 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500962 if i == 1:
963 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800964 self.handle.sendline( "" )
965 self.handle.expect( "\$" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500966 return main.TRUE
967
968 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800969 main.log.error( self.name + ": EOF exception found" )
970 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -0500971 main.cleanup()
972 main.exit()
973 except:
kelvin8ec71442015-01-15 16:57:00 -0800974 main.log.info( self.name + " ::::::" )
975 main.log.error( traceback.print_exc() )
976 main.log.info( self.name + " ::::::" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500977 main.cleanup()
978 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -0500979
kelvin8ec71442015-01-15 16:57:00 -0800980 def onos_start_network( self, mntopo ):
981 """
982 Calls the command 'onos-start-network [ <mininet-topo> ]
983 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -0400984 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -0800985 cell."
andrewonlab94282092014-10-10 13:00:11 -0400986 * Specify mininet topology file name for mntopo
987 * Topo files should be placed at:
988 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -0800989
andrewonlab94282092014-10-10 13:00:11 -0400990 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -0800991 """
andrewonlab94282092014-10-10 13:00:11 -0400992 try:
993 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -0800994 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -0400995 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -0400996
kelvin8ec71442015-01-15 16:57:00 -0800997 mntopo = str( mntopo )
998 self.handle.sendline( "" )
999 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -04001000
kelvin8ec71442015-01-15 16:57:00 -08001001 self.handle.sendline( "onos-start-network " + mntopo )
1002 self.handle.expect( "mininet>" )
1003 main.log.info( "Network started, entered mininet prompt" )
1004
1005 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001006
1007 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001008 main.log.error( self.name + ": EOF exception found" )
1009 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001010 main.cleanup()
1011 main.exit()
1012 except:
kelvin8ec71442015-01-15 16:57:00 -08001013 main.log.info( self.name + " ::::::" )
1014 main.log.error( traceback.print_exc() )
1015 main.log.info( self.name + " ::::::" )
andrewonlab94282092014-10-10 13:00:11 -04001016 main.cleanup()
1017 main.exit()
1018
kelvin8ec71442015-01-15 16:57:00 -08001019 def isup( self, node="" ):
1020 """
1021 Run's onos-wait-for-start which only returns once ONOS is at run
1022 level 100( ready for use )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001023
Jon Hall7993bfc2014-10-09 16:30:14 -04001024 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001025 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001026 try:
kelvin8ec71442015-01-15 16:57:00 -08001027 self.handle.sendline( "onos-wait-for-start " + node )
1028 self.handle.expect( "onos-wait-for-start" )
1029 # NOTE: this timeout is arbitrary"
1030 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], timeout=120 )
Jon Hall7993bfc2014-10-09 16:30:14 -04001031 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001032 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001033 return main.TRUE
1034 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001035 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001036 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001037 main.log.error( "ONOS has not started yet" )
1038 self.handle.send( "\x03" ) # Control-C
1039 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001040 return main.FALSE
1041 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001042 main.log.error( self.name + ": EOF exception found" )
1043 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001044 main.cleanup()
1045 main.exit()
1046 except:
kelvin8ec71442015-01-15 16:57:00 -08001047 main.log.info( self.name + " ::::::" )
1048 main.log.error( traceback.print_exc() )
1049 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001050 main.cleanup()
1051 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001052
kelvin8ec71442015-01-15 16:57:00 -08001053 def push_test_intents_shell( self, dpid_src, dpid_dst, num_intents,
1054 dir_file, onos_ip, num_mult="", app_id="", report=True,
1055 options="" ):
1056 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001057 Description:
kelvin8ec71442015-01-15 16:57:00 -08001058 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001059 better parallelize the results than the CLI
1060 Required:
1061 * dpid_src: specify source dpid
1062 * dpid_dst: specify destination dpid
1063 * num_intents: specify number of intents to push
1064 * dir_file: specify directory and file name to save
1065 results
1066 * onos_ip: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001067 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001068 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001069 """
1070 try:
1071 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001072 if options:
kelvin8ec71442015-01-15 16:57:00 -08001073 base_cmd = "onos " + str( onos_ip ) + " push-test-intents " +\
1074 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001075 else:
kelvin8ec71442015-01-15 16:57:00 -08001076 base_cmd = "onos " + str( onos_ip ) + " push-test-intents "
1077
1078 add_dpid = base_cmd + str( dpid_src ) + " " + str( dpid_dst )
andrewonlabb66dfa12014-12-02 15:51:10 -05001079 if not num_mult:
kelvin8ec71442015-01-15 16:57:00 -08001080 add_intents = add_dpid + " " + str( num_intents )
andrewonlabb66dfa12014-12-02 15:51:10 -05001081 elif num_mult:
kelvin8ec71442015-01-15 16:57:00 -08001082 add_intents = add_dpid + " " + str( num_intents ) + " " +\
1083 str( num_mult )
andrewonlabb66dfa12014-12-02 15:51:10 -05001084 if app_id:
kelvin8ec71442015-01-15 16:57:00 -08001085 add_app = add_intents + " " + str( app_id )
andrewonlabb66dfa12014-12-02 15:51:10 -05001086 else:
1087 add_app = add_intents
1088
andrewonlabaedc8332014-12-04 12:43:03 -05001089 if report:
kelvin8ec71442015-01-15 16:57:00 -08001090 send_cmd = add_app + " > " + str( dir_file ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001091 else:
1092 send_cmd = add_app + " &"
kelvin8ec71442015-01-15 16:57:00 -08001093 main.log.info( "Send cmd: " + send_cmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001094
kelvin8ec71442015-01-15 16:57:00 -08001095 self.handle.sendline( send_cmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001096
1097 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001098 main.log.error( self.name + ": EOF exception found" )
1099 main.log.error( self.name + ": " + self.handle.before )
andrewonlabb66dfa12014-12-02 15:51:10 -05001100 main.cleanup()
1101 main.exit()
1102 except:
kelvin8ec71442015-01-15 16:57:00 -08001103 main.log.info( self.name + " ::::::" )
1104 main.log.error( traceback.print_exc() )
1105 main.log.info( self.name + " ::::::" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001106 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001107 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001108
kelvin8ec71442015-01-15 16:57:00 -08001109 def get_topology( self, topology_output ):
1110 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001111 parses the onos:topology output
kelvin8ec71442015-01-15 16:57:00 -08001112 Returns: a topology dict populated by the key values found in
Jon Hall77f53ce2014-10-13 18:02:06 -04001113 the cli command.
kelvin8ec71442015-01-15 16:57:00 -08001114 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001115 try:
kelvin8ec71442015-01-15 16:57:00 -08001116 # call the cli to get the topology summary
1117 # cmdstr = "onos:topology"
1118 # cli_result = self.onos_cli( ip, cmdstr )
1119 # print "cli_result = ", cli_result
Jon Hall77f53ce2014-10-13 18:02:06 -04001120
kelvin8ec71442015-01-15 16:57:00 -08001121 # Parse the output
Jon Hall77f53ce2014-10-13 18:02:06 -04001122 topology = {}
kelvin8ec71442015-01-15 16:57:00 -08001123 # for line in cli_result.split( "\n" ):
Shreya Shaha73aaad2014-10-27 18:03:09 -04001124 for line in topology_output.splitlines():
kelvin8ec71442015-01-15 16:57:00 -08001125 if not line.startswith( "time=" ):
Jon Hall77f53ce2014-10-13 18:02:06 -04001126 continue
kelvin8ec71442015-01-15 16:57:00 -08001127 # else
1128 # print line
1129 for var in line.split( "," ):
1130 # print "'"+var+"'"
1131 # print "'"+var.strip()+"'"
1132 key, value = var.strip().split( "=" )
1133 topology[ key ] = value
1134 # print "topology = ", topology
1135 # devices = topology.get( 'devices', False )
1136 # print "devices = ", devices
1137 # links = topology.get( 'links', False )
1138 # print "links = ", links
1139 # SCCs = topology.get( 'SCC(s)', False )
1140 # print "SCCs = ", SCCs
1141 # paths = topology.get( 'paths', False )
1142 # print "paths = ", paths
Jon Hall77f53ce2014-10-13 18:02:06 -04001143
1144 return topology
1145 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001146 main.log.error( self.name + ": EOF exception found" )
1147 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001148 main.cleanup()
1149 main.exit()
1150 except:
kelvin8ec71442015-01-15 16:57:00 -08001151 main.log.info( self.name + " ::::::" )
1152 main.log.error( traceback.print_exc() )
1153 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001154 main.cleanup()
1155 main.exit()
1156
kelvin8ec71442015-01-15 16:57:00 -08001157 def check_status(
1158 self,
1159 topology_result,
1160 numoswitch,
1161 numolink,
1162 log_level="info" ):
1163 """
1164 Checks the number of swithes & links that ONOS sees against the
1165 supplied values. By default this will report to main.log, but the
Jon Hall77f53ce2014-10-13 18:02:06 -04001166 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001167
Jon Hall77f53ce2014-10-13 18:02:06 -04001168 Params: ip = ip used for the onos cli
1169 numoswitch = expected number of switches
1170 numlink = expected number of links
1171 log_level = level to log to. Currently accepts 'info', 'warn' and 'report'
1172
1173
1174 log_level can
1175
kelvin8ec71442015-01-15 16:57:00 -08001176 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall77f53ce2014-10-13 18:02:06 -04001177 main.FALSE if the numer of switches and links is incorrect,
1178 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001179 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001180 try:
kelvin8ec71442015-01-15 16:57:00 -08001181 topology = self.get_topology( topology_result )
Jon Hall77f53ce2014-10-13 18:02:06 -04001182 if topology == {}:
1183 return main.ERROR
1184 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001185 # Is the number of switches is what we expected
1186 devices = topology.get( 'devices', False )
1187 links = topology.get( 'links', False )
Jon Hall77f53ce2014-10-13 18:02:06 -04001188 if devices == False or links == False:
1189 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001190 switch_check = ( int( devices ) == int( numoswitch ) )
1191 # Is the number of links is what we expected
1192 link_check = ( int( links ) == int( numolink ) )
1193 if ( switch_check and link_check ):
1194 # We expected the correct numbers
Jon Hall77f53ce2014-10-13 18:02:06 -04001195 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001196 + "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001197 result = main.TRUE
1198 else:
1199 output = output + \
kelvin8ec71442015-01-15 16:57:00 -08001200 "The number of links and switches does not match what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001201 result = main.FALSE
1202 output = output + "\n ONOS sees %i devices (%i expected) and %i links (%i expected)"\
kelvin8ec71442015-01-15 16:57:00 -08001203 % ( int( devices ), int( numoswitch ), int( links ), int( numolink ) )
Jon Hall77f53ce2014-10-13 18:02:06 -04001204 if log_level == "report":
kelvin8ec71442015-01-15 16:57:00 -08001205 main.log.report( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001206 elif log_level == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001207 main.log.warn( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001208 else:
kelvin8ec71442015-01-15 16:57:00 -08001209 main.log.info( output )
1210 return result
Jon Hall77f53ce2014-10-13 18:02:06 -04001211 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001212 main.log.error( self.name + ": EOF exception found" )
1213 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001214 main.cleanup()
1215 main.exit()
1216 except:
kelvin8ec71442015-01-15 16:57:00 -08001217 main.log.info( self.name + " ::::::" )
1218 main.log.error( traceback.print_exc() )
1219 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001220 main.cleanup()
1221 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001222
kelvin8ec71442015-01-15 16:57:00 -08001223 def tshark_pcap( self, interface, dir_file ):
1224 """
andrewonlab970399c2014-11-07 13:09:32 -05001225 Capture all packet activity and store in specified
1226 directory/file
1227
1228 Required:
1229 * interface: interface to capture
1230 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001231 """
1232 self.handle.sendline( "" )
1233 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001234
kelvin8ec71442015-01-15 16:57:00 -08001235 self.handle.sendline( "tshark -i " + str( interface ) +
1236 " -t e -w " + str( dir_file ) + " &" )
1237 self.handle.sendline( "\r" )
1238 self.handle.expect( "Capturing on" )
1239 self.handle.sendline( "\r" )
1240 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001241
kelvin8ec71442015-01-15 16:57:00 -08001242 main.log.info( "Tshark started capturing files on " +
1243 str( interface ) + " and saving to directory: " +
1244 str( dir_file ) )
Shreya Shaha73aaad2014-10-27 18:03:09 -04001245
kelvin8ec71442015-01-15 16:57:00 -08001246 def run_onos_topo_cfg( self, instance_name, json_file ):
1247 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001248 On ONOS bench, run this command: ./~/ONOS/tools/test/bin/onos-topo-cfg $OC1 filename
shahshreya4d79aab2014-11-07 15:20:41 -08001249 which starts the rest and copies the json file to the onos instance
kelvin8ec71442015-01-15 16:57:00 -08001250 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001251 try:
kelvin8ec71442015-01-15 16:57:00 -08001252 self.handle.sendline( "" )
1253 self.handle.expect( "\$" )
1254 self.handle.sendline( "cd ~/ONOS/tools/test/bin" )
1255 self.handle.expect( "/bin$" )
1256 cmd = "./onos-topo-cfg " + instance_name + " " + json_file
shahshreyae6c7cf42014-11-26 16:39:01 -08001257 print "cmd = ", cmd
kelvin8ec71442015-01-15 16:57:00 -08001258 self.handle.sendline( cmd )
1259 self.handle.expect( "\$" )
1260 self.handle.sendline( "cd ~" )
1261 self.handle.expect( "\$" )
shahshreyae6c7cf42014-11-26 16:39:01 -08001262 return main.TRUE
1263 except:
1264 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001265
1266 def tshark_grep( self, grep, directory, interface='eth0' ):
1267 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001268 Required:
kelvin8ec71442015-01-15 16:57:00 -08001269 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001270 * directory to store results
1271 Optional:
1272 * interface - default: eth0
1273 Description:
1274 Uses tshark command to grep specific group of packets
1275 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001276 The timestamp is hardcoded to be in epoch
1277 """
1278 self.handle.sendline( "" )
1279 self.handle.expect( "\$" )
1280 self.handle.sendline( "" )
1281 self.handle.sendline( "tshark -i " + str( interface ) +
1282 " -t e | grep --line-buffered \"" + str(grep) + "\" >" + directory + " &" )
1283 self.handle.sendline( "\r" )
1284 self.handle.expect( "Capturing on" )
1285 self.handle.sendline( "\r" )
1286 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001287
kelvin8ec71442015-01-15 16:57:00 -08001288 def tshark_stop( self ):
1289 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001290 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001291 """
1292 # Remove all pcap from previous captures
1293 self.execute( cmd="sudo rm /tmp/wireshark*" )
1294 self.handle.sendline( "" )
1295 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\" |" +
1296 " grep -v grep | awk '{print $2}'`" )
1297 self.handle.sendline( "" )
1298 main.log.info( "Tshark stopped" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001299
kelvin8ec71442015-01-15 16:57:00 -08001300 def ptpd( self, args ):
1301 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001302 Initiate ptp with user-specified args.
1303 Required:
1304 * args: specify string of args after command
1305 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001306 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001307 try:
kelvin8ec71442015-01-15 16:57:00 -08001308 self.handle.sendline( "sudo ptpd " + str( args ) )
1309 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001310 "Multiple",
1311 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001312 "\$" ] )
1313 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001314
andrewonlab0c38a4a2014-10-28 18:35:35 -04001315 if i == 0:
1316 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001317 main.log.info( "ptpd returned an error: " +
1318 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001319 return handle
1320 elif i == 1:
1321 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001322 main.log.error( "ptpd returned an error: " +
1323 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001324 return handle
1325 else:
1326 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001327
andrewonlab0c38a4a2014-10-28 18:35:35 -04001328 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001329 main.log.error( self.name + ": EOF exception found" )
1330 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001331 main.cleanup()
1332 main.exit()
1333 except:
kelvin8ec71442015-01-15 16:57:00 -08001334 main.log.info( self.name + " ::::::" )
1335 main.log.error( traceback.print_exc() )
1336 main.log.info( self.name + " ::::::" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001337 main.cleanup()
1338 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001339
kelvin8ec71442015-01-15 16:57:00 -08001340 def cp_logs_to_dir( self, log_to_copy,
1341 dest_dir, copy_file_name="" ):
1342 """
1343 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001344 Current implementation of ONOS deletes its karaf
1345 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001346 you may want to use this function to capture
1347 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001348 Localtime will be attached to the filename
1349
1350 Required:
1351 * log_to_copy: specify directory and log name to
1352 copy.
kelvin8ec71442015-01-15 16:57:00 -08001353 ex ) /opt/onos/log/karaf.log.1
andrewonlab5d7a8f32014-11-10 13:07:56 -05001354 For copying multiple files, leave copy_file_name
kelvin8ec71442015-01-15 16:57:00 -08001355 empty and only specify dest_dir -
1356 ex ) /opt/onos/log/karaf*
andrewonlab5d7a8f32014-11-10 13:07:56 -05001357 * dest_dir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001358 ex ) /tmp/
1359 Optional:
andrewonlab5d7a8f32014-11-10 13:07:56 -05001360 * copy_file_name: If you want to rename the log
1361 file, specify copy_file_name. This will not work
1362 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001363 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001364 try:
kelvin8ec71442015-01-15 16:57:00 -08001365 localtime = time.strftime( '%x %X' )
1366 localtime = localtime.replace( "/", "" )
1367 localtime = localtime.replace( " ", "_" )
1368 localtime = localtime.replace( ":", "" )
1369 if dest_dir[ -1: ] != "/":
andrewonlab5d7a8f32014-11-10 13:07:56 -05001370 dest_dir += "/"
1371
1372 if copy_file_name:
kelvin8ec71442015-01-15 16:57:00 -08001373 self.handle.sendline( "cp " + str( log_to_copy ) +
1374 " " + str( dest_dir ) + str( copy_file_name ) +
1375 localtime )
1376 self.handle.expect( "cp" )
1377 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001378 else:
kelvin8ec71442015-01-15 16:57:00 -08001379 self.handle.sendline( "cp " + str( log_to_copy ) +
1380 " " + str( dest_dir ) )
1381 self.handle.expect( "cp" )
1382 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001383
kelvin8ec71442015-01-15 16:57:00 -08001384 return self.handle.before
1385
1386 except pexpect.EOF:
1387 main.log.error( "Copying files failed" )
1388 main.log.error( self.name + ": EOF exception found" )
1389 main.log.error( self.name + ": " + self.handle.before )
1390 except:
1391 main.log.error( "Copying files failed" )
1392 main.log.info( self.name + " ::::::" )
1393 main.log.error( traceback.print_exc() )
1394 main.log.info( self.name + " ::::::" )
1395
1396 def check_logs( self, onos_ip ):
1397 """
Jon Hall94fd0472014-12-08 11:52:42 -08001398 runs onos-check-logs on the given onos node
1399 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001400 """
Jon Hall94fd0472014-12-08 11:52:42 -08001401 try:
kelvin8ec71442015-01-15 16:57:00 -08001402 cmd = "onos-check-logs " + str( onos_ip )
1403 self.handle.sendline( cmd )
1404 self.handle.expect( cmd )
1405 self.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -08001406 response = self.handle.before
1407 return response
1408 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001409 main.log.error( "Lost ssh connection" )
1410 main.log.error( self.name + ": EOF exception found" )
1411 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001412 except:
kelvin8ec71442015-01-15 16:57:00 -08001413 main.log.error( "Some error in check_logs:" )
1414 main.log.info( self.name + " ::::::" )
1415 main.log.error( traceback.print_exc() )
1416 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001417
kelvin8ec71442015-01-15 16:57:00 -08001418 def onos_status( self, node="" ):
1419 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001420 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001421 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001422 try:
kelvin8ec71442015-01-15 16:57:00 -08001423 self.handle.sendline( "" )
1424 self.handle.expect( "\$" )
1425 self.handle.sendline( "onos-service " + str( node ) +
1426 " status" )
1427 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001428 "start/running",
1429 "stop/waiting",
kelvin8ec71442015-01-15 16:57:00 -08001430 pexpect.TIMEOUT ], timeout=120 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001431
1432 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001433 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001434 return main.TRUE
1435 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001436 main.log.info( "ONOS is stopped" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001437 return main.FALSE
1438 else:
kelvin8ec71442015-01-15 16:57:00 -08001439 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001440 main.cleanup()
1441 main.exit()
1442 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001443 main.log.error( self.name + ": EOF exception found" )
1444 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001445 main.cleanup()
1446 main.exit()
1447 except:
kelvin8ec71442015-01-15 16:57:00 -08001448 main.log.info( self.name + " ::::::" )
1449 main.log.error( traceback.print_exc() )
1450 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001451 main.cleanup()
1452 main.exit()