blob: 50994eec54d25e51e5cf92cae3b5b16e218f20db [file] [log] [blame]
Jon Hall05b2b432014-10-08 19:53:25 -04001#!/usr/bin/env python
andrewonlabe8e56fd2014-10-09 17:12:44 -04002
kelvin8ec71442015-01-15 16:57:00 -08003"""
4This driver interacts with ONOS bench, the OSGi platform
5that configures the ONOS nodes. ( aka ONOS-next )
andrewonlabe8e56fd2014-10-09 17:12:44 -04006
kelvin8ec71442015-01-15 16:57:00 -08007Please follow the coding style demonstrated by existing
andrewonlabe8e56fd2014-10-09 17:12:44 -04008functions and document properly.
9
10If you are a contributor to the driver, please
11list your email here for future contact:
12
13jhall@onlab.us
14andrew@onlab.us
15
16OCT 9 2014
17
kelvin8ec71442015-01-15 16:57:00 -080018"""
andrewonlab7735d852014-10-09 13:02:47 -040019import sys
Jon Hall05b2b432014-10-08 19:53:25 -040020import time
21import pexpect
Jon Hall05b2b432014-10-08 19:53:25 -040022import traceback
andrewonlab7735d852014-10-09 13:02:47 -040023import os.path
kelvin8ec71442015-01-15 16:57:00 -080024sys.path.append( "../" )
Jon Hall05b2b432014-10-08 19:53:25 -040025from drivers.common.clidriver import CLI
26
Jon Hall05b2b432014-10-08 19:53:25 -040027
kelvin8ec71442015-01-15 16:57:00 -080028class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040029
kelvin8ec71442015-01-15 16:57:00 -080030 def __init__( self ):
31 """
32 Initialize client
33 """
34 super( CLI, self ).__init__()
35
36 def connect( self, **connectargs ):
37 """
Jon Hall05b2b432014-10-08 19:53:25 -040038 Creates ssh handle for ONOS "bench".
kelvin8ec71442015-01-15 16:57:00 -080039 """
Jon Hall05b2b432014-10-08 19:53:25 -040040 try:
41 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080042 vars( self )[ key ] = connectargs[ key ]
Jon Hall05b2b432014-10-08 19:53:25 -040043 self.home = "~/ONOS"
44 for key in self.options:
45 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080046 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040047 break
kelvin-onlaba1484582015-02-02 15:46:20 -080048 if self.home == None or self.home == "":
49 self.home = "~/ONOS"
50
kelvin8ec71442015-01-15 16:57:00 -080051 self.name = self.options[ 'name' ]
52 self.handle = super( OnosDriver, self ).connect(
53 user_name=self.user_name,
kelvin-onlab08679eb2015-01-21 16:11:48 -080054 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -080055 port=self.port,
56 pwd=self.pwd,
57 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -040058
kelvin8ec71442015-01-15 16:57:00 -080059 self.handle.sendline( "cd " + self.home )
60 self.handle.expect( "\$" )
Jon Hall05b2b432014-10-08 19:53:25 -040061 if self.handle:
62 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080063 else:
64 main.log.info( "NO ONOS HANDLE" )
Jon Hall05b2b432014-10-08 19:53:25 -040065 return main.FALSE
66 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080067 main.log.error( self.name + ": EOF exception found" )
68 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040069 main.cleanup()
70 main.exit()
71 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -080072 main.log.info( self.name + ":" * 30 )
Jon Hall05b2b432014-10-08 19:53:25 -040073 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -080074 main.log.info( ":" * 30 )
Jon Hall05b2b432014-10-08 19:53:25 -040075 main.cleanup()
76 main.exit()
77
kelvin8ec71442015-01-15 16:57:00 -080078 def disconnect( self ):
79 """
Jon Hall05b2b432014-10-08 19:53:25 -040080 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080081 """
Jon Hall05b2b432014-10-08 19:53:25 -040082 response = ''
83 try:
kelvin8ec71442015-01-15 16:57:00 -080084 self.handle.sendline( "" )
85 self.handle.expect( "\$" )
86 self.handle.sendline( "exit" )
87 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -040088 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080089 main.log.error( self.name + ": EOF exception found" )
90 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -040091 except:
kelvin8ec71442015-01-15 16:57:00 -080092 main.log.error( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -040093 response = main.FALSE
94 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040095
kelvin-onlabd3b64892015-01-20 13:26:24 -080096 def onosPackage( self ):
kelvin8ec71442015-01-15 16:57:00 -080097 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -040098 Produce a self-contained tar.gz file that can be deployed
kelvin8ec71442015-01-15 16:57:00 -080099 and executed on any platform with Java 7 JRE.
100 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400101 try:
kelvin8ec71442015-01-15 16:57:00 -0800102 self.handle.sendline( "onos-package" )
103 self.handle.expect( "onos-package" )
104 self.handle.expect( "tar.gz", timeout=30 )
105 handle = str( self.handle.before )
106 main.log.info( "onos-package command returned: " +
107 handle )
108 # As long as the sendline does not time out,
109 # return true. However, be careful to interpret
110 # the results of the onos-package command return
andrewonlab0748d2a2014-10-09 13:24:17 -0400111 return main.TRUE
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400112
andrewonlab7735d852014-10-09 13:02:47 -0400113 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800114 main.log.error( self.name + ": EOF exception found" )
115 main.log.error( self.name + ": " + self.handle.before )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400116 except:
kelvin8ec71442015-01-15 16:57:00 -0800117 main.log.error( "Failed to package ONOS" )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400118 main.cleanup()
119 main.exit()
120
kelvin-onlabd3b64892015-01-20 13:26:24 -0800121 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800122 """
andrewonlab8790abb2014-11-06 13:51:54 -0500123 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800124 """
andrewonlab8790abb2014-11-06 13:51:54 -0500125 try:
kelvin8ec71442015-01-15 16:57:00 -0800126 self.handle.sendline( "onos-build" )
127 self.handle.expect( "onos-build" )
128 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800129 "BUILD SUCCESS",
130 "ERROR",
131 "BUILD FAILED" ],
132 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800133 handle = str( self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500134
kelvin8ec71442015-01-15 16:57:00 -0800135 main.log.info( "onos-build command returned: " +
136 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500137
138 if i == 0:
139 return main.TRUE
140 else:
141 return handle
142
143 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800144 main.log.error( self.name + ": EOF exception found" )
145 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8790abb2014-11-06 13:51:54 -0500146 except:
kelvin8ec71442015-01-15 16:57:00 -0800147 main.log.error( "Failed to build ONOS" )
andrewonlab8790abb2014-11-06 13:51:54 -0500148 main.cleanup()
149 main.exit()
150
kelvin-onlabd3b64892015-01-20 13:26:24 -0800151 def cleanInstall( self ):
kelvin8ec71442015-01-15 16:57:00 -0800152 """
153 Runs mvn clean install in the root of the ONOS directory.
154 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400155
kelvin8ec71442015-01-15 16:57:00 -0800156 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400157 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800158 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400159 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800160 main.log.info( "Running 'mvn clean install' on " +
161 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800162 ". This may take some time." )
163 self.handle.sendline( "cd " + self.home )
164 self.handle.expect( "\$" )
Jon Hallea7818b2014-10-09 14:30:59 -0400165
kelvin8ec71442015-01-15 16:57:00 -0800166 self.handle.sendline( "" )
167 self.handle.expect( "\$" )
168 self.handle.sendline( "mvn clean install" )
169 self.handle.expect( "mvn clean install" )
170 while True:
171 i = self.handle.expect( [
Jon Hallde9d9aa2014-10-08 20:36:02 -0400172 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\
173 Runtime\sEnvironment\sto\scontinue',
174 'BUILD\sFAILURE',
175 'BUILD\sSUCCESS',
176 'ONOS\$',
kelvin8ec71442015-01-15 16:57:00 -0800177 pexpect.TIMEOUT ], timeout=600 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400178 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800179 main.log.error( self.name + ":There is insufficient memory \
180 for the Java Runtime Environment to continue." )
181 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400182 main.cleanup()
183 main.exit()
184 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800185 main.log.error( self.name + ": Build failure!" )
186 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400187 main.cleanup()
188 main.exit()
189 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800190 main.log.info( self.name + ": Build success!" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400191 elif i == 3:
kelvin8ec71442015-01-15 16:57:00 -0800192 main.log.info( self.name + ": Build complete" )
193 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400194 for line in self.handle.before.splitlines():
195 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800196 main.log.info( line )
197 self.handle.sendline( "" )
198 self.handle.expect( "\$", timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400199 return main.TRUE
200 elif i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800201 main.log.error(
202 self.name +
203 ": mvn clean install TIMEOUT!" )
204 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400205 main.cleanup()
206 main.exit()
207 else:
kelvin8ec71442015-01-15 16:57:00 -0800208 main.log.error( self.name + ": unexpected response from \
209 mvn clean install" )
210 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400211 main.cleanup()
212 main.exit()
213 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800214 main.log.error( self.name + ": EOF exception found" )
215 main.log.error( self.name + ": " + self.handle.before )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400216 main.cleanup()
217 main.exit()
218 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800219 main.log.info( self.name + ":" * 60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400220 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800221 main.log.info( ":" * 60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400222 main.cleanup()
223 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400224
kelvin-onlabd3b64892015-01-20 13:26:24 -0800225 def gitPull( self, comp1="" ):
kelvin8ec71442015-01-15 16:57:00 -0800226 """
Jon Hallacabffd2014-10-09 12:36:53 -0400227 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800228
Jon Hallacabffd2014-10-09 12:36:53 -0400229 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800230 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400231 for the purpose of pulling from other nodes if necessary.
232
Jon Hall47a93fb2015-01-06 16:46:06 -0800233 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400234 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800235 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400236 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400237
kelvin8ec71442015-01-15 16:57:00 -0800238 """
Jon Hallacabffd2014-10-09 12:36:53 -0400239 try:
kelvin8ec71442015-01-15 16:57:00 -0800240 # main.log.info( self.name + ": Stopping ONOS" )
241 # self.stop()
242 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800243 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800244 if comp1 == "":
245 self.handle.sendline( "git pull" )
Jon Hallacabffd2014-10-09 12:36:53 -0400246 else:
kelvin8ec71442015-01-15 16:57:00 -0800247 self.handle.sendline( "git pull " + comp1 )
Jon Hall47a93fb2015-01-06 16:46:06 -0800248
kelvin-onlabd3b64892015-01-20 13:26:24 -0800249 i = self.handle.expect(
250 [
251 'fatal',
252 'Username\sfor\s(.*):\s',
253 '\sfile(s*) changed,\s',
254 'Already up-to-date',
255 'Aborting',
256 'You\sare\snot\scurrently\son\sa\sbranch',
257 'You\sasked\sme\sto\spull\swithout\stelling\sme\swhich\
258 \sbranch\syou',
259 'Pull\sis\snot\spossible\sbecause\syou\shave\sunmerged\
260 \sfiles',
261 pexpect.TIMEOUT ],
262 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800263 # debug
kelvin-onlabd3b64892015-01-20 13:26:24 -0800264 # main.log.report( self.name +": DEBUG: \n"+
265 # "git pull response: " +
266 # str( self.handle.before ) + str( self.handle.after ) )
kelvin8ec71442015-01-15 16:57:00 -0800267 if i == 0:
268 main.log.error( self.name + ": Git pull had some issue..." )
Jon Hallacabffd2014-10-09 12:36:53 -0400269 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800270 elif i == 1:
271 main.log.error(
272 self.name +
273 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400274 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800275 elif i == 2:
276 main.log.info(
277 self.name +
278 ": Git Pull - pulling repository now" )
kelvin-onlaba1484582015-02-02 15:46:20 -0800279 self.handle.expect( self.home + "\$", 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800280 # So that only when git pull is done, we do mvn clean compile
281 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800282 elif i == 3:
283 main.log.info( self.name + ": Git Pull - Already up to date" )
Jon Hall47a93fb2015-01-06 16:46:06 -0800284 return i
kelvin8ec71442015-01-15 16:57:00 -0800285 elif i == 4:
286 main.log.info(
287 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800288 ": Git Pull - Aborting...\
289 Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400290 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800291 elif i == 5:
292 main.log.info(
293 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800294 ": Git Pull - You are not currently\
295 on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400296 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800297 elif i == 6:
298 main.log.info(
299 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800300 ": Git Pull - You have not configured\
301 an upstream branch to pull from\
302 . Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400303 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800304 elif i == 7:
305 main.log.info(
306 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800307 ": Git Pull - Pull is not possible\
308 because you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400309 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800310 elif i == 8:
311 main.log.error( self.name + ": Git Pull - TIMEOUT" )
312 main.log.error(
313 self.name + " Response was: " + str(
314 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400315 return main.ERROR
316 else:
kelvin8ec71442015-01-15 16:57:00 -0800317 main.log.error(
318 self.name +
319 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400320 return main.ERROR
321 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800322 main.log.error( self.name + ": EOF exception found" )
323 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400324 main.cleanup()
325 main.exit()
326 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800327 main.log.info( self.name + ":" * 60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400328 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800329 main.log.info( ":" * 80 )
Jon Hallacabffd2014-10-09 12:36:53 -0400330 main.cleanup()
331 main.exit()
332
kelvin-onlabd3b64892015-01-20 13:26:24 -0800333 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800334 """
Jon Hallacabffd2014-10-09 12:36:53 -0400335 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800336
Jon Hallacabffd2014-10-09 12:36:53 -0400337 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800338 If used as gitCheckout( "branch" ) it will do git checkout
339 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400340
341 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800342 branch of the ONOS repository. If it has any problems, it will return
343 main.ERROR.
344 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400345 successful then the function will return main.TRUE.
346
kelvin8ec71442015-01-15 16:57:00 -0800347 """
Jon Hallacabffd2014-10-09 12:36:53 -0400348 try:
kelvin8ec71442015-01-15 16:57:00 -0800349 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800350 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800351 main.log.info(
352 self.name +
353 ": Checking out git branch: " +
354 branch +
355 "..." )
356 cmd = "git checkout " + branch
357 self.handle.sendline( cmd )
358 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800359 i = self.handle.expect(
360 [
361 'fatal',
362 'Username\sfor\s(.*):\s',
363 'Already\son\s\'',
364 'Switched\sto\sbranch\s\'' +
365 str( branch ),
366 pexpect.TIMEOUT,
367 'error: Your local changes to the following files\
368 would be overwritten by checkout:',
369 'error: you need to resolve your current index first' ],
370 timeout=60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400371
kelvin8ec71442015-01-15 16:57:00 -0800372 if i == 0:
373 main.log.error(
374 self.name +
375 ": Git checkout had some issue..." )
376 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400377 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800378 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800379 main.log.error(
380 self.name +
381 ": Git checkout asking for username." +
382 " Please configure your local git repository to be able " +
383 "to access your remote repository passwordlessly" )
Jon Hallacabffd2014-10-09 12:36:53 -0400384 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800385 elif i == 2:
386 main.log.info(
387 self.name +
388 ": Git Checkout %s : Already on this branch" %
389 branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800390 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800391 # main.log.info( "DEBUG: after checkout cmd = "+
392 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400393 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800394 elif i == 3:
395 main.log.info(
396 self.name +
397 ": Git checkout %s - Switched to this branch" %
398 branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800399 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800400 # main.log.info( "DEBUG: after checkout cmd = "+
401 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400402 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800403 elif i == 4:
404 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
405 main.log.error(
406 self.name + " Response was: " + str(
407 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400408 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800409 elif i == 5:
410 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800411 main.log.error(
412 self.name +
413 ": Git checkout error: \n" +
414 "Your local changes to the following\
415 files would be overwritten by checkout:" +
416 str(
417 self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800418 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500419 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800420 elif i == 6:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800421 main.log.error( self.name +
422 ": Git checkout error: \n" +
423 "You need to resolve your\
424 current index first:" +
kelvin8ec71442015-01-15 16:57:00 -0800425 str( self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800426 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500427 return main.ERROR
Jon Hallacabffd2014-10-09 12:36:53 -0400428 else:
kelvin8ec71442015-01-15 16:57:00 -0800429 main.log.error(
430 self.name +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800431 ": Git Checkout - Unexpected response,\
432 check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800433 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400434 return main.ERROR
435
436 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800437 main.log.error( self.name + ": EOF exception found" )
438 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400439 main.cleanup()
440 main.exit()
441 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800442 main.log.info( self.name + ":" * 60 )
Jon Hallacabffd2014-10-09 12:36:53 -0400443 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800444 main.log.info( ":" * 80 )
Jon Hallacabffd2014-10-09 12:36:53 -0400445 main.cleanup()
446 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400447
kelvin-onlabd3b64892015-01-20 13:26:24 -0800448 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800449 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800450 Writes the COMMIT number to the report to be parsed\
451 by Jenkins data collecter.
kelvin8ec71442015-01-15 16:57:00 -0800452 """
Jon Hall45ec0922014-10-10 19:33:49 -0400453 try:
kelvin8ec71442015-01-15 16:57:00 -0800454 self.handle.sendline( "" )
455 self.handle.expect( "\$" )
456 self.handle.sendline(
457 "cd " +
458 self.home +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800459 "; git log -1 --pretty=fuller --decorate=short | grep -A 6\
460 \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800461 # NOTE: for some reason there are backspaces inserted in this
462 # phrase when run from Jenkins on some tests
463 self.handle.expect( "never" )
464 self.handle.expect( "\$" )
465 response = ( self.name + ": \n" + str(
466 self.handle.before + self.handle.after ) )
467 self.handle.sendline( "cd " + self.home )
468 self.handle.expect( "\$" )
469 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400470 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500471 print line
472 if report:
kelvin8ec71442015-01-15 16:57:00 -0800473 for line in lines[ 2:-1 ]:
474 # Bracket replacement is for Wiki-compliant
475 # formatting. '<' or '>' are interpreted
476 # as xml specific tags that cause errors
477 line = line.replace( "<", "[" )
478 line = line.replace( ">", "]" )
479 main.log.report( "\t" + line )
480 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400481 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800482 main.log.error( self.name + ": EOF exception found" )
483 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400484 main.cleanup()
485 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800486 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800487 main.log.error( self.name + ": TIMEOUT exception found" )
488 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800489 main.cleanup()
490 main.exit()
Jon Hall45ec0922014-10-10 19:33:49 -0400491 except:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800492 main.log.info( self.name + ":" * 60 )
Jon Hall45ec0922014-10-10 19:33:49 -0400493 main.log.error( traceback.print_exc() )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800494 main.log.info( ":" * 80 )
Jon Hall45ec0922014-10-10 19:33:49 -0400495 main.cleanup()
496 main.exit()
497
kelvin-onlabd3b64892015-01-20 13:26:24 -0800498 def createCellFile( self, benchIp, fileName, mnIpAddrs,
499 extraFeatureString, *onosIpAddrs ):
kelvin8ec71442015-01-15 16:57:00 -0800500 """
andrewonlab94282092014-10-10 13:00:11 -0400501 Creates a cell file based on arguments
502 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800503 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400504 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800505 * File name of the cell file ( fileName )
506 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800507 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400508 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800509 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400510 - Must be passed in as last arguments
kelvin8ec71442015-01-15 16:57:00 -0800511
andrewonlab94282092014-10-10 13:00:11 -0400512 NOTE: Assumes cells are located at:
513 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800514 """
515 # Variable initialization
kelvin-onlabd3b64892015-01-20 13:26:24 -0800516 cellDirectory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800517 # We want to create the cell file in the dependencies directory
518 # of TestON first, then copy over to ONOS bench
kelvin-onlabd3b64892015-01-20 13:26:24 -0800519 tempDirectory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800520 # Create the cell file in the directory for writing ( w+ )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800521 cellFile = open( tempDirectory + fileName, 'w+' )
kelvin8ec71442015-01-15 16:57:00 -0800522
523 # Feature string is hardcoded environment variables
524 # That you may wish to use by default on startup.
525 # Note that you may not want certain features listed
526 # on here.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800527 coreFeatureString = "export ONOS_FEATURES=webconsole,onos-api," +\
528 "onos-cli,onos-openflow," + extraFeatureString
529 mnString = "export OCN="
530 onosString = "export OC"
531 tempCount = 1
kelvin8ec71442015-01-15 16:57:00 -0800532
kelvin-onlabd3b64892015-01-20 13:26:24 -0800533 # Create ONOSNIC ip address prefix
534 tempOnosIp = onosIpAddrs[ 0 ]
535 tempList = []
536 tempList = tempOnosIp.split( "." )
kelvin8ec71442015-01-15 16:57:00 -0800537 # Omit last element of list to format for NIC
kelvin-onlabd3b64892015-01-20 13:26:24 -0800538 tempList = tempList[ :-1 ]
kelvin8ec71442015-01-15 16:57:00 -0800539 # Structure the nic string ip
kelvin-onlabd3b64892015-01-20 13:26:24 -0800540 nicAddr = ".".join( tempList ) + ".*"
541 onosNicString = "export ONOS_NIC=" + nicAddr
andrewonlab94282092014-10-10 13:00:11 -0400542
543 try:
kelvin8ec71442015-01-15 16:57:00 -0800544 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800545 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400546
kelvin-onlabd3b64892015-01-20 13:26:24 -0800547 for arg in onosIpAddrs:
548 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800549 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400550 # export OC1="10.128.20.11"
551 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800552 cellFile.write( onosString + str( tempCount ) +
553 "=" + "\"" + arg + "\"" + "\n" )
554 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800555
kelvin-onlabd3b64892015-01-20 13:26:24 -0800556 cellFile.write( mnString + "\"" + mnIpAddrs + "\"" + "\n" )
557 cellFile.write( coreFeatureString + "\n" )
558 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400559
kelvin8ec71442015-01-15 16:57:00 -0800560 # We use os.system to send the command to TestON cluster
561 # to account for the case in which TestON is not located
562 # on the same cluster as the ONOS bench
563 # Note that even if TestON is located on the same cluster
564 # as ONOS bench, you must setup passwordless ssh
565 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800566 os.system( "scp " + tempDirectory + fileName +
567 " admin@" + benchIp + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400568
andrewonlab2a6c9342014-10-16 13:40:15 -0400569 return main.TRUE
570
andrewonlab94282092014-10-10 13:00:11 -0400571 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800572 main.log.error( self.name + ": EOF exception found" )
573 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -0400574 main.cleanup()
575 main.exit()
576 except:
kelvin8ec71442015-01-15 16:57:00 -0800577 main.log.info( self.name + ":::::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400578 main.log.error( traceback.print_exc() )
kelvin8ec71442015-01-15 16:57:00 -0800579 main.log.info( ":::::::" )
andrewonlab94282092014-10-10 13:00:11 -0400580 main.cleanup()
581 main.exit()
582
kelvin-onlabd3b64892015-01-20 13:26:24 -0800583 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800584 """
andrewonlab95ca1462014-10-09 14:04:24 -0400585 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800586 """
andrewonlab95ca1462014-10-09 14:04:24 -0400587 try:
588 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800589 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400590 main.cleanup()
591 main.exit()
592 else:
kelvin8ec71442015-01-15 16:57:00 -0800593 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800594 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800595 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400596 # and that this driver will have to change accordingly
kelvin8ec71442015-01-15 16:57:00 -0800597 self.handle.expect( "ONOS_CELL=" + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800598 handleBefore = self.handle.before
599 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800600 # Get the rest of the handle
601 self.handle.sendline( "" )
602 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800603 handleMore = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400604
kelvin-onlabd3b64892015-01-20 13:26:24 -0800605 main.log.info( "Cell call returned: " + handleBefore +
606 handleAfter + handleMore )
andrewonlab95ca1462014-10-09 14:04:24 -0400607
608 return main.TRUE
609
610 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800611 main.log.error( self.name + ": EOF exception found" )
612 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400613 main.cleanup()
614 main.exit()
615 except:
kelvin8ec71442015-01-15 16:57:00 -0800616 main.log.info( self.name + " ::::::" )
617 main.log.error( traceback.print_exc() )
618 main.log.info( self.name + " ::::::" )
andrewonlab95ca1462014-10-09 14:04:24 -0400619 main.cleanup()
620 main.exit()
621
kelvin-onlabd3b64892015-01-20 13:26:24 -0800622 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800623 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400624 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800625 """
626 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400627
andrewonlabc03bf6c2014-10-09 14:56:18 -0400628 try:
kelvin8ec71442015-01-15 16:57:00 -0800629 # Clean handle by sending empty and expecting $
630 self.handle.sendline( "" )
631 self.handle.expect( "\$" )
632 self.handle.sendline( "onos-verify-cell" )
633 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800634 handleBefore = self.handle.before
635 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800636 # Get the rest of the handle
637 self.handle.sendline( "" )
638 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800639 handleMore = self.handle.before
andrewonlabc03bf6c2014-10-09 14:56:18 -0400640
kelvin-onlabd3b64892015-01-20 13:26:24 -0800641 main.log.info( "Verify cell returned: " + handleBefore +
642 handleAfter + handleMore )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400643
644 return main.TRUE
Jon Hall7993bfc2014-10-09 16:30:14 -0400645 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800646 main.log.error( self.name + ": EOF exception found" )
647 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400648 main.cleanup()
649 main.exit()
650 except:
kelvin8ec71442015-01-15 16:57:00 -0800651 main.log.info( self.name + " ::::::" )
652 main.log.error( traceback.print_exc() )
653 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400654 main.cleanup()
655 main.exit()
656
kelvin-onlabd3b64892015-01-20 13:26:24 -0800657 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800658 """
andrewonlab05e362f2014-10-10 00:40:57 -0400659 Uses 'onos' command to send various ONOS CLI arguments.
660 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800661 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400662 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800663
664 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400665 CLI commands for ONOS. Try to use this function first
666 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800667 function.
668 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400669 by starting onos, and typing in 'onos' to enter the
670 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800671 available commands.
672 """
andrewonlab05e362f2014-10-10 00:40:57 -0400673 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800674 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800675 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400676 return main.FALSE
677 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800678 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400679 return main.FALSE
680
kelvin8ec71442015-01-15 16:57:00 -0800681 cmdstr = str( cmdstr )
682 self.handle.sendline( "" )
683 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400684
kelvin-onlabd3b64892015-01-20 13:26:24 -0800685 self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr )
kelvin8ec71442015-01-15 16:57:00 -0800686 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400687
kelvin-onlabd3b64892015-01-20 13:26:24 -0800688 handleBefore = self.handle.before
Shreya Shaha73aaad2014-10-27 18:03:09 -0400689 print "handle_before = ", self.handle.before
kelvin-onlabd3b64892015-01-20 13:26:24 -0800690 # handleAfter = str( self.handle.after )
Jon Hall47a93fb2015-01-06 16:46:06 -0800691
kelvin8ec71442015-01-15 16:57:00 -0800692 # self.handle.sendline( "" )
693 # self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800694 # handleMore = str( self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400695
kelvin8ec71442015-01-15 16:57:00 -0800696 main.log.info( "Command sent successfully" )
andrewonlab05e362f2014-10-10 00:40:57 -0400697
kelvin8ec71442015-01-15 16:57:00 -0800698 # Obtain return handle that consists of result from
699 # the onos command. The string may need to be
700 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800701 # returnString = handleBefore + handleAfter
702 returnString = handleBefore
703 print "return_string = ", returnString
704 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400705
706 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800707 main.log.error( self.name + ": EOF exception found" )
708 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400709 main.cleanup()
710 main.exit()
711 except:
kelvin8ec71442015-01-15 16:57:00 -0800712 main.log.info( self.name + " ::::::" )
713 main.log.error( traceback.print_exc() )
714 main.log.info( self.name + " ::::::" )
andrewonlab05e362f2014-10-10 00:40:57 -0400715 main.cleanup()
716 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400717
kelvin-onlabd3b64892015-01-20 13:26:24 -0800718 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -0800719 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400720 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800721 If -f option is provided, it also forces an uninstall.
722 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400723 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800724 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400725 files to certain onos nodes
726
727 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800728 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400729 try:
andrewonlab114768a2014-11-14 12:44:44 -0500730 if options:
kelvin8ec71442015-01-15 16:57:00 -0800731 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500732 else:
kelvin8ec71442015-01-15 16:57:00 -0800733 self.handle.sendline( "onos-install " + node )
734 self.handle.expect( "onos-install " )
735 # NOTE: this timeout may need to change depending on the network
736 # and size of ONOS
737 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800738 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -0800739 "ONOS\sis\salready\sinstalled",
740 pexpect.TIMEOUT ], timeout=60 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400741
Jon Hall7993bfc2014-10-09 16:30:14 -0400742 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800743 main.log.warn( "Network is unreachable" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400744 return main.FALSE
745 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800746 main.log.info(
747 "ONOS was installed on " +
748 node +
749 " and started" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400750 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500751 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800752 main.log.info( "ONOS is already installed on " + node )
andrewonlabd9a73a72014-11-14 17:28:21 -0500753 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800754 elif i == 3:
755 main.log.info(
756 "Installation of ONOS on " +
757 node +
758 " timed out" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400759 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400760
761 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800762 main.log.error( self.name + ": EOF exception found" )
763 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400764 main.cleanup()
765 main.exit()
766 except:
kelvin8ec71442015-01-15 16:57:00 -0800767 main.log.info( self.name + " ::::::" )
768 main.log.error( traceback.print_exc() )
769 main.log.info( self.name + " ::::::" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400770 main.cleanup()
771 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400772
kelvin-onlabd3b64892015-01-20 13:26:24 -0800773 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800774 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400775 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400776 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800777 """
andrewonlab8d0d7d72014-10-09 16:33:15 -0400778 try:
kelvin8ec71442015-01-15 16:57:00 -0800779 self.handle.sendline( "" )
780 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800781 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800782 " start" )
783 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -0400784 "Job\sis\salready\srunning",
785 "start/running",
786 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800787 pexpect.TIMEOUT ], timeout=120 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400788
789 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800790 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400791 return main.TRUE
792 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800793 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400794 return main.TRUE
795 else:
kelvin8ec71442015-01-15 16:57:00 -0800796 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400797 main.cleanup()
798 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -0400799 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 )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400802 main.cleanup()
803 main.exit()
804 except:
kelvin8ec71442015-01-15 16:57:00 -0800805 main.log.info( self.name + " ::::::" )
806 main.log.error( traceback.print_exc() )
807 main.log.info( self.name + " ::::::" )
andrewonlab8d0d7d72014-10-09 16:33:15 -0400808 main.cleanup()
809 main.exit()
810
kelvin-onlabd3b64892015-01-20 13:26:24 -0800811 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800812 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400813 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -0400814 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -0800815 """
andrewonlab2b30bd32014-10-09 16:48:55 -0400816 try:
kelvin8ec71442015-01-15 16:57:00 -0800817 self.handle.sendline( "" )
818 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800819 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800820 " stop" )
821 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -0400822 "stop/waiting",
823 "Unknown\sinstance",
kelvin8ec71442015-01-15 16:57:00 -0800824 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2b30bd32014-10-09 16:48:55 -0400825
826 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800827 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400828 return main.TRUE
829 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800830 main.log.info( "Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800831 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -0400832 return main.FALSE
833 else:
kelvin8ec71442015-01-15 16:57:00 -0800834 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400835 return main.FALSE
836
837 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800838 main.log.error( self.name + ": EOF exception found" )
839 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -0400840 main.cleanup()
841 main.exit()
842 except:
kelvin8ec71442015-01-15 16:57:00 -0800843 main.log.info( self.name + " ::::::" )
844 main.log.error( traceback.print_exc() )
845 main.log.info( self.name + " ::::::" )
andrewonlab2b30bd32014-10-09 16:48:55 -0400846 main.cleanup()
847 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800848
kelvin-onlabd3b64892015-01-20 13:26:24 -0800849 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -0800850 """
andrewonlabc8d47972014-10-09 16:52:36 -0400851 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -0800852 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -0400853 if needed
kelvin8ec71442015-01-15 16:57:00 -0800854 """
andrewonlabc8d47972014-10-09 16:52:36 -0400855 try:
kelvin8ec71442015-01-15 16:57:00 -0800856 self.handle.sendline( "" )
857 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800858 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800859 self.handle.expect( "\$" )
andrewonlabc8d47972014-10-09 16:52:36 -0400860
kelvin-onlabd3b64892015-01-20 13:26:24 -0800861 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
andrewonlab9dfd2082014-11-13 17:44:03 -0500862
kelvin8ec71442015-01-15 16:57:00 -0800863 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -0400864 return main.TRUE
865
866 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800867 main.log.error( self.name + ": EOF exception found" )
868 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -0400869 main.cleanup()
870 main.exit()
871 except:
kelvin8ec71442015-01-15 16:57:00 -0800872 main.log.info( self.name + " ::::::" )
873 main.log.error( traceback.print_exc() )
874 main.log.info( self.name + " ::::::" )
andrewonlabc8d47972014-10-09 16:52:36 -0400875 main.cleanup()
876 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -0400877
kelvin-onlabd3b64892015-01-20 13:26:24 -0800878 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800879 """
andrewonlabaedc8332014-12-04 12:43:03 -0500880 Issues the command 'onos-die <node-ip>'
881 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -0800882 """
andrewonlabaedc8332014-12-04 12:43:03 -0500883 try:
kelvin8ec71442015-01-15 16:57:00 -0800884 self.handle.sendline( "" )
885 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800886 cmdStr = "onos-kill " + str( nodeIp )
887 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800888 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -0500889 "Killing\sONOS",
890 "ONOS\sprocess\sis\snot\srunning",
kelvin8ec71442015-01-15 16:57:00 -0800891 pexpect.TIMEOUT ], timeout=20 )
andrewonlabaedc8332014-12-04 12:43:03 -0500892 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800893 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -0800894 " was killed and stopped" )
andrewonlabaedc8332014-12-04 12:43:03 -0500895 return main.TRUE
896 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800897 main.log.info( "ONOS process was not running" )
andrewonlabaedc8332014-12-04 12:43:03 -0500898 return main.FALSE
899 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800900 main.log.error( self.name + ": EOF exception found" )
901 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -0500902 main.cleanup()
903 main.exit()
904 except:
kelvin8ec71442015-01-15 16:57:00 -0800905 main.log.info( self.name + " ::::::" )
906 main.log.error( traceback.print_exc() )
907 main.log.info( self.name + " ::::::" )
andrewonlabaedc8332014-12-04 12:43:03 -0500908 main.cleanup()
909 main.exit()
910
kelvin-onlabd3b64892015-01-20 13:26:24 -0800911 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -0800912 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400913 Calls the command: 'onos-kill [<node-ip>]'
914 "Remotely, and unceremoniously kills the ONOS instance running on
915 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -0800916 """
andrewonlabe8e56fd2014-10-09 17:12:44 -0400917 try:
kelvin8ec71442015-01-15 16:57:00 -0800918 self.handle.sendline( "" )
919 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800920 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800921 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -0400922 "\$",
923 "No\sroute\sto\shost",
924 "password:",
kelvin8ec71442015-01-15 16:57:00 -0800925 pexpect.TIMEOUT ], timeout=20 )
926
andrewonlabe8e56fd2014-10-09 17:12:44 -0400927 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800928 main.log.info(
929 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800930 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400931 return main.TRUE
932 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800933 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400934 return main.FALSE
935 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800936 main.log.info(
937 "Passwordless login for host: " +
938 str( nodeIp ) +
939 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400940 return main.FALSE
941 else:
kelvin8ec71442015-01-15 16:57:00 -0800942 main.log.info( "ONOS instasnce was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400943 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800944
andrewonlabe8e56fd2014-10-09 17:12:44 -0400945 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800946 main.log.error( self.name + ": EOF exception found" )
947 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400948 main.cleanup()
949 main.exit()
950 except:
kelvin8ec71442015-01-15 16:57:00 -0800951 main.log.info( self.name + " ::::::" )
952 main.log.error( traceback.print_exc() )
953 main.log.info( self.name + " ::::::" )
andrewonlabe8e56fd2014-10-09 17:12:44 -0400954 main.cleanup()
955 main.exit()
956
kelvin-onlabd3b64892015-01-20 13:26:24 -0800957 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -0800958 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500959 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -0500960 a cleaner environment.
961
andrewonlab19fbdca2014-11-14 12:55:59 -0500962 Description:
Jon Hallfcc88622014-11-25 13:09:54 -0500963 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -0500964 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -0800965 """
andrewonlab19fbdca2014-11-14 12:55:59 -0500966 try:
kelvin8ec71442015-01-15 16:57:00 -0800967 self.handle.sendline( "" )
968 self.handle.expect( "\$" )
969 self.handle.sendline( "onos-remove-raft-logs" )
970 # Sometimes this command hangs
971 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
972 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500973 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800974 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
975 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -0500976 if i == 1:
977 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800978 self.handle.sendline( "" )
979 self.handle.expect( "\$" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500980 return main.TRUE
981
982 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800983 main.log.error( self.name + ": EOF exception found" )
984 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -0500985 main.cleanup()
986 main.exit()
987 except:
kelvin8ec71442015-01-15 16:57:00 -0800988 main.log.info( self.name + " ::::::" )
989 main.log.error( traceback.print_exc() )
990 main.log.info( self.name + " ::::::" )
andrewonlab19fbdca2014-11-14 12:55:59 -0500991 main.cleanup()
992 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -0500993
kelvin-onlabd3b64892015-01-20 13:26:24 -0800994 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -0800995 """
996 Calls the command 'onos-start-network [ <mininet-topo> ]
997 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -0400998 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -0800999 cell."
andrewonlab94282092014-10-10 13:00:11 -04001000 * Specify mininet topology file name for mntopo
1001 * Topo files should be placed at:
1002 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001003
andrewonlab94282092014-10-10 13:00:11 -04001004 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001005 """
andrewonlab94282092014-10-10 13:00:11 -04001006 try:
1007 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001008 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001009 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001010
kelvin8ec71442015-01-15 16:57:00 -08001011 mntopo = str( mntopo )
1012 self.handle.sendline( "" )
1013 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -04001014
kelvin8ec71442015-01-15 16:57:00 -08001015 self.handle.sendline( "onos-start-network " + mntopo )
1016 self.handle.expect( "mininet>" )
1017 main.log.info( "Network started, entered mininet prompt" )
1018
1019 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001020
1021 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001022 main.log.error( self.name + ": EOF exception found" )
1023 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001024 main.cleanup()
1025 main.exit()
1026 except:
kelvin8ec71442015-01-15 16:57:00 -08001027 main.log.info( self.name + " ::::::" )
1028 main.log.error( traceback.print_exc() )
1029 main.log.info( self.name + " ::::::" )
andrewonlab94282092014-10-10 13:00:11 -04001030 main.cleanup()
1031 main.exit()
1032
kelvin8ec71442015-01-15 16:57:00 -08001033 def isup( self, node="" ):
1034 """
1035 Run's onos-wait-for-start which only returns once ONOS is at run
1036 level 100( ready for use )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001037
Jon Hall7993bfc2014-10-09 16:30:14 -04001038 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001039 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001040 try:
kelvin8ec71442015-01-15 16:57:00 -08001041 self.handle.sendline( "onos-wait-for-start " + node )
1042 self.handle.expect( "onos-wait-for-start" )
1043 # NOTE: this timeout is arbitrary"
1044 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ], timeout=120 )
Jon Hall7993bfc2014-10-09 16:30:14 -04001045 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001046 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001047 return main.TRUE
1048 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001049 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001050 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001051 main.log.error( "ONOS has not started yet" )
1052 self.handle.send( "\x03" ) # Control-C
1053 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001054 return main.FALSE
1055 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001056 main.log.error( self.name + ": EOF exception found" )
1057 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001058 main.cleanup()
1059 main.exit()
1060 except:
kelvin8ec71442015-01-15 16:57:00 -08001061 main.log.info( self.name + " ::::::" )
1062 main.log.error( traceback.print_exc() )
1063 main.log.info( self.name + " ::::::" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001064 main.cleanup()
1065 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001066
kelvin-onlabd3b64892015-01-20 13:26:24 -08001067 def pushTestIntentsShell(
1068 self,
1069 dpidSrc,
1070 dpidDst,
1071 numIntents,
1072 dirFile,
1073 onosIp,
1074 numMult="",
1075 appId="",
1076 report=True,
1077 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001078 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001079 Description:
kelvin8ec71442015-01-15 16:57:00 -08001080 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001081 better parallelize the results than the CLI
1082 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001083 * dpidSrc: specify source dpid
1084 * dpidDst: specify destination dpid
1085 * numIntents: specify number of intents to push
1086 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001087 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001088 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001089 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001090 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001091 """
1092 try:
1093 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001094 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001095 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001096 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001097 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001098 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001099
kelvin-onlabd3b64892015-01-20 13:26:24 -08001100 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1101 if not numMult:
1102 addIntents = addDpid + " " + str( numIntents )
1103 elif numMult:
1104 addIntents = addDpid + " " + str( numIntents ) + " " +\
1105 str( numMult )
1106 if appId:
1107 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001108 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001109 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001110
andrewonlabaedc8332014-12-04 12:43:03 -05001111 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001112 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001113 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001114 sendCmd = addApp + " &"
1115 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001116
kelvin-onlabd3b64892015-01-20 13:26:24 -08001117 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001118
1119 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001120 main.log.error( self.name + ": EOF exception found" )
1121 main.log.error( self.name + ": " + self.handle.before )
andrewonlabb66dfa12014-12-02 15:51:10 -05001122 main.cleanup()
1123 main.exit()
1124 except:
kelvin8ec71442015-01-15 16:57:00 -08001125 main.log.info( self.name + " ::::::" )
1126 main.log.error( traceback.print_exc() )
1127 main.log.info( self.name + " ::::::" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001128 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001129 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001130
kelvin-onlabd3b64892015-01-20 13:26:24 -08001131 def getTopology( self, topologyOutput ):
kelvin8ec71442015-01-15 16:57:00 -08001132 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001133 parses the onos:topology output
kelvin8ec71442015-01-15 16:57:00 -08001134 Returns: a topology dict populated by the key values found in
Jon Hall77f53ce2014-10-13 18:02:06 -04001135 the cli command.
kelvin8ec71442015-01-15 16:57:00 -08001136 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001137 try:
kelvin8ec71442015-01-15 16:57:00 -08001138 # call the cli to get the topology summary
1139 # cmdstr = "onos:topology"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001140 # cliResult = self.onosCli( ip, cmdstr )
1141 # print "cli_result = ", cliResult
Jon Hall77f53ce2014-10-13 18:02:06 -04001142
kelvin8ec71442015-01-15 16:57:00 -08001143 # Parse the output
Jon Hall77f53ce2014-10-13 18:02:06 -04001144 topology = {}
kelvin-onlabd3b64892015-01-20 13:26:24 -08001145 # for line in cliResult.split( "\n" ):
1146 for line in topologyOutput.splitlines():
kelvin8ec71442015-01-15 16:57:00 -08001147 if not line.startswith( "time=" ):
Jon Hall77f53ce2014-10-13 18:02:06 -04001148 continue
kelvin8ec71442015-01-15 16:57:00 -08001149 # else
1150 # print line
1151 for var in line.split( "," ):
1152 # print "'"+var+"'"
1153 # print "'"+var.strip()+"'"
1154 key, value = var.strip().split( "=" )
1155 topology[ key ] = value
1156 # print "topology = ", topology
1157 # devices = topology.get( 'devices', False )
1158 # print "devices = ", devices
1159 # links = topology.get( 'links', False )
1160 # print "links = ", links
1161 # SCCs = topology.get( 'SCC(s)', False )
1162 # print "SCCs = ", SCCs
1163 # paths = topology.get( 'paths', False )
1164 # print "paths = ", paths
Jon Hall77f53ce2014-10-13 18:02:06 -04001165
1166 return topology
1167 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001168 main.log.error( self.name + ": EOF exception found" )
1169 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001170 main.cleanup()
1171 main.exit()
1172 except:
kelvin8ec71442015-01-15 16:57:00 -08001173 main.log.info( self.name + " ::::::" )
1174 main.log.error( traceback.print_exc() )
1175 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001176 main.cleanup()
1177 main.exit()
1178
kelvin-onlabd3b64892015-01-20 13:26:24 -08001179 def checkStatus(
1180 self,
1181 topologyResult,
1182 numoswitch,
1183 numolink,
1184 logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001185 """
1186 Checks the number of swithes & links that ONOS sees against the
1187 supplied values. By default this will report to main.log, but the
Jon Hall77f53ce2014-10-13 18:02:06 -04001188 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001189
Jon Hall77f53ce2014-10-13 18:02:06 -04001190 Params: ip = ip used for the onos cli
1191 numoswitch = expected number of switches
1192 numlink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001193 logLevel = level to log to.
1194 Currently accepts 'info', 'warn' and 'report'
Jon Hall77f53ce2014-10-13 18:02:06 -04001195
1196
kelvin-onlabd3b64892015-01-20 13:26:24 -08001197 logLevel can
Jon Hall77f53ce2014-10-13 18:02:06 -04001198
kelvin8ec71442015-01-15 16:57:00 -08001199 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall77f53ce2014-10-13 18:02:06 -04001200 main.FALSE if the numer of switches and links is incorrect,
1201 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001202 """
Jon Hall77f53ce2014-10-13 18:02:06 -04001203 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001204 topology = self.getTopology( topologyResult )
Jon Hall77f53ce2014-10-13 18:02:06 -04001205 if topology == {}:
1206 return main.ERROR
1207 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001208 # Is the number of switches is what we expected
1209 devices = topology.get( 'devices', False )
1210 links = topology.get( 'links', False )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001211 if not devices or not links:
Jon Hall77f53ce2014-10-13 18:02:06 -04001212 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001213 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001214 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001215 linkCheck = ( int( links ) == int( numolink ) )
1216 if ( switchCheck and linkCheck ):
kelvin8ec71442015-01-15 16:57:00 -08001217 # We expected the correct numbers
Jon Hall77f53ce2014-10-13 18:02:06 -04001218 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001219 + "what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001220 result = main.TRUE
1221 else:
1222 output = output + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001223 "The number of links and switches does not match\
1224 what was expected"
Jon Hall77f53ce2014-10-13 18:02:06 -04001225 result = main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001226 output = output + "\n ONOS sees %i devices (%i expected)\
1227 and %i links (%i expected)" %\
1228 ( int( devices ), int( numoswitch ),
1229 int( links ), int( numolink ) )
1230 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001231 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001232 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001233 main.log.warn( output )
Jon Hall77f53ce2014-10-13 18:02:06 -04001234 else:
kelvin8ec71442015-01-15 16:57:00 -08001235 main.log.info( output )
1236 return result
Jon Hall77f53ce2014-10-13 18:02:06 -04001237 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001238 main.log.error( self.name + ": EOF exception found" )
1239 main.log.error( self.name + ": " + self.handle.before )
Jon Hall77f53ce2014-10-13 18:02:06 -04001240 main.cleanup()
1241 main.exit()
1242 except:
kelvin8ec71442015-01-15 16:57:00 -08001243 main.log.info( self.name + " ::::::" )
1244 main.log.error( traceback.print_exc() )
1245 main.log.info( self.name + " ::::::" )
Jon Hall77f53ce2014-10-13 18:02:06 -04001246 main.cleanup()
1247 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001248
kelvin-onlabd3b64892015-01-20 13:26:24 -08001249 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001250 """
andrewonlab970399c2014-11-07 13:09:32 -05001251 Capture all packet activity and store in specified
1252 directory/file
1253
1254 Required:
1255 * interface: interface to capture
1256 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001257 """
1258 self.handle.sendline( "" )
1259 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001260
kelvin8ec71442015-01-15 16:57:00 -08001261 self.handle.sendline( "tshark -i " + str( interface ) +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001262 " -t e -w " + str( dirFile ) + " &" )
kelvin8ec71442015-01-15 16:57:00 -08001263 self.handle.sendline( "\r" )
1264 self.handle.expect( "Capturing on" )
1265 self.handle.sendline( "\r" )
1266 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001267
kelvin8ec71442015-01-15 16:57:00 -08001268 main.log.info( "Tshark started capturing files on " +
1269 str( interface ) + " and saving to directory: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001270 str( dirFile ) )
Shreya Shaha73aaad2014-10-27 18:03:09 -04001271
kelvin-onlabd3b64892015-01-20 13:26:24 -08001272 def runOnosTopoCfg( self, instanceName, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001273 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001274 On ONOS bench, run this command:
1275 ./~/ONOS/tools/test/bin/onos-topo-cfg $OC1 filename
1276 which starts the rest and copies
1277 the json file to the onos instance
kelvin8ec71442015-01-15 16:57:00 -08001278 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001279 try:
kelvin8ec71442015-01-15 16:57:00 -08001280 self.handle.sendline( "" )
1281 self.handle.expect( "\$" )
1282 self.handle.sendline( "cd ~/ONOS/tools/test/bin" )
1283 self.handle.expect( "/bin$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001284 cmd = "./onos-topo-cfg " + instanceName + " " + jsonFile
shahshreyae6c7cf42014-11-26 16:39:01 -08001285 print "cmd = ", cmd
kelvin8ec71442015-01-15 16:57:00 -08001286 self.handle.sendline( cmd )
1287 self.handle.expect( "\$" )
1288 self.handle.sendline( "cd ~" )
1289 self.handle.expect( "\$" )
shahshreyae6c7cf42014-11-26 16:39:01 -08001290 return main.TRUE
1291 except:
1292 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001293
kelvin-onlabd3b64892015-01-20 13:26:24 -08001294 def tsharkGrep( self, grep, directory, interface='eth0' ):
kelvin8ec71442015-01-15 16:57:00 -08001295 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001296 Required:
kelvin8ec71442015-01-15 16:57:00 -08001297 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001298 * directory to store results
1299 Optional:
1300 * interface - default: eth0
1301 Description:
1302 Uses tshark command to grep specific group of packets
1303 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001304 The timestamp is hardcoded to be in epoch
1305 """
1306 self.handle.sendline( "" )
1307 self.handle.expect( "\$" )
1308 self.handle.sendline( "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001309 self.handle.sendline(
1310 "tshark -i " +
1311 str( interface ) +
1312 " -t e | grep --line-buffered \"" +
1313 str(grep) +
1314 "\" >" +
1315 directory +
1316 " &" )
kelvin8ec71442015-01-15 16:57:00 -08001317 self.handle.sendline( "\r" )
1318 self.handle.expect( "Capturing on" )
1319 self.handle.sendline( "\r" )
1320 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001321
kelvin-onlabd3b64892015-01-20 13:26:24 -08001322 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001323 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001324 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001325 """
1326 # Remove all pcap from previous captures
1327 self.execute( cmd="sudo rm /tmp/wireshark*" )
1328 self.handle.sendline( "" )
1329 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\" |" +
1330 " grep -v grep | awk '{print $2}'`" )
1331 self.handle.sendline( "" )
1332 main.log.info( "Tshark stopped" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001333
kelvin8ec71442015-01-15 16:57:00 -08001334 def ptpd( self, args ):
1335 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001336 Initiate ptp with user-specified args.
1337 Required:
1338 * args: specify string of args after command
1339 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001340 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001341 try:
kelvin8ec71442015-01-15 16:57:00 -08001342 self.handle.sendline( "sudo ptpd " + str( args ) )
1343 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001344 "Multiple",
1345 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001346 "\$" ] )
1347 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001348
andrewonlab0c38a4a2014-10-28 18:35:35 -04001349 if i == 0:
1350 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001351 main.log.info( "ptpd returned an error: " +
1352 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001353 return handle
1354 elif i == 1:
1355 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001356 main.log.error( "ptpd returned an error: " +
1357 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001358 return handle
1359 else:
1360 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001361
andrewonlab0c38a4a2014-10-28 18:35:35 -04001362 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001363 main.log.error( self.name + ": EOF exception found" )
1364 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001365 main.cleanup()
1366 main.exit()
1367 except:
kelvin8ec71442015-01-15 16:57:00 -08001368 main.log.info( self.name + " ::::::" )
1369 main.log.error( traceback.print_exc() )
1370 main.log.info( self.name + " ::::::" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001371 main.cleanup()
1372 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001373
kelvin-onlabd3b64892015-01-20 13:26:24 -08001374 def cpLogsToDir( self, logToCopy,
1375 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001376 """
1377 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001378 Current implementation of ONOS deletes its karaf
1379 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001380 you may want to use this function to capture
1381 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001382 Localtime will be attached to the filename
1383
1384 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001385 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001386 copy.
kelvin8ec71442015-01-15 16:57:00 -08001387 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001388 For copying multiple files, leave copyFileName
1389 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001390 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001391 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001392 ex ) /tmp/
1393 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001394 * copyFileName: If you want to rename the log
1395 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001396 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001397 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001398 try:
kelvin8ec71442015-01-15 16:57:00 -08001399 localtime = time.strftime( '%x %X' )
1400 localtime = localtime.replace( "/", "" )
1401 localtime = localtime.replace( " ", "_" )
1402 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001403 if destDir[ -1: ] != "/":
1404 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001405
kelvin-onlabd3b64892015-01-20 13:26:24 -08001406 if copyFileName:
1407 self.handle.sendline(
1408 "cp " +
1409 str( logToCopy ) +
1410 " " +
1411 str( destDir ) +
1412 str( copyFileName ) +
1413 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001414 self.handle.expect( "cp" )
1415 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001416 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001417 self.handle.sendline( "cp " + str( logToCopy ) +
1418 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001419 self.handle.expect( "cp" )
1420 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001421
kelvin8ec71442015-01-15 16:57:00 -08001422 return self.handle.before
1423
1424 except pexpect.EOF:
1425 main.log.error( "Copying files failed" )
1426 main.log.error( self.name + ": EOF exception found" )
1427 main.log.error( self.name + ": " + self.handle.before )
1428 except:
1429 main.log.error( "Copying files failed" )
1430 main.log.info( self.name + " ::::::" )
1431 main.log.error( traceback.print_exc() )
1432 main.log.info( self.name + " ::::::" )
1433
kelvin-onlabd3b64892015-01-20 13:26:24 -08001434 def checkLogs( self, onosIp ):
kelvin8ec71442015-01-15 16:57:00 -08001435 """
Jon Hall94fd0472014-12-08 11:52:42 -08001436 runs onos-check-logs on the given onos node
1437 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001438 """
Jon Hall94fd0472014-12-08 11:52:42 -08001439 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001440 cmd = "onos-check-logs " + str( onosIp )
kelvin8ec71442015-01-15 16:57:00 -08001441 self.handle.sendline( cmd )
1442 self.handle.expect( cmd )
1443 self.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -08001444 response = self.handle.before
1445 return response
1446 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001447 main.log.error( "Lost ssh connection" )
1448 main.log.error( self.name + ": EOF exception found" )
1449 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001450 except:
kelvin8ec71442015-01-15 16:57:00 -08001451 main.log.error( "Some error in check_logs:" )
1452 main.log.info( self.name + " ::::::" )
1453 main.log.error( traceback.print_exc() )
1454 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001455
kelvin-onlabd3b64892015-01-20 13:26:24 -08001456 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001457 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001458 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001459 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001460 try:
kelvin8ec71442015-01-15 16:57:00 -08001461 self.handle.sendline( "" )
1462 self.handle.expect( "\$" )
1463 self.handle.sendline( "onos-service " + str( node ) +
1464 " status" )
1465 i = self.handle.expect( [
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001466 "start/running",
1467 "stop/waiting",
kelvin8ec71442015-01-15 16:57:00 -08001468 pexpect.TIMEOUT ], timeout=120 )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001469
1470 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001471 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001472 return main.TRUE
1473 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001474 main.log.info( "ONOS is stopped" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001475 return main.FALSE
1476 else:
kelvin8ec71442015-01-15 16:57:00 -08001477 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001478 main.cleanup()
1479 main.exit()
1480 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001481 main.log.error( self.name + ": EOF exception found" )
1482 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001483 main.cleanup()
1484 main.exit()
1485 except:
kelvin8ec71442015-01-15 16:57:00 -08001486 main.log.info( self.name + " ::::::" )
1487 main.log.error( traceback.print_exc() )
1488 main.log.info( self.name + " ::::::" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001489 main.cleanup()
1490 main.exit()