blob: 450297130cf682839ed8c961196feca7e215dfb3 [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
andrewonlab7735d852014-10-09 13:02:47 -040022import os.path
kelvin8ec71442015-01-15 16:57:00 -080023sys.path.append( "../" )
Jon Hall05b2b432014-10-08 19:53:25 -040024from drivers.common.clidriver import CLI
25
Jon Hall05b2b432014-10-08 19:53:25 -040026
kelvin8ec71442015-01-15 16:57:00 -080027class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040028
kelvin8ec71442015-01-15 16:57:00 -080029 def __init__( self ):
30 """
31 Initialize client
32 """
Jon Hallefbd9792015-03-05 16:11:36 -080033 self.name = None
34 self.home = None
35 self.handle = None
kelvin8ec71442015-01-15 16:57:00 -080036 super( CLI, self ).__init__()
37
38 def connect( self, **connectargs ):
39 """
Jon Hall05b2b432014-10-08 19:53:25 -040040 Creates ssh handle for ONOS "bench".
kelvin8ec71442015-01-15 16:57:00 -080041 """
Jon Hall05b2b432014-10-08 19:53:25 -040042 try:
43 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080044 vars( self )[ key ] = connectargs[ key ]
andrew@onlab.us3b087132015-03-11 15:00:08 -070045 self.home = "~/onos"
Jon Hall05b2b432014-10-08 19:53:25 -040046 for key in self.options:
47 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080048 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040049 break
Jon Hall274b6642015-02-17 11:57:17 -080050 if self.home is None or self.home == "":
Jon Halle94919c2015-03-23 11:42:57 -070051 self.home = "~/onos"
Jon Hall21270ac2015-02-16 17:59:55 -080052
kelvin8ec71442015-01-15 16:57:00 -080053 self.name = self.options[ 'name' ]
54 self.handle = super( OnosDriver, self ).connect(
55 user_name=self.user_name,
kelvin-onlab08679eb2015-01-21 16:11:48 -080056 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -080057 port=self.port,
58 pwd=self.pwd,
59 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -040060
kelvin8ec71442015-01-15 16:57:00 -080061 self.handle.sendline( "cd " + self.home )
62 self.handle.expect( "\$" )
Jon Hall05b2b432014-10-08 19:53:25 -040063 if self.handle:
64 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080065 else:
66 main.log.info( "NO ONOS HANDLE" )
Jon Hall05b2b432014-10-08 19:53:25 -040067 return main.FALSE
68 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080069 main.log.error( self.name + ": EOF exception found" )
70 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040071 main.cleanup()
72 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -080073 except Exception:
74 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall05b2b432014-10-08 19:53:25 -040075 main.cleanup()
76 main.exit()
77
kelvin8ec71442015-01-15 16:57:00 -080078 def disconnect( self ):
79 """
Jon Hall05b2b432014-10-08 19:53:25 -040080 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080081 """
Jon Halld61331b2015-02-17 16:35:47 -080082 response = main.TRUE
Jon Hall05b2b432014-10-08 19:53:25 -040083 try:
Jon Hall61282e32015-03-19 11:34:11 -070084 if self.handle:
85 self.handle.sendline( "" )
86 self.handle.expect( "\$" )
87 self.handle.sendline( "exit" )
88 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -040089 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080090 main.log.error( self.name + ": EOF exception found" )
91 main.log.error( self.name + ": " + self.handle.before )
Jon Hall61282e32015-03-19 11:34:11 -070092 except ValueError:
Jon Hall1a77a1e2015-04-06 10:41:13 -070093 main.log.exception( "Exception in disconnect of " + self.name )
Jon Hall61282e32015-03-19 11:34:11 -070094 response = main.TRUE
Jon Hallfebb1c72015-03-05 13:30:09 -080095 except Exception:
96 main.log.exception( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -040097 response = main.FALSE
98 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040099
kelvin-onlabd3b64892015-01-20 13:26:24 -0800100 def onosPackage( self ):
kelvin8ec71442015-01-15 16:57:00 -0800101 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400102 Produce a self-contained tar.gz file that can be deployed
kelvin8ec71442015-01-15 16:57:00 -0800103 and executed on any platform with Java 7 JRE.
104 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400105 try:
kelvin8ec71442015-01-15 16:57:00 -0800106 self.handle.sendline( "onos-package" )
107 self.handle.expect( "onos-package" )
108 self.handle.expect( "tar.gz", timeout=30 )
109 handle = str( self.handle.before )
110 main.log.info( "onos-package command returned: " +
111 handle )
112 # As long as the sendline does not time out,
113 # return true. However, be careful to interpret
114 # the results of the onos-package command return
andrewonlab0748d2a2014-10-09 13:24:17 -0400115 return main.TRUE
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400116
andrewonlab7735d852014-10-09 13:02:47 -0400117 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800118 main.log.error( self.name + ": EOF exception found" )
119 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800120 except Exception:
121 main.log.exception( "Failed to package ONOS" )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400122 main.cleanup()
123 main.exit()
124
kelvin-onlabd3b64892015-01-20 13:26:24 -0800125 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800126 """
andrewonlab8790abb2014-11-06 13:51:54 -0500127 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800128 """
andrewonlab8790abb2014-11-06 13:51:54 -0500129 try:
kelvin8ec71442015-01-15 16:57:00 -0800130 self.handle.sendline( "onos-build" )
131 self.handle.expect( "onos-build" )
132 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800133 "BUILD SUCCESS",
134 "ERROR",
135 "BUILD FAILED" ],
136 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800137 handle = str( self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500138
kelvin8ec71442015-01-15 16:57:00 -0800139 main.log.info( "onos-build command returned: " +
140 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500141
142 if i == 0:
143 return main.TRUE
144 else:
145 return handle
146
147 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800148 main.log.error( self.name + ": EOF exception found" )
149 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800150 except Exception:
151 main.log.exception( "Failed to build ONOS" )
andrewonlab8790abb2014-11-06 13:51:54 -0500152 main.cleanup()
153 main.exit()
154
kelvin-onlabd3b64892015-01-20 13:26:24 -0800155 def cleanInstall( self ):
kelvin8ec71442015-01-15 16:57:00 -0800156 """
157 Runs mvn clean install in the root of the ONOS directory.
158 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400159
kelvin8ec71442015-01-15 16:57:00 -0800160 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400161 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800162 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400163 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800164 main.log.info( "Running 'mvn clean install' on " +
165 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800166 ". This may take some time." )
167 self.handle.sendline( "cd " + self.home )
168 self.handle.expect( "\$" )
Jon Hallea7818b2014-10-09 14:30:59 -0400169
kelvin8ec71442015-01-15 16:57:00 -0800170 self.handle.sendline( "" )
171 self.handle.expect( "\$" )
172 self.handle.sendline( "mvn clean install" )
173 self.handle.expect( "mvn clean install" )
174 while True:
175 i = self.handle.expect( [
Jon Hall274b6642015-02-17 11:57:17 -0800176 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' +
Jon Hallefbd9792015-03-05 16:11:36 -0800177 'Runtime\sEnvironment\sto\scontinue',
Jon Hallde9d9aa2014-10-08 20:36:02 -0400178 'BUILD\sFAILURE',
179 'BUILD\sSUCCESS',
Jon Halle94919c2015-03-23 11:42:57 -0700180 'onos\$', #TODO: fix this to be more generic?
Jon Hallde9d9aa2014-10-08 20:36:02 -0400181 'ONOS\$',
kelvin8ec71442015-01-15 16:57:00 -0800182 pexpect.TIMEOUT ], timeout=600 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400183 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800184 main.log.error( self.name + ":There is insufficient memory \
185 for the Java Runtime Environment to continue." )
186 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400187 main.cleanup()
188 main.exit()
189 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800190 main.log.error( self.name + ": Build failure!" )
191 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400192 main.cleanup()
193 main.exit()
194 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800195 main.log.info( self.name + ": Build success!" )
Jon Halle94919c2015-03-23 11:42:57 -0700196 elif i == 3 or i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800197 main.log.info( self.name + ": Build complete" )
198 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400199 for line in self.handle.before.splitlines():
200 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800201 main.log.info( line )
202 self.handle.sendline( "" )
203 self.handle.expect( "\$", timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400204 return main.TRUE
Jon Halle94919c2015-03-23 11:42:57 -0700205 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800206 main.log.error(
207 self.name +
208 ": mvn clean install TIMEOUT!" )
209 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400210 main.cleanup()
211 main.exit()
212 else:
Jon Hall274b6642015-02-17 11:57:17 -0800213 main.log.error( self.name + ": unexpected response from " +
Jon Hallefbd9792015-03-05 16:11:36 -0800214 "mvn clean install" )
kelvin8ec71442015-01-15 16:57:00 -0800215 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400216 main.cleanup()
217 main.exit()
218 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800219 main.log.error( self.name + ": EOF exception found" )
220 main.log.error( self.name + ": " + self.handle.before )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400221 main.cleanup()
222 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800223 except Exception:
224 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400225 main.cleanup()
226 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400227
Jon Hall61282e32015-03-19 11:34:11 -0700228 def gitPull( self, comp1="", fastForward=True ):
kelvin8ec71442015-01-15 16:57:00 -0800229 """
Jon Hallacabffd2014-10-09 12:36:53 -0400230 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800231
Jon Hall61282e32015-03-19 11:34:11 -0700232 If the fastForward boolean is set to true, only git pulls that can
233 be fast forwarded will be performed. IE if you have not local commits
234 in your branch.
235
Jon Hallacabffd2014-10-09 12:36:53 -0400236 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800237 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400238 for the purpose of pulling from other nodes if necessary.
239
Jon Hall47a93fb2015-01-06 16:46:06 -0800240 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400241 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800242 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400243 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400244
kelvin8ec71442015-01-15 16:57:00 -0800245 """
Jon Hallacabffd2014-10-09 12:36:53 -0400246 try:
kelvin8ec71442015-01-15 16:57:00 -0800247 # main.log.info( self.name + ": Stopping ONOS" )
248 # self.stop()
249 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800250 self.handle.expect( self.home + "\$" )
Jon Hall61282e32015-03-19 11:34:11 -0700251 cmd = "git pull"
252 if comp1 != "":
253 cmd += ' ' + comp1
254 if fastForward:
255 cmd += ' ' + " --ff-only"
256 self.handle.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800257 i = self.handle.expect(
258 [
259 'fatal',
260 'Username\sfor\s(.*):\s',
261 '\sfile(s*) changed,\s',
262 'Already up-to-date',
263 'Aborting',
264 'You\sare\snot\scurrently\son\sa\sbranch',
Jon Hall274b6642015-02-17 11:57:17 -0800265 'You asked me to pull without telling me which branch you',
266 'Pull is not possible because you have unmerged files',
Jon Hall61282e32015-03-19 11:34:11 -0700267 'Please enter a commit message to explain why this merge',
268 'Found a swap file by the name',
269 'Please, commit your changes before you can merge.',
kelvin-onlabd3b64892015-01-20 13:26:24 -0800270 pexpect.TIMEOUT ],
271 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800272 # debug
kelvin-onlabd3b64892015-01-20 13:26:24 -0800273 # main.log.report( self.name +": DEBUG: \n"+
274 # "git pull response: " +
275 # str( self.handle.before ) + str( self.handle.after ) )
kelvin8ec71442015-01-15 16:57:00 -0800276 if i == 0:
Jon Hall61282e32015-03-19 11:34:11 -0700277 main.log.error( self.name + ": Git pull had some issue" )
278 output = self.handle.after
279 self.handle.expect( '\$' )
280 output += self.handle.before
281 main.log.warn( output )
Jon Hallacabffd2014-10-09 12:36:53 -0400282 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800283 elif i == 1:
284 main.log.error(
285 self.name +
286 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400287 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800288 elif i == 2:
289 main.log.info(
290 self.name +
291 ": Git Pull - pulling repository now" )
kelvin-onlaba1484582015-02-02 15:46:20 -0800292 self.handle.expect( self.home + "\$", 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800293 # So that only when git pull is done, we do mvn clean compile
294 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800295 elif i == 3:
296 main.log.info( self.name + ": Git Pull - Already up to date" )
Jon Hall47a93fb2015-01-06 16:46:06 -0800297 return i
kelvin8ec71442015-01-15 16:57:00 -0800298 elif i == 4:
299 main.log.info(
300 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800301 ": Git Pull - Aborting..." +
302 "Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400303 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800304 elif i == 5:
305 main.log.info(
306 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800307 ": Git Pull - You are not currently " +
308 "on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400309 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800310 elif i == 6:
311 main.log.info(
312 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800313 ": Git Pull - You have not configured an upstream " +
314 "branch to pull from. Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400315 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800316 elif i == 7:
317 main.log.info(
318 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800319 ": Git Pull - Pull is not possible because " +
320 "you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400321 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800322 elif i == 8:
Jon Hall61282e32015-03-19 11:34:11 -0700323 # NOTE: abandoning test since we can't reliably handle this
324 # there could be different default text editors and we
325 # also don't know if we actually want to make the commit
326 main.log.error( "Git pull resulted in a merge commit message" +
327 ". Exiting test!" )
328 main.cleanup()
329 main.exit()
330 elif i == 9: # Merge commit message but swap file exists
331 main.log.error( "Git pull resulted in a merge commit message" +
332 " but a swap file exists." )
333 try:
334 self.handle.send( 'A' ) # Abort
335 self.handle.expect( "\$" )
336 return main.ERROR
337 except Exception:
338 main.log.exception( "Couldn't exit editor prompt!")
339 main.cleanup()
340 main.exit()
341 elif i == 10: # In the middle of a merge commit
342 main.log.error( "Git branch is in the middle of a merge. " )
343 main.log.warn( self.handle.before + self.handle.after )
344 return main.ERROR
345 elif i == 11:
kelvin8ec71442015-01-15 16:57:00 -0800346 main.log.error( self.name + ": Git Pull - TIMEOUT" )
347 main.log.error(
348 self.name + " Response was: " + str(
349 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400350 return main.ERROR
351 else:
kelvin8ec71442015-01-15 16:57:00 -0800352 main.log.error(
353 self.name +
354 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400355 return main.ERROR
356 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800357 main.log.error( self.name + ": EOF exception found" )
358 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400359 main.cleanup()
360 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800361 except Exception:
362 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400363 main.cleanup()
364 main.exit()
365
kelvin-onlabd3b64892015-01-20 13:26:24 -0800366 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800367 """
Jon Hallacabffd2014-10-09 12:36:53 -0400368 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800369
Jon Hallacabffd2014-10-09 12:36:53 -0400370 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800371 If used as gitCheckout( "branch" ) it will do git checkout
372 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400373
374 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800375 branch of the ONOS repository. If it has any problems, it will return
376 main.ERROR.
377 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400378 successful then the function will return main.TRUE.
379
kelvin8ec71442015-01-15 16:57:00 -0800380 """
Jon Hallacabffd2014-10-09 12:36:53 -0400381 try:
kelvin8ec71442015-01-15 16:57:00 -0800382 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800383 self.handle.expect( self.home + "\$" )
Jon Hall274b6642015-02-17 11:57:17 -0800384 main.log.info( self.name +
385 ": Checking out git branch/ref: " + branch + "..." )
kelvin8ec71442015-01-15 16:57:00 -0800386 cmd = "git checkout " + branch
387 self.handle.sendline( cmd )
388 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800389 i = self.handle.expect(
Jon Hall274b6642015-02-17 11:57:17 -0800390 [ 'fatal',
Jon Hall61282e32015-03-19 11:34:11 -0700391 'Username for (.*): ',
392 'Already on \'',
393 'Switched to branch \'' + str( branch ),
Jon Hall274b6642015-02-17 11:57:17 -0800394 pexpect.TIMEOUT,
395 'error: Your local changes to the following files' +
Jon Hallefbd9792015-03-05 16:11:36 -0800396 'would be overwritten by checkout:',
Jon Hall274b6642015-02-17 11:57:17 -0800397 'error: you need to resolve your current index first',
398 "You are in 'detached HEAD' state.",
399 "HEAD is now at " ],
kelvin-onlabd3b64892015-01-20 13:26:24 -0800400 timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -0800401 if i == 0:
402 main.log.error(
403 self.name +
404 ": Git checkout had some issue..." )
405 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400406 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800407 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800408 main.log.error(
409 self.name +
410 ": Git checkout asking for username." +
411 " Please configure your local git repository to be able " +
412 "to access your remote repository passwordlessly" )
Jon Hall274b6642015-02-17 11:57:17 -0800413 # TODO add support for authenticating
Jon Hallacabffd2014-10-09 12:36:53 -0400414 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800415 elif i == 2:
416 main.log.info(
417 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800418 ": Git Checkout %s : Already on this branch" % branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800419 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800420 # main.log.info( "DEBUG: after checkout cmd = "+
421 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400422 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800423 elif i == 3:
424 main.log.info(
425 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800426 ": Git checkout %s - Switched to this branch" % branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800427 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800428 # main.log.info( "DEBUG: after checkout cmd = "+
429 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400430 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800431 elif i == 4:
432 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
433 main.log.error(
Jon Hall274b6642015-02-17 11:57:17 -0800434 self.name + " Response was: " + str( self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400435 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800436 elif i == 5:
437 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800438 main.log.error(
439 self.name +
440 ": Git checkout error: \n" +
Jon Hall274b6642015-02-17 11:57:17 -0800441 "Your local changes to the following files would" +
442 " be overwritten by checkout:" +
443 str( self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800444 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500445 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800446 elif i == 6:
Jon Hall274b6642015-02-17 11:57:17 -0800447 main.log.error(
448 self.name +
449 ": Git checkout error: \n" +
450 "You need to resolve your current index first:" +
451 str( self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800452 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500453 return main.ERROR
Jon Hall274b6642015-02-17 11:57:17 -0800454 elif i == 7:
455 main.log.info(
456 self.name +
457 ": Git checkout " + str( branch ) +
458 " - You are in 'detached HEAD' state. HEAD is now at " +
459 str( branch ) )
460 self.handle.expect( self.home + "\$" )
461 return main.TRUE
462 elif i == 8: # Already in detached HEAD on the specified commit
463 main.log.info(
464 self.name +
465 ": Git Checkout %s : Already on commit" % branch )
466 self.handle.expect( self.home + "\$" )
467 return main.TRUE
Jon Hallacabffd2014-10-09 12:36:53 -0400468 else:
kelvin8ec71442015-01-15 16:57:00 -0800469 main.log.error(
470 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800471 ": Git Checkout - Unexpected response, " +
472 "check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800473 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400474 return main.ERROR
475
476 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800477 main.log.error( self.name + ": EOF exception found" )
478 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400479 main.cleanup()
480 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800481 except Exception:
482 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400483 main.cleanup()
484 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400485
kelvin-onlabd3b64892015-01-20 13:26:24 -0800486 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800487 """
Jon Hall274b6642015-02-17 11:57:17 -0800488 Writes the COMMIT number to the report to be parsed
Jon Hallefbd9792015-03-05 16:11:36 -0800489 by Jenkins data collector.
kelvin8ec71442015-01-15 16:57:00 -0800490 """
Jon Hall45ec0922014-10-10 19:33:49 -0400491 try:
kelvin8ec71442015-01-15 16:57:00 -0800492 self.handle.sendline( "" )
493 self.handle.expect( "\$" )
494 self.handle.sendline(
495 "cd " +
496 self.home +
Jon Hall274b6642015-02-17 11:57:17 -0800497 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " +
498 " \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800499 # NOTE: for some reason there are backspaces inserted in this
500 # phrase when run from Jenkins on some tests
501 self.handle.expect( "never" )
502 self.handle.expect( "\$" )
503 response = ( self.name + ": \n" + str(
504 self.handle.before + self.handle.after ) )
505 self.handle.sendline( "cd " + self.home )
506 self.handle.expect( "\$" )
507 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400508 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500509 print line
510 if report:
kelvin8ec71442015-01-15 16:57:00 -0800511 for line in lines[ 2:-1 ]:
512 # Bracket replacement is for Wiki-compliant
513 # formatting. '<' or '>' are interpreted
514 # as xml specific tags that cause errors
515 line = line.replace( "<", "[" )
516 line = line.replace( ">", "]" )
517 main.log.report( "\t" + line )
518 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400519 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800520 main.log.error( self.name + ": EOF exception found" )
521 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400522 main.cleanup()
523 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800524 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800525 main.log.error( self.name + ": TIMEOUT exception found" )
526 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800527 main.cleanup()
528 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800529 except Exception:
530 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall45ec0922014-10-10 19:33:49 -0400531 main.cleanup()
532 main.exit()
533
kelvin-onlabd3b64892015-01-20 13:26:24 -0800534 def createCellFile( self, benchIp, fileName, mnIpAddrs,
cameron@onlab.us75900962015-03-30 13:22:49 -0700535 appString, *onosIpAddrs ):
kelvin8ec71442015-01-15 16:57:00 -0800536 """
andrewonlab94282092014-10-10 13:00:11 -0400537 Creates a cell file based on arguments
538 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800539 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400540 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800541 * File name of the cell file ( fileName )
542 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800543 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400544 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800545 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400546 - Must be passed in as last arguments
kelvin8ec71442015-01-15 16:57:00 -0800547
andrewonlab94282092014-10-10 13:00:11 -0400548 NOTE: Assumes cells are located at:
549 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800550 """
551 # Variable initialization
kelvin-onlabd3b64892015-01-20 13:26:24 -0800552 cellDirectory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800553 # We want to create the cell file in the dependencies directory
554 # of TestON first, then copy over to ONOS bench
kelvin-onlabd3b64892015-01-20 13:26:24 -0800555 tempDirectory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800556 # Create the cell file in the directory for writing ( w+ )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800557 cellFile = open( tempDirectory + fileName, 'w+' )
kelvin8ec71442015-01-15 16:57:00 -0800558
cameron@onlab.us75900962015-03-30 13:22:49 -0700559 # App string is hardcoded environment variables
kelvin8ec71442015-01-15 16:57:00 -0800560 # That you may wish to use by default on startup.
cameron@onlab.us75900962015-03-30 13:22:49 -0700561 # Note that you may not want certain apps listed
kelvin8ec71442015-01-15 16:57:00 -0800562 # on here.
cameron@onlab.us75900962015-03-30 13:22:49 -0700563 appString = "export ONOS_APPS=" + appString
kelvin-onlabd3b64892015-01-20 13:26:24 -0800564 mnString = "export OCN="
kelvin-onlabf70fd542015-05-07 18:41:40 -0700565 if mnIpAddrs == "":
566 mnString = ""
kelvin-onlabd3b64892015-01-20 13:26:24 -0800567 onosString = "export OC"
568 tempCount = 1
kelvin8ec71442015-01-15 16:57:00 -0800569
kelvin-onlabd3b64892015-01-20 13:26:24 -0800570 # Create ONOSNIC ip address prefix
571 tempOnosIp = onosIpAddrs[ 0 ]
572 tempList = []
573 tempList = tempOnosIp.split( "." )
kelvin8ec71442015-01-15 16:57:00 -0800574 # Omit last element of list to format for NIC
kelvin-onlabd3b64892015-01-20 13:26:24 -0800575 tempList = tempList[ :-1 ]
kelvin8ec71442015-01-15 16:57:00 -0800576 # Structure the nic string ip
kelvin-onlabd3b64892015-01-20 13:26:24 -0800577 nicAddr = ".".join( tempList ) + ".*"
578 onosNicString = "export ONOS_NIC=" + nicAddr
andrewonlab94282092014-10-10 13:00:11 -0400579
580 try:
kelvin8ec71442015-01-15 16:57:00 -0800581 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800582 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400583
kelvin-onlabd3b64892015-01-20 13:26:24 -0800584 for arg in onosIpAddrs:
585 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800586 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400587 # export OC1="10.128.20.11"
588 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800589 cellFile.write( onosString + str( tempCount ) +
590 "=" + "\"" + arg + "\"" + "\n" )
591 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800592
kelvin-onlabd3b64892015-01-20 13:26:24 -0800593 cellFile.write( mnString + "\"" + mnIpAddrs + "\"" + "\n" )
cameron@onlab.us75900962015-03-30 13:22:49 -0700594 cellFile.write( appString + "\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800595 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400596
kelvin8ec71442015-01-15 16:57:00 -0800597 # We use os.system to send the command to TestON cluster
598 # to account for the case in which TestON is not located
599 # on the same cluster as the ONOS bench
600 # Note that even if TestON is located on the same cluster
601 # as ONOS bench, you must setup passwordless ssh
602 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800603 os.system( "scp " + tempDirectory + fileName +
604 " admin@" + benchIp + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400605
andrewonlab2a6c9342014-10-16 13:40:15 -0400606 return main.TRUE
607
andrewonlab94282092014-10-10 13:00:11 -0400608 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 )
andrewonlab94282092014-10-10 13:00:11 -0400611 main.cleanup()
612 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800613 except Exception:
614 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab94282092014-10-10 13:00:11 -0400615 main.cleanup()
616 main.exit()
617
kelvin-onlabd3b64892015-01-20 13:26:24 -0800618 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800619 """
andrewonlab95ca1462014-10-09 14:04:24 -0400620 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800621 """
andrewonlab95ca1462014-10-09 14:04:24 -0400622 try:
623 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800624 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400625 main.cleanup()
626 main.exit()
627 else:
kelvin8ec71442015-01-15 16:57:00 -0800628 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800629 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800630 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400631 # and that this driver will have to change accordingly
Cameron Franke9c94fb02015-01-21 10:20:20 -0800632 self.handle.expect(str(cellname))
kelvin-onlabd3b64892015-01-20 13:26:24 -0800633 handleBefore = self.handle.before
634 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800635 # Get the rest of the handle
Cameron Franke9c94fb02015-01-21 10:20:20 -0800636 self.handle.sendline("")
637 self.handle.expect("\$")
kelvin-onlabd3b64892015-01-20 13:26:24 -0800638 handleMore = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400639
kelvin-onlabd3b64892015-01-20 13:26:24 -0800640 main.log.info( "Cell call returned: " + handleBefore +
641 handleAfter + handleMore )
andrewonlab95ca1462014-10-09 14:04:24 -0400642
643 return main.TRUE
644
645 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800646 main.log.error( self.name + ": EOF exception found" )
647 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400648 main.cleanup()
649 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800650 except Exception:
651 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab95ca1462014-10-09 14:04:24 -0400652 main.cleanup()
653 main.exit()
654
kelvin-onlabd3b64892015-01-20 13:26:24 -0800655 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800656 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400657 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800658 """
659 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400660
andrewonlabc03bf6c2014-10-09 14:56:18 -0400661 try:
kelvin8ec71442015-01-15 16:57:00 -0800662 # Clean handle by sending empty and expecting $
663 self.handle.sendline( "" )
664 self.handle.expect( "\$" )
665 self.handle.sendline( "onos-verify-cell" )
666 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800667 handleBefore = self.handle.before
668 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800669 # Get the rest of the handle
670 self.handle.sendline( "" )
671 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800672 handleMore = self.handle.before
andrewonlabc03bf6c2014-10-09 14:56:18 -0400673
kelvin-onlabd3b64892015-01-20 13:26:24 -0800674 main.log.info( "Verify cell returned: " + handleBefore +
675 handleAfter + handleMore )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400676
677 return main.TRUE
Jon Halla5cb6172015-02-23 09:28:28 -0800678 except pexpect.ExceptionPexpect as e:
679 main.log.error( self.name + ": Pexpect exception found of type " +
680 str( type( e ) ) )
681 main.log.error ( e.get_trace() )
kelvin8ec71442015-01-15 16:57:00 -0800682 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400683 main.cleanup()
684 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800685 except Exception:
686 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400687 main.cleanup()
688 main.exit()
689
jenkins1e99e7b2015-04-02 18:15:39 -0700690 def onosCfgSet( self, ONOSIp, configName, configParam ):
691 """
692 Uses 'onos <node-ip> cfg set' to change a parameter value of an
693 application.
694
695 ex)
696 onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1
697
698 ONOSIp = '10.0.0.1'
699 configName = 'org.onosproject.myapp'
700 configParam = 'appSetting 1'
701
702 """
703 try:
704 cfgStr = ( "onos "+str(ONOSIp)+" cfg set "+
705 str(configName) + " " +
706 str(configParam)
707 )
708
709 self.handle.sendline( "" )
710 self.handle.expect( "\$" )
711 self.handle.sendline( cfgStr )
712 self.handle.expect( "\$" )
713
714 # TODO: Add meaningful assertion
715
716 return main.TRUE
717
718 except pexpect.ExceptionPexpect as e:
719 main.log.error( self.name + ": Pexpect exception found of type " +
720 str( type( e ) ) )
721 main.log.error ( e.get_trace() )
722 main.log.error( self.name + ": " + self.handle.before )
723 main.cleanup()
724 main.exit()
725 except Exception:
726 main.log.exception( self.name + ": Uncaught exception!" )
727 main.cleanup()
728 main.exit()
729
kelvin-onlabd3b64892015-01-20 13:26:24 -0800730 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800731 """
andrewonlab05e362f2014-10-10 00:40:57 -0400732 Uses 'onos' command to send various ONOS CLI arguments.
733 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800734 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400735 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800736
737 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400738 CLI commands for ONOS. Try to use this function first
739 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800740 function.
741 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400742 by starting onos, and typing in 'onos' to enter the
743 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800744 available commands.
745 """
andrewonlab05e362f2014-10-10 00:40:57 -0400746 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800747 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800748 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400749 return main.FALSE
750 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800751 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400752 return main.FALSE
753
kelvin8ec71442015-01-15 16:57:00 -0800754 cmdstr = str( cmdstr )
755 self.handle.sendline( "" )
756 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400757
kelvin-onlabd3b64892015-01-20 13:26:24 -0800758 self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr )
kelvin8ec71442015-01-15 16:57:00 -0800759 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400760
kelvin-onlabd3b64892015-01-20 13:26:24 -0800761 handleBefore = self.handle.before
Shreya Shaha73aaad2014-10-27 18:03:09 -0400762 print "handle_before = ", self.handle.before
kelvin-onlabd3b64892015-01-20 13:26:24 -0800763 # handleAfter = str( self.handle.after )
Jon Hall47a93fb2015-01-06 16:46:06 -0800764
kelvin8ec71442015-01-15 16:57:00 -0800765 # self.handle.sendline( "" )
766 # self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800767 # handleMore = str( self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400768
kelvin8ec71442015-01-15 16:57:00 -0800769 main.log.info( "Command sent successfully" )
andrewonlab05e362f2014-10-10 00:40:57 -0400770
kelvin8ec71442015-01-15 16:57:00 -0800771 # Obtain return handle that consists of result from
772 # the onos command. The string may need to be
773 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800774 # returnString = handleBefore + handleAfter
775 returnString = handleBefore
776 print "return_string = ", returnString
777 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400778
779 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800780 main.log.error( self.name + ": EOF exception found" )
781 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400782 main.cleanup()
783 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800784 except Exception:
785 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab05e362f2014-10-10 00:40:57 -0400786 main.cleanup()
787 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400788
kelvin-onlabd3b64892015-01-20 13:26:24 -0800789 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -0800790 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400791 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800792 If -f option is provided, it also forces an uninstall.
793 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400794 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800795 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400796 files to certain onos nodes
797
798 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800799 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400800 try:
andrewonlab114768a2014-11-14 12:44:44 -0500801 if options:
kelvin8ec71442015-01-15 16:57:00 -0800802 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500803 else:
kelvin8ec71442015-01-15 16:57:00 -0800804 self.handle.sendline( "onos-install " + node )
805 self.handle.expect( "onos-install " )
806 # NOTE: this timeout may need to change depending on the network
807 # and size of ONOS
808 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800809 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -0800810 "ONOS\sis\salready\sinstalled",
811 pexpect.TIMEOUT ], timeout=60 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400812
Jon Hall7993bfc2014-10-09 16:30:14 -0400813 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800814 main.log.warn( "Network is unreachable" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400815 return main.FALSE
816 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800817 main.log.info(
818 "ONOS was installed on " +
819 node +
820 " and started" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400821 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500822 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800823 main.log.info( "ONOS is already installed on " + node )
andrewonlabd9a73a72014-11-14 17:28:21 -0500824 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800825 elif i == 3:
826 main.log.info(
827 "Installation of ONOS on " +
828 node +
829 " timed out" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400830 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400831
832 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800833 main.log.error( self.name + ": EOF exception found" )
834 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400835 main.cleanup()
836 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800837 except Exception:
838 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400839 main.cleanup()
840 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400841
kelvin-onlabd3b64892015-01-20 13:26:24 -0800842 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800843 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400844 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400845 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800846 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400847 try:
kelvin8ec71442015-01-15 16:57:00 -0800848 self.handle.sendline( "" )
849 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800850 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800851 " start" )
852 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -0400853 "Job\sis\salready\srunning",
854 "start/running",
855 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800856 pexpect.TIMEOUT ], timeout=120 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400857
858 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800859 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400860 return main.TRUE
861 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800862 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400863 return main.TRUE
864 else:
kelvin8ec71442015-01-15 16:57:00 -0800865 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400866 main.cleanup()
867 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400868 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800869 main.log.error( self.name + ": EOF exception found" )
870 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400871 main.cleanup()
872 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800873 except Exception:
874 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400875 main.cleanup()
876 main.exit()
877
kelvin-onlabd3b64892015-01-20 13:26:24 -0800878 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800879 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400880 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400881 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800882 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400883 try:
kelvin8ec71442015-01-15 16:57:00 -0800884 self.handle.sendline( "" )
885 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800886 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800887 " stop" )
888 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -0400889 "stop/waiting",
Jon Hall61282e32015-03-19 11:34:11 -0700890 "Could not resolve hostname",
andrewonlab2b30bd32014-10-09 16:48:55 -0400891 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800892 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2b30bd32014-10-09 16:48:55 -0400893
894 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800895 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400896 return main.TRUE
897 elif i == 1:
Jon Hall65844a32015-03-09 19:09:37 -0700898 main.log.info( "onosStop() Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800899 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -0400900 return main.FALSE
Jon Hall61282e32015-03-19 11:34:11 -0700901 elif i == 2:
902 main.log.warn( "ONOS wasn't running" )
903 return main.TRUE
andrewonlab2b30bd32014-10-09 16:48:55 -0400904 else:
kelvin8ec71442015-01-15 16:57:00 -0800905 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400906 return main.FALSE
907
908 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800909 main.log.error( self.name + ": EOF exception found" )
910 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -0400911 main.cleanup()
912 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800913 except Exception:
914 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400915 main.cleanup()
916 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800917
kelvin-onlabd3b64892015-01-20 13:26:24 -0800918 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -0800919 """
andrewonlabc8d47972014-10-09 16:52:36 -0400920 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -0800921 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -0400922 if needed
kelvin8ec71442015-01-15 16:57:00 -0800923 """
andrewonlabc8d47972014-10-09 16:52:36 -0400924 try:
kelvin8ec71442015-01-15 16:57:00 -0800925 self.handle.sendline( "" )
926 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800927 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800928 self.handle.expect( "\$" )
andrewonlabc8d47972014-10-09 16:52:36 -0400929
kelvin-onlabd3b64892015-01-20 13:26:24 -0800930 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
andrewonlab9dfd2082014-11-13 17:44:03 -0500931
kelvin8ec71442015-01-15 16:57:00 -0800932 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -0400933 return main.TRUE
934
935 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800936 main.log.error( self.name + ": EOF exception found" )
937 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -0400938 main.cleanup()
939 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800940 except Exception:
941 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc8d47972014-10-09 16:52:36 -0400942 main.cleanup()
943 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400944
kelvin-onlabd3b64892015-01-20 13:26:24 -0800945 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800946 """
andrewonlabaedc8332014-12-04 12:43:03 -0500947 Issues the command 'onos-die <node-ip>'
948 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -0800949 """
andrewonlabaedc8332014-12-04 12:43:03 -0500950 try:
kelvin8ec71442015-01-15 16:57:00 -0800951 self.handle.sendline( "" )
952 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800953 cmdStr = "onos-kill " + str( nodeIp )
954 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800955 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -0500956 "Killing\sONOS",
957 "ONOS\sprocess\sis\snot\srunning",
kelvin8ec71442015-01-15 16:57:00 -0800958 pexpect.TIMEOUT ], timeout=20 )
andrewonlabaedc8332014-12-04 12:43:03 -0500959 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800960 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800961 " was killed and stopped" )
andrewonlabaedc8332014-12-04 12:43:03 -0500962 return main.TRUE
963 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800964 main.log.info( "ONOS process was not running" )
andrewonlabaedc8332014-12-04 12:43:03 -0500965 return main.FALSE
966 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800967 main.log.error( self.name + ": EOF exception found" )
968 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -0500969 main.cleanup()
970 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800971 except Exception:
972 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabaedc8332014-12-04 12:43:03 -0500973 main.cleanup()
974 main.exit()
975
kelvin-onlabd3b64892015-01-20 13:26:24 -0800976 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800977 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400978 Calls the command: 'onos-kill [<node-ip>]'
979 "Remotely, and unceremoniously kills the ONOS instance running on
980 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -0800981 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400982 try:
kelvin8ec71442015-01-15 16:57:00 -0800983 self.handle.sendline( "" )
984 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800985 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800986 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -0400987 "\$",
988 "No\sroute\sto\shost",
989 "password:",
kelvin8ec71442015-01-15 16:57:00 -0800990 pexpect.TIMEOUT ], timeout=20 )
991
andrewonlabe8e56fd2014-10-09 17:12:44 -0400992 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800993 main.log.info(
994 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800995 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400996 return main.TRUE
997 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800998 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400999 return main.FALSE
1000 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001001 main.log.info(
1002 "Passwordless login for host: " +
1003 str( nodeIp ) +
1004 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001005 return main.FALSE
1006 else:
Jon Hallefbd9792015-03-05 16:11:36 -08001007 main.log.info( "ONOS instance was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001008 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001009
andrewonlabe8e56fd2014-10-09 17:12:44 -04001010 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001011 main.log.error( self.name + ": EOF exception found" )
1012 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001013 main.cleanup()
1014 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001015 except Exception:
1016 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001017 main.cleanup()
1018 main.exit()
1019
kelvin-onlabd3b64892015-01-20 13:26:24 -08001020 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -08001021 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001022 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -05001023 a cleaner environment.
1024
andrewonlab19fbdca2014-11-14 12:55:59 -05001025 Description:
Jon Hallfcc88622014-11-25 13:09:54 -05001026 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -05001027 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -08001028 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001029 try:
kelvin8ec71442015-01-15 16:57:00 -08001030 self.handle.sendline( "" )
1031 self.handle.expect( "\$" )
1032 self.handle.sendline( "onos-remove-raft-logs" )
1033 # Sometimes this command hangs
1034 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
1035 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001036 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001037 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
1038 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001039 if i == 1:
1040 return main.FALSE
shahshreya957feaa2015-03-23 16:08:29 -07001041 #self.handle.sendline( "" )
1042 #self.handle.expect( "\$" )
andrewonlab19fbdca2014-11-14 12:55:59 -05001043 return main.TRUE
1044
1045 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001046 main.log.error( self.name + ": EOF exception found" )
1047 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -05001048 main.cleanup()
1049 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001050 except Exception:
1051 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab19fbdca2014-11-14 12:55:59 -05001052 main.cleanup()
1053 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -05001054
kelvin-onlabd3b64892015-01-20 13:26:24 -08001055 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -08001056 """
1057 Calls the command 'onos-start-network [ <mininet-topo> ]
1058 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -04001059 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -08001060 cell."
andrewonlab94282092014-10-10 13:00:11 -04001061 * Specify mininet topology file name for mntopo
1062 * Topo files should be placed at:
1063 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001064
andrewonlab94282092014-10-10 13:00:11 -04001065 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001066 """
andrewonlab94282092014-10-10 13:00:11 -04001067 try:
1068 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001069 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001070 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001071
kelvin8ec71442015-01-15 16:57:00 -08001072 mntopo = str( mntopo )
1073 self.handle.sendline( "" )
1074 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -04001075
kelvin8ec71442015-01-15 16:57:00 -08001076 self.handle.sendline( "onos-start-network " + mntopo )
1077 self.handle.expect( "mininet>" )
1078 main.log.info( "Network started, entered mininet prompt" )
1079
1080 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001081
1082 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001083 main.log.error( self.name + ": EOF exception found" )
1084 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001085 main.cleanup()
1086 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001087 except Exception:
1088 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab94282092014-10-10 13:00:11 -04001089 main.cleanup()
1090 main.exit()
1091
Cameron Franke9c94fb02015-01-21 10:20:20 -08001092 def isup(self, node = "", timeout = 120):
kelvin8ec71442015-01-15 16:57:00 -08001093 """
1094 Run's onos-wait-for-start which only returns once ONOS is at run
Cameron Franke9c94fb02015-01-21 10:20:20 -08001095 level 100(ready for use)
andrewonlab8d0d7d72014-10-09 16:33:15 -04001096
Jon Hall7993bfc2014-10-09 16:30:14 -04001097 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001098 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001099 try:
Cameron Franke9c94fb02015-01-21 10:20:20 -08001100 self.handle.sendline("onos-wait-for-start " + node )
1101 self.handle.expect("onos-wait-for-start")
kelvin8ec71442015-01-15 16:57:00 -08001102 # NOTE: this timeout is arbitrary"
Cameron Franke9c94fb02015-01-21 10:20:20 -08001103 i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout)
Jon Hall7993bfc2014-10-09 16:30:14 -04001104 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001105 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001106 return main.TRUE
1107 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001108 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001109 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001110 main.log.error( "ONOS has not started yet" )
1111 self.handle.send( "\x03" ) # Control-C
1112 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001113 return main.FALSE
1114 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001115 main.log.error( self.name + ": EOF exception found" )
1116 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001117 main.cleanup()
1118 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001119 except Exception:
1120 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001121 main.cleanup()
1122 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001123
kelvin-onlabd3b64892015-01-20 13:26:24 -08001124 def pushTestIntentsShell(
1125 self,
1126 dpidSrc,
1127 dpidDst,
1128 numIntents,
1129 dirFile,
1130 onosIp,
1131 numMult="",
1132 appId="",
1133 report=True,
1134 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001135 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001136 Description:
kelvin8ec71442015-01-15 16:57:00 -08001137 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001138 better parallelize the results than the CLI
1139 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001140 * dpidSrc: specify source dpid
1141 * dpidDst: specify destination dpid
1142 * numIntents: specify number of intents to push
1143 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001144 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001145 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001146 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001147 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001148 """
1149 try:
1150 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001151 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001152 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001153 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001154 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001155 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001156
kelvin-onlabd3b64892015-01-20 13:26:24 -08001157 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1158 if not numMult:
1159 addIntents = addDpid + " " + str( numIntents )
1160 elif numMult:
1161 addIntents = addDpid + " " + str( numIntents ) + " " +\
1162 str( numMult )
1163 if appId:
1164 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001165 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001166 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001167
andrewonlabaedc8332014-12-04 12:43:03 -05001168 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001169 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001170 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001171 sendCmd = addApp + " &"
1172 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001173
kelvin-onlabd3b64892015-01-20 13:26:24 -08001174 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001175
1176 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001177 main.log.error( self.name + ": EOF exception found" )
1178 main.log.error( self.name + ": " + self.handle.before )
andrewonlabb66dfa12014-12-02 15:51:10 -05001179 main.cleanup()
1180 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001181 except Exception:
1182 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001183 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001184 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001185
kelvin-onlabd3b64892015-01-20 13:26:24 -08001186 def getTopology( self, topologyOutput ):
kelvin8ec71442015-01-15 16:57:00 -08001187 """
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001188 Definition:
1189 Loads a json topology output
1190 Return:
1191 topology = current ONOS topology
kelvin8ec71442015-01-15 16:57:00 -08001192 """
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001193 import json
Jon Hall77f53ce2014-10-13 18:02:06 -04001194 try:
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001195 # either onos:topology or 'topology' will work in CLI
1196 topology = json.loads(topologyOutput)
1197 print topology
Jon Hall77f53ce2014-10-13 18:02:06 -04001198 return topology
1199 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001200 main.log.error( self.name + ": EOF exception found" )
1201 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001202 main.cleanup()
1203 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001204 except Exception:
1205 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001206 main.cleanup()
1207 main.exit()
1208
kelvin-onlabd3b64892015-01-20 13:26:24 -08001209 def checkStatus(
1210 self,
1211 topologyResult,
1212 numoswitch,
1213 numolink,
1214 logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001215 """
Jon Hallefbd9792015-03-05 16:11:36 -08001216 Checks the number of switches & links that ONOS sees against the
kelvin8ec71442015-01-15 16:57:00 -08001217 supplied values. By default this will report to main.log, but the
Jon Hallefbd9792015-03-05 16:11:36 -08001218 log level can be specific.
kelvin8ec71442015-01-15 16:57:00 -08001219
Jon Hall77f53ce2014-10-13 18:02:06 -04001220 Params: ip = ip used for the onos cli
1221 numoswitch = expected number of switches
Jon Hallefbd9792015-03-05 16:11:36 -08001222 numolink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001223 logLevel = level to log to.
1224 Currently accepts 'info', 'warn' and 'report'
Jon Hall77f53ce2014-10-13 18:02:06 -04001225
1226
kelvin-onlabd3b64892015-01-20 13:26:24 -08001227 logLevel can
Jon Hall77f53ce2014-10-13 18:02:06 -04001228
Jon Hallefbd9792015-03-05 16:11:36 -08001229 Returns: main.TRUE if the number of switches and links are correct,
1230 main.FALSE if the number of switches and links is incorrect,
Jon Hall77f53ce2014-10-13 18:02:06 -04001231 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001232 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001233 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001234 topology = self.getTopology( topologyResult )
Jon Hall77f53ce2014-10-13 18:02:06 -04001235 if topology == {}:
1236 return main.ERROR
1237 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001238 # Is the number of switches is what we expected
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001239 devices = topology.get( 'deviceCount', False )
1240 links = topology.get( 'linkCount', False )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001241 if not devices or not links:
Jon Hall77f53ce2014-10-13 18:02:06 -04001242 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001243 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001244 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001245 linkCheck = ( int( links ) == int( numolink ) )
Jon Hallefbd9792015-03-05 16:11:36 -08001246 if switchCheck and linkCheck:
kelvin8ec71442015-01-15 16:57:00 -08001247 # We expected the correct numbers
Jon Hall77f53ce2014-10-13 18:02:06 -04001248 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001249 + "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001250 result = main.TRUE
1251 else:
1252 output = output + \
Jon Hall274b6642015-02-17 11:57:17 -08001253 "The number of links and switches does not match " + \
1254 "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001255 result = main.FALSE
Jon Hallefbd9792015-03-05 16:11:36 -08001256 output = output + "\n ONOS sees %i devices" % int( devices )
1257 output = output + " (%i expected) " % int( numoswitch )
Jon Hall274b6642015-02-17 11:57:17 -08001258 output = output + "and %i links " % int( links )
1259 output = output + "(%i expected)" % int( numolink )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001260 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001261 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001262 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001263 main.log.warn( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001264 else:
kelvin8ec71442015-01-15 16:57:00 -08001265 main.log.info( output )
1266 return result
Jon Hall77f53ce2014-10-13 18:02:06 -04001267 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001268 main.log.error( self.name + ": EOF exception found" )
1269 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001270 main.cleanup()
1271 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001272 except Exception:
1273 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001274 main.cleanup()
1275 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001276
kelvin-onlabd3b64892015-01-20 13:26:24 -08001277 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001278 """
andrewonlab970399c2014-11-07 13:09:32 -05001279 Capture all packet activity and store in specified
1280 directory/file
1281
1282 Required:
1283 * interface: interface to capture
1284 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001285 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001286 try:
1287 self.handle.sendline( "" )
1288 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001289
Jon Hallfebb1c72015-03-05 13:30:09 -08001290 self.handle.sendline( "tshark -i " + str( interface ) +
1291 " -t e -w " + str( dirFile ) + " &" )
1292 self.handle.sendline( "\r" )
1293 self.handle.expect( "Capturing on" )
1294 self.handle.sendline( "\r" )
1295 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001296
Jon Hallfebb1c72015-03-05 13:30:09 -08001297 main.log.info( "Tshark started capturing files on " +
1298 str( interface ) + " and saving to directory: " +
1299 str( dirFile ) )
1300 except pexpect.EOF:
1301 main.log.error( self.name + ": EOF exception found" )
1302 main.log.error( self.name + ": " + self.handle.before )
1303 main.cleanup()
1304 main.exit()
1305 except Exception:
1306 main.log.exception( self.name + ": Uncaught exception!" )
1307 main.cleanup()
1308 main.exit()
Shreya Shaha73aaad2014-10-27 18:03:09 -04001309
kelvin-onlabd3b64892015-01-20 13:26:24 -08001310 def runOnosTopoCfg( self, instanceName, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001311 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001312 On ONOS bench, run this command:
Jon Halle94919c2015-03-23 11:42:57 -07001313 {ONOS_HOME}/tools/test/bin/onos-topo-cfg $OC1 filename
kelvin-onlabd3b64892015-01-20 13:26:24 -08001314 which starts the rest and copies
1315 the json file to the onos instance
kelvin8ec71442015-01-15 16:57:00 -08001316 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001317 try:
kelvin8ec71442015-01-15 16:57:00 -08001318 self.handle.sendline( "" )
1319 self.handle.expect( "\$" )
Jon Halle94919c2015-03-23 11:42:57 -07001320 self.handle.sendline( "cd " + self.home + "/tools/test/bin" )
kelvin8ec71442015-01-15 16:57:00 -08001321 self.handle.expect( "/bin$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001322 cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile
shahshreyae6c7cf42014-11-26 16:39:01 -08001323 print "cmd = ", cmd
kelvin8ec71442015-01-15 16:57:00 -08001324 self.handle.sendline( cmd )
1325 self.handle.expect( "\$" )
1326 self.handle.sendline( "cd ~" )
1327 self.handle.expect( "\$" )
shahshreyae6c7cf42014-11-26 16:39:01 -08001328 return main.TRUE
Jon Hallfebb1c72015-03-05 13:30:09 -08001329 except pexpect.EOF:
1330 main.log.error( self.name + ": EOF exception found" )
1331 main.log.error( self.name + ": " + self.handle.before )
1332 main.cleanup()
1333 main.exit()
1334 except Exception:
1335 main.log.exception( self.name + ": Uncaught exception!" )
1336 main.cleanup()
1337 main.exit()
kelvin8ec71442015-01-15 16:57:00 -08001338
jenkins1e99e7b2015-04-02 18:15:39 -07001339 def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ):
kelvin8ec71442015-01-15 16:57:00 -08001340 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001341 Required:
kelvin8ec71442015-01-15 16:57:00 -08001342 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001343 * directory to store results
1344 Optional:
1345 * interface - default: eth0
jenkins1e99e7b2015-04-02 18:15:39 -07001346 * grepOptions - options for grep
andrewonlabba44bcf2014-10-16 16:54:41 -04001347 Description:
1348 Uses tshark command to grep specific group of packets
1349 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001350 The timestamp is hardcoded to be in epoch
1351 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001352 try:
1353 self.handle.sendline( "" )
1354 self.handle.expect( "\$" )
1355 self.handle.sendline( "" )
jenkins1e99e7b2015-04-02 18:15:39 -07001356 if grepOptions:
1357 grepStr = "grep "+str(grepOptions)
1358 else:
1359 grepStr = "grep"
1360
Jon Hallfebb1c72015-03-05 13:30:09 -08001361 self.handle.sendline(
1362 "tshark -i " +
1363 str( interface ) +
jenkins1e99e7b2015-04-02 18:15:39 -07001364 " -t e | " +
1365 grepStr + " --line-buffered \"" +
Jon Hallfebb1c72015-03-05 13:30:09 -08001366 str(grep) +
1367 "\" >" +
1368 directory +
1369 " &" )
1370 self.handle.sendline( "\r" )
1371 self.handle.expect( "Capturing on" )
1372 self.handle.sendline( "\r" )
1373 self.handle.expect( "\$" )
1374 except pexpect.EOF:
1375 main.log.error( self.name + ": EOF exception found" )
1376 main.log.error( self.name + ": " + self.handle.before )
1377 main.cleanup()
1378 main.exit()
1379 except Exception:
1380 main.log.exception( self.name + ": Uncaught exception!" )
1381 main.cleanup()
1382 main.exit()
1383
kelvin-onlabd3b64892015-01-20 13:26:24 -08001384 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001385 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001386 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001387 """
1388 # Remove all pcap from previous captures
Jon Hallfebb1c72015-03-05 13:30:09 -08001389 try:
1390 self.execute( cmd="sudo rm /tmp/wireshark*" )
1391 self.handle.sendline( "" )
Jon Hallefbd9792015-03-05 16:11:36 -08001392 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" +
1393 " | grep -v grep | awk '{print $2}'`" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001394 self.handle.sendline( "" )
1395 main.log.info( "Tshark stopped" )
1396 except pexpect.EOF:
1397 main.log.error( self.name + ": EOF exception found" )
1398 main.log.error( self.name + ": " + self.handle.before )
1399 main.cleanup()
1400 main.exit()
1401 except Exception:
1402 main.log.exception( self.name + ": Uncaught exception!" )
1403 main.cleanup()
1404 main.exit()
1405
kelvin8ec71442015-01-15 16:57:00 -08001406 def ptpd( self, args ):
1407 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001408 Initiate ptp with user-specified args.
1409 Required:
1410 * args: specify string of args after command
1411 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001412 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001413 try:
kelvin8ec71442015-01-15 16:57:00 -08001414 self.handle.sendline( "sudo ptpd " + str( args ) )
1415 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001416 "Multiple",
1417 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001418 "\$" ] )
1419 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001420
andrewonlab0c38a4a2014-10-28 18:35:35 -04001421 if i == 0:
1422 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001423 main.log.info( "ptpd returned an error: " +
1424 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001425 return handle
1426 elif i == 1:
1427 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001428 main.log.error( "ptpd returned an error: " +
1429 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001430 return handle
1431 else:
1432 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001433
andrewonlab0c38a4a2014-10-28 18:35:35 -04001434 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001435 main.log.error( self.name + ": EOF exception found" )
1436 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001437 main.cleanup()
1438 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001439 except Exception:
1440 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001441 main.cleanup()
1442 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001443
kelvin-onlabd3b64892015-01-20 13:26:24 -08001444 def cpLogsToDir( self, logToCopy,
Jon Hallefbd9792015-03-05 16:11:36 -08001445 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001446 """
1447 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001448 Current implementation of ONOS deletes its karaf
1449 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001450 you may want to use this function to capture
1451 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001452 Localtime will be attached to the filename
1453
1454 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001455 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001456 copy.
kelvin8ec71442015-01-15 16:57:00 -08001457 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001458 For copying multiple files, leave copyFileName
1459 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001460 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001461 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001462 ex ) /tmp/
1463 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001464 * copyFileName: If you want to rename the log
1465 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001466 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001467 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001468 try:
kelvin8ec71442015-01-15 16:57:00 -08001469 localtime = time.strftime( '%x %X' )
1470 localtime = localtime.replace( "/", "" )
1471 localtime = localtime.replace( " ", "_" )
1472 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001473 if destDir[ -1: ] != "/":
1474 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001475
kelvin-onlabd3b64892015-01-20 13:26:24 -08001476 if copyFileName:
Jon Hallfebb1c72015-03-05 13:30:09 -08001477 self.handle.sendline( "cp " + str( logToCopy ) + " " +
1478 str( destDir ) + str( copyFileName ) +
1479 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001480 self.handle.expect( "cp" )
1481 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001482 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001483 self.handle.sendline( "cp " + str( logToCopy ) +
1484 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001485 self.handle.expect( "cp" )
1486 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001487
kelvin8ec71442015-01-15 16:57:00 -08001488 return self.handle.before
1489
1490 except pexpect.EOF:
1491 main.log.error( "Copying files failed" )
1492 main.log.error( self.name + ": EOF exception found" )
1493 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001494 except Exception:
1495 main.log.exception( "Copying files failed" )
1496
kelvin-onlabd3b64892015-01-20 13:26:24 -08001497 def checkLogs( self, onosIp ):
kelvin8ec71442015-01-15 16:57:00 -08001498 """
Jon Hall94fd0472014-12-08 11:52:42 -08001499 runs onos-check-logs on the given onos node
1500 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001501 """
Jon Hall94fd0472014-12-08 11:52:42 -08001502 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001503 cmd = "onos-check-logs " + str( onosIp )
kelvin8ec71442015-01-15 16:57:00 -08001504 self.handle.sendline( cmd )
1505 self.handle.expect( cmd )
1506 self.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -08001507 response = self.handle.before
1508 return response
1509 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001510 main.log.error( "Lost ssh connection" )
1511 main.log.error( self.name + ": EOF exception found" )
1512 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001513 except Exception:
1514 main.log.exception( self.name + ": Uncaught exception!" )
1515 main.cleanup()
1516 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -08001517
kelvin-onlabd3b64892015-01-20 13:26:24 -08001518 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001519 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001520 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001521 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001522 try:
kelvin8ec71442015-01-15 16:57:00 -08001523 self.handle.sendline( "" )
1524 self.handle.expect( "\$" )
1525 self.handle.sendline( "onos-service " + str( node ) +
1526 " status" )
1527 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001528 "start/running",
1529 "stop/waiting",
kelvin8ec71442015-01-15 16:57:00 -08001530 pexpect.TIMEOUT ], timeout=120 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001531
1532 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001533 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001534 return main.TRUE
1535 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001536 main.log.info( "ONOS is stopped" )
kelvin8ec71442015-01-15 16:57:00 -08001537 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001538 main.cleanup()
1539 main.exit()
1540 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001541 main.log.error( self.name + ": EOF exception found" )
1542 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001543 main.cleanup()
1544 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001545 except Exception:
1546 main.log.exception( self.name + ": Uncaught exception!" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001547 main.cleanup()
1548 main.exit()
Jon Hall21270ac2015-02-16 17:59:55 -08001549
Jon Hall63604932015-02-26 17:09:50 -08001550 def setIpTables( self, ip, port='', action='add', packet_type='',
1551 direction='INPUT', rule='DROP', states=True ):
Jon Hallefbd9792015-03-05 16:11:36 -08001552 """
Jon Hall21270ac2015-02-16 17:59:55 -08001553 Description:
1554 add or remove iptables rule to DROP (default) packets from
1555 specific IP and PORT
1556 Usage:
1557 * specify action ('add' or 'remove')
1558 when removing, pass in the same argument as you would add. It will
1559 delete that specific rule.
1560 * specify the ip to block
1561 * specify the destination port to block (defaults to all ports)
1562 * optional packet type to block (default tcp)
1563 * optional iptables rule (default DROP)
1564 * optional direction to block (default 'INPUT')
Jon Hall63604932015-02-26 17:09:50 -08001565 * States boolean toggles adding all supported tcp states to the
1566 firewall rule
Jon Hall21270ac2015-02-16 17:59:55 -08001567 Returns:
1568 main.TRUE on success or
1569 main.FALSE if given invalid input or
1570 main.ERROR if there is an error in response from iptables
1571 WARNING:
1572 * This function uses root privilege iptables command which may result
1573 in unwanted network errors. USE WITH CAUTION
Jon Hallefbd9792015-03-05 16:11:36 -08001574 """
Jon Hall21270ac2015-02-16 17:59:55 -08001575 import time
1576
1577 # NOTE*********
1578 # The strict checking methods of this driver function is intentional
1579 # to discourage any misuse or error of iptables, which can cause
1580 # severe network errors
1581 # *************
1582
1583 # NOTE: Sleep needed to give some time for rule to be added and
1584 # registered to the instance. If you are calling this function
1585 # multiple times this sleep will prevent any errors.
1586 # DO NOT REMOVE
Jon Hall63604932015-02-26 17:09:50 -08001587 # time.sleep( 5 )
Jon Hall21270ac2015-02-16 17:59:55 -08001588 try:
1589 # input validation
1590 action_type = action.lower()
1591 rule = rule.upper()
1592 direction = direction.upper()
1593 if action_type != 'add' and action_type != 'remove':
1594 main.log.error( "Invalid action type. Use 'add' or "
1595 "'remove' table rule" )
1596 if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
1597 # NOTE Currently only supports rules DROP, ACCEPT, and LOG
1598 main.log.error( "Invalid rule. Valid rules are 'DROP' or "
1599 "'ACCEPT' or 'LOG' only." )
1600 if direction != 'INPUT' and direction != 'OUTPUT':
1601 # NOTE currently only supports rules INPUT and OUPTUT
1602 main.log.error( "Invalid rule. Valid directions are"
1603 " 'OUTPUT' or 'INPUT'" )
1604 return main.FALSE
1605 return main.FALSE
1606 return main.FALSE
1607 if action_type == 'add':
1608 # -A is the 'append' action of iptables
1609 actionFlag = '-A'
1610 elif action_type == 'remove':
1611 # -D is the 'delete' rule of iptables
1612 actionFlag = '-D'
1613 self.handle.sendline( "" )
1614 self.handle.expect( "\$" )
1615 cmd = "sudo iptables " + actionFlag + " " +\
1616 direction +\
Jon Hall21270ac2015-02-16 17:59:55 -08001617 " -s " + str( ip )
Jon Hall63604932015-02-26 17:09:50 -08001618 # " -p " + str( packet_type ) +\
1619 if packet_type:
1620 cmd += " -p " + str( packet_type )
Jon Hall21270ac2015-02-16 17:59:55 -08001621 if port:
1622 cmd += " --dport " + str( port )
Jon Hall63604932015-02-26 17:09:50 -08001623 if states:
1624 cmd += " -m state --state="
1625 #FIXME- Allow user to configure which states to block
1626 cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED"
Jon Hall21270ac2015-02-16 17:59:55 -08001627 cmd += " -j " + str( rule )
1628
1629 self.handle.sendline( cmd )
1630 self.handle.expect( "\$" )
1631 main.log.warn( self.handle.before )
1632
1633 info_string = "On " + str( self.name )
1634 info_string += " " + str( action_type )
1635 info_string += " iptable rule [ "
1636 info_string += " IP: " + str( ip )
1637 info_string += " Port: " + str( port )
1638 info_string += " Rule: " + str( rule )
1639 info_string += " Direction: " + str( direction ) + " ]"
1640 main.log.info( info_string )
1641 return main.TRUE
1642 except pexpect.TIMEOUT:
1643 main.log.exception( self.name + ": Timeout exception in "
1644 "setIpTables function" )
1645 return main.ERROR
1646 except pexpect.EOF:
1647 main.log.error( self.name + ": EOF exception found" )
1648 main.log.error( self.name + ": " + self.handle.before )
1649 main.cleanup()
1650 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001651 except Exception:
1652 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall21270ac2015-02-16 17:59:55 -08001653 main.cleanup()
1654 main.exit()
1655
Jon Hall0468b042015-02-19 19:08:21 -08001656 def detailed_status(self, log_filename):
Jon Hallefbd9792015-03-05 16:11:36 -08001657 """
Jon Hall0468b042015-02-19 19:08:21 -08001658 This method is used by STS to check the status of the controller
1659 Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
Jon Hallefbd9792015-03-05 16:11:36 -08001660 """
Jon Hall0468b042015-02-19 19:08:21 -08001661 import re
1662 try:
1663 self.handle.sendline( "" )
1664 self.handle.expect( "\$" )
1665 self.handle.sendline( "cd " + self.home )
1666 self.handle.expect( "\$" )
1667 self.handle.sendline( "service onos status" )
1668 self.handle.expect( "\$" )
1669 response = self.handle.before
1670 if re.search( "onos start/running", response ):
1671 # onos start/running, process 10457
1672 return 'RUNNING'
1673 # FIXME: Implement this case
1674 # elif re.search( pattern, response ):
1675 # return 'STARTING'
1676 elif re.search( "onos stop/", response ):
1677 # onos stop/waiting
1678 # FIXME handle this differently?: onos stop/pre-stop
1679 return 'STOPPED'
1680 # FIXME: Implement this case
1681 # elif re.search( pattern, response ):
1682 # return 'FROZEN'
1683 else:
1684 main.log.warn( self.name +
Jon Hallefbd9792015-03-05 16:11:36 -08001685 " WARNING: status received unknown response" )
Jon Hall0468b042015-02-19 19:08:21 -08001686 main.log.warn( response )
1687 return 'ERROR', "Unknown response: %s" % response
1688 except pexpect.TIMEOUT:
1689 main.log.exception( self.name + ": Timeout exception in "
1690 "setIpTables function" )
1691 return 'ERROR', "Pexpect Timeout"
1692 except pexpect.EOF:
1693 main.log.error( self.name + ": EOF exception found" )
1694 main.log.error( self.name + ": " + self.handle.before )
1695 main.cleanup()
1696 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001697 except Exception:
1698 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall0468b042015-02-19 19:08:21 -08001699 main.cleanup()
1700 main.exit()
1701
andrew@onlab.us3b087132015-03-11 15:00:08 -07001702 def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount):
1703 '''
1704 Create/formats the LinkGraph.cfg file based on arguments
1705 -only creates a linear topology and connects islands
1706 -evenly distributes devices
1707 -must be called by ONOSbench
1708
1709 ONOSIpList - list of all of the node IPs to be used
1710
1711 deviceCount - number of switches to be assigned
1712 '''
1713 main.log.step("Creating link graph configuration file." )
1714 linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg"
1715 tempFile = "/tmp/linkGraph.cfg"
1716
1717 linkGraph = open(tempFile, 'w+')
1718 linkGraph.write("# NullLinkProvider topology description (config file).\n")
1719 linkGraph.write("# The NodeId is only added if the destination is another node's device.\n")
1720 linkGraph.write("# Bugs: Comments cannot be appended to a line to be read.\n")
1721
1722 clusterCount = len(ONOSIpList)
1723
1724 if type(deviceCount) is int or type(deviceCount) is str:
1725 deviceCount = int(deviceCount)
1726 switchList = [0]*(clusterCount+1)
1727 baselineSwitchCount = deviceCount/clusterCount
1728
1729 for node in range(1, clusterCount + 1):
1730 switchList[node] = baselineSwitchCount
1731
1732 for node in range(1, (deviceCount%clusterCount)+1):
1733 switchList[node] += 1
1734
1735 if type(deviceCount) is list:
1736 main.log.info("Using provided device distribution")
1737 switchList = [0]
1738 for i in deviceCount:
1739 switchList.append(int(i))
1740
1741 tempList = ['0']
1742 tempList.extend(ONOSIpList)
1743 ONOSIpList = tempList
1744
1745 myPort = 6
1746 lastSwitch = 0
1747 for node in range(1, clusterCount+1):
1748 if switchList[node] == 0:
1749 continue
1750
1751 linkGraph.write("graph " + ONOSIpList[node] + " {\n")
1752
1753 if node > 1:
1754 #connect to last device on previous node
1755 line = ("\t0:5 -> " + str(lastSwitch) + ":6:" + lastIp + "\n") #ONOSIpList[node-1]
1756 linkGraph.write(line)
1757
1758 lastSwitch = 0
1759 for switch in range (0, switchList[node]-1):
1760 line = ""
1761 line = ("\t" + str(switch) + ":" + str(myPort))
1762 line += " -- "
1763 line += (str(switch+1) + ":" + str(myPort-1) + "\n")
1764 linkGraph.write(line)
1765 lastSwitch = switch+1
1766 lastIp = ONOSIpList[node]
1767
1768 #lastSwitch += 1
1769 if node < (clusterCount):
1770 #connect to first device on the next node
1771 line = ("\t" + str(lastSwitch) + ":6 -> 0:5:" + ONOSIpList[node+1] + "\n")
1772 linkGraph.write(line)
1773
1774 linkGraph.write("}\n")
1775 linkGraph.close()
1776
1777 #SCP
1778 os.system( "scp " + tempFile + " admin@" + benchIp + ":" + linkGraphPath)
1779 main.log.info("linkGraph.cfg creation complete")
1780
cameron@onlab.us75900962015-03-30 13:22:49 -07001781 def configNullDev( self, ONOSIpList, deviceCount, numPorts=10):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001782
1783 '''
andrew@onlab.us3b087132015-03-11 15:00:08 -07001784 ONOSIpList = list of Ip addresses of nodes switches will be devided amongst
cameron@onlab.us75900962015-03-30 13:22:49 -07001785 deviceCount = number of switches to distribute, or list of values to use as custom distribution
1786 numPorts = number of ports per device. Defaults to 10 both in this function and in ONOS. Optional arg
andrew@onlab.us3b087132015-03-11 15:00:08 -07001787 '''
1788
cameron@onlab.us75900962015-03-30 13:22:49 -07001789 main.log.step("Configuring Null Device Provider" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001790 clusterCount = len(ONOSIpList)
1791
cameron@onlab.us75900962015-03-30 13:22:49 -07001792 try:
1793
1794 if type(deviceCount) is int or type(deviceCount) is str:
1795 main.log.step("Creating device distribution")
1796 deviceCount = int(deviceCount)
1797 switchList = [0]*(clusterCount+1)
1798 baselineSwitchCount = deviceCount/clusterCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001799
cameron@onlab.us75900962015-03-30 13:22:49 -07001800 for node in range(1, clusterCount + 1):
1801 switchList[node] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001802
cameron@onlab.us75900962015-03-30 13:22:49 -07001803 for node in range(1, (deviceCount%clusterCount)+1):
1804 switchList[node] += 1
1805
1806 if type(deviceCount) is list:
1807 main.log.info("Using provided device distribution")
1808
1809 if len(deviceCount) == clusterCount:
1810 switchList = ['0']
1811 switchList.extend(deviceCount)
1812
1813 if len(deviceCount) == (clusterCount + 1):
1814 if deviceCount[0] == '0' or deviceCount[0] == 0:
1815 switchList = deviceCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001816
cameron@onlab.us75900962015-03-30 13:22:49 -07001817 assert len(switchList) == (clusterCount + 1)
1818
1819 except AssertionError:
1820 main.log.error( "Bad device/Ip list match")
1821 except TypeError:
1822 main.log.exception( self.name + ": Object not as expected" )
1823 return None
Jon Hall77ba41c2015-04-06 10:25:40 -07001824 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07001825 main.log.exception( self.name + ": Uncaught exception!" )
1826 main.cleanup()
1827 main.exit()
1828
andrew@onlab.us3b087132015-03-11 15:00:08 -07001829
1830 ONOSIp = [0]
1831 ONOSIp.extend(ONOSIpList)
1832
1833 devicesString = "devConfigs = "
1834 for node in range(1, len(ONOSIp)):
1835 devicesString += (ONOSIp[node] + ":" + str(switchList[node] ))
1836 if node < clusterCount:
1837 devicesString += (",")
cameron@onlab.us75900962015-03-30 13:22:49 -07001838
1839 try:
1840 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString )
1841 self.handle.expect(":~")
1842 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str(numPorts) )
1843 self.handle.expect(":~")
andrew@onlab.us3b087132015-03-11 15:00:08 -07001844
cameron@onlab.us75900962015-03-30 13:22:49 -07001845 for i in range(10):
1846 self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider")
1847 self.handle.expect(":~")
1848 verification = self.handle.before
1849 if (" value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification:
1850 break
1851 else:
1852 time.sleep(1)
andrew@onlab.us3b087132015-03-11 15:00:08 -07001853
cameron@onlab.us2cc8bf12015-04-02 14:12:30 -07001854 assert ("value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification
cameron@onlab.us75900962015-03-30 13:22:49 -07001855
1856 except AssertionError:
1857 main.log.error("Incorrect Config settings: " + verification)
Jon Hall77ba41c2015-04-06 10:25:40 -07001858 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07001859 main.log.exception( self.name + ": Uncaught exception!" )
1860 main.cleanup()
1861 main.exit()
1862
cameron@onlab.usc80a8c82015-04-15 14:57:37 -07001863 def configNullLink( self,fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001864 '''
cameron@onlab.us75900962015-03-30 13:22:49 -07001865 fileName default is currently the same as the default on ONOS, specify alternate file if
1866 you want to use a different topology file than linkGraph.cfg
andrew@onlab.us3b087132015-03-11 15:00:08 -07001867 '''
1868
andrew@onlab.us3b087132015-03-11 15:00:08 -07001869
cameron@onlab.us75900962015-03-30 13:22:49 -07001870 try:
1871 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str(eventRate))
1872 self.handle.expect(":~")
1873 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName )
1874 self.handle.expect(":~")
1875
1876 for i in range(10):
1877 self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider")
1878 self.handle.expect(":~")
1879 verification = self.handle.before
1880 if (" value=" + str(eventRate)) in verification and (" value=" + fileName) in verification:
1881 break
1882 else:
1883 time.sleep(1)
1884
1885 assert ("value=" + str(eventRate)) in verification and (" value=" + fileName) in verification
1886
1887 except pexpect.EOF:
1888 main.log.error( self.name + ": EOF exception found" )
1889 main.log.error( self.name + ": " + self.handle.before )
1890 main.cleanup()
1891 main.exit()
cameron@onlab.us75900962015-03-30 13:22:49 -07001892 except AssertionError:
1893 main.log.info("Settings did not post to ONOS")
1894 main.log.error(varification)
Jon Hall77ba41c2015-04-06 10:25:40 -07001895 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07001896 main.log.exception( self.name + ": Uncaught exception!" )
1897 main.log.error(varification)
1898 main.cleanup()
1899 main.exit()
andrew@onlab.us3b087132015-03-11 15:00:08 -07001900