blob: ffed6682efaad5c7dd5f00f796bc88862c59ec0e [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
pingping-lin6d23d9e2015-02-02 16:54:24 -080024from requests.models import Response
kelvin8ec71442015-01-15 16:57:00 -080025sys.path.append( "../" )
Jon Hall05b2b432014-10-08 19:53:25 -040026from drivers.common.clidriver import CLI
27
Jon Hall05b2b432014-10-08 19:53:25 -040028
kelvin8ec71442015-01-15 16:57:00 -080029class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040030
kelvin8ec71442015-01-15 16:57:00 -080031 def __init__( self ):
32 """
33 Initialize client
34 """
35 super( CLI, self ).__init__()
36
37 def connect( self, **connectargs ):
38 """
Jon Hall05b2b432014-10-08 19:53:25 -040039 Creates ssh handle for ONOS "bench".
kelvin8ec71442015-01-15 16:57:00 -080040 """
Jon Hall05b2b432014-10-08 19:53:25 -040041 try:
42 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080043 vars( self )[ key ] = connectargs[ key ]
Jon Hall05b2b432014-10-08 19:53:25 -040044 self.home = "~/ONOS"
45 for key in self.options:
46 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080047 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040048 break
49
kelvin8ec71442015-01-15 16:57:00 -080050 self.name = self.options[ 'name' ]
51 self.handle = super( OnosDriver, self ).connect(
52 user_name=self.user_name,
kelvin-onlab08679eb2015-01-21 16:11:48 -080053 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -080054 port=self.port,
55 pwd=self.pwd,
56 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -040057
kelvin8ec71442015-01-15 16:57:00 -080058 self.handle.sendline( "cd " + self.home )
59 self.handle.expect( "\$" )
Jon Hall05b2b432014-10-08 19:53:25 -040060 if self.handle:
61 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080062 else:
63 main.log.info( "NO ONOS HANDLE" )
Jon Hall05b2b432014-10-08 19:53:25 -040064 return main.FALSE
65 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080066 main.log.error( self.name + ": EOF exception found" )
67 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040068 main.cleanup()
69 main.exit()
70 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -080071 main.log.info( self.name + ":" * 30 )
Jon Hall05b2b432014-10-08 19:53:25 -040072 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -080073 main.log.info( ":" * 30 )
Jon Hall05b2b432014-10-08 19:53:25 -040074 main.cleanup()
75 main.exit()
76
kelvin8ec71442015-01-15 16:57:00 -080077 def disconnect( self ):
78 """
Jon Hall05b2b432014-10-08 19:53:25 -040079 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080080 """
Jon Hall05b2b432014-10-08 19:53:25 -040081 response = ''
82 try:
kelvin8ec71442015-01-15 16:57:00 -080083 self.handle.sendline( "" )
84 self.handle.expect( "\$" )
85 self.handle.sendline( "exit" )
86 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -040087 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080088 main.log.error( self.name + ": EOF exception found" )
89 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040090 except:
kelvin8ec71442015-01-15 16:57:00 -080091 main.log.error( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -040092 response = main.FALSE
93 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040094
pingping-lin57a56ce2015-05-20 16:43:48 -070095 def onosPackage( self, opTimeout=30 ):
kelvin8ec71442015-01-15 16:57:00 -080096 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040097 Produce a self-contained tar.gz file that can be deployed
kelvin8ec71442015-01-15 16:57:00 -080098 and executed on any platform with Java 7 JRE.
99 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400100 try:
kelvin8ec71442015-01-15 16:57:00 -0800101 self.handle.sendline( "onos-package" )
102 self.handle.expect( "onos-package" )
pingping-lin57a56ce2015-05-20 16:43:48 -0700103 self.handle.expect( "tar.gz", opTimeout )
kelvin8ec71442015-01-15 16:57:00 -0800104 handle = str( self.handle.before )
105 main.log.info( "onos-package command returned: " +
106 handle )
107 # As long as the sendline does not time out,
108 # return true. However, be careful to interpret
109 # the results of the onos-package command return
andrewonlab0748d2a2014-10-09 13:24:17 -0400110 return main.TRUE
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400111
andrewonlab7735d852014-10-09 13:02:47 -0400112 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800113 main.log.error( self.name + ": EOF exception found" )
114 main.log.error( self.name + ": " + self.handle.before )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400115 except:
kelvin8ec71442015-01-15 16:57:00 -0800116 main.log.error( "Failed to package ONOS" )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400117 main.cleanup()
118 main.exit()
119
kelvin-onlabd3b64892015-01-20 13:26:24 -0800120 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800121 """
andrewonlab8790abb2014-11-06 13:51:54 -0500122 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800123 """
andrewonlab8790abb2014-11-06 13:51:54 -0500124 try:
kelvin8ec71442015-01-15 16:57:00 -0800125 self.handle.sendline( "onos-build" )
126 self.handle.expect( "onos-build" )
127 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800128 "BUILD SUCCESS",
129 "ERROR",
130 "BUILD FAILED" ],
131 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800132 handle = str( self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500133
kelvin8ec71442015-01-15 16:57:00 -0800134 main.log.info( "onos-build command returned: " +
135 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500136
137 if i == 0:
138 return main.TRUE
139 else:
140 return handle
141
142 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800143 main.log.error( self.name + ": EOF exception found" )
144 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500145 except:
kelvin8ec71442015-01-15 16:57:00 -0800146 main.log.error( "Failed to build ONOS" )
andrewonlab8790abb2014-11-06 13:51:54 -0500147 main.cleanup()
148 main.exit()
149
pingping-lin57a56ce2015-05-20 16:43:48 -0700150 def cleanInstall( self, mciTimeout=600 ):
kelvin8ec71442015-01-15 16:57:00 -0800151 """
152 Runs mvn clean install in the root of the ONOS directory.
153 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400154
kelvin8ec71442015-01-15 16:57:00 -0800155 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400156 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800157 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400158 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800159 main.log.info( "Running 'mvn clean install' on " +
160 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800161 ". This may take some time." )
162 self.handle.sendline( "cd " + self.home )
163 self.handle.expect( "\$" )
Jon Hallea7818b2014-10-09 14:30:59 -0400164
kelvin8ec71442015-01-15 16:57:00 -0800165 self.handle.sendline( "" )
166 self.handle.expect( "\$" )
167 self.handle.sendline( "mvn clean install" )
168 self.handle.expect( "mvn clean install" )
169 while True:
170 i = self.handle.expect( [
Jon Hallde9d9aa2014-10-08 20:36:02 -0400171 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\
172 Runtime\sEnvironment\sto\scontinue',
173 'BUILD\sFAILURE',
174 'BUILD\sSUCCESS',
175 'ONOS\$',
pingping-lin57a56ce2015-05-20 16:43:48 -0700176 pexpect.TIMEOUT ], mciTimeout )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400177 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800178 main.log.error( self.name + ":There is insufficient memory \
179 for the Java Runtime Environment to continue." )
180 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400181 main.cleanup()
182 main.exit()
183 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800184 main.log.error( self.name + ": Build failure!" )
185 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400186 main.cleanup()
187 main.exit()
188 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800189 main.log.info( self.name + ": Build success!" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400190 elif i == 3:
kelvin8ec71442015-01-15 16:57:00 -0800191 main.log.info( self.name + ": Build complete" )
192 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400193 for line in self.handle.before.splitlines():
194 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800195 main.log.info( line )
196 self.handle.sendline( "" )
197 self.handle.expect( "\$", timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400198 return main.TRUE
199 elif i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800200 main.log.error(
201 self.name +
202 ": mvn clean install TIMEOUT!" )
203 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400204 main.cleanup()
205 main.exit()
206 else:
kelvin8ec71442015-01-15 16:57:00 -0800207 main.log.error( self.name + ": unexpected response from \
208 mvn clean install" )
209 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400210 main.cleanup()
211 main.exit()
212 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800213 main.log.error( self.name + ": EOF exception found" )
214 main.log.error( self.name + ": " + self.handle.before )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400215 main.cleanup()
216 main.exit()
217 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800218 main.log.info( self.name + ":" * 60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400219 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800220 main.log.info( ":" * 60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400221 main.cleanup()
222 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400223
kelvin-onlabd3b64892015-01-20 13:26:24 -0800224 def gitPull( self, comp1="" ):
kelvin8ec71442015-01-15 16:57:00 -0800225 """
Jon Hallacabffd2014-10-09 12:36:53 -0400226 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800227
Jon Hallacabffd2014-10-09 12:36:53 -0400228 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800229 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400230 for the purpose of pulling from other nodes if necessary.
231
Jon Hall47a93fb2015-01-06 16:46:06 -0800232 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400233 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800234 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400235 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400236
kelvin8ec71442015-01-15 16:57:00 -0800237 """
Jon Hallacabffd2014-10-09 12:36:53 -0400238 try:
kelvin8ec71442015-01-15 16:57:00 -0800239 # main.log.info( self.name + ": Stopping ONOS" )
240 # self.stop()
241 self.handle.sendline( "cd " + self.home )
242 self.handle.expect( "ONOS\$" )
243 if comp1 == "":
244 self.handle.sendline( "git pull" )
Jon Hallacabffd2014-10-09 12:36:53 -0400245 else:
kelvin8ec71442015-01-15 16:57:00 -0800246 self.handle.sendline( "git pull " + comp1 )
Jon Hall47a93fb2015-01-06 16:46:06 -0800247
kelvin-onlabd3b64892015-01-20 13:26:24 -0800248 i = self.handle.expect(
249 [
250 'fatal',
251 'Username\sfor\s(.*):\s',
252 '\sfile(s*) changed,\s',
253 'Already up-to-date',
254 'Aborting',
255 'You\sare\snot\scurrently\son\sa\sbranch',
256 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\
257 \sbranch\syou',
258 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\
259 \sfiles',
260 pexpect.TIMEOUT ],
261 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800262 # debug
kelvin-onlabd3b64892015-01-20 13:26:24 -0800263 # main.log.report( self.name +": DEBUG: \n"+
264 # "git pull response: " +
265 # str( self.handle.before ) + str( self.handle.after ) )
kelvin8ec71442015-01-15 16:57:00 -0800266 if i == 0:
267 main.log.error( self.name + ": Git pull had some issue..." )
Jon Hallacabffd2014-10-09 12:36:53 -0400268 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800269 elif i == 1:
270 main.log.error(
271 self.name +
272 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400273 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800274 elif i == 2:
275 main.log.info(
276 self.name +
277 ": Git Pull - pulling repository now" )
278 self.handle.expect( "ONOS\$", 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800279 # So that only when git pull is done, we do mvn clean compile
280 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800281 elif i == 3:
282 main.log.info( self.name + ": Git Pull - Already up to date" )
Jon Hall47a93fb2015-01-06 16:46:06 -0800283 return i
kelvin8ec71442015-01-15 16:57:00 -0800284 elif i == 4:
285 main.log.info(
286 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800287 ": Git Pull - Aborting...\
288 Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400289 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800290 elif i == 5:
291 main.log.info(
292 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800293 ": Git Pull - You are not currently\
294 on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400295 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800296 elif i == 6:
297 main.log.info(
298 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800299 ": Git Pull - You have not configured\
300 an upstream branch to pull from\
301 . Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400302 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800303 elif i == 7:
304 main.log.info(
305 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800306 ": Git Pull - Pull is not possible\
307 because you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400308 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800309 elif i == 8:
310 main.log.error( self.name + ": Git Pull - TIMEOUT" )
311 main.log.error(
312 self.name + " Response was: " + str(
313 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400314 return main.ERROR
315 else:
kelvin8ec71442015-01-15 16:57:00 -0800316 main.log.error(
317 self.name +
318 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400319 return main.ERROR
320 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800321 main.log.error( self.name + ": EOF exception found" )
322 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400323 main.cleanup()
324 main.exit()
325 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800326 main.log.info( self.name + ":" * 60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400327 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800328 main.log.info( ":" * 80 )
Jon Hallacabffd2014-10-09 12:36:53 -0400329 main.cleanup()
330 main.exit()
331
kelvin-onlabd3b64892015-01-20 13:26:24 -0800332 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800333 """
Jon Hallacabffd2014-10-09 12:36:53 -0400334 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800335
Jon Hallacabffd2014-10-09 12:36:53 -0400336 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800337 If used as gitCheckout( "branch" ) it will do git checkout
338 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400339
340 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800341 branch of the ONOS repository. If it has any problems, it will return
342 main.ERROR.
343 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400344 successful then the function will return main.TRUE.
345
kelvin8ec71442015-01-15 16:57:00 -0800346 """
Jon Hallacabffd2014-10-09 12:36:53 -0400347 try:
kelvin8ec71442015-01-15 16:57:00 -0800348 self.handle.sendline( "cd " + self.home )
349 self.handle.expect( "ONOS\$" )
350 main.log.info(
351 self.name +
352 ": Checking out git branch: " +
353 branch +
354 "..." )
355 cmd = "git checkout " + branch
356 self.handle.sendline( cmd )
357 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800358 i = self.handle.expect(
359 [
360 'fatal',
361 'Username\sfor\s(.*):\s',
362 'Already\son\s\'',
363 'Switched\sto\sbranch\s\'' +
364 str( branch ),
365 pexpect.TIMEOUT,
366 'error: Your local changes to the following files\
367 would be overwritten by checkout:',
368 'error: you need to resolve your current index first' ],
369 timeout=60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400370
kelvin8ec71442015-01-15 16:57:00 -0800371 if i == 0:
372 main.log.error(
373 self.name +
374 ": Git checkout had some issue..." )
375 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400376 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800377 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800378 main.log.error(
379 self.name +
380 ": Git checkout asking for username." +
381 " Please configure your local git repository to be able " +
382 "to access your remote repository passwordlessly" )
Jon Hallacabffd2014-10-09 12:36:53 -0400383 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800384 elif i == 2:
385 main.log.info(
386 self.name +
387 ": Git Checkout %s : Already on this branch" %
388 branch )
389 self.handle.expect( "ONOS\$" )
390 # main.log.info( "DEBUG: after checkout cmd = "+
391 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400392 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800393 elif i == 3:
394 main.log.info(
395 self.name +
396 ": Git checkout %s - Switched to this branch" %
397 branch )
398 self.handle.expect( "ONOS\$" )
399 # main.log.info( "DEBUG: after checkout cmd = "+
400 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400401 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800402 elif i == 4:
403 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
404 main.log.error(
405 self.name + " Response was: " + str(
406 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400407 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800408 elif i == 5:
409 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800410 main.log.error(
411 self.name +
412 ": Git checkout error: \n" +
413 "Your local changes to the following\
414 files would be overwritten by checkout:" +
415 str(
416 self.handle.before ) )
kelvin8ec71442015-01-15 16:57:00 -0800417 self.handle.expect( "ONOS\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500418 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800419 elif i == 6:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800420 main.log.error( self.name +
421 ": Git checkout error: \n" +
422 "You need to resolve your\
423 current index first:" +
kelvin8ec71442015-01-15 16:57:00 -0800424 str( self.handle.before ) )
425 self.handle.expect( "ONOS\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500426 return main.ERROR
Jon Hallacabffd2014-10-09 12:36:53 -0400427 else:
kelvin8ec71442015-01-15 16:57:00 -0800428 main.log.error(
429 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800430 ": Git Checkout - Unexpected response,\
431 check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800432 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400433 return main.ERROR
434
435 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800436 main.log.error( self.name + ": EOF exception found" )
437 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400438 main.cleanup()
439 main.exit()
440 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800441 main.log.info( self.name + ":" * 60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400442 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800443 main.log.info( ":" * 80 )
Jon Hallacabffd2014-10-09 12:36:53 -0400444 main.cleanup()
445 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400446
pingping-lin6d23d9e2015-02-02 16:54:24 -0800447 def getBranchName( self ):
448 self.handle.sendline( "cd " + self.home )
449 self.handle.expect( "ONOS\$" )
450 self.handle.sendline( "git name-rev --name-only HEAD" )
451 self.handle.expect( "git name-rev --name-only HEAD" )
452 self.handle.expect( "\$" )
453
454 lines = self.handle.before.splitlines()
455 if lines[1] == "master":
456 return "master"
457 elif lines[1] == "onos-1.0":
458 return "onos-1.0"
459 else:
460 main.log.info( lines[1] )
461 return "unexpected ONOS branch for SDN-IP test"
462
kelvin-onlabd3b64892015-01-20 13:26:24 -0800463 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800464 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800465 Writes the COMMIT number to the report to be parsed\
466 by Jenkins data collecter.
kelvin8ec71442015-01-15 16:57:00 -0800467 """
Jon Hall45ec0922014-10-10 19:33:49 -0400468 try:
kelvin8ec71442015-01-15 16:57:00 -0800469 self.handle.sendline( "" )
470 self.handle.expect( "\$" )
471 self.handle.sendline(
472 "cd " +
473 self.home +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800474 "; git log -1 --pretty=fuller --decorate=short | grep -A 6\
475 \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800476 # NOTE: for some reason there are backspaces inserted in this
477 # phrase when run from Jenkins on some tests
478 self.handle.expect( "never" )
479 self.handle.expect( "\$" )
480 response = ( self.name + ": \n" + str(
481 self.handle.before + self.handle.after ) )
482 self.handle.sendline( "cd " + self.home )
483 self.handle.expect( "\$" )
484 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400485 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500486 print line
487 if report:
kelvin8ec71442015-01-15 16:57:00 -0800488 for line in lines[ 2:-1 ]:
489 # Bracket replacement is for Wiki-compliant
490 # formatting. '<' or '>' are interpreted
491 # as xml specific tags that cause errors
492 line = line.replace( "<", "[" )
493 line = line.replace( ">", "]" )
494 main.log.report( "\t" + line )
495 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400496 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800497 main.log.error( self.name + ": EOF exception found" )
498 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400499 main.cleanup()
500 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800501 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800502 main.log.error( self.name + ": TIMEOUT exception found" )
503 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800504 main.cleanup()
505 main.exit()
Jon Hall45ec0922014-10-10 19:33:49 -0400506 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800507 main.log.info( self.name + ":" * 60 )
Jon Hall45ec0922014-10-10 19:33:49 -0400508 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800509 main.log.info( ":" * 80 )
Jon Hall45ec0922014-10-10 19:33:49 -0400510 main.cleanup()
511 main.exit()
512
kelvin-onlabd3b64892015-01-20 13:26:24 -0800513 def createCellFile( self, benchIp, fileName, mnIpAddrs,
514 extraFeatureString, *onosIpAddrs ):
kelvin8ec71442015-01-15 16:57:00 -0800515 """
andrewonlab94282092014-10-10 13:00:11 -0400516 Creates a cell file based on arguments
517 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800518 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400519 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800520 * File name of the cell file ( fileName )
521 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800522 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400523 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800524 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400525 - Must be passed in as last arguments
kelvin8ec71442015-01-15 16:57:00 -0800526
andrewonlab94282092014-10-10 13:00:11 -0400527 NOTE: Assumes cells are located at:
528 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800529 """
530 # Variable initialization
kelvin-onlabd3b64892015-01-20 13:26:24 -0800531 cellDirectory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800532 # We want to create the cell file in the dependencies directory
533 # of TestON first, then copy over to ONOS bench
kelvin-onlabd3b64892015-01-20 13:26:24 -0800534 tempDirectory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800535 # Create the cell file in the directory for writing ( w+ )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800536 cellFile = open( tempDirectory + fileName, 'w+' )
kelvin8ec71442015-01-15 16:57:00 -0800537
538 # Feature string is hardcoded environment variables
539 # That you may wish to use by default on startup.
540 # Note that you may not want certain features listed
541 # on here.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800542 coreFeatureString = "export ONOS_FEATURES=webconsole,onos-api," +\
543 "onos-cli,onos-openflow," + extraFeatureString
544 mnString = "export OCN="
545 onosString = "export OC"
546 tempCount = 1
kelvin8ec71442015-01-15 16:57:00 -0800547
kelvin-onlabd3b64892015-01-20 13:26:24 -0800548 # Create ONOSNIC ip address prefix
549 tempOnosIp = onosIpAddrs[ 0 ]
550 tempList = []
551 tempList = tempOnosIp.split( "." )
kelvin8ec71442015-01-15 16:57:00 -0800552 # Omit last element of list to format for NIC
kelvin-onlabd3b64892015-01-20 13:26:24 -0800553 tempList = tempList[ :-1 ]
kelvin8ec71442015-01-15 16:57:00 -0800554 # Structure the nic string ip
kelvin-onlabd3b64892015-01-20 13:26:24 -0800555 nicAddr = ".".join( tempList ) + ".*"
556 onosNicString = "export ONOS_NIC=" + nicAddr
andrewonlab94282092014-10-10 13:00:11 -0400557
558 try:
kelvin8ec71442015-01-15 16:57:00 -0800559 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800560 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400561
kelvin-onlabd3b64892015-01-20 13:26:24 -0800562 for arg in onosIpAddrs:
563 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800564 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400565 # export OC1="10.128.20.11"
566 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800567 cellFile.write( onosString + str( tempCount ) +
568 "=" + "\"" + arg + "\"" + "\n" )
569 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800570
kelvin-onlabd3b64892015-01-20 13:26:24 -0800571 cellFile.write( mnString + "\"" + mnIpAddrs + "\"" + "\n" )
572 cellFile.write( coreFeatureString + "\n" )
573 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400574
kelvin8ec71442015-01-15 16:57:00 -0800575 # We use os.system to send the command to TestON cluster
576 # to account for the case in which TestON is not located
577 # on the same cluster as the ONOS bench
578 # Note that even if TestON is located on the same cluster
579 # as ONOS bench, you must setup passwordless ssh
580 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800581 os.system( "scp " + tempDirectory + fileName +
582 " admin@" + benchIp + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400583
andrewonlab2a6c9342014-10-16 13:40:15 -0400584 return main.TRUE
585
andrewonlab94282092014-10-10 13:00:11 -0400586 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800587 main.log.error( self.name + ": EOF exception found" )
588 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -0400589 main.cleanup()
590 main.exit()
591 except:
kelvin8ec71442015-01-15 16:57:00 -0800592 main.log.info( self.name + ":::::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400593 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800594 main.log.info( ":::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400595 main.cleanup()
596 main.exit()
597
kelvin-onlabd3b64892015-01-20 13:26:24 -0800598 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800599 """
andrewonlab95ca1462014-10-09 14:04:24 -0400600 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800601 """
andrewonlab95ca1462014-10-09 14:04:24 -0400602 try:
603 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800604 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400605 main.cleanup()
606 main.exit()
607 else:
kelvin8ec71442015-01-15 16:57:00 -0800608 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800609 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800610 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400611 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800612 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800613 handleBefore = self.handle.before
614 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800615 # Get the rest of the handle
616 self.handle.sendline( "" )
617 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800618 handleMore = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400619
kelvin-onlabd3b64892015-01-20 13:26:24 -0800620 main.log.info( "Cell call returned: " + handleBefore +
621 handleAfter + handleMore )
andrewonlab95ca1462014-10-09 14:04:24 -0400622
623 return main.TRUE
624
625 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800626 main.log.error( self.name + ": EOF exception found" )
627 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400628 main.cleanup()
629 main.exit()
630 except:
kelvin8ec71442015-01-15 16:57:00 -0800631 main.log.info( self.name + " ::::::" )
632 main.log.error( traceback.print_exc() )
633 main.log.info( self.name + " ::::::" )
andrewonlab95ca1462014-10-09 14:04:24 -0400634 main.cleanup()
635 main.exit()
636
kelvin-onlabd3b64892015-01-20 13:26:24 -0800637 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800638 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400639 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800640 """
641 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400642
andrewonlabc03bf6c2014-10-09 14:56:18 -0400643 try:
kelvin8ec71442015-01-15 16:57:00 -0800644 # Clean handle by sending empty and expecting $
645 self.handle.sendline( "" )
646 self.handle.expect( "\$" )
647 self.handle.sendline( "onos-verify-cell" )
648 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800649 handleBefore = self.handle.before
650 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800651 # Get the rest of the handle
652 self.handle.sendline( "" )
653 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800654 handleMore = self.handle.before
andrewonlabc03bf6c2014-10-09 14:56:18 -0400655
kelvin-onlabd3b64892015-01-20 13:26:24 -0800656 main.log.info( "Verify cell returned: " + handleBefore +
657 handleAfter + handleMore )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400658
659 return main.TRUE
Jon Hall7993bfc2014-10-09 16:30:14 -0400660 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800661 main.log.error( self.name + ": EOF exception found" )
662 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400663 main.cleanup()
664 main.exit()
665 except:
kelvin8ec71442015-01-15 16:57:00 -0800666 main.log.info( self.name + " ::::::" )
667 main.log.error( traceback.print_exc() )
668 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400669 main.cleanup()
670 main.exit()
671
kelvin-onlabd3b64892015-01-20 13:26:24 -0800672 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800673 """
andrewonlab05e362f2014-10-10 00:40:57 -0400674 Uses 'onos' command to send various ONOS CLI arguments.
675 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800676 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400677 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800678
679 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400680 CLI commands for ONOS. Try to use this function first
681 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800682 function.
683 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400684 by starting onos, and typing in 'onos' to enter the
685 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800686 available commands.
687 """
andrewonlab05e362f2014-10-10 00:40:57 -0400688 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800689 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800690 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400691 return main.FALSE
692 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800693 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400694 return main.FALSE
695
kelvin8ec71442015-01-15 16:57:00 -0800696 cmdstr = str( cmdstr )
697 self.handle.sendline( "" )
698 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400699
kelvin-onlabd3b64892015-01-20 13:26:24 -0800700 self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr )
kelvin8ec71442015-01-15 16:57:00 -0800701 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400702
kelvin-onlabd3b64892015-01-20 13:26:24 -0800703 handleBefore = self.handle.before
Shreya Shaha73aaad2014-10-27 18:03:09 -0400704 print "handle_before = ", self.handle.before
kelvin-onlabd3b64892015-01-20 13:26:24 -0800705 # handleAfter = str( self.handle.after )
Jon Hall47a93fb2015-01-06 16:46:06 -0800706
kelvin8ec71442015-01-15 16:57:00 -0800707 # self.handle.sendline( "" )
708 # self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800709 # handleMore = str( self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400710
kelvin8ec71442015-01-15 16:57:00 -0800711 main.log.info( "Command sent successfully" )
andrewonlab05e362f2014-10-10 00:40:57 -0400712
kelvin8ec71442015-01-15 16:57:00 -0800713 # Obtain return handle that consists of result from
714 # the onos command. The string may need to be
715 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800716 # returnString = handleBefore + handleAfter
717 returnString = handleBefore
718 print "return_string = ", returnString
719 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400720
721 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800722 main.log.error( self.name + ": EOF exception found" )
723 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400724 main.cleanup()
725 main.exit()
726 except:
kelvin8ec71442015-01-15 16:57:00 -0800727 main.log.info( self.name + " ::::::" )
728 main.log.error( traceback.print_exc() )
729 main.log.info( self.name + " ::::::" )
andrewonlab05e362f2014-10-10 00:40:57 -0400730 main.cleanup()
731 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400732
kelvin-onlabd3b64892015-01-20 13:26:24 -0800733 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -0800734 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400735 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800736 If -f option is provided, it also forces an uninstall.
737 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400738 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800739 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400740 files to certain onos nodes
741
742 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800743 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400744 try:
andrewonlab114768a2014-11-14 12:44:44 -0500745 if options:
kelvin8ec71442015-01-15 16:57:00 -0800746 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500747 else:
kelvin8ec71442015-01-15 16:57:00 -0800748 self.handle.sendline( "onos-install " + node )
749 self.handle.expect( "onos-install " )
750 # NOTE: this timeout may need to change depending on the network
751 # and size of ONOS
752 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800753 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -0800754 "ONOS\sis\salready\sinstalled",
755 pexpect.TIMEOUT ], timeout=60 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400756
Jon Hall7993bfc2014-10-09 16:30:14 -0400757 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800758 main.log.warn( "Network is unreachable" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400759 return main.FALSE
760 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800761 main.log.info(
762 "ONOS was installed on " +
763 node +
764 " and started" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400765 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500766 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800767 main.log.info( "ONOS is already installed on " + node )
andrewonlabd9a73a72014-11-14 17:28:21 -0500768 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800769 elif i == 3:
770 main.log.info(
771 "Installation of ONOS on " +
772 node +
773 " timed out" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400774 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400775
776 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800777 main.log.error( self.name + ": EOF exception found" )
778 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400779 main.cleanup()
780 main.exit()
781 except:
kelvin8ec71442015-01-15 16:57:00 -0800782 main.log.info( self.name + " ::::::" )
783 main.log.error( traceback.print_exc() )
784 main.log.info( self.name + " ::::::" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400785 main.cleanup()
786 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400787
kelvin-onlabd3b64892015-01-20 13:26:24 -0800788 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800789 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400790 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400791 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800792 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400793 try:
kelvin8ec71442015-01-15 16:57:00 -0800794 self.handle.sendline( "" )
795 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800796 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800797 " start" )
798 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -0400799 "Job\sis\salready\srunning",
800 "start/running",
801 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800802 pexpect.TIMEOUT ], timeout=120 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400803
804 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800805 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400806 return main.TRUE
807 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800808 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400809 return main.TRUE
810 else:
kelvin8ec71442015-01-15 16:57:00 -0800811 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400812 main.cleanup()
813 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400814 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800815 main.log.error( self.name + ": EOF exception found" )
816 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400817 main.cleanup()
818 main.exit()
819 except:
kelvin8ec71442015-01-15 16:57:00 -0800820 main.log.info( self.name + " ::::::" )
821 main.log.error( traceback.print_exc() )
822 main.log.info( self.name + " ::::::" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400823 main.cleanup()
824 main.exit()
825
kelvin-onlabd3b64892015-01-20 13:26:24 -0800826 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800827 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400828 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400829 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800830 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400831 try:
kelvin8ec71442015-01-15 16:57:00 -0800832 self.handle.sendline( "" )
833 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800834 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800835 " stop" )
836 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -0400837 "stop/waiting",
838 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800839 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2b30bd32014-10-09 16:48:55 -0400840
841 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800842 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400843 return main.TRUE
844 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800845 main.log.info( "Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800846 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -0400847 return main.FALSE
848 else:
kelvin8ec71442015-01-15 16:57:00 -0800849 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400850 return main.FALSE
851
852 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800853 main.log.error( self.name + ": EOF exception found" )
854 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -0400855 main.cleanup()
856 main.exit()
857 except:
kelvin8ec71442015-01-15 16:57:00 -0800858 main.log.info( self.name + " ::::::" )
859 main.log.error( traceback.print_exc() )
860 main.log.info( self.name + " ::::::" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400861 main.cleanup()
862 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800863
kelvin-onlabd3b64892015-01-20 13:26:24 -0800864 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -0800865 """
andrewonlabc8d47972014-10-09 16:52:36 -0400866 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -0800867 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -0400868 if needed
kelvin8ec71442015-01-15 16:57:00 -0800869 """
andrewonlabc8d47972014-10-09 16:52:36 -0400870 try:
kelvin8ec71442015-01-15 16:57:00 -0800871 self.handle.sendline( "" )
872 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800873 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800874 self.handle.expect( "\$" )
andrewonlabc8d47972014-10-09 16:52:36 -0400875
kelvin-onlabd3b64892015-01-20 13:26:24 -0800876 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
andrewonlab9dfd2082014-11-13 17:44:03 -0500877
kelvin8ec71442015-01-15 16:57:00 -0800878 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -0400879 return main.TRUE
880
881 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800882 main.log.error( self.name + ": EOF exception found" )
883 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -0400884 main.cleanup()
885 main.exit()
886 except:
kelvin8ec71442015-01-15 16:57:00 -0800887 main.log.info( self.name + " ::::::" )
888 main.log.error( traceback.print_exc() )
889 main.log.info( self.name + " ::::::" )
andrewonlabc8d47972014-10-09 16:52:36 -0400890 main.cleanup()
891 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400892
kelvin-onlabd3b64892015-01-20 13:26:24 -0800893 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800894 """
andrewonlabaedc8332014-12-04 12:43:03 -0500895 Issues the command 'onos-die <node-ip>'
896 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -0800897 """
andrewonlabaedc8332014-12-04 12:43:03 -0500898 try:
kelvin8ec71442015-01-15 16:57:00 -0800899 self.handle.sendline( "" )
900 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800901 cmdStr = "onos-kill " + str( nodeIp )
902 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800903 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -0500904 "Killing\sONOS",
905 "ONOS\sprocess\sis\snot\srunning",
kelvin8ec71442015-01-15 16:57:00 -0800906 pexpect.TIMEOUT ], timeout=20 )
andrewonlabaedc8332014-12-04 12:43:03 -0500907 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800908 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800909 " was killed and stopped" )
andrewonlabaedc8332014-12-04 12:43:03 -0500910 return main.TRUE
911 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800912 main.log.info( "ONOS process was not running" )
andrewonlabaedc8332014-12-04 12:43:03 -0500913 return main.FALSE
914 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800915 main.log.error( self.name + ": EOF exception found" )
916 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -0500917 main.cleanup()
918 main.exit()
919 except:
kelvin8ec71442015-01-15 16:57:00 -0800920 main.log.info( self.name + " ::::::" )
921 main.log.error( traceback.print_exc() )
922 main.log.info( self.name + " ::::::" )
andrewonlabaedc8332014-12-04 12:43:03 -0500923 main.cleanup()
924 main.exit()
925
kelvin-onlabd3b64892015-01-20 13:26:24 -0800926 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800927 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400928 Calls the command: 'onos-kill [<node-ip>]'
929 "Remotely, and unceremoniously kills the ONOS instance running on
930 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -0800931 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400932 try:
kelvin8ec71442015-01-15 16:57:00 -0800933 self.handle.sendline( "" )
934 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800935 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800936 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -0400937 "\$",
938 "No\sroute\sto\shost",
939 "password:",
kelvin8ec71442015-01-15 16:57:00 -0800940 pexpect.TIMEOUT ], timeout=20 )
941
andrewonlabe8e56fd2014-10-09 17:12:44 -0400942 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800943 main.log.info(
944 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800945 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400946 return main.TRUE
947 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800948 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400949 return main.FALSE
950 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800951 main.log.info(
952 "Passwordless login for host: " +
953 str( nodeIp ) +
954 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400955 return main.FALSE
956 else:
kelvin8ec71442015-01-15 16:57:00 -0800957 main.log.info( "ONOS instasnce was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400958 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800959
andrewonlabe8e56fd2014-10-09 17:12:44 -0400960 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800961 main.log.error( self.name + ": EOF exception found" )
962 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400963 main.cleanup()
964 main.exit()
965 except:
kelvin8ec71442015-01-15 16:57:00 -0800966 main.log.info( self.name + " ::::::" )
967 main.log.error( traceback.print_exc() )
968 main.log.info( self.name + " ::::::" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400969 main.cleanup()
970 main.exit()
971
kelvin-onlabd3b64892015-01-20 13:26:24 -0800972 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -0800973 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500974 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -0500975 a cleaner environment.
976
andrewonlab19fbdca2014-11-14 12:55:59 -0500977 Description:
Jon Hallfcc88622014-11-25 13:09:54 -0500978 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -0500979 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -0800980 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500981 try:
kelvin8ec71442015-01-15 16:57:00 -0800982 self.handle.sendline( "" )
983 self.handle.expect( "\$" )
984 self.handle.sendline( "onos-remove-raft-logs" )
985 # Sometimes this command hangs
986 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
987 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500988 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800989 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
990 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500991 if i == 1:
992 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800993 self.handle.sendline( "" )
994 self.handle.expect( "\$" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500995 return main.TRUE
996
997 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800998 main.log.error( self.name + ": EOF exception found" )
999 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -05001000 main.cleanup()
1001 main.exit()
1002 except:
kelvin8ec71442015-01-15 16:57:00 -08001003 main.log.info( self.name + " ::::::" )
1004 main.log.error( traceback.print_exc() )
1005 main.log.info( self.name + " ::::::" )
andrewonlab19fbdca2014-11-14 12:55:59 -05001006 main.cleanup()
1007 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -05001008
kelvin-onlabd3b64892015-01-20 13:26:24 -08001009 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -08001010 """
1011 Calls the command 'onos-start-network [ <mininet-topo> ]
1012 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -04001013 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -08001014 cell."
andrewonlab94282092014-10-10 13:00:11 -04001015 * Specify mininet topology file name for mntopo
1016 * Topo files should be placed at:
1017 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001018
andrewonlab94282092014-10-10 13:00:11 -04001019 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001020 """
andrewonlab94282092014-10-10 13:00:11 -04001021 try:
1022 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001023 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001024 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001025
kelvin8ec71442015-01-15 16:57:00 -08001026 mntopo = str( mntopo )
1027 self.handle.sendline( "" )
1028 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -04001029
kelvin8ec71442015-01-15 16:57:00 -08001030 self.handle.sendline( "onos-start-network " + mntopo )
1031 self.handle.expect( "mininet>" )
1032 main.log.info( "Network started, entered mininet prompt" )
1033
1034 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001035
1036 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001037 main.log.error( self.name + ": EOF exception found" )
1038 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001039 main.cleanup()
1040 main.exit()
1041 except:
kelvin8ec71442015-01-15 16:57:00 -08001042 main.log.info( self.name + " ::::::" )
1043 main.log.error( traceback.print_exc() )
1044 main.log.info( self.name + " ::::::" )
andrewonlab94282092014-10-10 13:00:11 -04001045 main.cleanup()
1046 main.exit()
1047
pingping-lin57a56ce2015-05-20 16:43:48 -07001048 def isup( self, node="", onosWaitStartTimeout=120 ):
kelvin8ec71442015-01-15 16:57:00 -08001049 """
1050 Run's onos-wait-for-start which only returns once ONOS is at run
1051 level 100( ready for use )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001052
Jon Hall7993bfc2014-10-09 16:30:14 -04001053 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001054 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001055 try:
kelvin8ec71442015-01-15 16:57:00 -08001056 self.handle.sendline( "onos-wait-for-start " + node )
1057 self.handle.expect( "onos-wait-for-start" )
1058 # NOTE: this timeout is arbitrary"
pingping-lin57a56ce2015-05-20 16:43:48 -07001059 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
1060 onosWaitStartTimeout )
Jon Hall7993bfc2014-10-09 16:30:14 -04001061 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001062 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001063 return main.TRUE
1064 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001065 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001066 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001067 main.log.error( "ONOS has not started yet" )
1068 self.handle.send( "\x03" ) # Control-C
1069 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001070 return main.FALSE
1071 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001072 main.log.error( self.name + ": EOF exception found" )
1073 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001074 main.cleanup()
1075 main.exit()
1076 except:
kelvin8ec71442015-01-15 16:57:00 -08001077 main.log.info( self.name + " ::::::" )
1078 main.log.error( traceback.print_exc() )
1079 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001080 main.cleanup()
1081 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001082
kelvin-onlabd3b64892015-01-20 13:26:24 -08001083 def pushTestIntentsShell(
1084 self,
1085 dpidSrc,
1086 dpidDst,
1087 numIntents,
1088 dirFile,
1089 onosIp,
1090 numMult="",
1091 appId="",
1092 report=True,
1093 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001094 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001095 Description:
kelvin8ec71442015-01-15 16:57:00 -08001096 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001097 better parallelize the results than the CLI
1098 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001099 * dpidSrc: specify source dpid
1100 * dpidDst: specify destination dpid
1101 * numIntents: specify number of intents to push
1102 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001103 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001104 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001105 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001106 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001107 """
1108 try:
1109 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001110 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001111 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001112 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001113 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001114 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001115
kelvin-onlabd3b64892015-01-20 13:26:24 -08001116 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1117 if not numMult:
1118 addIntents = addDpid + " " + str( numIntents )
1119 elif numMult:
1120 addIntents = addDpid + " " + str( numIntents ) + " " +\
1121 str( numMult )
1122 if appId:
1123 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001124 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001125 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001126
andrewonlabaedc8332014-12-04 12:43:03 -05001127 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001128 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001129 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001130 sendCmd = addApp + " &"
1131 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001132
kelvin-onlabd3b64892015-01-20 13:26:24 -08001133 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001134
1135 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001136 main.log.error( self.name + ": EOF exception found" )
1137 main.log.error( self.name + ": " + self.handle.before )
andrewonlabb66dfa12014-12-02 15:51:10 -05001138 main.cleanup()
1139 main.exit()
1140 except:
kelvin8ec71442015-01-15 16:57:00 -08001141 main.log.info( self.name + " ::::::" )
1142 main.log.error( traceback.print_exc() )
1143 main.log.info( self.name + " ::::::" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001144 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001145 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001146
kelvin-onlabd3b64892015-01-20 13:26:24 -08001147 def getTopology( self, topologyOutput ):
kelvin8ec71442015-01-15 16:57:00 -08001148 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001149 parses the onos:topology output
kelvin8ec71442015-01-15 16:57:00 -08001150 Returns: a topology dict populated by the key values found in
Jon Hall77f53ce2014-10-13 18:02:06 -04001151 the cli command.
kelvin8ec71442015-01-15 16:57:00 -08001152 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001153 try:
kelvin8ec71442015-01-15 16:57:00 -08001154 # call the cli to get the topology summary
1155 # cmdstr = "onos:topology"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001156 # cliResult = self.onosCli( ip, cmdstr )
1157 # print "cli_result = ", cliResult
Jon Hall77f53ce2014-10-13 18:02:06 -04001158
kelvin8ec71442015-01-15 16:57:00 -08001159 # Parse the output
Jon Hall77f53ce2014-10-13 18:02:06 -04001160 topology = {}
kelvin-onlabd3b64892015-01-20 13:26:24 -08001161 # for line in cliResult.split( "\n" ):
1162 for line in topologyOutput.splitlines():
kelvin8ec71442015-01-15 16:57:00 -08001163 if not line.startswith( "time=" ):
Jon Hall77f53ce2014-10-13 18:02:06 -04001164 continue
kelvin8ec71442015-01-15 16:57:00 -08001165 # else
1166 # print line
1167 for var in line.split( "," ):
1168 # print "'"+var+"'"
1169 # print "'"+var.strip()+"'"
1170 key, value = var.strip().split( "=" )
1171 topology[ key ] = value
1172 # print "topology = ", topology
1173 # devices = topology.get( 'devices', False )
1174 # print "devices = ", devices
1175 # links = topology.get( 'links', False )
1176 # print "links = ", links
1177 # SCCs = topology.get( 'SCC(s)', False )
1178 # print "SCCs = ", SCCs
1179 # paths = topology.get( 'paths', False )
1180 # print "paths = ", paths
Jon Hall77f53ce2014-10-13 18:02:06 -04001181
1182 return topology
1183 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001184 main.log.error( self.name + ": EOF exception found" )
1185 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001186 main.cleanup()
1187 main.exit()
1188 except:
kelvin8ec71442015-01-15 16:57:00 -08001189 main.log.info( self.name + " ::::::" )
1190 main.log.error( traceback.print_exc() )
1191 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001192 main.cleanup()
1193 main.exit()
1194
kelvin-onlabd3b64892015-01-20 13:26:24 -08001195 def checkStatus(
1196 self,
1197 topologyResult,
1198 numoswitch,
1199 numolink,
1200 logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001201 """
1202 Checks the number of swithes & links that ONOS sees against the
1203 supplied values. By default this will report to main.log, but the
Jon Hall77f53ce2014-10-13 18:02:06 -04001204 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001205
Jon Hall77f53ce2014-10-13 18:02:06 -04001206 Params: ip = ip used for the onos cli
1207 numoswitch = expected number of switches
1208 numlink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001209 logLevel = level to log to.
1210 Currently accepts 'info', 'warn' and 'report'
Jon Hall77f53ce2014-10-13 18:02:06 -04001211
1212
kelvin-onlabd3b64892015-01-20 13:26:24 -08001213 logLevel can
Jon Hall77f53ce2014-10-13 18:02:06 -04001214
kelvin8ec71442015-01-15 16:57:00 -08001215 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall77f53ce2014-10-13 18:02:06 -04001216 main.FALSE if the numer of switches and links is incorrect,
1217 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001218 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001219 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001220 topology = self.getTopology( topologyResult )
Jon Hall77f53ce2014-10-13 18:02:06 -04001221 if topology == {}:
1222 return main.ERROR
1223 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001224 # Is the number of switches is what we expected
1225 devices = topology.get( 'devices', False )
1226 links = topology.get( 'links', False )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001227 if not devices or not links:
Jon Hall77f53ce2014-10-13 18:02:06 -04001228 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001229 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001230 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001231 linkCheck = ( int( links ) == int( numolink ) )
1232 if ( switchCheck and linkCheck ):
kelvin8ec71442015-01-15 16:57:00 -08001233 # We expected the correct numbers
Jon Hall77f53ce2014-10-13 18:02:06 -04001234 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001235 + "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001236 result = main.TRUE
1237 else:
1238 output = output + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001239 "The number of links and switches does not match\
1240 what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001241 result = main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001242 output = output + "\n ONOS sees %i devices (%i expected)\
1243 and %i links (%i expected)" %\
1244 ( int( devices ), int( numoswitch ),
1245 int( links ), int( numolink ) )
1246 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001247 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001248 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001249 main.log.warn( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001250 else:
kelvin8ec71442015-01-15 16:57:00 -08001251 main.log.info( output )
1252 return result
Jon Hall77f53ce2014-10-13 18:02:06 -04001253 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001254 main.log.error( self.name + ": EOF exception found" )
1255 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001256 main.cleanup()
1257 main.exit()
1258 except:
kelvin8ec71442015-01-15 16:57:00 -08001259 main.log.info( self.name + " ::::::" )
1260 main.log.error( traceback.print_exc() )
1261 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001262 main.cleanup()
1263 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001264
kelvin-onlabd3b64892015-01-20 13:26:24 -08001265 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001266 """
andrewonlab970399c2014-11-07 13:09:32 -05001267 Capture all packet activity and store in specified
1268 directory/file
1269
1270 Required:
1271 * interface: interface to capture
1272 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001273 """
1274 self.handle.sendline( "" )
1275 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001276
kelvin8ec71442015-01-15 16:57:00 -08001277 self.handle.sendline( "tshark -i " + str( interface ) +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001278 " -t e -w " + str( dirFile ) + " &" )
kelvin8ec71442015-01-15 16:57:00 -08001279 self.handle.sendline( "\r" )
1280 self.handle.expect( "Capturing on" )
1281 self.handle.sendline( "\r" )
1282 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001283
kelvin8ec71442015-01-15 16:57:00 -08001284 main.log.info( "Tshark started capturing files on " +
1285 str( interface ) + " and saving to directory: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001286 str( dirFile ) )
Shreya Shaha73aaad2014-10-27 18:03:09 -04001287
kelvin-onlabd3b64892015-01-20 13:26:24 -08001288 def runOnosTopoCfg( self, instanceName, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001289 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001290 On ONOS bench, run this command:
1291 ./~/ONOS/tools/test/bin/onos-topo-cfg $OC1 filename
1292 which starts the rest and copies
1293 the json file to the onos instance
kelvin8ec71442015-01-15 16:57:00 -08001294 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001295 try:
kelvin8ec71442015-01-15 16:57:00 -08001296 self.handle.sendline( "" )
1297 self.handle.expect( "\$" )
1298 self.handle.sendline( "cd ~/ONOS/tools/test/bin" )
1299 self.handle.expect( "/bin$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001300 cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile
shahshreyae6c7cf42014-11-26 16:39:01 -08001301 print "cmd = ", cmd
kelvin8ec71442015-01-15 16:57:00 -08001302 self.handle.sendline( cmd )
1303 self.handle.expect( "\$" )
1304 self.handle.sendline( "cd ~" )
1305 self.handle.expect( "\$" )
shahshreyae6c7cf42014-11-26 16:39:01 -08001306 return main.TRUE
1307 except:
1308 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001309
kelvin-onlabd3b64892015-01-20 13:26:24 -08001310 def tsharkGrep( self, grep, directory, interface='eth0' ):
kelvin8ec71442015-01-15 16:57:00 -08001311 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001312 Required:
kelvin8ec71442015-01-15 16:57:00 -08001313 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001314 * directory to store results
1315 Optional:
1316 * interface - default: eth0
1317 Description:
1318 Uses tshark command to grep specific group of packets
1319 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001320 The timestamp is hardcoded to be in epoch
1321 """
1322 self.handle.sendline( "" )
1323 self.handle.expect( "\$" )
1324 self.handle.sendline( "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001325 self.handle.sendline(
1326 "tshark -i " +
1327 str( interface ) +
1328 " -t e | grep --line-buffered \"" +
1329 str(grep) +
1330 "\" >" +
1331 directory +
1332 " &" )
kelvin8ec71442015-01-15 16:57:00 -08001333 self.handle.sendline( "\r" )
1334 self.handle.expect( "Capturing on" )
1335 self.handle.sendline( "\r" )
1336 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001337
kelvin-onlabd3b64892015-01-20 13:26:24 -08001338 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001339 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001340 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001341 """
1342 # Remove all pcap from previous captures
1343 self.execute( cmd="sudo rm /tmp/wireshark*" )
1344 self.handle.sendline( "" )
1345 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\" |" +
1346 " grep -v grep | awk '{print $2}'`" )
1347 self.handle.sendline( "" )
1348 main.log.info( "Tshark stopped" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001349
kelvin8ec71442015-01-15 16:57:00 -08001350 def ptpd( self, args ):
1351 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001352 Initiate ptp with user-specified args.
1353 Required:
1354 * args: specify string of args after command
1355 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001356 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001357 try:
kelvin8ec71442015-01-15 16:57:00 -08001358 self.handle.sendline( "sudo ptpd " + str( args ) )
1359 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001360 "Multiple",
1361 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001362 "\$" ] )
1363 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001364
andrewonlab0c38a4a2014-10-28 18:35:35 -04001365 if i == 0:
1366 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001367 main.log.info( "ptpd returned an error: " +
1368 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001369 return handle
1370 elif i == 1:
1371 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001372 main.log.error( "ptpd returned an error: " +
1373 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001374 return handle
1375 else:
1376 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001377
andrewonlab0c38a4a2014-10-28 18:35:35 -04001378 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001379 main.log.error( self.name + ": EOF exception found" )
1380 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001381 main.cleanup()
1382 main.exit()
1383 except:
kelvin8ec71442015-01-15 16:57:00 -08001384 main.log.info( self.name + " ::::::" )
1385 main.log.error( traceback.print_exc() )
1386 main.log.info( self.name + " ::::::" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001387 main.cleanup()
1388 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001389
kelvin-onlabd3b64892015-01-20 13:26:24 -08001390 def cpLogsToDir( self, logToCopy,
1391 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001392 """
1393 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001394 Current implementation of ONOS deletes its karaf
1395 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001396 you may want to use this function to capture
1397 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001398 Localtime will be attached to the filename
1399
1400 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001401 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001402 copy.
kelvin8ec71442015-01-15 16:57:00 -08001403 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001404 For copying multiple files, leave copyFileName
1405 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001406 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001407 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001408 ex ) /tmp/
1409 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001410 * copyFileName: If you want to rename the log
1411 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001412 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001413 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001414 try:
kelvin8ec71442015-01-15 16:57:00 -08001415 localtime = time.strftime( '%x %X' )
1416 localtime = localtime.replace( "/", "" )
1417 localtime = localtime.replace( " ", "_" )
1418 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001419 if destDir[ -1: ] != "/":
1420 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001421
kelvin-onlabd3b64892015-01-20 13:26:24 -08001422 if copyFileName:
1423 self.handle.sendline(
1424 "cp " +
1425 str( logToCopy ) +
1426 " " +
1427 str( destDir ) +
1428 str( copyFileName ) +
1429 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001430 self.handle.expect( "cp" )
1431 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001432 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001433 self.handle.sendline( "cp " + str( logToCopy ) +
1434 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001435 self.handle.expect( "cp" )
1436 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001437
kelvin8ec71442015-01-15 16:57:00 -08001438 return self.handle.before
1439
1440 except pexpect.EOF:
1441 main.log.error( "Copying files failed" )
1442 main.log.error( self.name + ": EOF exception found" )
1443 main.log.error( self.name + ": " + self.handle.before )
1444 except:
1445 main.log.error( "Copying files failed" )
1446 main.log.info( self.name + " ::::::" )
1447 main.log.error( traceback.print_exc() )
1448 main.log.info( self.name + " ::::::" )
1449
kelvin-onlabd3b64892015-01-20 13:26:24 -08001450 def checkLogs( self, onosIp ):
kelvin8ec71442015-01-15 16:57:00 -08001451 """
Jon Hall94fd0472014-12-08 11:52:42 -08001452 runs onos-check-logs on the given onos node
1453 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001454 """
Jon Hall94fd0472014-12-08 11:52:42 -08001455 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001456 cmd = "onos-check-logs " + str( onosIp )
kelvin8ec71442015-01-15 16:57:00 -08001457 self.handle.sendline( cmd )
1458 self.handle.expect( cmd )
1459 self.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -08001460 response = self.handle.before
1461 return response
1462 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001463 main.log.error( "Lost ssh connection" )
1464 main.log.error( self.name + ": EOF exception found" )
1465 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001466 except:
kelvin8ec71442015-01-15 16:57:00 -08001467 main.log.error( "Some error in check_logs:" )
1468 main.log.info( self.name + " ::::::" )
1469 main.log.error( traceback.print_exc() )
1470 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001471
kelvin-onlabd3b64892015-01-20 13:26:24 -08001472 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001473 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001474 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001475 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001476 try:
kelvin8ec71442015-01-15 16:57:00 -08001477 self.handle.sendline( "" )
1478 self.handle.expect( "\$" )
1479 self.handle.sendline( "onos-service " + str( node ) +
1480 " status" )
1481 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001482 "start/running",
1483 "stop/waiting",
kelvin8ec71442015-01-15 16:57:00 -08001484 pexpect.TIMEOUT ], timeout=120 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001485
1486 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001487 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001488 return main.TRUE
1489 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001490 main.log.info( "ONOS is stopped" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001491 return main.FALSE
1492 else:
kelvin8ec71442015-01-15 16:57:00 -08001493 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001494 main.cleanup()
1495 main.exit()
1496 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001497 main.log.error( self.name + ": EOF exception found" )
1498 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001499 main.cleanup()
1500 main.exit()
1501 except:
kelvin8ec71442015-01-15 16:57:00 -08001502 main.log.info( self.name + " ::::::" )
1503 main.log.error( traceback.print_exc() )
1504 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001505 main.cleanup()
1506 main.exit()