blob: a9a5a038067d017509205b8d988d67c1ca415961 [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,
kelvin-onlab08679eb2015-01-21 16:11:48 -080052 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -080053 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:
kelvin-onlabd3b64892015-01-20 13:26:24 -080070 main.log.info( self.name + ":" * 30 )
Jon Hall05b2b432014-10-08 19:53:25 -040071 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -080072 main.log.info( ":" * 30 )
Jon Hall05b2b432014-10-08 19:53:25 -040073 main.cleanup()
74 main.exit()
75
kelvin8ec71442015-01-15 16:57:00 -080076 def disconnect( self ):
77 """
Jon Hall05b2b432014-10-08 19:53:25 -040078 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080079 """
Jon Hall05b2b432014-10-08 19:53:25 -040080 response = ''
81 try:
kelvin8ec71442015-01-15 16:57:00 -080082 self.handle.sendline( "" )
83 self.handle.expect( "\$" )
84 self.handle.sendline( "exit" )
85 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -040086 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080087 main.log.error( self.name + ": EOF exception found" )
88 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040089 except:
kelvin8ec71442015-01-15 16:57:00 -080090 main.log.error( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -040091 response = main.FALSE
92 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040093
kelvin-onlabd3b64892015-01-20 13:26:24 -080094 def onosPackage( self ):
kelvin8ec71442015-01-15 16:57:00 -080095 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040096 Produce a self-contained tar.gz file that can be deployed
kelvin8ec71442015-01-15 16:57:00 -080097 and executed on any platform with Java 7 JRE.
98 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040099 try:
kelvin8ec71442015-01-15 16:57:00 -0800100 self.handle.sendline( "onos-package" )
101 self.handle.expect( "onos-package" )
102 self.handle.expect( "tar.gz", timeout=30 )
103 handle = str( self.handle.before )
104 main.log.info( "onos-package command returned: " +
105 handle )
106 # As long as the sendline does not time out,
107 # return true. However, be careful to interpret
108 # the results of the onos-package command return
andrewonlab0748d2a2014-10-09 13:24:17 -0400109 return main.TRUE
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400110
andrewonlab7735d852014-10-09 13:02:47 -0400111 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800112 main.log.error( self.name + ": EOF exception found" )
113 main.log.error( self.name + ": " + self.handle.before )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400114 except:
kelvin8ec71442015-01-15 16:57:00 -0800115 main.log.error( "Failed to package ONOS" )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400116 main.cleanup()
117 main.exit()
118
kelvin-onlabd3b64892015-01-20 13:26:24 -0800119 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800120 """
andrewonlab8790abb2014-11-06 13:51:54 -0500121 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800122 """
andrewonlab8790abb2014-11-06 13:51:54 -0500123 try:
kelvin8ec71442015-01-15 16:57:00 -0800124 self.handle.sendline( "onos-build" )
125 self.handle.expect( "onos-build" )
126 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800127 "BUILD SUCCESS",
128 "ERROR",
129 "BUILD FAILED" ],
130 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800131 handle = str( self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500132
kelvin8ec71442015-01-15 16:57:00 -0800133 main.log.info( "onos-build command returned: " +
134 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500135
136 if i == 0:
137 return main.TRUE
138 else:
139 return handle
140
141 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800142 main.log.error( self.name + ": EOF exception found" )
143 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500144 except:
kelvin8ec71442015-01-15 16:57:00 -0800145 main.log.error( "Failed to build ONOS" )
andrewonlab8790abb2014-11-06 13:51:54 -0500146 main.cleanup()
147 main.exit()
148
kelvin-onlabd3b64892015-01-20 13:26:24 -0800149 def cleanInstall( self ):
kelvin8ec71442015-01-15 16:57:00 -0800150 """
151 Runs mvn clean install in the root of the ONOS directory.
152 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400153
kelvin8ec71442015-01-15 16:57:00 -0800154 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400155 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800156 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400157 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800158 main.log.info( "Running 'mvn clean install' on " +
159 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800160 ". This may take some time." )
161 self.handle.sendline( "cd " + self.home )
162 self.handle.expect( "\$" )
Jon Hallea7818b2014-10-09 14:30:59 -0400163
kelvin8ec71442015-01-15 16:57:00 -0800164 self.handle.sendline( "" )
165 self.handle.expect( "\$" )
166 self.handle.sendline( "mvn clean install" )
167 self.handle.expect( "mvn clean install" )
168 while True:
169 i = self.handle.expect( [
Jon Hallde9d9aa2014-10-08 20:36:02 -0400170 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\
171 Runtime\sEnvironment\sto\scontinue',
172 'BUILD\sFAILURE',
173 'BUILD\sSUCCESS',
174 'ONOS\$',
kelvin8ec71442015-01-15 16:57:00 -0800175 pexpect.TIMEOUT ], timeout=600 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400176 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800177 main.log.error( self.name + ":There is insufficient memory \
178 for the Java Runtime Environment to continue." )
179 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400180 main.cleanup()
181 main.exit()
182 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800183 main.log.error( self.name + ": Build failure!" )
184 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400185 main.cleanup()
186 main.exit()
187 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800188 main.log.info( self.name + ": Build success!" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400189 elif i == 3:
kelvin8ec71442015-01-15 16:57:00 -0800190 main.log.info( self.name + ": Build complete" )
191 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400192 for line in self.handle.before.splitlines():
193 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800194 main.log.info( line )
195 self.handle.sendline( "" )
196 self.handle.expect( "\$", timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400197 return main.TRUE
198 elif i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800199 main.log.error(
200 self.name +
201 ": mvn clean install TIMEOUT!" )
202 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400203 main.cleanup()
204 main.exit()
205 else:
kelvin8ec71442015-01-15 16:57:00 -0800206 main.log.error( self.name + ": unexpected response from \
207 mvn clean install" )
208 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400209 main.cleanup()
210 main.exit()
211 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800212 main.log.error( self.name + ": EOF exception found" )
213 main.log.error( self.name + ": " + self.handle.before )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400214 main.cleanup()
215 main.exit()
216 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800217 main.log.info( self.name + ":" * 60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400218 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800219 main.log.info( ":" * 60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400220 main.cleanup()
221 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400222
kelvin-onlabd3b64892015-01-20 13:26:24 -0800223 def gitPull( self, comp1="" ):
kelvin8ec71442015-01-15 16:57:00 -0800224 """
Jon Hallacabffd2014-10-09 12:36:53 -0400225 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800226
Jon Hallacabffd2014-10-09 12:36:53 -0400227 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800228 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400229 for the purpose of pulling from other nodes if necessary.
230
Jon Hall47a93fb2015-01-06 16:46:06 -0800231 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400232 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800233 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400234 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400235
kelvin8ec71442015-01-15 16:57:00 -0800236 """
Jon Hallacabffd2014-10-09 12:36:53 -0400237 try:
kelvin8ec71442015-01-15 16:57:00 -0800238 # main.log.info( self.name + ": Stopping ONOS" )
239 # self.stop()
240 self.handle.sendline( "cd " + self.home )
241 self.handle.expect( "ONOS\$" )
242 if comp1 == "":
243 self.handle.sendline( "git pull" )
Jon Hallacabffd2014-10-09 12:36:53 -0400244 else:
kelvin8ec71442015-01-15 16:57:00 -0800245 self.handle.sendline( "git pull " + comp1 )
Jon Hall47a93fb2015-01-06 16:46:06 -0800246
kelvin-onlabd3b64892015-01-20 13:26:24 -0800247 i = self.handle.expect(
248 [
249 'fatal',
250 'Username\sfor\s(.*):\s',
251 '\sfile(s*) changed,\s',
252 'Already up-to-date',
253 'Aborting',
254 'You\sare\snot\scurrently\son\sa\sbranch',
255 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\
256 \sbranch\syou',
257 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\
258 \sfiles',
259 pexpect.TIMEOUT ],
260 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800261 # debug
kelvin-onlabd3b64892015-01-20 13:26:24 -0800262 # main.log.report( self.name +": DEBUG: \n"+
263 # "git pull response: " +
264 # str( self.handle.before ) + str( self.handle.after ) )
kelvin8ec71442015-01-15 16:57:00 -0800265 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 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800278 # So that only when git pull is done, we do mvn clean compile
279 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800280 elif i == 3:
281 main.log.info( self.name + ": Git Pull - Already up to date" )
Jon Hall47a93fb2015-01-06 16:46:06 -0800282 return i
kelvin8ec71442015-01-15 16:57:00 -0800283 elif i == 4:
284 main.log.info(
285 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800286 ": Git Pull - Aborting...\
287 Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400288 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800289 elif i == 5:
290 main.log.info(
291 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800292 ": Git Pull - You are not currently\
293 on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400294 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800295 elif i == 6:
296 main.log.info(
297 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800298 ": Git Pull - You have not configured\
299 an upstream branch to pull from\
300 . Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400301 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800302 elif i == 7:
303 main.log.info(
304 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800305 ": Git Pull - Pull is not possible\
306 because you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400307 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800308 elif i == 8:
309 main.log.error( self.name + ": Git Pull - TIMEOUT" )
310 main.log.error(
311 self.name + " Response was: " + str(
312 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400313 return main.ERROR
314 else:
kelvin8ec71442015-01-15 16:57:00 -0800315 main.log.error(
316 self.name +
317 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400318 return main.ERROR
319 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800320 main.log.error( self.name + ": EOF exception found" )
321 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400322 main.cleanup()
323 main.exit()
324 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800325 main.log.info( self.name + ":" * 60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400326 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800327 main.log.info( ":" * 80 )
Jon Hallacabffd2014-10-09 12:36:53 -0400328 main.cleanup()
329 main.exit()
330
kelvin-onlabd3b64892015-01-20 13:26:24 -0800331 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800332 """
Jon Hallacabffd2014-10-09 12:36:53 -0400333 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800334
Jon Hallacabffd2014-10-09 12:36:53 -0400335 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800336 If used as gitCheckout( "branch" ) it will do git checkout
337 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400338
339 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800340 branch of the ONOS repository. If it has any problems, it will return
341 main.ERROR.
342 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400343 successful then the function will return main.TRUE.
344
kelvin8ec71442015-01-15 16:57:00 -0800345 """
Jon Hallacabffd2014-10-09 12:36:53 -0400346 try:
kelvin8ec71442015-01-15 16:57:00 -0800347 self.handle.sendline( "cd " + self.home )
348 self.handle.expect( "ONOS\$" )
349 main.log.info(
350 self.name +
351 ": Checking out git branch: " +
352 branch +
353 "..." )
354 cmd = "git checkout " + branch
355 self.handle.sendline( cmd )
356 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800357 i = self.handle.expect(
358 [
359 'fatal',
360 'Username\sfor\s(.*):\s',
361 'Already\son\s\'',
362 'Switched\sto\sbranch\s\'' +
363 str( branch ),
364 pexpect.TIMEOUT,
365 'error: Your local changes to the following files\
366 would be overwritten by checkout:',
367 'error: you need to resolve your current index first' ],
368 timeout=60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400369
kelvin8ec71442015-01-15 16:57:00 -0800370 if i == 0:
371 main.log.error(
372 self.name +
373 ": Git checkout had some issue..." )
374 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400375 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800376 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800377 main.log.error(
378 self.name +
379 ": Git checkout asking for username." +
380 " Please configure your local git repository to be able " +
381 "to access your remote repository passwordlessly" )
Jon Hallacabffd2014-10-09 12:36:53 -0400382 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800383 elif i == 2:
384 main.log.info(
385 self.name +
386 ": Git Checkout %s : Already on this branch" %
387 branch )
388 self.handle.expect( "ONOS\$" )
389 # main.log.info( "DEBUG: after checkout cmd = "+
390 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400391 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800392 elif i == 3:
393 main.log.info(
394 self.name +
395 ": Git checkout %s - Switched to this branch" %
396 branch )
397 self.handle.expect( "ONOS\$" )
398 # main.log.info( "DEBUG: after checkout cmd = "+
399 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400400 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800401 elif i == 4:
402 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
403 main.log.error(
404 self.name + " Response was: " + str(
405 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400406 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800407 elif i == 5:
408 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800409 main.log.error(
410 self.name +
411 ": Git checkout error: \n" +
412 "Your local changes to the following\
413 files would be overwritten by checkout:" +
414 str(
415 self.handle.before ) )
kelvin8ec71442015-01-15 16:57:00 -0800416 self.handle.expect( "ONOS\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500417 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800418 elif i == 6:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800419 main.log.error( self.name +
420 ": Git checkout error: \n" +
421 "You need to resolve your\
422 current index first:" +
kelvin8ec71442015-01-15 16:57:00 -0800423 str( self.handle.before ) )
424 self.handle.expect( "ONOS\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500425 return main.ERROR
Jon Hallacabffd2014-10-09 12:36:53 -0400426 else:
kelvin8ec71442015-01-15 16:57:00 -0800427 main.log.error(
428 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800429 ": Git Checkout - Unexpected response,\
430 check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800431 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400432 return main.ERROR
433
434 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800435 main.log.error( self.name + ": EOF exception found" )
436 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400437 main.cleanup()
438 main.exit()
439 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800440 main.log.info( self.name + ":" * 60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400441 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800442 main.log.info( ":" * 80 )
Jon Hallacabffd2014-10-09 12:36:53 -0400443 main.cleanup()
444 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400445
kelvin-onlabd3b64892015-01-20 13:26:24 -0800446 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800447 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800448 Writes the COMMIT number to the report to be parsed\
449 by Jenkins data collecter.
kelvin8ec71442015-01-15 16:57:00 -0800450 """
Jon Hall45ec0922014-10-10 19:33:49 -0400451 try:
kelvin8ec71442015-01-15 16:57:00 -0800452 self.handle.sendline( "" )
453 self.handle.expect( "\$" )
454 self.handle.sendline(
455 "cd " +
456 self.home +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800457 "; git log -1 --pretty=fuller --decorate=short | grep -A 6\
458 \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800459 # NOTE: for some reason there are backspaces inserted in this
460 # phrase when run from Jenkins on some tests
461 self.handle.expect( "never" )
462 self.handle.expect( "\$" )
463 response = ( self.name + ": \n" + str(
464 self.handle.before + self.handle.after ) )
465 self.handle.sendline( "cd " + self.home )
466 self.handle.expect( "\$" )
467 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400468 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500469 print line
470 if report:
kelvin8ec71442015-01-15 16:57:00 -0800471 for line in lines[ 2:-1 ]:
472 # Bracket replacement is for Wiki-compliant
473 # formatting. '<' or '>' are interpreted
474 # as xml specific tags that cause errors
475 line = line.replace( "<", "[" )
476 line = line.replace( ">", "]" )
477 main.log.report( "\t" + line )
478 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400479 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800480 main.log.error( self.name + ": EOF exception found" )
481 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400482 main.cleanup()
483 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800484 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800485 main.log.error( self.name + ": TIMEOUT exception found" )
486 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800487 main.cleanup()
488 main.exit()
Jon Hall45ec0922014-10-10 19:33:49 -0400489 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800490 main.log.info( self.name + ":" * 60 )
Jon Hall45ec0922014-10-10 19:33:49 -0400491 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800492 main.log.info( ":" * 80 )
Jon Hall45ec0922014-10-10 19:33:49 -0400493 main.cleanup()
494 main.exit()
495
kelvin-onlabd3b64892015-01-20 13:26:24 -0800496 def createCellFile( self, benchIp, fileName, mnIpAddrs,
497 extraFeatureString, *onosIpAddrs ):
kelvin8ec71442015-01-15 16:57:00 -0800498 """
andrewonlab94282092014-10-10 13:00:11 -0400499 Creates a cell file based on arguments
500 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800501 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400502 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800503 * File name of the cell file ( fileName )
504 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800505 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400506 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800507 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400508 - Must be passed in as last arguments
kelvin8ec71442015-01-15 16:57:00 -0800509
andrewonlab94282092014-10-10 13:00:11 -0400510 NOTE: Assumes cells are located at:
511 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800512 """
513 # Variable initialization
kelvin-onlabd3b64892015-01-20 13:26:24 -0800514 cellDirectory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800515 # We want to create the cell file in the dependencies directory
516 # of TestON first, then copy over to ONOS bench
kelvin-onlabd3b64892015-01-20 13:26:24 -0800517 tempDirectory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800518 # Create the cell file in the directory for writing ( w+ )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800519 cellFile = open( tempDirectory + fileName, 'w+' )
kelvin8ec71442015-01-15 16:57:00 -0800520
521 # Feature string is hardcoded environment variables
522 # That you may wish to use by default on startup.
523 # Note that you may not want certain features listed
524 # on here.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800525 coreFeatureString = "export ONOS_FEATURES=webconsole,onos-api," +\
526 "onos-cli,onos-openflow," + extraFeatureString
527 mnString = "export OCN="
528 onosString = "export OC"
529 tempCount = 1
kelvin8ec71442015-01-15 16:57:00 -0800530
kelvin-onlabd3b64892015-01-20 13:26:24 -0800531 # Create ONOSNIC ip address prefix
532 tempOnosIp = onosIpAddrs[ 0 ]
533 tempList = []
534 tempList = tempOnosIp.split( "." )
kelvin8ec71442015-01-15 16:57:00 -0800535 # Omit last element of list to format for NIC
kelvin-onlabd3b64892015-01-20 13:26:24 -0800536 tempList = tempList[ :-1 ]
kelvin8ec71442015-01-15 16:57:00 -0800537 # Structure the nic string ip
kelvin-onlabd3b64892015-01-20 13:26:24 -0800538 nicAddr = ".".join( tempList ) + ".*"
539 onosNicString = "export ONOS_NIC=" + nicAddr
andrewonlab94282092014-10-10 13:00:11 -0400540
541 try:
kelvin8ec71442015-01-15 16:57:00 -0800542 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800543 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400544
kelvin-onlabd3b64892015-01-20 13:26:24 -0800545 for arg in onosIpAddrs:
546 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800547 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400548 # export OC1="10.128.20.11"
549 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800550 cellFile.write( onosString + str( tempCount ) +
551 "=" + "\"" + arg + "\"" + "\n" )
552 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800553
kelvin-onlabd3b64892015-01-20 13:26:24 -0800554 cellFile.write( mnString + "\"" + mnIpAddrs + "\"" + "\n" )
555 cellFile.write( coreFeatureString + "\n" )
556 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400557
kelvin8ec71442015-01-15 16:57:00 -0800558 # We use os.system to send the command to TestON cluster
559 # to account for the case in which TestON is not located
560 # on the same cluster as the ONOS bench
561 # Note that even if TestON is located on the same cluster
562 # as ONOS bench, you must setup passwordless ssh
563 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800564 os.system( "scp " + tempDirectory + fileName +
565 " admin@" + benchIp + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400566
andrewonlab2a6c9342014-10-16 13:40:15 -0400567 return main.TRUE
568
andrewonlab94282092014-10-10 13:00:11 -0400569 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800570 main.log.error( self.name + ": EOF exception found" )
571 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -0400572 main.cleanup()
573 main.exit()
574 except:
kelvin8ec71442015-01-15 16:57:00 -0800575 main.log.info( self.name + ":::::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400576 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800577 main.log.info( ":::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400578 main.cleanup()
579 main.exit()
580
kelvin-onlabd3b64892015-01-20 13:26:24 -0800581 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800582 """
andrewonlab95ca1462014-10-09 14:04:24 -0400583 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800584 """
andrewonlab95ca1462014-10-09 14:04:24 -0400585 try:
586 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800587 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400588 main.cleanup()
589 main.exit()
590 else:
kelvin8ec71442015-01-15 16:57:00 -0800591 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800592 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800593 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400594 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800595 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800596 handleBefore = self.handle.before
597 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800598 # Get the rest of the handle
599 self.handle.sendline( "" )
600 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800601 handleMore = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400602
kelvin-onlabd3b64892015-01-20 13:26:24 -0800603 main.log.info( "Cell call returned: " + handleBefore +
604 handleAfter + handleMore )
andrewonlab95ca1462014-10-09 14:04:24 -0400605
606 return main.TRUE
607
608 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800609 main.log.error( self.name + ": EOF exception found" )
610 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400611 main.cleanup()
612 main.exit()
613 except:
kelvin8ec71442015-01-15 16:57:00 -0800614 main.log.info( self.name + " ::::::" )
615 main.log.error( traceback.print_exc() )
616 main.log.info( self.name + " ::::::" )
andrewonlab95ca1462014-10-09 14:04:24 -0400617 main.cleanup()
618 main.exit()
619
kelvin-onlabd3b64892015-01-20 13:26:24 -0800620 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800621 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400622 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800623 """
624 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400625
andrewonlabc03bf6c2014-10-09 14:56:18 -0400626 try:
kelvin8ec71442015-01-15 16:57:00 -0800627 # Clean handle by sending empty and expecting $
628 self.handle.sendline( "" )
629 self.handle.expect( "\$" )
630 self.handle.sendline( "onos-verify-cell" )
631 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800632 handleBefore = self.handle.before
633 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800634 # Get the rest of the handle
635 self.handle.sendline( "" )
636 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800637 handleMore = self.handle.before
andrewonlabc03bf6c2014-10-09 14:56:18 -0400638
kelvin-onlabd3b64892015-01-20 13:26:24 -0800639 main.log.info( "Verify cell returned: " + handleBefore +
640 handleAfter + handleMore )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400641
642 return main.TRUE
Jon Hall7993bfc2014-10-09 16:30:14 -0400643 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800644 main.log.error( self.name + ": EOF exception found" )
645 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400646 main.cleanup()
647 main.exit()
648 except:
kelvin8ec71442015-01-15 16:57:00 -0800649 main.log.info( self.name + " ::::::" )
650 main.log.error( traceback.print_exc() )
651 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400652 main.cleanup()
653 main.exit()
654
kelvin-onlabd3b64892015-01-20 13:26:24 -0800655 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800656 """
andrewonlab05e362f2014-10-10 00:40:57 -0400657 Uses 'onos' command to send various ONOS CLI arguments.
658 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800659 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400660 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800661
662 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400663 CLI commands for ONOS. Try to use this function first
664 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800665 function.
666 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400667 by starting onos, and typing in 'onos' to enter the
668 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800669 available commands.
670 """
andrewonlab05e362f2014-10-10 00:40:57 -0400671 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800672 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800673 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400674 return main.FALSE
675 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800676 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400677 return main.FALSE
678
kelvin8ec71442015-01-15 16:57:00 -0800679 cmdstr = str( cmdstr )
680 self.handle.sendline( "" )
681 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400682
kelvin-onlabd3b64892015-01-20 13:26:24 -0800683 self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr )
kelvin8ec71442015-01-15 16:57:00 -0800684 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400685
kelvin-onlabd3b64892015-01-20 13:26:24 -0800686 handleBefore = self.handle.before
Shreya Shaha73aaad2014-10-27 18:03:09 -0400687 print "handle_before = ", self.handle.before
kelvin-onlabd3b64892015-01-20 13:26:24 -0800688 # handleAfter = str( self.handle.after )
Jon Hall47a93fb2015-01-06 16:46:06 -0800689
kelvin8ec71442015-01-15 16:57:00 -0800690 # self.handle.sendline( "" )
691 # self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800692 # handleMore = str( self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400693
kelvin8ec71442015-01-15 16:57:00 -0800694 main.log.info( "Command sent successfully" )
andrewonlab05e362f2014-10-10 00:40:57 -0400695
kelvin8ec71442015-01-15 16:57:00 -0800696 # Obtain return handle that consists of result from
697 # the onos command. The string may need to be
698 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800699 # returnString = handleBefore + handleAfter
700 returnString = handleBefore
701 print "return_string = ", returnString
702 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400703
704 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800705 main.log.error( self.name + ": EOF exception found" )
706 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400707 main.cleanup()
708 main.exit()
709 except:
kelvin8ec71442015-01-15 16:57:00 -0800710 main.log.info( self.name + " ::::::" )
711 main.log.error( traceback.print_exc() )
712 main.log.info( self.name + " ::::::" )
andrewonlab05e362f2014-10-10 00:40:57 -0400713 main.cleanup()
714 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400715
kelvin-onlabd3b64892015-01-20 13:26:24 -0800716 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -0800717 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400718 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800719 If -f option is provided, it also forces an uninstall.
720 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400721 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800722 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400723 files to certain onos nodes
724
725 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800726 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400727 try:
andrewonlab114768a2014-11-14 12:44:44 -0500728 if options:
kelvin8ec71442015-01-15 16:57:00 -0800729 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500730 else:
kelvin8ec71442015-01-15 16:57:00 -0800731 self.handle.sendline( "onos-install " + node )
732 self.handle.expect( "onos-install " )
733 # NOTE: this timeout may need to change depending on the network
734 # and size of ONOS
735 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800736 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -0800737 "ONOS\sis\salready\sinstalled",
738 pexpect.TIMEOUT ], timeout=60 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400739
Jon Hall7993bfc2014-10-09 16:30:14 -0400740 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800741 main.log.warn( "Network is unreachable" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400742 return main.FALSE
743 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800744 main.log.info(
745 "ONOS was installed on " +
746 node +
747 " and started" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400748 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500749 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800750 main.log.info( "ONOS is already installed on " + node )
andrewonlabd9a73a72014-11-14 17:28:21 -0500751 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800752 elif i == 3:
753 main.log.info(
754 "Installation of ONOS on " +
755 node +
756 " timed out" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400757 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400758
759 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800760 main.log.error( self.name + ": EOF exception found" )
761 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400762 main.cleanup()
763 main.exit()
764 except:
kelvin8ec71442015-01-15 16:57:00 -0800765 main.log.info( self.name + " ::::::" )
766 main.log.error( traceback.print_exc() )
767 main.log.info( self.name + " ::::::" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400768 main.cleanup()
769 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400770
kelvin-onlabd3b64892015-01-20 13:26:24 -0800771 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800772 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400773 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400774 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800775 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400776 try:
kelvin8ec71442015-01-15 16:57:00 -0800777 self.handle.sendline( "" )
778 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800779 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800780 " start" )
781 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -0400782 "Job\sis\salready\srunning",
783 "start/running",
784 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800785 pexpect.TIMEOUT ], timeout=120 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400786
787 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800788 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400789 return main.TRUE
790 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800791 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400792 return main.TRUE
793 else:
kelvin8ec71442015-01-15 16:57:00 -0800794 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400795 main.cleanup()
796 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400797 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800798 main.log.error( self.name + ": EOF exception found" )
799 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400800 main.cleanup()
801 main.exit()
802 except:
kelvin8ec71442015-01-15 16:57:00 -0800803 main.log.info( self.name + " ::::::" )
804 main.log.error( traceback.print_exc() )
805 main.log.info( self.name + " ::::::" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400806 main.cleanup()
807 main.exit()
808
kelvin-onlabd3b64892015-01-20 13:26:24 -0800809 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800810 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400811 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400812 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800813 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400814 try:
kelvin8ec71442015-01-15 16:57:00 -0800815 self.handle.sendline( "" )
816 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800817 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800818 " stop" )
819 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -0400820 "stop/waiting",
821 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800822 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2b30bd32014-10-09 16:48:55 -0400823
824 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800825 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400826 return main.TRUE
827 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800828 main.log.info( "Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800829 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -0400830 return main.FALSE
831 else:
kelvin8ec71442015-01-15 16:57:00 -0800832 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400833 return main.FALSE
834
835 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800836 main.log.error( self.name + ": EOF exception found" )
837 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -0400838 main.cleanup()
839 main.exit()
840 except:
kelvin8ec71442015-01-15 16:57:00 -0800841 main.log.info( self.name + " ::::::" )
842 main.log.error( traceback.print_exc() )
843 main.log.info( self.name + " ::::::" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400844 main.cleanup()
845 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800846
kelvin-onlabd3b64892015-01-20 13:26:24 -0800847 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -0800848 """
andrewonlabc8d47972014-10-09 16:52:36 -0400849 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -0800850 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -0400851 if needed
kelvin8ec71442015-01-15 16:57:00 -0800852 """
andrewonlabc8d47972014-10-09 16:52:36 -0400853 try:
kelvin8ec71442015-01-15 16:57:00 -0800854 self.handle.sendline( "" )
855 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800856 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800857 self.handle.expect( "\$" )
andrewonlabc8d47972014-10-09 16:52:36 -0400858
kelvin-onlabd3b64892015-01-20 13:26:24 -0800859 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
andrewonlab9dfd2082014-11-13 17:44:03 -0500860
kelvin8ec71442015-01-15 16:57:00 -0800861 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -0400862 return main.TRUE
863
864 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800865 main.log.error( self.name + ": EOF exception found" )
866 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -0400867 main.cleanup()
868 main.exit()
869 except:
kelvin8ec71442015-01-15 16:57:00 -0800870 main.log.info( self.name + " ::::::" )
871 main.log.error( traceback.print_exc() )
872 main.log.info( self.name + " ::::::" )
andrewonlabc8d47972014-10-09 16:52:36 -0400873 main.cleanup()
874 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400875
kelvin-onlabd3b64892015-01-20 13:26:24 -0800876 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800877 """
andrewonlabaedc8332014-12-04 12:43:03 -0500878 Issues the command 'onos-die <node-ip>'
879 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -0800880 """
andrewonlabaedc8332014-12-04 12:43:03 -0500881 try:
kelvin8ec71442015-01-15 16:57:00 -0800882 self.handle.sendline( "" )
883 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800884 cmdStr = "onos-kill " + str( nodeIp )
885 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800886 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -0500887 "Killing\sONOS",
888 "ONOS\sprocess\sis\snot\srunning",
kelvin8ec71442015-01-15 16:57:00 -0800889 pexpect.TIMEOUT ], timeout=20 )
andrewonlabaedc8332014-12-04 12:43:03 -0500890 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800891 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800892 " was killed and stopped" )
andrewonlabaedc8332014-12-04 12:43:03 -0500893 return main.TRUE
894 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800895 main.log.info( "ONOS process was not running" )
andrewonlabaedc8332014-12-04 12:43:03 -0500896 return main.FALSE
897 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800898 main.log.error( self.name + ": EOF exception found" )
899 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -0500900 main.cleanup()
901 main.exit()
902 except:
kelvin8ec71442015-01-15 16:57:00 -0800903 main.log.info( self.name + " ::::::" )
904 main.log.error( traceback.print_exc() )
905 main.log.info( self.name + " ::::::" )
andrewonlabaedc8332014-12-04 12:43:03 -0500906 main.cleanup()
907 main.exit()
908
kelvin-onlabd3b64892015-01-20 13:26:24 -0800909 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800910 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400911 Calls the command: 'onos-kill [<node-ip>]'
912 "Remotely, and unceremoniously kills the ONOS instance running on
913 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -0800914 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400915 try:
kelvin8ec71442015-01-15 16:57:00 -0800916 self.handle.sendline( "" )
917 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800918 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800919 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -0400920 "\$",
921 "No\sroute\sto\shost",
922 "password:",
kelvin8ec71442015-01-15 16:57:00 -0800923 pexpect.TIMEOUT ], timeout=20 )
924
andrewonlabe8e56fd2014-10-09 17:12:44 -0400925 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800926 main.log.info(
927 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800928 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400929 return main.TRUE
930 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800931 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400932 return main.FALSE
933 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800934 main.log.info(
935 "Passwordless login for host: " +
936 str( nodeIp ) +
937 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400938 return main.FALSE
939 else:
kelvin8ec71442015-01-15 16:57:00 -0800940 main.log.info( "ONOS instasnce was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400941 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800942
andrewonlabe8e56fd2014-10-09 17:12:44 -0400943 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800944 main.log.error( self.name + ": EOF exception found" )
945 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400946 main.cleanup()
947 main.exit()
948 except:
kelvin8ec71442015-01-15 16:57:00 -0800949 main.log.info( self.name + " ::::::" )
950 main.log.error( traceback.print_exc() )
951 main.log.info( self.name + " ::::::" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400952 main.cleanup()
953 main.exit()
954
kelvin-onlabd3b64892015-01-20 13:26:24 -0800955 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -0800956 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500957 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -0500958 a cleaner environment.
959
andrewonlab19fbdca2014-11-14 12:55:59 -0500960 Description:
Jon Hallfcc88622014-11-25 13:09:54 -0500961 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -0500962 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -0800963 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500964 try:
kelvin8ec71442015-01-15 16:57:00 -0800965 self.handle.sendline( "" )
966 self.handle.expect( "\$" )
967 self.handle.sendline( "onos-remove-raft-logs" )
968 # Sometimes this command hangs
969 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
970 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500971 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800972 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
973 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500974 if i == 1:
975 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800976 self.handle.sendline( "" )
977 self.handle.expect( "\$" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500978 return main.TRUE
979
980 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800981 main.log.error( self.name + ": EOF exception found" )
982 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -0500983 main.cleanup()
984 main.exit()
985 except:
kelvin8ec71442015-01-15 16:57:00 -0800986 main.log.info( self.name + " ::::::" )
987 main.log.error( traceback.print_exc() )
988 main.log.info( self.name + " ::::::" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500989 main.cleanup()
990 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -0500991
kelvin-onlabd3b64892015-01-20 13:26:24 -0800992 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -0800993 """
994 Calls the command 'onos-start-network [ <mininet-topo> ]
995 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -0400996 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -0800997 cell."
andrewonlab94282092014-10-10 13:00:11 -0400998 * Specify mininet topology file name for mntopo
999 * Topo files should be placed at:
1000 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001001
andrewonlab94282092014-10-10 13:00:11 -04001002 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001003 """
andrewonlab94282092014-10-10 13:00:11 -04001004 try:
1005 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001006 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001007 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001008
kelvin8ec71442015-01-15 16:57:00 -08001009 mntopo = str( mntopo )
1010 self.handle.sendline( "" )
1011 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -04001012
kelvin8ec71442015-01-15 16:57:00 -08001013 self.handle.sendline( "onos-start-network " + mntopo )
1014 self.handle.expect( "mininet>" )
1015 main.log.info( "Network started, entered mininet prompt" )
1016
1017 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001018
1019 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001020 main.log.error( self.name + ": EOF exception found" )
1021 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001022 main.cleanup()
1023 main.exit()
1024 except:
kelvin8ec71442015-01-15 16:57:00 -08001025 main.log.info( self.name + " ::::::" )
1026 main.log.error( traceback.print_exc() )
1027 main.log.info( self.name + " ::::::" )
andrewonlab94282092014-10-10 13:00:11 -04001028 main.cleanup()
1029 main.exit()
1030
kelvin8ec71442015-01-15 16:57:00 -08001031 def isup( self, node="" ):
1032 """
1033 Run's onos-wait-for-start which only returns once ONOS is at run
1034 level 100( ready for use )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001035
Jon Hall7993bfc2014-10-09 16:30:14 -04001036 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001037 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001038 try:
kelvin8ec71442015-01-15 16:57:00 -08001039 self.handle.sendline( "onos-wait-for-start " + node )
1040 self.handle.expect( "onos-wait-for-start" )
1041 # NOTE: this timeout is arbitrary"
1042 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], timeout=120 )
Jon Hall7993bfc2014-10-09 16:30:14 -04001043 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001044 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001045 return main.TRUE
1046 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001047 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001048 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001049 main.log.error( "ONOS has not started yet" )
1050 self.handle.send( "\x03" ) # Control-C
1051 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001052 return main.FALSE
1053 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001054 main.log.error( self.name + ": EOF exception found" )
1055 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001056 main.cleanup()
1057 main.exit()
1058 except:
kelvin8ec71442015-01-15 16:57:00 -08001059 main.log.info( self.name + " ::::::" )
1060 main.log.error( traceback.print_exc() )
1061 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001062 main.cleanup()
1063 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001064
kelvin-onlabd3b64892015-01-20 13:26:24 -08001065 def pushTestIntentsShell(
1066 self,
1067 dpidSrc,
1068 dpidDst,
1069 numIntents,
1070 dirFile,
1071 onosIp,
1072 numMult="",
1073 appId="",
1074 report=True,
1075 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001076 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001077 Description:
kelvin8ec71442015-01-15 16:57:00 -08001078 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001079 better parallelize the results than the CLI
1080 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001081 * dpidSrc: specify source dpid
1082 * dpidDst: specify destination dpid
1083 * numIntents: specify number of intents to push
1084 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001085 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001086 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001087 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001088 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001089 """
1090 try:
1091 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001092 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001093 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001094 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001095 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001096 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001097
kelvin-onlabd3b64892015-01-20 13:26:24 -08001098 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1099 if not numMult:
1100 addIntents = addDpid + " " + str( numIntents )
1101 elif numMult:
1102 addIntents = addDpid + " " + str( numIntents ) + " " +\
1103 str( numMult )
1104 if appId:
1105 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001106 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001107 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001108
andrewonlabaedc8332014-12-04 12:43:03 -05001109 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001110 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001111 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001112 sendCmd = addApp + " &"
1113 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001114
kelvin-onlabd3b64892015-01-20 13:26:24 -08001115 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001116
1117 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001118 main.log.error( self.name + ": EOF exception found" )
1119 main.log.error( self.name + ": " + self.handle.before )
andrewonlabb66dfa12014-12-02 15:51:10 -05001120 main.cleanup()
1121 main.exit()
1122 except:
kelvin8ec71442015-01-15 16:57:00 -08001123 main.log.info( self.name + " ::::::" )
1124 main.log.error( traceback.print_exc() )
1125 main.log.info( self.name + " ::::::" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001126 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001127 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001128
kelvin-onlabd3b64892015-01-20 13:26:24 -08001129 def getTopology( self, topologyOutput ):
kelvin8ec71442015-01-15 16:57:00 -08001130 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001131 parses the onos:topology output
kelvin8ec71442015-01-15 16:57:00 -08001132 Returns: a topology dict populated by the key values found in
Jon Hall77f53ce2014-10-13 18:02:06 -04001133 the cli command.
kelvin8ec71442015-01-15 16:57:00 -08001134 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001135 try:
kelvin8ec71442015-01-15 16:57:00 -08001136 # call the cli to get the topology summary
1137 # cmdstr = "onos:topology"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001138 # cliResult = self.onosCli( ip, cmdstr )
1139 # print "cli_result = ", cliResult
Jon Hall77f53ce2014-10-13 18:02:06 -04001140
kelvin8ec71442015-01-15 16:57:00 -08001141 # Parse the output
Jon Hall77f53ce2014-10-13 18:02:06 -04001142 topology = {}
kelvin-onlabd3b64892015-01-20 13:26:24 -08001143 # for line in cliResult.split( "\n" ):
1144 for line in topologyOutput.splitlines():
kelvin8ec71442015-01-15 16:57:00 -08001145 if not line.startswith( "time=" ):
Jon Hall77f53ce2014-10-13 18:02:06 -04001146 continue
kelvin8ec71442015-01-15 16:57:00 -08001147 # else
1148 # print line
1149 for var in line.split( "," ):
1150 # print "'"+var+"'"
1151 # print "'"+var.strip()+"'"
1152 key, value = var.strip().split( "=" )
1153 topology[ key ] = value
1154 # print "topology = ", topology
1155 # devices = topology.get( 'devices', False )
1156 # print "devices = ", devices
1157 # links = topology.get( 'links', False )
1158 # print "links = ", links
1159 # SCCs = topology.get( 'SCC(s)', False )
1160 # print "SCCs = ", SCCs
1161 # paths = topology.get( 'paths', False )
1162 # print "paths = ", paths
Jon Hall77f53ce2014-10-13 18:02:06 -04001163
1164 return topology
1165 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001166 main.log.error( self.name + ": EOF exception found" )
1167 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001168 main.cleanup()
1169 main.exit()
1170 except:
kelvin8ec71442015-01-15 16:57:00 -08001171 main.log.info( self.name + " ::::::" )
1172 main.log.error( traceback.print_exc() )
1173 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001174 main.cleanup()
1175 main.exit()
1176
kelvin-onlabd3b64892015-01-20 13:26:24 -08001177 def checkStatus(
1178 self,
1179 topologyResult,
1180 numoswitch,
1181 numolink,
1182 logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001183 """
1184 Checks the number of swithes & links that ONOS sees against the
1185 supplied values. By default this will report to main.log, but the
Jon Hall77f53ce2014-10-13 18:02:06 -04001186 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001187
Jon Hall77f53ce2014-10-13 18:02:06 -04001188 Params: ip = ip used for the onos cli
1189 numoswitch = expected number of switches
1190 numlink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001191 logLevel = level to log to.
1192 Currently accepts 'info', 'warn' and 'report'
Jon Hall77f53ce2014-10-13 18:02:06 -04001193
1194
kelvin-onlabd3b64892015-01-20 13:26:24 -08001195 logLevel can
Jon Hall77f53ce2014-10-13 18:02:06 -04001196
kelvin8ec71442015-01-15 16:57:00 -08001197 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall77f53ce2014-10-13 18:02:06 -04001198 main.FALSE if the numer of switches and links is incorrect,
1199 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001200 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001201 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001202 topology = self.getTopology( topologyResult )
Jon Hall77f53ce2014-10-13 18:02:06 -04001203 if topology == {}:
1204 return main.ERROR
1205 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001206 # Is the number of switches is what we expected
1207 devices = topology.get( 'devices', False )
1208 links = topology.get( 'links', False )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001209 if not devices or not links:
Jon Hall77f53ce2014-10-13 18:02:06 -04001210 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001211 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001212 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001213 linkCheck = ( int( links ) == int( numolink ) )
1214 if ( switchCheck and linkCheck ):
kelvin8ec71442015-01-15 16:57:00 -08001215 # We expected the correct numbers
Jon Hall77f53ce2014-10-13 18:02:06 -04001216 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001217 + "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001218 result = main.TRUE
1219 else:
1220 output = output + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001221 "The number of links and switches does not match\
1222 what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001223 result = main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001224 output = output + "\n ONOS sees %i devices (%i expected)\
1225 and %i links (%i expected)" %\
1226 ( int( devices ), int( numoswitch ),
1227 int( links ), int( numolink ) )
1228 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001229 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001230 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001231 main.log.warn( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001232 else:
kelvin8ec71442015-01-15 16:57:00 -08001233 main.log.info( output )
1234 return result
Jon Hall77f53ce2014-10-13 18:02:06 -04001235 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001236 main.log.error( self.name + ": EOF exception found" )
1237 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001238 main.cleanup()
1239 main.exit()
1240 except:
kelvin8ec71442015-01-15 16:57:00 -08001241 main.log.info( self.name + " ::::::" )
1242 main.log.error( traceback.print_exc() )
1243 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001244 main.cleanup()
1245 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001246
kelvin-onlabd3b64892015-01-20 13:26:24 -08001247 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001248 """
andrewonlab970399c2014-11-07 13:09:32 -05001249 Capture all packet activity and store in specified
1250 directory/file
1251
1252 Required:
1253 * interface: interface to capture
1254 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001255 """
1256 self.handle.sendline( "" )
1257 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001258
kelvin8ec71442015-01-15 16:57:00 -08001259 self.handle.sendline( "tshark -i " + str( interface ) +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001260 " -t e -w " + str( dirFile ) + " &" )
kelvin8ec71442015-01-15 16:57:00 -08001261 self.handle.sendline( "\r" )
1262 self.handle.expect( "Capturing on" )
1263 self.handle.sendline( "\r" )
1264 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001265
kelvin8ec71442015-01-15 16:57:00 -08001266 main.log.info( "Tshark started capturing files on " +
1267 str( interface ) + " and saving to directory: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001268 str( dirFile ) )
Shreya Shaha73aaad2014-10-27 18:03:09 -04001269
kelvin-onlabd3b64892015-01-20 13:26:24 -08001270 def runOnosTopoCfg( self, instanceName, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001271 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001272 On ONOS bench, run this command:
1273 ./~/ONOS/tools/test/bin/onos-topo-cfg $OC1 filename
1274 which starts the rest and copies
1275 the json file to the onos instance
kelvin8ec71442015-01-15 16:57:00 -08001276 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001277 try:
kelvin8ec71442015-01-15 16:57:00 -08001278 self.handle.sendline( "" )
1279 self.handle.expect( "\$" )
1280 self.handle.sendline( "cd ~/ONOS/tools/test/bin" )
1281 self.handle.expect( "/bin$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001282 cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile
shahshreyae6c7cf42014-11-26 16:39:01 -08001283 print "cmd = ", cmd
kelvin8ec71442015-01-15 16:57:00 -08001284 self.handle.sendline( cmd )
1285 self.handle.expect( "\$" )
1286 self.handle.sendline( "cd ~" )
1287 self.handle.expect( "\$" )
shahshreyae6c7cf42014-11-26 16:39:01 -08001288 return main.TRUE
1289 except:
1290 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001291
kelvin-onlabd3b64892015-01-20 13:26:24 -08001292 def tsharkGrep( self, grep, directory, interface='eth0' ):
kelvin8ec71442015-01-15 16:57:00 -08001293 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001294 Required:
kelvin8ec71442015-01-15 16:57:00 -08001295 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001296 * directory to store results
1297 Optional:
1298 * interface - default: eth0
1299 Description:
1300 Uses tshark command to grep specific group of packets
1301 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001302 The timestamp is hardcoded to be in epoch
1303 """
1304 self.handle.sendline( "" )
1305 self.handle.expect( "\$" )
1306 self.handle.sendline( "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001307 self.handle.sendline(
1308 "tshark -i " +
1309 str( interface ) +
1310 " -t e | grep --line-buffered \"" +
1311 str(grep) +
1312 "\" >" +
1313 directory +
1314 " &" )
kelvin8ec71442015-01-15 16:57:00 -08001315 self.handle.sendline( "\r" )
1316 self.handle.expect( "Capturing on" )
1317 self.handle.sendline( "\r" )
1318 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001319
kelvin-onlabd3b64892015-01-20 13:26:24 -08001320 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001321 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001322 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001323 """
1324 # Remove all pcap from previous captures
1325 self.execute( cmd="sudo rm /tmp/wireshark*" )
1326 self.handle.sendline( "" )
1327 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\" |" +
1328 " grep -v grep | awk '{print $2}'`" )
1329 self.handle.sendline( "" )
1330 main.log.info( "Tshark stopped" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001331
kelvin8ec71442015-01-15 16:57:00 -08001332 def ptpd( self, args ):
1333 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001334 Initiate ptp with user-specified args.
1335 Required:
1336 * args: specify string of args after command
1337 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001338 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001339 try:
kelvin8ec71442015-01-15 16:57:00 -08001340 self.handle.sendline( "sudo ptpd " + str( args ) )
1341 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001342 "Multiple",
1343 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001344 "\$" ] )
1345 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001346
andrewonlab0c38a4a2014-10-28 18:35:35 -04001347 if i == 0:
1348 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001349 main.log.info( "ptpd returned an error: " +
1350 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001351 return handle
1352 elif i == 1:
1353 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001354 main.log.error( "ptpd returned an error: " +
1355 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001356 return handle
1357 else:
1358 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001359
andrewonlab0c38a4a2014-10-28 18:35:35 -04001360 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001361 main.log.error( self.name + ": EOF exception found" )
1362 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001363 main.cleanup()
1364 main.exit()
1365 except:
kelvin8ec71442015-01-15 16:57:00 -08001366 main.log.info( self.name + " ::::::" )
1367 main.log.error( traceback.print_exc() )
1368 main.log.info( self.name + " ::::::" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001369 main.cleanup()
1370 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001371
kelvin-onlabd3b64892015-01-20 13:26:24 -08001372 def cpLogsToDir( self, logToCopy,
1373 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001374 """
1375 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001376 Current implementation of ONOS deletes its karaf
1377 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001378 you may want to use this function to capture
1379 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001380 Localtime will be attached to the filename
1381
1382 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001383 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001384 copy.
kelvin8ec71442015-01-15 16:57:00 -08001385 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001386 For copying multiple files, leave copyFileName
1387 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001388 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001389 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001390 ex ) /tmp/
1391 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001392 * copyFileName: If you want to rename the log
1393 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001394 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001395 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001396 try:
kelvin8ec71442015-01-15 16:57:00 -08001397 localtime = time.strftime( '%x %X' )
1398 localtime = localtime.replace( "/", "" )
1399 localtime = localtime.replace( " ", "_" )
1400 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001401 if destDir[ -1: ] != "/":
1402 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001403
kelvin-onlabd3b64892015-01-20 13:26:24 -08001404 if copyFileName:
1405 self.handle.sendline(
1406 "cp " +
1407 str( logToCopy ) +
1408 " " +
1409 str( destDir ) +
1410 str( copyFileName ) +
1411 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001412 self.handle.expect( "cp" )
1413 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001414 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001415 self.handle.sendline( "cp " + str( logToCopy ) +
1416 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001417 self.handle.expect( "cp" )
1418 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001419
kelvin8ec71442015-01-15 16:57:00 -08001420 return self.handle.before
1421
1422 except pexpect.EOF:
1423 main.log.error( "Copying files failed" )
1424 main.log.error( self.name + ": EOF exception found" )
1425 main.log.error( self.name + ": " + self.handle.before )
1426 except:
1427 main.log.error( "Copying files failed" )
1428 main.log.info( self.name + " ::::::" )
1429 main.log.error( traceback.print_exc() )
1430 main.log.info( self.name + " ::::::" )
1431
kelvin-onlabd3b64892015-01-20 13:26:24 -08001432 def checkLogs( self, onosIp ):
kelvin8ec71442015-01-15 16:57:00 -08001433 """
Jon Hall94fd0472014-12-08 11:52:42 -08001434 runs onos-check-logs on the given onos node
1435 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001436 """
Jon Hall94fd0472014-12-08 11:52:42 -08001437 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001438 cmd = "onos-check-logs " + str( onosIp )
kelvin8ec71442015-01-15 16:57:00 -08001439 self.handle.sendline( cmd )
1440 self.handle.expect( cmd )
1441 self.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -08001442 response = self.handle.before
1443 return response
1444 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001445 main.log.error( "Lost ssh connection" )
1446 main.log.error( self.name + ": EOF exception found" )
1447 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001448 except:
kelvin8ec71442015-01-15 16:57:00 -08001449 main.log.error( "Some error in check_logs:" )
1450 main.log.info( self.name + " ::::::" )
1451 main.log.error( traceback.print_exc() )
1452 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001453
kelvin-onlabd3b64892015-01-20 13:26:24 -08001454 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001455 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001456 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001457 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001458 try:
kelvin8ec71442015-01-15 16:57:00 -08001459 self.handle.sendline( "" )
1460 self.handle.expect( "\$" )
1461 self.handle.sendline( "onos-service " + str( node ) +
1462 " status" )
1463 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001464 "start/running",
1465 "stop/waiting",
kelvin8ec71442015-01-15 16:57:00 -08001466 pexpect.TIMEOUT ], timeout=120 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001467
1468 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001469 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001470 return main.TRUE
1471 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001472 main.log.info( "ONOS is stopped" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001473 return main.FALSE
1474 else:
kelvin8ec71442015-01-15 16:57:00 -08001475 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001476 main.cleanup()
1477 main.exit()
1478 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001479 main.log.error( self.name + ": EOF exception found" )
1480 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001481 main.cleanup()
1482 main.exit()
1483 except:
kelvin8ec71442015-01-15 16:57:00 -08001484 main.log.info( self.name + " ::::::" )
1485 main.log.error( traceback.print_exc() )
1486 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001487 main.cleanup()
1488 main.exit()