blob: a0a1b44bd8c0e1caf3c750a234ba4c40173e3e0c [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
pingping-lin6d23d9e2015-02-02 16:54:24 -080023from requests.models import Response
kelvin8ec71442015-01-15 16:57:00 -080024sys.path.append( "../" )
Jon Hall05b2b432014-10-08 19:53:25 -040025from drivers.common.clidriver import CLI
26
Jon Hall05b2b432014-10-08 19:53:25 -040027
kelvin8ec71442015-01-15 16:57:00 -080028class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040029
kelvin8ec71442015-01-15 16:57:00 -080030 def __init__( self ):
31 """
32 Initialize client
33 """
Jon Hallefbd9792015-03-05 16:11:36 -080034 self.name = None
35 self.home = None
36 self.handle = None
kelvin8ec71442015-01-15 16:57:00 -080037 super( CLI, self ).__init__()
38
39 def connect( self, **connectargs ):
40 """
Jon Hall05b2b432014-10-08 19:53:25 -040041 Creates ssh handle for ONOS "bench".
kelvin8ec71442015-01-15 16:57:00 -080042 """
Jon Hall05b2b432014-10-08 19:53:25 -040043 try:
44 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080045 vars( self )[ key ] = connectargs[ key ]
andrew@onlab.us3b087132015-03-11 15:00:08 -070046 self.home = "~/onos"
Jon Hall05b2b432014-10-08 19:53:25 -040047 for key in self.options:
48 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080049 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040050 break
Jon Hall274b6642015-02-17 11:57:17 -080051 if self.home is None or self.home == "":
Jon Halle94919c2015-03-23 11:42:57 -070052 self.home = "~/onos"
Jon Hall21270ac2015-02-16 17:59:55 -080053
kelvin8ec71442015-01-15 16:57:00 -080054 self.name = self.options[ 'name' ]
55 self.handle = super( OnosDriver, self ).connect(
56 user_name=self.user_name,
kelvin-onlab08679eb2015-01-21 16:11:48 -080057 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -080058 port=self.port,
59 pwd=self.pwd,
60 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -040061
kelvin8ec71442015-01-15 16:57:00 -080062 self.handle.sendline( "cd " + self.home )
63 self.handle.expect( "\$" )
Jon Hall05b2b432014-10-08 19:53:25 -040064 if self.handle:
65 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080066 else:
67 main.log.info( "NO ONOS HANDLE" )
Jon Hall05b2b432014-10-08 19:53:25 -040068 return main.FALSE
69 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080070 main.log.error( self.name + ": EOF exception found" )
71 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040072 main.cleanup()
73 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -080074 except Exception:
75 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall05b2b432014-10-08 19:53:25 -040076 main.cleanup()
77 main.exit()
78
kelvin8ec71442015-01-15 16:57:00 -080079 def disconnect( self ):
80 """
Jon Hall05b2b432014-10-08 19:53:25 -040081 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080082 """
Jon Halld61331b2015-02-17 16:35:47 -080083 response = main.TRUE
Jon Hall05b2b432014-10-08 19:53:25 -040084 try:
Jon Hall61282e32015-03-19 11:34:11 -070085 if self.handle:
86 self.handle.sendline( "" )
87 self.handle.expect( "\$" )
88 self.handle.sendline( "exit" )
89 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -040090 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080091 main.log.error( self.name + ": EOF exception found" )
92 main.log.error( self.name + ": " + self.handle.before )
Jon Hall61282e32015-03-19 11:34:11 -070093 except ValueError:
Jon Hall1a77a1e2015-04-06 10:41:13 -070094 main.log.exception( "Exception in disconnect of " + self.name )
Jon Hall61282e32015-03-19 11:34:11 -070095 response = main.TRUE
Jon Hallfebb1c72015-03-05 13:30:09 -080096 except Exception:
97 main.log.exception( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -040098 response = main.FALSE
99 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400100
kelvin-onlabd3b64892015-01-20 13:26:24 -0800101 def onosPackage( self ):
kelvin8ec71442015-01-15 16:57:00 -0800102 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400103 Produce a self-contained tar.gz file that can be deployed
kelvin8ec71442015-01-15 16:57:00 -0800104 and executed on any platform with Java 7 JRE.
105 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400106 try:
kelvin8ec71442015-01-15 16:57:00 -0800107 self.handle.sendline( "onos-package" )
108 self.handle.expect( "onos-package" )
109 self.handle.expect( "tar.gz", timeout=30 )
110 handle = str( self.handle.before )
111 main.log.info( "onos-package command returned: " +
112 handle )
113 # As long as the sendline does not time out,
114 # return true. However, be careful to interpret
115 # the results of the onos-package command return
andrewonlab0748d2a2014-10-09 13:24:17 -0400116 return main.TRUE
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400117
andrewonlab7735d852014-10-09 13:02:47 -0400118 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800119 main.log.error( self.name + ": EOF exception found" )
120 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800121 except Exception:
122 main.log.exception( "Failed to package ONOS" )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400123 main.cleanup()
124 main.exit()
125
kelvin-onlabd3b64892015-01-20 13:26:24 -0800126 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800127 """
andrewonlab8790abb2014-11-06 13:51:54 -0500128 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800129 """
andrewonlab8790abb2014-11-06 13:51:54 -0500130 try:
kelvin8ec71442015-01-15 16:57:00 -0800131 self.handle.sendline( "onos-build" )
132 self.handle.expect( "onos-build" )
133 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800134 "BUILD SUCCESS",
135 "ERROR",
136 "BUILD FAILED" ],
137 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800138 handle = str( self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500139
kelvin8ec71442015-01-15 16:57:00 -0800140 main.log.info( "onos-build command returned: " +
141 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500142
143 if i == 0:
144 return main.TRUE
145 else:
146 return handle
147
148 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800149 main.log.error( self.name + ": EOF exception found" )
150 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800151 except Exception:
152 main.log.exception( "Failed to build ONOS" )
andrewonlab8790abb2014-11-06 13:51:54 -0500153 main.cleanup()
154 main.exit()
155
kelvin-onlabd3b64892015-01-20 13:26:24 -0800156 def cleanInstall( self ):
kelvin8ec71442015-01-15 16:57:00 -0800157 """
158 Runs mvn clean install in the root of the ONOS directory.
159 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400160
kelvin8ec71442015-01-15 16:57:00 -0800161 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400162 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800163 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400164 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800165 main.log.info( "Running 'mvn clean install' on " +
166 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800167 ". This may take some time." )
168 self.handle.sendline( "cd " + self.home )
169 self.handle.expect( "\$" )
Jon Hallea7818b2014-10-09 14:30:59 -0400170
kelvin8ec71442015-01-15 16:57:00 -0800171 self.handle.sendline( "" )
172 self.handle.expect( "\$" )
173 self.handle.sendline( "mvn clean install" )
174 self.handle.expect( "mvn clean install" )
175 while True:
176 i = self.handle.expect( [
Jon Hall274b6642015-02-17 11:57:17 -0800177 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' +
Jon Hallefbd9792015-03-05 16:11:36 -0800178 'Runtime\sEnvironment\sto\scontinue',
Jon Hallde9d9aa2014-10-08 20:36:02 -0400179 'BUILD\sFAILURE',
180 'BUILD\sSUCCESS',
Jon Halle94919c2015-03-23 11:42:57 -0700181 'onos\$', #TODO: fix this to be more generic?
Jon Hallde9d9aa2014-10-08 20:36:02 -0400182 'ONOS\$',
kelvin8ec71442015-01-15 16:57:00 -0800183 pexpect.TIMEOUT ], timeout=600 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400184 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800185 main.log.error( self.name + ":There is insufficient memory \
186 for the Java Runtime Environment to continue." )
187 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400188 main.cleanup()
189 main.exit()
190 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800191 main.log.error( self.name + ": Build failure!" )
192 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400193 main.cleanup()
194 main.exit()
195 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800196 main.log.info( self.name + ": Build success!" )
Jon Halle94919c2015-03-23 11:42:57 -0700197 elif i == 3 or i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800198 main.log.info( self.name + ": Build complete" )
199 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400200 for line in self.handle.before.splitlines():
201 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800202 main.log.info( line )
203 self.handle.sendline( "" )
204 self.handle.expect( "\$", timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400205 return main.TRUE
Jon Halle94919c2015-03-23 11:42:57 -0700206 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800207 main.log.error(
208 self.name +
209 ": mvn clean install TIMEOUT!" )
210 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400211 main.cleanup()
212 main.exit()
213 else:
Jon Hall274b6642015-02-17 11:57:17 -0800214 main.log.error( self.name + ": unexpected response from " +
Jon Hallefbd9792015-03-05 16:11:36 -0800215 "mvn clean install" )
kelvin8ec71442015-01-15 16:57:00 -0800216 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400217 main.cleanup()
218 main.exit()
219 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800220 main.log.error( self.name + ": EOF exception found" )
221 main.log.error( self.name + ": " + self.handle.before )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400222 main.cleanup()
223 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800224 except Exception:
225 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400226 main.cleanup()
227 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400228
Jon Hall61282e32015-03-19 11:34:11 -0700229 def gitPull( self, comp1="", fastForward=True ):
kelvin8ec71442015-01-15 16:57:00 -0800230 """
Jon Hallacabffd2014-10-09 12:36:53 -0400231 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800232
Jon Hall61282e32015-03-19 11:34:11 -0700233 If the fastForward boolean is set to true, only git pulls that can
234 be fast forwarded will be performed. IE if you have not local commits
235 in your branch.
236
Jon Hallacabffd2014-10-09 12:36:53 -0400237 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800238 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400239 for the purpose of pulling from other nodes if necessary.
240
Jon Hall47a93fb2015-01-06 16:46:06 -0800241 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400242 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800243 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400244 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400245
kelvin8ec71442015-01-15 16:57:00 -0800246 """
Jon Hallacabffd2014-10-09 12:36:53 -0400247 try:
kelvin8ec71442015-01-15 16:57:00 -0800248 # main.log.info( self.name + ": Stopping ONOS" )
249 # self.stop()
250 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800251 self.handle.expect( self.home + "\$" )
Jon Hall61282e32015-03-19 11:34:11 -0700252 cmd = "git pull"
253 if comp1 != "":
254 cmd += ' ' + comp1
255 if fastForward:
256 cmd += ' ' + " --ff-only"
257 self.handle.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800258 i = self.handle.expect(
259 [
260 'fatal',
261 'Username\sfor\s(.*):\s',
262 '\sfile(s*) changed,\s',
263 'Already up-to-date',
264 'Aborting',
265 'You\sare\snot\scurrently\son\sa\sbranch',
Jon Hall274b6642015-02-17 11:57:17 -0800266 'You asked me to pull without telling me which branch you',
267 'Pull is not possible because you have unmerged files',
Jon Hall61282e32015-03-19 11:34:11 -0700268 'Please enter a commit message to explain why this merge',
269 'Found a swap file by the name',
270 'Please, commit your changes before you can merge.',
kelvin-onlabd3b64892015-01-20 13:26:24 -0800271 pexpect.TIMEOUT ],
272 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800273 # debug
kelvin-onlabd3b64892015-01-20 13:26:24 -0800274 # main.log.report( self.name +": DEBUG: \n"+
275 # "git pull response: " +
276 # str( self.handle.before ) + str( self.handle.after ) )
kelvin8ec71442015-01-15 16:57:00 -0800277 if i == 0:
Jon Hall61282e32015-03-19 11:34:11 -0700278 main.log.error( self.name + ": Git pull had some issue" )
279 output = self.handle.after
280 self.handle.expect( '\$' )
281 output += self.handle.before
282 main.log.warn( output )
Jon Hallacabffd2014-10-09 12:36:53 -0400283 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800284 elif i == 1:
285 main.log.error(
286 self.name +
287 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400288 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800289 elif i == 2:
290 main.log.info(
291 self.name +
292 ": Git Pull - pulling repository now" )
kelvin-onlaba1484582015-02-02 15:46:20 -0800293 self.handle.expect( self.home + "\$", 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800294 # So that only when git pull is done, we do mvn clean compile
295 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800296 elif i == 3:
297 main.log.info( self.name + ": Git Pull - Already up to date" )
Jon Hall47a93fb2015-01-06 16:46:06 -0800298 return i
kelvin8ec71442015-01-15 16:57:00 -0800299 elif i == 4:
300 main.log.info(
301 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800302 ": Git Pull - Aborting..." +
303 "Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400304 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800305 elif i == 5:
306 main.log.info(
307 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800308 ": Git Pull - You are not currently " +
309 "on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400310 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800311 elif i == 6:
312 main.log.info(
313 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800314 ": Git Pull - You have not configured an upstream " +
315 "branch to pull from. Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400316 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800317 elif i == 7:
318 main.log.info(
319 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800320 ": Git Pull - Pull is not possible because " +
321 "you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400322 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800323 elif i == 8:
Jon Hall61282e32015-03-19 11:34:11 -0700324 # NOTE: abandoning test since we can't reliably handle this
325 # there could be different default text editors and we
326 # also don't know if we actually want to make the commit
327 main.log.error( "Git pull resulted in a merge commit message" +
328 ". Exiting test!" )
329 main.cleanup()
330 main.exit()
331 elif i == 9: # Merge commit message but swap file exists
332 main.log.error( "Git pull resulted in a merge commit message" +
333 " but a swap file exists." )
334 try:
335 self.handle.send( 'A' ) # Abort
336 self.handle.expect( "\$" )
337 return main.ERROR
338 except Exception:
339 main.log.exception( "Couldn't exit editor prompt!")
340 main.cleanup()
341 main.exit()
342 elif i == 10: # In the middle of a merge commit
343 main.log.error( "Git branch is in the middle of a merge. " )
344 main.log.warn( self.handle.before + self.handle.after )
345 return main.ERROR
346 elif i == 11:
kelvin8ec71442015-01-15 16:57:00 -0800347 main.log.error( self.name + ": Git Pull - TIMEOUT" )
348 main.log.error(
349 self.name + " Response was: " + str(
350 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400351 return main.ERROR
352 else:
kelvin8ec71442015-01-15 16:57:00 -0800353 main.log.error(
354 self.name +
355 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400356 return main.ERROR
357 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800358 main.log.error( self.name + ": EOF exception found" )
359 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400360 main.cleanup()
361 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800362 except Exception:
363 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400364 main.cleanup()
365 main.exit()
366
kelvin-onlabd3b64892015-01-20 13:26:24 -0800367 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800368 """
Jon Hallacabffd2014-10-09 12:36:53 -0400369 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800370
Jon Hallacabffd2014-10-09 12:36:53 -0400371 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800372 If used as gitCheckout( "branch" ) it will do git checkout
373 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400374
375 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800376 branch of the ONOS repository. If it has any problems, it will return
377 main.ERROR.
378 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400379 successful then the function will return main.TRUE.
380
kelvin8ec71442015-01-15 16:57:00 -0800381 """
Jon Hallacabffd2014-10-09 12:36:53 -0400382 try:
kelvin8ec71442015-01-15 16:57:00 -0800383 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800384 self.handle.expect( self.home + "\$" )
Jon Hall274b6642015-02-17 11:57:17 -0800385 main.log.info( self.name +
386 ": Checking out git branch/ref: " + branch + "..." )
kelvin8ec71442015-01-15 16:57:00 -0800387 cmd = "git checkout " + branch
388 self.handle.sendline( cmd )
389 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800390 i = self.handle.expect(
Jon Hall274b6642015-02-17 11:57:17 -0800391 [ 'fatal',
Jon Hall61282e32015-03-19 11:34:11 -0700392 'Username for (.*): ',
393 'Already on \'',
394 'Switched to branch \'' + str( branch ),
Jon Hall274b6642015-02-17 11:57:17 -0800395 pexpect.TIMEOUT,
396 'error: Your local changes to the following files' +
Jon Hallefbd9792015-03-05 16:11:36 -0800397 'would be overwritten by checkout:',
Jon Hall274b6642015-02-17 11:57:17 -0800398 'error: you need to resolve your current index first',
399 "You are in 'detached HEAD' state.",
400 "HEAD is now at " ],
kelvin-onlabd3b64892015-01-20 13:26:24 -0800401 timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -0800402 if i == 0:
403 main.log.error(
404 self.name +
405 ": Git checkout had some issue..." )
406 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400407 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800408 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800409 main.log.error(
410 self.name +
411 ": Git checkout asking for username." +
412 " Please configure your local git repository to be able " +
413 "to access your remote repository passwordlessly" )
Jon Hall274b6642015-02-17 11:57:17 -0800414 # TODO add support for authenticating
Jon Hallacabffd2014-10-09 12:36:53 -0400415 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800416 elif i == 2:
417 main.log.info(
418 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800419 ": Git Checkout %s : Already on this branch" % branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800420 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800421 # main.log.info( "DEBUG: after checkout cmd = "+
422 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400423 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800424 elif i == 3:
425 main.log.info(
426 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800427 ": Git checkout %s - Switched to this branch" % branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800428 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800429 # main.log.info( "DEBUG: after checkout cmd = "+
430 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400431 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800432 elif i == 4:
433 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
434 main.log.error(
Jon Hall274b6642015-02-17 11:57:17 -0800435 self.name + " Response was: " + str( self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400436 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800437 elif i == 5:
438 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800439 main.log.error(
440 self.name +
441 ": Git checkout error: \n" +
Jon Hall274b6642015-02-17 11:57:17 -0800442 "Your local changes to the following files would" +
443 " be overwritten by checkout:" +
444 str( self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800445 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500446 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800447 elif i == 6:
Jon Hall274b6642015-02-17 11:57:17 -0800448 main.log.error(
449 self.name +
450 ": Git checkout error: \n" +
451 "You need to resolve your current index first:" +
452 str( self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800453 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500454 return main.ERROR
Jon Hall274b6642015-02-17 11:57:17 -0800455 elif i == 7:
456 main.log.info(
457 self.name +
458 ": Git checkout " + str( branch ) +
459 " - You are in 'detached HEAD' state. HEAD is now at " +
460 str( branch ) )
461 self.handle.expect( self.home + "\$" )
462 return main.TRUE
463 elif i == 8: # Already in detached HEAD on the specified commit
464 main.log.info(
465 self.name +
466 ": Git Checkout %s : Already on commit" % branch )
467 self.handle.expect( self.home + "\$" )
468 return main.TRUE
Jon Hallacabffd2014-10-09 12:36:53 -0400469 else:
kelvin8ec71442015-01-15 16:57:00 -0800470 main.log.error(
471 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800472 ": Git Checkout - Unexpected response, " +
473 "check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800474 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400475 return main.ERROR
476
477 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800478 main.log.error( self.name + ": EOF exception found" )
479 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400480 main.cleanup()
481 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800482 except Exception:
483 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400484 main.cleanup()
485 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400486
pingping-lin6d23d9e2015-02-02 16:54:24 -0800487 def getBranchName( self ):
488 self.handle.sendline( "cd " + self.home )
489 self.handle.expect( "ONOS\$" )
490 self.handle.sendline( "git name-rev --name-only HEAD" )
491 self.handle.expect( "git name-rev --name-only HEAD" )
492 self.handle.expect( "\$" )
493
494 lines = self.handle.before.splitlines()
495 if lines[1] == "master":
496 return "master"
497 elif lines[1] == "onos-1.0":
498 return "onos-1.0"
499 else:
500 main.log.info( lines[1] )
501 return "unexpected ONOS branch for SDN-IP test"
502
kelvin-onlabd3b64892015-01-20 13:26:24 -0800503 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800504 """
Jon Hall274b6642015-02-17 11:57:17 -0800505 Writes the COMMIT number to the report to be parsed
Jon Hallefbd9792015-03-05 16:11:36 -0800506 by Jenkins data collector.
kelvin8ec71442015-01-15 16:57:00 -0800507 """
Jon Hall45ec0922014-10-10 19:33:49 -0400508 try:
kelvin8ec71442015-01-15 16:57:00 -0800509 self.handle.sendline( "" )
510 self.handle.expect( "\$" )
511 self.handle.sendline(
512 "cd " +
513 self.home +
Jon Hall274b6642015-02-17 11:57:17 -0800514 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " +
515 " \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800516 # NOTE: for some reason there are backspaces inserted in this
517 # phrase when run from Jenkins on some tests
518 self.handle.expect( "never" )
519 self.handle.expect( "\$" )
520 response = ( self.name + ": \n" + str(
521 self.handle.before + self.handle.after ) )
522 self.handle.sendline( "cd " + self.home )
523 self.handle.expect( "\$" )
524 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400525 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500526 print line
527 if report:
Jon Hall82a7dad2015-04-30 16:26:08 -0700528 main.log.wiki( "<blockquote>" )
kelvin8ec71442015-01-15 16:57:00 -0800529 for line in lines[ 2:-1 ]:
530 # Bracket replacement is for Wiki-compliant
531 # formatting. '<' or '>' are interpreted
532 # as xml specific tags that cause errors
533 line = line.replace( "<", "[" )
534 line = line.replace( ">", "]" )
Jon Hall82a7dad2015-04-30 16:26:08 -0700535 #main.log.wiki( "\t" + line )
536 main.log.wiki( line + "<br /> " )
537 main.log.summary( line )
538 main.log.wiki( "</blockquote>" )
539 main.log.summary("\n")
kelvin8ec71442015-01-15 16:57:00 -0800540 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400541 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800542 main.log.error( self.name + ": EOF exception found" )
543 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400544 main.cleanup()
545 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800546 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800547 main.log.error( self.name + ": TIMEOUT exception found" )
548 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800549 main.cleanup()
550 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800551 except Exception:
552 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall45ec0922014-10-10 19:33:49 -0400553 main.cleanup()
554 main.exit()
555
kelvin-onlabd3b64892015-01-20 13:26:24 -0800556 def createCellFile( self, benchIp, fileName, mnIpAddrs,
cameron@onlab.us75900962015-03-30 13:22:49 -0700557 appString, *onosIpAddrs ):
kelvin8ec71442015-01-15 16:57:00 -0800558 """
andrewonlab94282092014-10-10 13:00:11 -0400559 Creates a cell file based on arguments
560 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800561 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400562 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800563 * File name of the cell file ( fileName )
564 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800565 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400566 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800567 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400568 - Must be passed in as last arguments
kelvin8ec71442015-01-15 16:57:00 -0800569
andrewonlab94282092014-10-10 13:00:11 -0400570 NOTE: Assumes cells are located at:
571 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800572 """
573 # Variable initialization
kelvin-onlabd3b64892015-01-20 13:26:24 -0800574 cellDirectory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800575 # We want to create the cell file in the dependencies directory
576 # of TestON first, then copy over to ONOS bench
kelvin-onlabd3b64892015-01-20 13:26:24 -0800577 tempDirectory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800578 # Create the cell file in the directory for writing ( w+ )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800579 cellFile = open( tempDirectory + fileName, 'w+' )
kelvin8ec71442015-01-15 16:57:00 -0800580
cameron@onlab.us75900962015-03-30 13:22:49 -0700581 # App string is hardcoded environment variables
kelvin8ec71442015-01-15 16:57:00 -0800582 # That you may wish to use by default on startup.
cameron@onlab.us75900962015-03-30 13:22:49 -0700583 # Note that you may not want certain apps listed
kelvin8ec71442015-01-15 16:57:00 -0800584 # on here.
cameron@onlab.us75900962015-03-30 13:22:49 -0700585 appString = "export ONOS_APPS=" + appString
kelvin-onlabd3b64892015-01-20 13:26:24 -0800586 mnString = "export OCN="
587 onosString = "export OC"
588 tempCount = 1
kelvin8ec71442015-01-15 16:57:00 -0800589
kelvin-onlabd3b64892015-01-20 13:26:24 -0800590 # Create ONOSNIC ip address prefix
591 tempOnosIp = onosIpAddrs[ 0 ]
592 tempList = []
593 tempList = tempOnosIp.split( "." )
kelvin8ec71442015-01-15 16:57:00 -0800594 # Omit last element of list to format for NIC
kelvin-onlabd3b64892015-01-20 13:26:24 -0800595 tempList = tempList[ :-1 ]
kelvin8ec71442015-01-15 16:57:00 -0800596 # Structure the nic string ip
kelvin-onlabd3b64892015-01-20 13:26:24 -0800597 nicAddr = ".".join( tempList ) + ".*"
598 onosNicString = "export ONOS_NIC=" + nicAddr
andrewonlab94282092014-10-10 13:00:11 -0400599
600 try:
kelvin8ec71442015-01-15 16:57:00 -0800601 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800602 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400603
kelvin-onlabd3b64892015-01-20 13:26:24 -0800604 for arg in onosIpAddrs:
605 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800606 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400607 # export OC1="10.128.20.11"
608 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800609 cellFile.write( onosString + str( tempCount ) +
610 "=" + "\"" + arg + "\"" + "\n" )
611 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800612
kelvin-onlabd3b64892015-01-20 13:26:24 -0800613 cellFile.write( mnString + "\"" + mnIpAddrs + "\"" + "\n" )
cameron@onlab.us75900962015-03-30 13:22:49 -0700614 cellFile.write( appString + "\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800615 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400616
kelvin8ec71442015-01-15 16:57:00 -0800617 # We use os.system to send the command to TestON cluster
618 # to account for the case in which TestON is not located
619 # on the same cluster as the ONOS bench
620 # Note that even if TestON is located on the same cluster
621 # as ONOS bench, you must setup passwordless ssh
622 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800623 os.system( "scp " + tempDirectory + fileName +
624 " admin@" + benchIp + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400625
andrewonlab2a6c9342014-10-16 13:40:15 -0400626 return main.TRUE
627
andrewonlab94282092014-10-10 13:00:11 -0400628 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800629 main.log.error( self.name + ": EOF exception found" )
630 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -0400631 main.cleanup()
632 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800633 except Exception:
634 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab94282092014-10-10 13:00:11 -0400635 main.cleanup()
636 main.exit()
637
kelvin-onlabd3b64892015-01-20 13:26:24 -0800638 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800639 """
andrewonlab95ca1462014-10-09 14:04:24 -0400640 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800641 """
andrewonlab95ca1462014-10-09 14:04:24 -0400642 try:
643 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800644 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400645 main.cleanup()
646 main.exit()
647 else:
kelvin8ec71442015-01-15 16:57:00 -0800648 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800649 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800650 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400651 # and that this driver will have to change accordingly
Cameron Franke9c94fb02015-01-21 10:20:20 -0800652 self.handle.expect(str(cellname))
kelvin-onlabd3b64892015-01-20 13:26:24 -0800653 handleBefore = self.handle.before
654 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800655 # Get the rest of the handle
Cameron Franke9c94fb02015-01-21 10:20:20 -0800656 self.handle.sendline("")
657 self.handle.expect("\$")
kelvin-onlabd3b64892015-01-20 13:26:24 -0800658 handleMore = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400659
kelvin-onlabd3b64892015-01-20 13:26:24 -0800660 main.log.info( "Cell call returned: " + handleBefore +
661 handleAfter + handleMore )
andrewonlab95ca1462014-10-09 14:04:24 -0400662
663 return main.TRUE
664
665 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800666 main.log.error( self.name + ": EOF exception found" )
667 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400668 main.cleanup()
669 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800670 except Exception:
671 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab95ca1462014-10-09 14:04:24 -0400672 main.cleanup()
673 main.exit()
674
kelvin-onlabd3b64892015-01-20 13:26:24 -0800675 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800676 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400677 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800678 """
679 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400680
andrewonlabc03bf6c2014-10-09 14:56:18 -0400681 try:
kelvin8ec71442015-01-15 16:57:00 -0800682 # Clean handle by sending empty and expecting $
683 self.handle.sendline( "" )
684 self.handle.expect( "\$" )
685 self.handle.sendline( "onos-verify-cell" )
686 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800687 handleBefore = self.handle.before
688 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800689 # Get the rest of the handle
690 self.handle.sendline( "" )
691 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800692 handleMore = self.handle.before
andrewonlabc03bf6c2014-10-09 14:56:18 -0400693
kelvin-onlabd3b64892015-01-20 13:26:24 -0800694 main.log.info( "Verify cell returned: " + handleBefore +
695 handleAfter + handleMore )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400696
697 return main.TRUE
Jon Halla5cb6172015-02-23 09:28:28 -0800698 except pexpect.ExceptionPexpect as e:
699 main.log.error( self.name + ": Pexpect exception found of type " +
700 str( type( e ) ) )
701 main.log.error ( e.get_trace() )
kelvin8ec71442015-01-15 16:57:00 -0800702 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400703 main.cleanup()
704 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800705 except Exception:
706 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400707 main.cleanup()
708 main.exit()
709
jenkins1e99e7b2015-04-02 18:15:39 -0700710 def onosCfgSet( self, ONOSIp, configName, configParam ):
711 """
712 Uses 'onos <node-ip> cfg set' to change a parameter value of an
713 application.
714
715 ex)
716 onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1
717
718 ONOSIp = '10.0.0.1'
719 configName = 'org.onosproject.myapp'
720 configParam = 'appSetting 1'
721
722 """
723 try:
724 cfgStr = ( "onos "+str(ONOSIp)+" cfg set "+
725 str(configName) + " " +
726 str(configParam)
727 )
728
729 self.handle.sendline( "" )
730 self.handle.expect( "\$" )
731 self.handle.sendline( cfgStr )
732 self.handle.expect( "\$" )
733
734 # TODO: Add meaningful assertion
735
736 return main.TRUE
737
738 except pexpect.ExceptionPexpect as e:
739 main.log.error( self.name + ": Pexpect exception found of type " +
740 str( type( e ) ) )
741 main.log.error ( e.get_trace() )
742 main.log.error( self.name + ": " + self.handle.before )
743 main.cleanup()
744 main.exit()
745 except Exception:
746 main.log.exception( self.name + ": Uncaught exception!" )
747 main.cleanup()
748 main.exit()
749
kelvin-onlabd3b64892015-01-20 13:26:24 -0800750 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800751 """
andrewonlab05e362f2014-10-10 00:40:57 -0400752 Uses 'onos' command to send various ONOS CLI arguments.
753 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800754 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400755 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800756
757 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400758 CLI commands for ONOS. Try to use this function first
759 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800760 function.
761 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400762 by starting onos, and typing in 'onos' to enter the
763 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800764 available commands.
765 """
andrewonlab05e362f2014-10-10 00:40:57 -0400766 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800767 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800768 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400769 return main.FALSE
770 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800771 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400772 return main.FALSE
773
kelvin8ec71442015-01-15 16:57:00 -0800774 cmdstr = str( cmdstr )
775 self.handle.sendline( "" )
776 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400777
kelvin-onlabd3b64892015-01-20 13:26:24 -0800778 self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr )
kelvin8ec71442015-01-15 16:57:00 -0800779 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400780
kelvin-onlabd3b64892015-01-20 13:26:24 -0800781 handleBefore = self.handle.before
Shreya Shaha73aaad2014-10-27 18:03:09 -0400782 print "handle_before = ", self.handle.before
kelvin-onlabd3b64892015-01-20 13:26:24 -0800783 # handleAfter = str( self.handle.after )
Jon Hall47a93fb2015-01-06 16:46:06 -0800784
kelvin8ec71442015-01-15 16:57:00 -0800785 # self.handle.sendline( "" )
786 # self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800787 # handleMore = str( self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400788
kelvin8ec71442015-01-15 16:57:00 -0800789 main.log.info( "Command sent successfully" )
andrewonlab05e362f2014-10-10 00:40:57 -0400790
kelvin8ec71442015-01-15 16:57:00 -0800791 # Obtain return handle that consists of result from
792 # the onos command. The string may need to be
793 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800794 # returnString = handleBefore + handleAfter
795 returnString = handleBefore
796 print "return_string = ", returnString
797 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400798
799 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800800 main.log.error( self.name + ": EOF exception found" )
801 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400802 main.cleanup()
803 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800804 except Exception:
805 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab05e362f2014-10-10 00:40:57 -0400806 main.cleanup()
807 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400808
kelvin-onlabd3b64892015-01-20 13:26:24 -0800809 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -0800810 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400811 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800812 If -f option is provided, it also forces an uninstall.
813 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400814 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800815 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400816 files to certain onos nodes
817
818 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800819 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400820 try:
andrewonlab114768a2014-11-14 12:44:44 -0500821 if options:
kelvin8ec71442015-01-15 16:57:00 -0800822 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500823 else:
kelvin8ec71442015-01-15 16:57:00 -0800824 self.handle.sendline( "onos-install " + node )
825 self.handle.expect( "onos-install " )
826 # NOTE: this timeout may need to change depending on the network
827 # and size of ONOS
828 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800829 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -0800830 "ONOS\sis\salready\sinstalled",
831 pexpect.TIMEOUT ], timeout=60 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400832
Jon Hall7993bfc2014-10-09 16:30:14 -0400833 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800834 main.log.warn( "Network is unreachable" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400835 return main.FALSE
836 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800837 main.log.info(
838 "ONOS was installed on " +
839 node +
840 " and started" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400841 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500842 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800843 main.log.info( "ONOS is already installed on " + node )
andrewonlabd9a73a72014-11-14 17:28:21 -0500844 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800845 elif i == 3:
846 main.log.info(
847 "Installation of ONOS on " +
848 node +
849 " timed out" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400850 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400851
852 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800853 main.log.error( self.name + ": EOF exception found" )
854 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400855 main.cleanup()
856 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800857 except Exception:
858 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400859 main.cleanup()
860 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400861
kelvin-onlabd3b64892015-01-20 13:26:24 -0800862 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800863 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400864 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400865 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800866 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400867 try:
kelvin8ec71442015-01-15 16:57:00 -0800868 self.handle.sendline( "" )
869 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800870 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800871 " start" )
872 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -0400873 "Job\sis\salready\srunning",
874 "start/running",
875 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800876 pexpect.TIMEOUT ], timeout=120 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400877
878 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800879 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400880 return main.TRUE
881 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800882 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400883 return main.TRUE
884 else:
kelvin8ec71442015-01-15 16:57:00 -0800885 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400886 main.cleanup()
887 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400888 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800889 main.log.error( self.name + ": EOF exception found" )
890 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400891 main.cleanup()
892 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800893 except Exception:
894 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400895 main.cleanup()
896 main.exit()
897
kelvin-onlabd3b64892015-01-20 13:26:24 -0800898 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800899 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400900 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400901 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800902 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400903 try:
kelvin8ec71442015-01-15 16:57:00 -0800904 self.handle.sendline( "" )
905 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800906 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800907 " stop" )
908 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -0400909 "stop/waiting",
Jon Hall61282e32015-03-19 11:34:11 -0700910 "Could not resolve hostname",
andrewonlab2b30bd32014-10-09 16:48:55 -0400911 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800912 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2b30bd32014-10-09 16:48:55 -0400913
914 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800915 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400916 return main.TRUE
917 elif i == 1:
Jon Hall65844a32015-03-09 19:09:37 -0700918 main.log.info( "onosStop() Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800919 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -0400920 return main.FALSE
Jon Hall61282e32015-03-19 11:34:11 -0700921 elif i == 2:
922 main.log.warn( "ONOS wasn't running" )
923 return main.TRUE
andrewonlab2b30bd32014-10-09 16:48:55 -0400924 else:
kelvin8ec71442015-01-15 16:57:00 -0800925 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400926 return main.FALSE
927
928 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800929 main.log.error( self.name + ": EOF exception found" )
930 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -0400931 main.cleanup()
932 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800933 except Exception:
934 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400935 main.cleanup()
936 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800937
kelvin-onlabd3b64892015-01-20 13:26:24 -0800938 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -0800939 """
andrewonlabc8d47972014-10-09 16:52:36 -0400940 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -0800941 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -0400942 if needed
kelvin8ec71442015-01-15 16:57:00 -0800943 """
andrewonlabc8d47972014-10-09 16:52:36 -0400944 try:
kelvin8ec71442015-01-15 16:57:00 -0800945 self.handle.sendline( "" )
Jon Hallfeff3082015-05-19 10:23:26 -0700946 self.handle.expect( "\$", timeout=60 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800947 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800948 self.handle.expect( "\$" )
andrewonlabc8d47972014-10-09 16:52:36 -0400949
kelvin-onlabd3b64892015-01-20 13:26:24 -0800950 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
andrewonlab9dfd2082014-11-13 17:44:03 -0500951
kelvin8ec71442015-01-15 16:57:00 -0800952 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -0400953 return main.TRUE
954
Jon Hallfeff3082015-05-19 10:23:26 -0700955 except pexpect.TIMEOUT:
956 main.log.exception( self.name + ": Timeout in onosUninstall" )
957 return main.FALSE
andrewonlabc8d47972014-10-09 16:52:36 -0400958 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800959 main.log.error( self.name + ": EOF exception found" )
960 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -0400961 main.cleanup()
962 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800963 except Exception:
964 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc8d47972014-10-09 16:52:36 -0400965 main.cleanup()
966 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400967
kelvin-onlabd3b64892015-01-20 13:26:24 -0800968 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800969 """
andrewonlabaedc8332014-12-04 12:43:03 -0500970 Issues the command 'onos-die <node-ip>'
971 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -0800972 """
andrewonlabaedc8332014-12-04 12:43:03 -0500973 try:
kelvin8ec71442015-01-15 16:57:00 -0800974 self.handle.sendline( "" )
975 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800976 cmdStr = "onos-kill " + str( nodeIp )
977 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800978 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -0500979 "Killing\sONOS",
980 "ONOS\sprocess\sis\snot\srunning",
kelvin8ec71442015-01-15 16:57:00 -0800981 pexpect.TIMEOUT ], timeout=20 )
andrewonlabaedc8332014-12-04 12:43:03 -0500982 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800983 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800984 " was killed and stopped" )
andrewonlabaedc8332014-12-04 12:43:03 -0500985 return main.TRUE
986 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800987 main.log.info( "ONOS process was not running" )
andrewonlabaedc8332014-12-04 12:43:03 -0500988 return main.FALSE
989 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800990 main.log.error( self.name + ": EOF exception found" )
991 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -0500992 main.cleanup()
993 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800994 except Exception:
995 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabaedc8332014-12-04 12:43:03 -0500996 main.cleanup()
997 main.exit()
998
kelvin-onlabd3b64892015-01-20 13:26:24 -0800999 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001000 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001001 Calls the command: 'onos-kill [<node-ip>]'
1002 "Remotely, and unceremoniously kills the ONOS instance running on
1003 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -08001004 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001005 try:
kelvin8ec71442015-01-15 16:57:00 -08001006 self.handle.sendline( "" )
1007 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001008 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -08001009 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -04001010 "\$",
1011 "No\sroute\sto\shost",
1012 "password:",
kelvin8ec71442015-01-15 16:57:00 -08001013 pexpect.TIMEOUT ], timeout=20 )
1014
andrewonlabe8e56fd2014-10-09 17:12:44 -04001015 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001016 main.log.info(
1017 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -08001018 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001019 return main.TRUE
1020 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001021 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001022 return main.FALSE
1023 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001024 main.log.info(
1025 "Passwordless login for host: " +
1026 str( nodeIp ) +
1027 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001028 return main.FALSE
1029 else:
Jon Hallefbd9792015-03-05 16:11:36 -08001030 main.log.info( "ONOS instance was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001031 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001032
andrewonlabe8e56fd2014-10-09 17:12:44 -04001033 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001034 main.log.error( self.name + ": EOF exception found" )
1035 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001036 main.cleanup()
1037 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001038 except Exception:
1039 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001040 main.cleanup()
1041 main.exit()
1042
kelvin-onlabd3b64892015-01-20 13:26:24 -08001043 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -08001044 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001045 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -05001046 a cleaner environment.
1047
andrewonlab19fbdca2014-11-14 12:55:59 -05001048 Description:
Jon Hallfcc88622014-11-25 13:09:54 -05001049 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -05001050 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -08001051 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001052 try:
kelvin8ec71442015-01-15 16:57:00 -08001053 self.handle.sendline( "" )
1054 self.handle.expect( "\$" )
1055 self.handle.sendline( "onos-remove-raft-logs" )
1056 # Sometimes this command hangs
1057 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
1058 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001059 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001060 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
1061 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001062 if i == 1:
1063 return main.FALSE
shahshreya957feaa2015-03-23 16:08:29 -07001064 #self.handle.sendline( "" )
1065 #self.handle.expect( "\$" )
andrewonlab19fbdca2014-11-14 12:55:59 -05001066 return main.TRUE
1067
1068 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001069 main.log.error( self.name + ": EOF exception found" )
1070 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -05001071 main.cleanup()
1072 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001073 except Exception:
1074 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab19fbdca2014-11-14 12:55:59 -05001075 main.cleanup()
1076 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -05001077
kelvin-onlabd3b64892015-01-20 13:26:24 -08001078 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -08001079 """
1080 Calls the command 'onos-start-network [ <mininet-topo> ]
1081 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -04001082 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -08001083 cell."
andrewonlab94282092014-10-10 13:00:11 -04001084 * Specify mininet topology file name for mntopo
1085 * Topo files should be placed at:
1086 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001087
andrewonlab94282092014-10-10 13:00:11 -04001088 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001089 """
andrewonlab94282092014-10-10 13:00:11 -04001090 try:
1091 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001092 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001093 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001094
kelvin8ec71442015-01-15 16:57:00 -08001095 mntopo = str( mntopo )
1096 self.handle.sendline( "" )
1097 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -04001098
kelvin8ec71442015-01-15 16:57:00 -08001099 self.handle.sendline( "onos-start-network " + mntopo )
1100 self.handle.expect( "mininet>" )
1101 main.log.info( "Network started, entered mininet prompt" )
1102
1103 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001104
1105 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001106 main.log.error( self.name + ": EOF exception found" )
1107 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001108 main.cleanup()
1109 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001110 except Exception:
1111 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab94282092014-10-10 13:00:11 -04001112 main.cleanup()
1113 main.exit()
1114
Cameron Franke9c94fb02015-01-21 10:20:20 -08001115 def isup(self, node = "", timeout = 120):
kelvin8ec71442015-01-15 16:57:00 -08001116 """
1117 Run's onos-wait-for-start which only returns once ONOS is at run
Cameron Franke9c94fb02015-01-21 10:20:20 -08001118 level 100(ready for use)
andrewonlab8d0d7d72014-10-09 16:33:15 -04001119
Jon Hall7993bfc2014-10-09 16:30:14 -04001120 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001121 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001122 try:
Cameron Franke9c94fb02015-01-21 10:20:20 -08001123 self.handle.sendline("onos-wait-for-start " + node )
1124 self.handle.expect("onos-wait-for-start")
kelvin8ec71442015-01-15 16:57:00 -08001125 # NOTE: this timeout is arbitrary"
Cameron Franke9c94fb02015-01-21 10:20:20 -08001126 i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout)
Jon Hall7993bfc2014-10-09 16:30:14 -04001127 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001128 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001129 return main.TRUE
1130 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001131 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001132 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001133 main.log.error( "ONOS has not started yet" )
1134 self.handle.send( "\x03" ) # Control-C
1135 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001136 return main.FALSE
1137 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001138 main.log.error( self.name + ": EOF exception found" )
1139 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001140 main.cleanup()
1141 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001142 except Exception:
1143 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001144 main.cleanup()
1145 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001146
kelvin-onlabd3b64892015-01-20 13:26:24 -08001147 def pushTestIntentsShell(
1148 self,
1149 dpidSrc,
1150 dpidDst,
1151 numIntents,
1152 dirFile,
1153 onosIp,
1154 numMult="",
1155 appId="",
1156 report=True,
1157 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001158 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001159 Description:
kelvin8ec71442015-01-15 16:57:00 -08001160 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001161 better parallelize the results than the CLI
1162 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001163 * dpidSrc: specify source dpid
1164 * dpidDst: specify destination dpid
1165 * numIntents: specify number of intents to push
1166 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001167 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001168 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001169 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001170 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001171 """
1172 try:
1173 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001174 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001175 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001176 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001177 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001178 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001179
kelvin-onlabd3b64892015-01-20 13:26:24 -08001180 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1181 if not numMult:
1182 addIntents = addDpid + " " + str( numIntents )
1183 elif numMult:
1184 addIntents = addDpid + " " + str( numIntents ) + " " +\
1185 str( numMult )
1186 if appId:
1187 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001188 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001189 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001190
andrewonlabaedc8332014-12-04 12:43:03 -05001191 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001192 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001193 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001194 sendCmd = addApp + " &"
1195 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001196
kelvin-onlabd3b64892015-01-20 13:26:24 -08001197 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001198
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 )
andrewonlabb66dfa12014-12-02 15:51:10 -05001202 main.cleanup()
1203 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001204 except Exception:
1205 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001206 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001207 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001208
kelvin-onlabd3b64892015-01-20 13:26:24 -08001209 def getTopology( self, topologyOutput ):
kelvin8ec71442015-01-15 16:57:00 -08001210 """
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001211 Definition:
1212 Loads a json topology output
1213 Return:
1214 topology = current ONOS topology
kelvin8ec71442015-01-15 16:57:00 -08001215 """
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001216 import json
Jon Hall77f53ce2014-10-13 18:02:06 -04001217 try:
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001218 # either onos:topology or 'topology' will work in CLI
1219 topology = json.loads(topologyOutput)
1220 print topology
Jon Hall77f53ce2014-10-13 18:02:06 -04001221 return topology
1222 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001223 main.log.error( self.name + ": EOF exception found" )
1224 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001225 main.cleanup()
1226 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001227 except Exception:
1228 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001229 main.cleanup()
1230 main.exit()
1231
kelvin-onlabd3b64892015-01-20 13:26:24 -08001232 def checkStatus(
1233 self,
1234 topologyResult,
1235 numoswitch,
1236 numolink,
1237 logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001238 """
Jon Hallefbd9792015-03-05 16:11:36 -08001239 Checks the number of switches & links that ONOS sees against the
kelvin8ec71442015-01-15 16:57:00 -08001240 supplied values. By default this will report to main.log, but the
Jon Hallefbd9792015-03-05 16:11:36 -08001241 log level can be specific.
kelvin8ec71442015-01-15 16:57:00 -08001242
Jon Hall77f53ce2014-10-13 18:02:06 -04001243 Params: ip = ip used for the onos cli
1244 numoswitch = expected number of switches
Jon Hallefbd9792015-03-05 16:11:36 -08001245 numolink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001246 logLevel = level to log to.
1247 Currently accepts 'info', 'warn' and 'report'
Jon Hall77f53ce2014-10-13 18:02:06 -04001248
1249
kelvin-onlabd3b64892015-01-20 13:26:24 -08001250 logLevel can
Jon Hall77f53ce2014-10-13 18:02:06 -04001251
Jon Hallefbd9792015-03-05 16:11:36 -08001252 Returns: main.TRUE if the number of switches and links are correct,
1253 main.FALSE if the number of switches and links is incorrect,
Jon Hall77f53ce2014-10-13 18:02:06 -04001254 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001255 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001256 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001257 topology = self.getTopology( topologyResult )
Jon Hall77f53ce2014-10-13 18:02:06 -04001258 if topology == {}:
1259 return main.ERROR
1260 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001261 # Is the number of switches is what we expected
Hari Krishnaef1bd4e2015-03-12 16:55:30 -07001262 devices = topology.get( 'deviceCount', False )
1263 links = topology.get( 'linkCount', False )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001264 if not devices or not links:
Jon Hall77f53ce2014-10-13 18:02:06 -04001265 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001266 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001267 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001268 linkCheck = ( int( links ) == int( numolink ) )
Jon Hallefbd9792015-03-05 16:11:36 -08001269 if switchCheck and linkCheck:
kelvin8ec71442015-01-15 16:57:00 -08001270 # We expected the correct numbers
Jon Hall77f53ce2014-10-13 18:02:06 -04001271 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001272 + "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001273 result = main.TRUE
1274 else:
1275 output = output + \
Jon Hall274b6642015-02-17 11:57:17 -08001276 "The number of links and switches does not match " + \
1277 "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001278 result = main.FALSE
Jon Hallefbd9792015-03-05 16:11:36 -08001279 output = output + "\n ONOS sees %i devices" % int( devices )
1280 output = output + " (%i expected) " % int( numoswitch )
Jon Hall274b6642015-02-17 11:57:17 -08001281 output = output + "and %i links " % int( links )
1282 output = output + "(%i expected)" % int( numolink )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001283 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001284 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001285 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001286 main.log.warn( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001287 else:
kelvin8ec71442015-01-15 16:57:00 -08001288 main.log.info( output )
1289 return result
Jon Hall77f53ce2014-10-13 18:02:06 -04001290 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001291 main.log.error( self.name + ": EOF exception found" )
1292 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001293 main.cleanup()
1294 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001295 except Exception:
1296 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001297 main.cleanup()
1298 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001299
kelvin-onlabd3b64892015-01-20 13:26:24 -08001300 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001301 """
andrewonlab970399c2014-11-07 13:09:32 -05001302 Capture all packet activity and store in specified
1303 directory/file
1304
1305 Required:
1306 * interface: interface to capture
1307 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001308 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001309 try:
1310 self.handle.sendline( "" )
1311 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001312
Jon Hallfebb1c72015-03-05 13:30:09 -08001313 self.handle.sendline( "tshark -i " + str( interface ) +
1314 " -t e -w " + str( dirFile ) + " &" )
1315 self.handle.sendline( "\r" )
1316 self.handle.expect( "Capturing on" )
1317 self.handle.sendline( "\r" )
1318 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001319
Jon Hallfebb1c72015-03-05 13:30:09 -08001320 main.log.info( "Tshark started capturing files on " +
1321 str( interface ) + " and saving to directory: " +
1322 str( dirFile ) )
1323 except pexpect.EOF:
1324 main.log.error( self.name + ": EOF exception found" )
1325 main.log.error( self.name + ": " + self.handle.before )
1326 main.cleanup()
1327 main.exit()
1328 except Exception:
1329 main.log.exception( self.name + ": Uncaught exception!" )
1330 main.cleanup()
1331 main.exit()
Shreya Shaha73aaad2014-10-27 18:03:09 -04001332
kelvin-onlabd3b64892015-01-20 13:26:24 -08001333 def runOnosTopoCfg( self, instanceName, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001334 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001335 On ONOS bench, run this command:
Jon Halle94919c2015-03-23 11:42:57 -07001336 {ONOS_HOME}/tools/test/bin/onos-topo-cfg $OC1 filename
kelvin-onlabd3b64892015-01-20 13:26:24 -08001337 which starts the rest and copies
1338 the json file to the onos instance
kelvin8ec71442015-01-15 16:57:00 -08001339 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001340 try:
kelvin8ec71442015-01-15 16:57:00 -08001341 self.handle.sendline( "" )
1342 self.handle.expect( "\$" )
Jon Halle94919c2015-03-23 11:42:57 -07001343 self.handle.sendline( "cd " + self.home + "/tools/test/bin" )
kelvin8ec71442015-01-15 16:57:00 -08001344 self.handle.expect( "/bin$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001345 cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile
shahshreyae6c7cf42014-11-26 16:39:01 -08001346 print "cmd = ", cmd
kelvin8ec71442015-01-15 16:57:00 -08001347 self.handle.sendline( cmd )
1348 self.handle.expect( "\$" )
1349 self.handle.sendline( "cd ~" )
1350 self.handle.expect( "\$" )
shahshreyae6c7cf42014-11-26 16:39:01 -08001351 return main.TRUE
Jon Hallfebb1c72015-03-05 13:30:09 -08001352 except pexpect.EOF:
1353 main.log.error( self.name + ": EOF exception found" )
1354 main.log.error( self.name + ": " + self.handle.before )
1355 main.cleanup()
1356 main.exit()
1357 except Exception:
1358 main.log.exception( self.name + ": Uncaught exception!" )
1359 main.cleanup()
1360 main.exit()
kelvin8ec71442015-01-15 16:57:00 -08001361
jenkins1e99e7b2015-04-02 18:15:39 -07001362 def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ):
kelvin8ec71442015-01-15 16:57:00 -08001363 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001364 Required:
kelvin8ec71442015-01-15 16:57:00 -08001365 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001366 * directory to store results
1367 Optional:
1368 * interface - default: eth0
jenkins1e99e7b2015-04-02 18:15:39 -07001369 * grepOptions - options for grep
andrewonlabba44bcf2014-10-16 16:54:41 -04001370 Description:
1371 Uses tshark command to grep specific group of packets
1372 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001373 The timestamp is hardcoded to be in epoch
1374 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001375 try:
1376 self.handle.sendline( "" )
1377 self.handle.expect( "\$" )
1378 self.handle.sendline( "" )
jenkins1e99e7b2015-04-02 18:15:39 -07001379 if grepOptions:
1380 grepStr = "grep "+str(grepOptions)
1381 else:
1382 grepStr = "grep"
1383
Jon Hallfebb1c72015-03-05 13:30:09 -08001384 self.handle.sendline(
1385 "tshark -i " +
1386 str( interface ) +
jenkins1e99e7b2015-04-02 18:15:39 -07001387 " -t e | " +
1388 grepStr + " --line-buffered \"" +
Jon Hallfebb1c72015-03-05 13:30:09 -08001389 str(grep) +
1390 "\" >" +
1391 directory +
1392 " &" )
1393 self.handle.sendline( "\r" )
1394 self.handle.expect( "Capturing on" )
1395 self.handle.sendline( "\r" )
1396 self.handle.expect( "\$" )
1397 except pexpect.EOF:
1398 main.log.error( self.name + ": EOF exception found" )
1399 main.log.error( self.name + ": " + self.handle.before )
1400 main.cleanup()
1401 main.exit()
1402 except Exception:
1403 main.log.exception( self.name + ": Uncaught exception!" )
1404 main.cleanup()
1405 main.exit()
1406
kelvin-onlabd3b64892015-01-20 13:26:24 -08001407 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001408 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001409 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001410 """
1411 # Remove all pcap from previous captures
Jon Hallfebb1c72015-03-05 13:30:09 -08001412 try:
1413 self.execute( cmd="sudo rm /tmp/wireshark*" )
1414 self.handle.sendline( "" )
Jon Hallefbd9792015-03-05 16:11:36 -08001415 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" +
1416 " | grep -v grep | awk '{print $2}'`" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001417 self.handle.sendline( "" )
1418 main.log.info( "Tshark stopped" )
1419 except pexpect.EOF:
1420 main.log.error( self.name + ": EOF exception found" )
1421 main.log.error( self.name + ": " + self.handle.before )
1422 main.cleanup()
1423 main.exit()
1424 except Exception:
1425 main.log.exception( self.name + ": Uncaught exception!" )
1426 main.cleanup()
1427 main.exit()
1428
kelvin8ec71442015-01-15 16:57:00 -08001429 def ptpd( self, args ):
1430 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001431 Initiate ptp with user-specified args.
1432 Required:
1433 * args: specify string of args after command
1434 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001435 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001436 try:
kelvin8ec71442015-01-15 16:57:00 -08001437 self.handle.sendline( "sudo ptpd " + str( args ) )
1438 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001439 "Multiple",
1440 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001441 "\$" ] )
1442 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001443
andrewonlab0c38a4a2014-10-28 18:35:35 -04001444 if i == 0:
1445 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001446 main.log.info( "ptpd returned an error: " +
1447 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001448 return handle
1449 elif i == 1:
1450 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001451 main.log.error( "ptpd returned an error: " +
1452 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001453 return handle
1454 else:
1455 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001456
andrewonlab0c38a4a2014-10-28 18:35:35 -04001457 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001458 main.log.error( self.name + ": EOF exception found" )
1459 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001460 main.cleanup()
1461 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001462 except Exception:
1463 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001464 main.cleanup()
1465 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001466
kelvin-onlabd3b64892015-01-20 13:26:24 -08001467 def cpLogsToDir( self, logToCopy,
Jon Hallefbd9792015-03-05 16:11:36 -08001468 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001469 """
1470 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001471 Current implementation of ONOS deletes its karaf
1472 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001473 you may want to use this function to capture
1474 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001475 Localtime will be attached to the filename
1476
1477 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001478 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001479 copy.
kelvin8ec71442015-01-15 16:57:00 -08001480 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001481 For copying multiple files, leave copyFileName
1482 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001483 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001484 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001485 ex ) /tmp/
1486 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001487 * copyFileName: If you want to rename the log
1488 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001489 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001490 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001491 try:
kelvin8ec71442015-01-15 16:57:00 -08001492 localtime = time.strftime( '%x %X' )
1493 localtime = localtime.replace( "/", "" )
1494 localtime = localtime.replace( " ", "_" )
1495 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001496 if destDir[ -1: ] != "/":
1497 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001498
kelvin-onlabd3b64892015-01-20 13:26:24 -08001499 if copyFileName:
Jon Hallfebb1c72015-03-05 13:30:09 -08001500 self.handle.sendline( "cp " + str( logToCopy ) + " " +
1501 str( destDir ) + str( copyFileName ) +
1502 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001503 self.handle.expect( "cp" )
1504 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001505 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001506 self.handle.sendline( "cp " + str( logToCopy ) +
1507 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001508 self.handle.expect( "cp" )
1509 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001510
kelvin8ec71442015-01-15 16:57:00 -08001511 return self.handle.before
1512
1513 except pexpect.EOF:
1514 main.log.error( "Copying files failed" )
1515 main.log.error( self.name + ": EOF exception found" )
1516 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001517 except Exception:
1518 main.log.exception( "Copying files failed" )
1519
kelvin-onlabd3b64892015-01-20 13:26:24 -08001520 def checkLogs( self, onosIp ):
kelvin8ec71442015-01-15 16:57:00 -08001521 """
Jon Hall94fd0472014-12-08 11:52:42 -08001522 runs onos-check-logs on the given onos node
1523 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001524 """
Jon Hall94fd0472014-12-08 11:52:42 -08001525 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001526 cmd = "onos-check-logs " + str( onosIp )
kelvin8ec71442015-01-15 16:57:00 -08001527 self.handle.sendline( cmd )
1528 self.handle.expect( cmd )
1529 self.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -08001530 response = self.handle.before
1531 return response
1532 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001533 main.log.error( "Lost ssh connection" )
1534 main.log.error( self.name + ": EOF exception found" )
1535 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001536 except Exception:
1537 main.log.exception( self.name + ": Uncaught exception!" )
1538 main.cleanup()
1539 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -08001540
kelvin-onlabd3b64892015-01-20 13:26:24 -08001541 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001542 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001543 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001544 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001545 try:
kelvin8ec71442015-01-15 16:57:00 -08001546 self.handle.sendline( "" )
1547 self.handle.expect( "\$" )
1548 self.handle.sendline( "onos-service " + str( node ) +
1549 " status" )
1550 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001551 "start/running",
1552 "stop/waiting",
kelvin8ec71442015-01-15 16:57:00 -08001553 pexpect.TIMEOUT ], timeout=120 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001554
1555 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001556 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001557 return main.TRUE
1558 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001559 main.log.info( "ONOS is stopped" )
kelvin8ec71442015-01-15 16:57:00 -08001560 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001561 main.cleanup()
1562 main.exit()
1563 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001564 main.log.error( self.name + ": EOF exception found" )
1565 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001566 main.cleanup()
1567 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001568 except Exception:
1569 main.log.exception( self.name + ": Uncaught exception!" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001570 main.cleanup()
1571 main.exit()
Jon Hall21270ac2015-02-16 17:59:55 -08001572
Jon Hall63604932015-02-26 17:09:50 -08001573 def setIpTables( self, ip, port='', action='add', packet_type='',
1574 direction='INPUT', rule='DROP', states=True ):
Jon Hallefbd9792015-03-05 16:11:36 -08001575 """
Jon Hall21270ac2015-02-16 17:59:55 -08001576 Description:
1577 add or remove iptables rule to DROP (default) packets from
1578 specific IP and PORT
1579 Usage:
1580 * specify action ('add' or 'remove')
1581 when removing, pass in the same argument as you would add. It will
1582 delete that specific rule.
1583 * specify the ip to block
1584 * specify the destination port to block (defaults to all ports)
1585 * optional packet type to block (default tcp)
1586 * optional iptables rule (default DROP)
1587 * optional direction to block (default 'INPUT')
Jon Hall63604932015-02-26 17:09:50 -08001588 * States boolean toggles adding all supported tcp states to the
1589 firewall rule
Jon Hall21270ac2015-02-16 17:59:55 -08001590 Returns:
1591 main.TRUE on success or
1592 main.FALSE if given invalid input or
1593 main.ERROR if there is an error in response from iptables
1594 WARNING:
1595 * This function uses root privilege iptables command which may result
1596 in unwanted network errors. USE WITH CAUTION
Jon Hallefbd9792015-03-05 16:11:36 -08001597 """
Jon Hall21270ac2015-02-16 17:59:55 -08001598 import time
1599
1600 # NOTE*********
1601 # The strict checking methods of this driver function is intentional
1602 # to discourage any misuse or error of iptables, which can cause
1603 # severe network errors
1604 # *************
1605
1606 # NOTE: Sleep needed to give some time for rule to be added and
1607 # registered to the instance. If you are calling this function
1608 # multiple times this sleep will prevent any errors.
1609 # DO NOT REMOVE
Jon Hall63604932015-02-26 17:09:50 -08001610 # time.sleep( 5 )
Jon Hall21270ac2015-02-16 17:59:55 -08001611 try:
1612 # input validation
1613 action_type = action.lower()
1614 rule = rule.upper()
1615 direction = direction.upper()
1616 if action_type != 'add' and action_type != 'remove':
1617 main.log.error( "Invalid action type. Use 'add' or "
1618 "'remove' table rule" )
1619 if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
1620 # NOTE Currently only supports rules DROP, ACCEPT, and LOG
1621 main.log.error( "Invalid rule. Valid rules are 'DROP' or "
1622 "'ACCEPT' or 'LOG' only." )
1623 if direction != 'INPUT' and direction != 'OUTPUT':
1624 # NOTE currently only supports rules INPUT and OUPTUT
1625 main.log.error( "Invalid rule. Valid directions are"
1626 " 'OUTPUT' or 'INPUT'" )
1627 return main.FALSE
1628 return main.FALSE
1629 return main.FALSE
1630 if action_type == 'add':
1631 # -A is the 'append' action of iptables
1632 actionFlag = '-A'
1633 elif action_type == 'remove':
1634 # -D is the 'delete' rule of iptables
1635 actionFlag = '-D'
1636 self.handle.sendline( "" )
1637 self.handle.expect( "\$" )
1638 cmd = "sudo iptables " + actionFlag + " " +\
1639 direction +\
Jon Hall21270ac2015-02-16 17:59:55 -08001640 " -s " + str( ip )
Jon Hall63604932015-02-26 17:09:50 -08001641 # " -p " + str( packet_type ) +\
1642 if packet_type:
1643 cmd += " -p " + str( packet_type )
Jon Hall21270ac2015-02-16 17:59:55 -08001644 if port:
1645 cmd += " --dport " + str( port )
Jon Hall63604932015-02-26 17:09:50 -08001646 if states:
1647 cmd += " -m state --state="
1648 #FIXME- Allow user to configure which states to block
1649 cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED"
Jon Hall21270ac2015-02-16 17:59:55 -08001650 cmd += " -j " + str( rule )
1651
1652 self.handle.sendline( cmd )
1653 self.handle.expect( "\$" )
1654 main.log.warn( self.handle.before )
1655
1656 info_string = "On " + str( self.name )
1657 info_string += " " + str( action_type )
1658 info_string += " iptable rule [ "
1659 info_string += " IP: " + str( ip )
1660 info_string += " Port: " + str( port )
1661 info_string += " Rule: " + str( rule )
1662 info_string += " Direction: " + str( direction ) + " ]"
1663 main.log.info( info_string )
1664 return main.TRUE
1665 except pexpect.TIMEOUT:
1666 main.log.exception( self.name + ": Timeout exception in "
1667 "setIpTables function" )
1668 return main.ERROR
1669 except pexpect.EOF:
1670 main.log.error( self.name + ": EOF exception found" )
1671 main.log.error( self.name + ": " + self.handle.before )
1672 main.cleanup()
1673 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001674 except Exception:
1675 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall21270ac2015-02-16 17:59:55 -08001676 main.cleanup()
1677 main.exit()
1678
Jon Hall0468b042015-02-19 19:08:21 -08001679 def detailed_status(self, log_filename):
Jon Hallefbd9792015-03-05 16:11:36 -08001680 """
Jon Hall0468b042015-02-19 19:08:21 -08001681 This method is used by STS to check the status of the controller
1682 Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
Jon Hallefbd9792015-03-05 16:11:36 -08001683 """
Jon Hall0468b042015-02-19 19:08:21 -08001684 import re
1685 try:
1686 self.handle.sendline( "" )
1687 self.handle.expect( "\$" )
1688 self.handle.sendline( "cd " + self.home )
1689 self.handle.expect( "\$" )
1690 self.handle.sendline( "service onos status" )
1691 self.handle.expect( "\$" )
1692 response = self.handle.before
1693 if re.search( "onos start/running", response ):
1694 # onos start/running, process 10457
1695 return 'RUNNING'
1696 # FIXME: Implement this case
1697 # elif re.search( pattern, response ):
1698 # return 'STARTING'
1699 elif re.search( "onos stop/", response ):
1700 # onos stop/waiting
1701 # FIXME handle this differently?: onos stop/pre-stop
1702 return 'STOPPED'
1703 # FIXME: Implement this case
1704 # elif re.search( pattern, response ):
1705 # return 'FROZEN'
1706 else:
1707 main.log.warn( self.name +
Jon Hallefbd9792015-03-05 16:11:36 -08001708 " WARNING: status received unknown response" )
Jon Hall0468b042015-02-19 19:08:21 -08001709 main.log.warn( response )
1710 return 'ERROR', "Unknown response: %s" % response
1711 except pexpect.TIMEOUT:
1712 main.log.exception( self.name + ": Timeout exception in "
1713 "setIpTables function" )
1714 return 'ERROR', "Pexpect Timeout"
1715 except pexpect.EOF:
1716 main.log.error( self.name + ": EOF exception found" )
1717 main.log.error( self.name + ": " + self.handle.before )
1718 main.cleanup()
1719 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001720 except Exception:
1721 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall0468b042015-02-19 19:08:21 -08001722 main.cleanup()
1723 main.exit()
1724
andrew@onlab.us3b087132015-03-11 15:00:08 -07001725 def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount):
1726 '''
1727 Create/formats the LinkGraph.cfg file based on arguments
1728 -only creates a linear topology and connects islands
1729 -evenly distributes devices
1730 -must be called by ONOSbench
1731
1732 ONOSIpList - list of all of the node IPs to be used
1733
1734 deviceCount - number of switches to be assigned
1735 '''
1736 main.log.step("Creating link graph configuration file." )
1737 linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg"
1738 tempFile = "/tmp/linkGraph.cfg"
1739
1740 linkGraph = open(tempFile, 'w+')
1741 linkGraph.write("# NullLinkProvider topology description (config file).\n")
1742 linkGraph.write("# The NodeId is only added if the destination is another node's device.\n")
1743 linkGraph.write("# Bugs: Comments cannot be appended to a line to be read.\n")
1744
1745 clusterCount = len(ONOSIpList)
1746
1747 if type(deviceCount) is int or type(deviceCount) is str:
1748 deviceCount = int(deviceCount)
1749 switchList = [0]*(clusterCount+1)
1750 baselineSwitchCount = deviceCount/clusterCount
1751
1752 for node in range(1, clusterCount + 1):
1753 switchList[node] = baselineSwitchCount
1754
1755 for node in range(1, (deviceCount%clusterCount)+1):
1756 switchList[node] += 1
1757
1758 if type(deviceCount) is list:
1759 main.log.info("Using provided device distribution")
1760 switchList = [0]
1761 for i in deviceCount:
1762 switchList.append(int(i))
1763
1764 tempList = ['0']
1765 tempList.extend(ONOSIpList)
1766 ONOSIpList = tempList
1767
1768 myPort = 6
1769 lastSwitch = 0
1770 for node in range(1, clusterCount+1):
1771 if switchList[node] == 0:
1772 continue
1773
1774 linkGraph.write("graph " + ONOSIpList[node] + " {\n")
1775
1776 if node > 1:
1777 #connect to last device on previous node
1778 line = ("\t0:5 -> " + str(lastSwitch) + ":6:" + lastIp + "\n") #ONOSIpList[node-1]
1779 linkGraph.write(line)
1780
1781 lastSwitch = 0
1782 for switch in range (0, switchList[node]-1):
1783 line = ""
1784 line = ("\t" + str(switch) + ":" + str(myPort))
1785 line += " -- "
1786 line += (str(switch+1) + ":" + str(myPort-1) + "\n")
1787 linkGraph.write(line)
1788 lastSwitch = switch+1
1789 lastIp = ONOSIpList[node]
1790
1791 #lastSwitch += 1
1792 if node < (clusterCount):
1793 #connect to first device on the next node
1794 line = ("\t" + str(lastSwitch) + ":6 -> 0:5:" + ONOSIpList[node+1] + "\n")
1795 linkGraph.write(line)
1796
1797 linkGraph.write("}\n")
1798 linkGraph.close()
1799
1800 #SCP
1801 os.system( "scp " + tempFile + " admin@" + benchIp + ":" + linkGraphPath)
1802 main.log.info("linkGraph.cfg creation complete")
1803
cameron@onlab.us75900962015-03-30 13:22:49 -07001804 def configNullDev( self, ONOSIpList, deviceCount, numPorts=10):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001805
1806 '''
andrew@onlab.us3b087132015-03-11 15:00:08 -07001807 ONOSIpList = list of Ip addresses of nodes switches will be devided amongst
cameron@onlab.us75900962015-03-30 13:22:49 -07001808 deviceCount = number of switches to distribute, or list of values to use as custom distribution
1809 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 -07001810 '''
1811
cameron@onlab.us75900962015-03-30 13:22:49 -07001812 main.log.step("Configuring Null Device Provider" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001813 clusterCount = len(ONOSIpList)
1814
cameron@onlab.us75900962015-03-30 13:22:49 -07001815 try:
1816
1817 if type(deviceCount) is int or type(deviceCount) is str:
1818 main.log.step("Creating device distribution")
1819 deviceCount = int(deviceCount)
1820 switchList = [0]*(clusterCount+1)
1821 baselineSwitchCount = deviceCount/clusterCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001822
cameron@onlab.us75900962015-03-30 13:22:49 -07001823 for node in range(1, clusterCount + 1):
1824 switchList[node] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001825
cameron@onlab.us75900962015-03-30 13:22:49 -07001826 for node in range(1, (deviceCount%clusterCount)+1):
1827 switchList[node] += 1
1828
1829 if type(deviceCount) is list:
1830 main.log.info("Using provided device distribution")
1831
1832 if len(deviceCount) == clusterCount:
1833 switchList = ['0']
1834 switchList.extend(deviceCount)
1835
1836 if len(deviceCount) == (clusterCount + 1):
1837 if deviceCount[0] == '0' or deviceCount[0] == 0:
1838 switchList = deviceCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001839
cameron@onlab.us75900962015-03-30 13:22:49 -07001840 assert len(switchList) == (clusterCount + 1)
1841
1842 except AssertionError:
1843 main.log.error( "Bad device/Ip list match")
1844 except TypeError:
1845 main.log.exception( self.name + ": Object not as expected" )
1846 return None
Jon Hall77ba41c2015-04-06 10:25:40 -07001847 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07001848 main.log.exception( self.name + ": Uncaught exception!" )
1849 main.cleanup()
1850 main.exit()
1851
andrew@onlab.us3b087132015-03-11 15:00:08 -07001852
1853 ONOSIp = [0]
1854 ONOSIp.extend(ONOSIpList)
1855
1856 devicesString = "devConfigs = "
1857 for node in range(1, len(ONOSIp)):
1858 devicesString += (ONOSIp[node] + ":" + str(switchList[node] ))
1859 if node < clusterCount:
1860 devicesString += (",")
cameron@onlab.us75900962015-03-30 13:22:49 -07001861
1862 try:
1863 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString )
1864 self.handle.expect(":~")
1865 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str(numPorts) )
1866 self.handle.expect(":~")
andrew@onlab.us3b087132015-03-11 15:00:08 -07001867
cameron@onlab.us75900962015-03-30 13:22:49 -07001868 for i in range(10):
1869 self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider")
1870 self.handle.expect(":~")
1871 verification = self.handle.before
1872 if (" value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification:
1873 break
1874 else:
1875 time.sleep(1)
andrew@onlab.us3b087132015-03-11 15:00:08 -07001876
cameron@onlab.us2cc8bf12015-04-02 14:12:30 -07001877 assert ("value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification
cameron@onlab.us75900962015-03-30 13:22:49 -07001878
1879 except AssertionError:
1880 main.log.error("Incorrect Config settings: " + verification)
Jon Hall77ba41c2015-04-06 10:25:40 -07001881 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07001882 main.log.exception( self.name + ": Uncaught exception!" )
1883 main.cleanup()
1884 main.exit()
1885
cameron@onlab.usc80a8c82015-04-15 14:57:37 -07001886 def configNullLink( self,fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001887 '''
cameron@onlab.us75900962015-03-30 13:22:49 -07001888 fileName default is currently the same as the default on ONOS, specify alternate file if
1889 you want to use a different topology file than linkGraph.cfg
andrew@onlab.us3b087132015-03-11 15:00:08 -07001890 '''
1891
andrew@onlab.us3b087132015-03-11 15:00:08 -07001892
cameron@onlab.us75900962015-03-30 13:22:49 -07001893 try:
1894 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str(eventRate))
1895 self.handle.expect(":~")
1896 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName )
1897 self.handle.expect(":~")
1898
1899 for i in range(10):
1900 self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider")
1901 self.handle.expect(":~")
1902 verification = self.handle.before
1903 if (" value=" + str(eventRate)) in verification and (" value=" + fileName) in verification:
1904 break
1905 else:
1906 time.sleep(1)
1907
1908 assert ("value=" + str(eventRate)) in verification and (" value=" + fileName) in verification
1909
1910 except pexpect.EOF:
1911 main.log.error( self.name + ": EOF exception found" )
1912 main.log.error( self.name + ": " + self.handle.before )
1913 main.cleanup()
1914 main.exit()
cameron@onlab.us75900962015-03-30 13:22:49 -07001915 except AssertionError:
1916 main.log.info("Settings did not post to ONOS")
1917 main.log.error(varification)
Jon Hall77ba41c2015-04-06 10:25:40 -07001918 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07001919 main.log.exception( self.name + ": Uncaught exception!" )
1920 main.log.error(varification)
1921 main.cleanup()
1922 main.exit()
andrew@onlab.us3b087132015-03-11 15:00:08 -07001923
cameron@onlab.uscd4e8a22015-05-11 10:58:43 -07001924
1925 def getOnosIpFromEnv(self):
1926
1927 import string
1928
1929 # returns a list of ip addresses for the onos nodes, will work with up to 7 nodes + OCN and OCI
1930 # returns in format [ 'x', OC1 ip, OC2 i... ect. ... , ONN ip ]
1931
1932 self.handle.sendline("env| grep OC")
1933 self.handle.expect(":~")
1934 rawOutput = self.handle.before
1935 print rawOutput
1936 print "-----------------------------"
1937 print repr(rawOutput)
1938 mpa = dict.fromkeys(range(32))
1939 translated = rawOutput.translate(mpa)
1940 print translated
1941
1942
1943 # create list with only the lines that have the needed IPs
1944 unparsedIps = []
1945
1946 # remove preceeding or trailing lines
1947 for line in rawOutput:
1948 if "OC" in line and "=" in line:
1949 unparsedIps.append(str(line))
1950
1951 # determine cluster size
1952 clusterCount = 0
1953 for line in unparsedIps:
1954 line = str(line)
1955 print line
1956 temp = line.replace("OC","")
1957 print("line index " + str(line.index("=")))
1958 OCindex = temp[0]
1959 for i in range(0, 7):
1960 if OCindex == str(i) and i > clusterCount:
1961 clusterCount == i
1962 print(clusterCount)
1963 # create list to hold ips such that OC1 is at list[1] and OCN and OCI are at the end (in that order)
1964 ONOSIps = ["x"] * (clusterCount + 3)
1965
1966 # populate list
1967 for line in unparsedIps:
1968 main.log.info(line)##########
1969 temp = str(line.replace("OC",""))
1970 main.log.info(str(list(temp)))
1971 OCindex = temp[0]
1972 main.log.info(OCindex)############
1973 if OCindex == "N":
1974 ONOSIps[ clusterCount + 1 ] = temp.replace("N=","")
1975
1976 if OCindex == "I":
1977 ONOSIps[ clusterCount + 2 ] = temp.replace("I=","")
1978
1979 else:
1980 ONOSIps[ int(OCindex) ] = temp.replace((OCindex + "=") ,"")
1981
1982 # validate
1983 for x in ONOSIps:
1984 if ONOSIps.index(x) != 0 and x == "x":
1985 main.log.error("ENV READ FAILURE, MISSING DATA: \n\n" + str(ONOSIps) + "\n\n")
1986
1987 return ONOSIps
1988
cameron@onlab.usc10e22c2015-05-13 13:07:28 -07001989
1990 def onosErrorLog(self, nodeIp):
1991
1992 cmd = "onos-ssh " + nodeIp + " cat /opt/onos/log/karaf.log | grep WARN"
1993 self.handle.sendline(cmd)
1994 self.handle.expect(":~")
1995 before = (self.handle.before).splitlines()
1996
1997 warnings = []
1998
1999 for line in before:
2000 if "WARN" in line and "grep" not in line:
2001 warnings.append(line)
2002 main.warnings[main.warnings[0]+1] = line
2003 main.warnings[0] += 1
2004 if main.warnings[0] >= 10:
2005 main.warnings[0] = 0
2006
2007 cmd = "onos-ssh " + nodeIp + " cat /opt/onos/log/karaf.log | grep ERROR"
2008 self.handle.sendline(cmd)
2009 self.handle.expect(":~")
2010 before = (self.handle.before).splitlines()
2011
2012 errors = []
2013
2014 for line in before:
2015 if "ERROR" in line and "grep" not in line:
2016 errors.append(line)
2017 main.errors[main.errors[0]+1] = line
2018 main.errors[0] += 1
2019 if main.errors[0] >= 10:
2020 main.errors[0] = 0
2021
2022 cmd = "onos-ssh " + nodeIp + " cat /opt/onos/log/karaf.log | grep Exept"
2023 self.handle.sendline(cmd)
2024 self.handle.expect(":~")
2025 before = (self.handle.before).splitlines()
2026
2027 exceptions = []
2028
2029 for line in before:
2030 if "Except" in line and "grep" not in line:
2031 exceptions.append(line)
2032 main.exceptions[main.errors[0]+1] = line
2033 main.exceptions[0] += 1
2034 if main.exceptions[0] >= 10:
2035 main.exceptions[0] = 0
2036
2037
2038
2039 ################################################################
2040
2041 msg1 = "WARNINGS: \n"
2042 for i in main.warnings:
2043 if type(i) is not int:
2044 msg1 += ( i + "\n")
2045
2046 msg2 = "ERRORS: \n"
2047 for i in main.errors:
2048 if type(i) is not int:
2049 msg2 += ( i + "\n")
2050
2051 msg3 = "EXCEPTIONS: \n"
2052 for i in main.exceptions:
2053 if type(i) is not int:
2054 msg3 += ( i + "\n")
2055
2056 main.log.info("===============================================================\n")
2057 main.log.info( "Warnings: " + str(len(warnings)))
2058 main.log.info( "Errors: " + str(len(errors)))
2059 main.log.info( "Exceptions: " + str(len(exceptions)))
2060 if len(warnings) > 0:
2061 main.log.info(msg1)
2062 if len(errors) > 0:
2063 main.log.info(msg2)
2064 if len(exceptions) > 0:
2065 main.log.info(msg3)
2066 main.log.info("===============================================================\n")
2067