blob: 5b12d0c26e01cd3287da37034b733cfc207556ed [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
Jeremy Songsterae01bba2016-07-11 15:39:17 -070017Modified 2016 by ON.Lab
18
19Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
20the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
21or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
andrewonlabe8e56fd2014-10-09 17:12:44 -040022
kelvin8ec71442015-01-15 16:57:00 -080023"""
Jon Hall05b2b432014-10-08 19:53:25 -040024import time
Jon Hall6801cda2015-07-15 14:13:45 -070025import types
Jon Hall05b2b432014-10-08 19:53:25 -040026import pexpect
kelvin-onlaba4074292015-07-09 15:19:49 -070027import os
Jon Hall6c44c0b2016-04-20 15:21:00 -070028import re
29import subprocess
pingping-lin6d23d9e2015-02-02 16:54:24 -080030from requests.models import Response
Jon Hall05b2b432014-10-08 19:53:25 -040031from drivers.common.clidriver import CLI
32
kelvin8ec71442015-01-15 16:57:00 -080033class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040034
kelvin8ec71442015-01-15 16:57:00 -080035 def __init__( self ):
36 """
37 Initialize client
38 """
Jon Hallefbd9792015-03-05 16:11:36 -080039 self.name = None
40 self.home = None
41 self.handle = None
Jon Hall6c44c0b2016-04-20 15:21:00 -070042 self.nicAddr = None
Devin Limdc78e202017-06-09 18:30:07 -070043 super( OnosDriver, self ).__init__()
kelvin8ec71442015-01-15 16:57:00 -080044
45 def connect( self, **connectargs ):
46 """
Jon Hall05b2b432014-10-08 19:53:25 -040047 Creates ssh handle for ONOS "bench".
kelvin-onlaba4074292015-07-09 15:19:49 -070048 NOTE:
49 The ip_address would come from the topo file using the host tag, the
50 value can be an environment variable as well as a "localhost" to get
51 the ip address needed to ssh to the "bench"
kelvin8ec71442015-01-15 16:57:00 -080052 """
Jon Hall05b2b432014-10-08 19:53:25 -040053 try:
Devin Limdc78e202017-06-09 18:30:07 -070054
Jon Hall05b2b432014-10-08 19:53:25 -040055 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080056 vars( self )[ key ] = connectargs[ key ]
andrew@onlab.us3b087132015-03-11 15:00:08 -070057 self.home = "~/onos"
Jon Hall05b2b432014-10-08 19:53:25 -040058 for key in self.options:
59 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080060 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040061 break
Jon Hall274b6642015-02-17 11:57:17 -080062 if self.home is None or self.home == "":
Jon Halle94919c2015-03-23 11:42:57 -070063 self.home = "~/onos"
Jon Hall21270ac2015-02-16 17:59:55 -080064
kelvin8ec71442015-01-15 16:57:00 -080065 self.name = self.options[ 'name' ]
kelvin-onlaba4074292015-07-09 15:19:49 -070066
kelvin-onlabc2b79102015-07-14 11:41:20 -070067 # The 'nodes' tag is optional and it is not required in .topo file
kelvin-onlaba4074292015-07-09 15:19:49 -070068 for key in self.options:
69 if key == "nodes":
kelvin-onlabc2b79102015-07-14 11:41:20 -070070 # Maximum number of ONOS nodes to run, if there is any
kelvin-onlaba4074292015-07-09 15:19:49 -070071 self.maxNodes = int( self.options[ 'nodes' ] )
72 break
73 self.maxNodes = None
74
Jeremy Ronquillo82705492017-10-18 14:19:55 -070075 if self.maxNodes is None or self.maxNodes == "":
kelvin-onlabc2b79102015-07-14 11:41:20 -070076 self.maxNodes = 100
kelvin-onlaba4074292015-07-09 15:19:49 -070077
kelvin-onlabc2b79102015-07-14 11:41:20 -070078 # Grabs all OC environment variables based on max number of nodes
kelvin-onlaba4074292015-07-09 15:19:49 -070079 self.onosIps = {} # Dictionary of all possible ONOS ip
80
81 try:
82 if self.maxNodes:
kelvin-onlaba4074292015-07-09 15:19:49 -070083 for i in range( self.maxNodes ):
84 envString = "OC" + str( i + 1 )
kelvin-onlabc2b79102015-07-14 11:41:20 -070085 # If there is no more OC# then break the loop
86 if os.getenv( envString ):
87 self.onosIps[ envString ] = os.getenv( envString )
88 else:
89 self.maxNodes = len( self.onosIps )
90 main.log.info( self.name +
91 ": Created cluster data with " +
92 str( self.maxNodes ) +
93 " maximum number" +
94 " of nodes" )
95 break
kelvin-onlaba4074292015-07-09 15:19:49 -070096
97 if not self.onosIps:
98 main.log.info( "Could not read any environment variable"
99 + " please load a cell file with all" +
100 " onos IP" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700101 self.maxNodes = None
kelvin-onlaba4074292015-07-09 15:19:49 -0700102 else:
103 main.log.info( self.name + ": Found " +
104 str( self.onosIps.values() ) +
105 " ONOS IPs" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700106 except KeyError:
107 main.log.info( "Invalid environment variable" )
108 except Exception as inst:
109 main.log.error( "Uncaught exception: " + str( inst ) )
110
111 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700112 if os.getenv( str( self.ip_address ) ) is not None:
kelvin-onlaba4074292015-07-09 15:19:49 -0700113 self.ip_address = os.getenv( str( self.ip_address ) )
114 else:
115 main.log.info( self.name +
116 ": Trying to connect to " +
117 self.ip_address )
kelvin-onlaba4074292015-07-09 15:19:49 -0700118 except KeyError:
119 main.log.info( "Invalid host name," +
120 " connecting to local host instead" )
121 self.ip_address = 'localhost'
122 except Exception as inst:
123 main.log.error( "Uncaught exception: " + str( inst ) )
124
kelvin8ec71442015-01-15 16:57:00 -0800125 self.handle = super( OnosDriver, self ).connect(
126 user_name=self.user_name,
kelvin-onlab08679eb2015-01-21 16:11:48 -0800127 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800128 port=self.port,
129 pwd=self.pwd,
130 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -0400131
Jon Hall05b2b432014-10-08 19:53:25 -0400132 if self.handle:
Jon Hall0fc0d452015-07-14 09:49:58 -0700133 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700134 self.handle.expect( self.prompt )
Jon Hall05b2b432014-10-08 19:53:25 -0400135 return self.handle
kelvin8ec71442015-01-15 16:57:00 -0800136 else:
Jon Hall0fc0d452015-07-14 09:49:58 -0700137 main.log.info( "Failed to create ONOS handle" )
Jon Hall05b2b432014-10-08 19:53:25 -0400138 return main.FALSE
139 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800140 main.log.error( self.name + ": EOF exception found" )
141 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700142 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800143 except Exception:
144 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700145 main.cleanAndExit()
Jon Hall05b2b432014-10-08 19:53:25 -0400146
kelvin8ec71442015-01-15 16:57:00 -0800147 def disconnect( self ):
148 """
Jon Hall05b2b432014-10-08 19:53:25 -0400149 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -0800150 """
Jon Halld61331b2015-02-17 16:35:47 -0800151 response = main.TRUE
Jon Hall05b2b432014-10-08 19:53:25 -0400152 try:
Jon Hall61282e32015-03-19 11:34:11 -0700153 if self.handle:
154 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700155 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700156 self.handle.sendline( "exit" )
157 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -0400158 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800159 main.log.error( self.name + ": EOF exception found" )
160 main.log.error( self.name + ": " + self.handle.before )
Jon Hall61282e32015-03-19 11:34:11 -0700161 except ValueError:
Jon Hall1a77a1e2015-04-06 10:41:13 -0700162 main.log.exception( "Exception in disconnect of " + self.name )
Jon Hall61282e32015-03-19 11:34:11 -0700163 response = main.TRUE
Jon Hallfebb1c72015-03-05 13:30:09 -0800164 except Exception:
165 main.log.exception( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -0400166 response = main.FALSE
167 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400168
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400169 def getEpochMs( self ):
170 """
171 Returns milliseconds since epoch
Jon Hall4ba53f02015-07-29 13:07:41 -0700172
173 When checking multiple nodes in a for loop,
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000174 around a hundred milliseconds of difference (ascending) is
Jon Hall4ba53f02015-07-29 13:07:41 -0700175 generally acceptable due to calltime of the function.
176 Few seconds, however, is not and it means clocks
177 are off sync.
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400178 """
179 try:
180 self.handle.sendline( 'date +%s.%N' )
181 self.handle.expect( 'date \+\%s\.\%N' )
Devin Limdc78e202017-06-09 18:30:07 -0700182 self.handle.expect( self.prompt )
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400183 epochMs = self.handle.before
184 return epochMs
185 except Exception:
186 main.log.exception( 'Uncaught exception getting epoch time' )
Devin Lim44075962017-08-11 10:56:37 -0700187 main.cleanAndExit()
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400188
Jon Hall6c44c0b2016-04-20 15:21:00 -0700189 def onosPackage( self, opTimeout=180 ):
kelvin8ec71442015-01-15 16:57:00 -0800190 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400191 Produce a self-contained tar.gz file that can be deployed
Jon Hall64af8502015-12-15 10:09:33 -0800192 and executed on any platform with Java 8 JRE.
kelvin8ec71442015-01-15 16:57:00 -0800193 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400194 try:
Jon Hall64af8502015-12-15 10:09:33 -0800195 ret = main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800196 self.handle.sendline( "onos-package" )
197 self.handle.expect( "onos-package" )
Jon Hall96451092016-05-04 09:42:30 -0700198 while True:
199 i = self.handle.expect( [ "Downloading",
200 "Unknown options",
201 "No such file or directory",
202 "tar.gz",
Devin Limc20e79a2017-06-07 10:29:57 -0700203 self.prompt ],
Jon Hall96451092016-05-04 09:42:30 -0700204 opTimeout )
205 handle = str( self.handle.before + self.handle.after )
206 if i == 0:
207 # Give more time to download the file
208 continue # expect again
209 elif i == 1:
210 # Incorrect usage
211 main.log.error( "onos-package does not recognize the given options" )
212 ret = main.FALSE
213 continue # expect again
214 elif i == 2:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000215 # File(s) not found
Jon Hall96451092016-05-04 09:42:30 -0700216 main.log.error( "onos-package could not find a file or directory" )
217 ret = main.FALSE
218 continue # expect again
219 elif i == 3:
220 # tar.gz
221 continue # expect again
222 elif i == 4:
223 # Prompt returned
224 break
Jon Hallc6793552016-01-19 14:18:37 -0800225 main.log.info( "onos-package command returned: " + handle )
kelvin8ec71442015-01-15 16:57:00 -0800226 # As long as the sendline does not time out,
227 # return true. However, be careful to interpret
228 # the results of the onos-package command return
Jon Hall64af8502015-12-15 10:09:33 -0800229 return ret
230 except pexpect.TIMEOUT:
231 main.log.exception( self.name + ": TIMEOUT exception found in onosPackage" )
232 main.log.error( self.name + ": " + self.handle.before )
233 return main.FALSE
andrewonlab7735d852014-10-09 13:02:47 -0400234 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800235 main.log.error( self.name + ": EOF exception found" )
236 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700237 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800238 except Exception:
239 main.log.exception( "Failed to package ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700240 main.cleanAndExit()
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400241
kelvin-onlabd3b64892015-01-20 13:26:24 -0800242 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800243 """
andrewonlab8790abb2014-11-06 13:51:54 -0500244 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800245 """
andrewonlab8790abb2014-11-06 13:51:54 -0500246 try:
kelvin8ec71442015-01-15 16:57:00 -0800247 self.handle.sendline( "onos-build" )
248 self.handle.expect( "onos-build" )
249 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800250 "BUILD SUCCESS",
251 "ERROR",
252 "BUILD FAILED" ],
253 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800254 handle = str( self.handle.before )
Devin Limc20e79a2017-06-07 10:29:57 -0700255 self.handle.expect( self.prompt )
andrewonlab8790abb2014-11-06 13:51:54 -0500256
kelvin8ec71442015-01-15 16:57:00 -0800257 main.log.info( "onos-build command returned: " +
258 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500259
260 if i == 0:
261 return main.TRUE
262 else:
263 return handle
264
265 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800266 main.log.error( self.name + ": EOF exception found" )
267 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800268 except Exception:
269 main.log.exception( "Failed to build ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700270 main.cleanAndExit()
andrewonlab8790abb2014-11-06 13:51:54 -0500271
shahshreya9f531fe2015-06-10 12:03:51 -0700272 def cleanInstall( self, skipTest=False, mciTimeout=600 ):
kelvin8ec71442015-01-15 16:57:00 -0800273 """
274 Runs mvn clean install in the root of the ONOS directory.
275 This will clean all ONOS artifacts then compile each module
shahshreya9f531fe2015-06-10 12:03:51 -0700276 Optional:
277 skipTest - Does "-DskipTests -Dcheckstyle.skip -U -T 1C" which
278 skip the test. This will make the building faster.
279 Disregarding the credibility of the build
kelvin8ec71442015-01-15 16:57:00 -0800280 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400281 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800282 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400283 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800284 main.log.info( "Running 'mvn clean install' on " +
285 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800286 ". This may take some time." )
287 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700288 self.handle.expect( self.prompt )
Jon Hallea7818b2014-10-09 14:30:59 -0400289
kelvin8ec71442015-01-15 16:57:00 -0800290 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700291 self.handle.expect( self.prompt )
shahshreya9f531fe2015-06-10 12:03:51 -0700292
293 if not skipTest:
294 self.handle.sendline( "mvn clean install" )
295 self.handle.expect( "mvn clean install" )
296 else:
297 self.handle.sendline( "mvn clean install -DskipTests" +
298 " -Dcheckstyle.skip -U -T 1C" )
299 self.handle.expect( "mvn clean install -DskipTests" +
300 " -Dcheckstyle.skip -U -T 1C" )
kelvin8ec71442015-01-15 16:57:00 -0800301 while True:
302 i = self.handle.expect( [
Jon Hall274b6642015-02-17 11:57:17 -0800303 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' +
Jon Hallefbd9792015-03-05 16:11:36 -0800304 'Runtime\sEnvironment\sto\scontinue',
Jon Hallde9d9aa2014-10-08 20:36:02 -0400305 'BUILD\sFAILURE',
306 'BUILD\sSUCCESS',
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700307 'onos' + self.prompt, # TODO: fix this to be more generic?
Devin Limdc78e202017-06-09 18:30:07 -0700308 'ONOS' + self.prompt,
pingping-lin57a56ce2015-05-20 16:43:48 -0700309 pexpect.TIMEOUT ], mciTimeout )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400310 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800311 main.log.error( self.name + ":There is insufficient memory \
312 for the Java Runtime Environment to continue." )
313 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700314
315 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400316 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800317 main.log.error( self.name + ": Build failure!" )
318 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700319
320 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400321 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800322 main.log.info( self.name + ": Build success!" )
Jon Halle94919c2015-03-23 11:42:57 -0700323 elif i == 3 or i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800324 main.log.info( self.name + ": Build complete" )
325 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400326 for line in self.handle.before.splitlines():
327 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800328 main.log.info( line )
329 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700330 self.handle.expect( self.prompt, timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400331 return main.TRUE
Jon Halle94919c2015-03-23 11:42:57 -0700332 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800333 main.log.error(
334 self.name +
335 ": mvn clean install TIMEOUT!" )
336 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700337
338 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400339 else:
Jon Hall274b6642015-02-17 11:57:17 -0800340 main.log.error( self.name + ": unexpected response from " +
Jon Hallefbd9792015-03-05 16:11:36 -0800341 "mvn clean install" )
kelvin8ec71442015-01-15 16:57:00 -0800342 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700343
344 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400345 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800346 main.log.error( self.name + ": EOF exception found" )
347 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700348 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800349 except Exception:
350 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700351 main.cleanAndExit()
Jon Hallacabffd2014-10-09 12:36:53 -0400352
Jon Hall3576f572016-08-23 10:01:07 -0700353 def buckBuild( self, timeout=180 ):
354 """
355 Build onos using buck.
356 """
357 try:
358 ret = main.TRUE
359 self.handle.sendline( "buck build onos" )
360 self.handle.expect( "buck build onos" )
361 output = ""
362 while True:
363 i = self.handle.expect( [ "This does not appear to be the root of a Buck project.",
364 "\n",
365 "BUILD FAILED",
Devin Limc20e79a2017-06-07 10:29:57 -0700366 self.prompt ],
Jon Hall3576f572016-08-23 10:01:07 -0700367 timeout=timeout )
368 output += str( self.handle.before + self.handle.after )
369 if i == 0:
370 main.log.error( "Wrong location" )
371 ret = main.FALSE
372 elif i == 1:
373 # end of a line, buck is still printing output
374 pass
375 elif i == 2:
376 # Build failed
377 main.log.error( "Build failed" )
378 ret = main.FALSE
379 elif i == 3:
380 # Prompt returned
381 break
382 main.log.debug( output )
383 return ret
384 except pexpect.TIMEOUT:
385 main.log.exception( self.name + ": TIMEOUT exception found" )
386 main.log.error( self.name + ": " + self.handle.before )
387 return main.FALSE
388 except pexpect.EOF:
389 main.log.error( self.name + ": EOF exception found" )
390 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700391 main.cleanAndExit()
Jon Hall3576f572016-08-23 10:01:07 -0700392 except Exception:
393 main.log.exception( "Failed to build and package ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700394 main.cleanAndExit()
Jon Hall3576f572016-08-23 10:01:07 -0700395
Jon Hall61282e32015-03-19 11:34:11 -0700396 def gitPull( self, comp1="", fastForward=True ):
kelvin8ec71442015-01-15 16:57:00 -0800397 """
Jon Hallacabffd2014-10-09 12:36:53 -0400398 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800399
Jon Hall61282e32015-03-19 11:34:11 -0700400 If the fastForward boolean is set to true, only git pulls that can
401 be fast forwarded will be performed. IE if you have not local commits
402 in your branch.
403
Jon Hallacabffd2014-10-09 12:36:53 -0400404 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800405 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400406 for the purpose of pulling from other nodes if necessary.
407
Jon Hall47a93fb2015-01-06 16:46:06 -0800408 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400409 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800410 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400411 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400412
kelvin8ec71442015-01-15 16:57:00 -0800413 """
Jon Hallacabffd2014-10-09 12:36:53 -0400414 try:
kelvin8ec71442015-01-15 16:57:00 -0800415 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700416 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700417 cmd = "git pull"
418 if comp1 != "":
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700419 cmd += ' ' + comp1
Jon Hall61282e32015-03-19 11:34:11 -0700420 if fastForward:
421 cmd += ' ' + " --ff-only"
422 self.handle.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800423 i = self.handle.expect(
424 [
425 'fatal',
426 'Username\sfor\s(.*):\s',
427 '\sfile(s*) changed,\s',
428 'Already up-to-date',
429 'Aborting',
430 'You\sare\snot\scurrently\son\sa\sbranch',
Jon Hall274b6642015-02-17 11:57:17 -0800431 'You asked me to pull without telling me which branch you',
432 'Pull is not possible because you have unmerged files',
Jon Hall61282e32015-03-19 11:34:11 -0700433 'Please enter a commit message to explain why this merge',
434 'Found a swap file by the name',
435 'Please, commit your changes before you can merge.',
kelvin-onlabd3b64892015-01-20 13:26:24 -0800436 pexpect.TIMEOUT ],
437 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800438 if i == 0:
Jon Hall61282e32015-03-19 11:34:11 -0700439 main.log.error( self.name + ": Git pull had some issue" )
440 output = self.handle.after
Devin Limdc78e202017-06-09 18:30:07 -0700441 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700442 output += self.handle.before
443 main.log.warn( output )
Jon Hallacabffd2014-10-09 12:36:53 -0400444 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800445 elif i == 1:
446 main.log.error(
447 self.name +
448 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400449 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800450 elif i == 2:
451 main.log.info(
452 self.name +
453 ": Git Pull - pulling repository now" )
Devin Limc20e79a2017-06-07 10:29:57 -0700454 self.handle.expect( self.prompt, 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800455 # So that only when git pull is done, we do mvn clean compile
456 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800457 elif i == 3:
458 main.log.info( self.name + ": Git Pull - Already up to date" )
Devin Limc20e79a2017-06-07 10:29:57 -0700459 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800460 elif i == 4:
461 main.log.info(
462 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800463 ": Git Pull - Aborting..." +
464 "Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400465 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800466 elif i == 5:
467 main.log.info(
468 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800469 ": Git Pull - You are not currently " +
470 "on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400471 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800472 elif i == 6:
473 main.log.info(
474 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800475 ": Git Pull - You have not configured an upstream " +
476 "branch to pull from. Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400477 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800478 elif i == 7:
479 main.log.info(
480 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800481 ": Git Pull - Pull is not possible because " +
482 "you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400483 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800484 elif i == 8:
Jon Hall61282e32015-03-19 11:34:11 -0700485 # NOTE: abandoning test since we can't reliably handle this
486 # there could be different default text editors and we
487 # also don't know if we actually want to make the commit
488 main.log.error( "Git pull resulted in a merge commit message" +
489 ". Exiting test!" )
Devin Lim44075962017-08-11 10:56:37 -0700490
491 main.cleanAndExit()
Jon Hall61282e32015-03-19 11:34:11 -0700492 elif i == 9: # Merge commit message but swap file exists
493 main.log.error( "Git pull resulted in a merge commit message" +
494 " but a swap file exists." )
495 try:
496 self.handle.send( 'A' ) # Abort
Devin Limc20e79a2017-06-07 10:29:57 -0700497 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700498 return main.ERROR
499 except Exception:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700500 main.log.exception( "Couldn't exit editor prompt!" )
Devin Lim44075962017-08-11 10:56:37 -0700501
502 main.cleanAndExit()
Jon Hall61282e32015-03-19 11:34:11 -0700503 elif i == 10: # In the middle of a merge commit
504 main.log.error( "Git branch is in the middle of a merge. " )
505 main.log.warn( self.handle.before + self.handle.after )
506 return main.ERROR
507 elif i == 11:
kelvin8ec71442015-01-15 16:57:00 -0800508 main.log.error( self.name + ": Git Pull - TIMEOUT" )
509 main.log.error(
510 self.name + " Response was: " + str(
511 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400512 return main.ERROR
513 else:
kelvin8ec71442015-01-15 16:57:00 -0800514 main.log.error(
515 self.name +
516 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400517 return main.ERROR
518 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800519 main.log.error( self.name + ": EOF exception found" )
520 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700521 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800522 except Exception:
523 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700524 main.cleanAndExit()
Jon Hallacabffd2014-10-09 12:36:53 -0400525
kelvin-onlabd3b64892015-01-20 13:26:24 -0800526 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800527 """
Jon Hallacabffd2014-10-09 12:36:53 -0400528 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800529
Jon Hallacabffd2014-10-09 12:36:53 -0400530 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800531 If used as gitCheckout( "branch" ) it will do git checkout
532 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400533
534 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800535 branch of the ONOS repository. If it has any problems, it will return
536 main.ERROR.
537 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400538 successful then the function will return main.TRUE.
539
kelvin8ec71442015-01-15 16:57:00 -0800540 """
Jon Hallacabffd2014-10-09 12:36:53 -0400541 try:
kelvin8ec71442015-01-15 16:57:00 -0800542 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700543 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800544 main.log.info( self.name +
545 ": Checking out git branch/ref: " + branch + "..." )
kelvin8ec71442015-01-15 16:57:00 -0800546 cmd = "git checkout " + branch
547 self.handle.sendline( cmd )
548 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800549 i = self.handle.expect(
Jon Hall274b6642015-02-17 11:57:17 -0800550 [ 'fatal',
Jon Hall61282e32015-03-19 11:34:11 -0700551 'Username for (.*): ',
552 'Already on \'',
Jon Hall7a8354f2015-06-10 15:37:00 -0700553 'Switched to (a new )?branch \'' + str( branch ),
Jon Hall274b6642015-02-17 11:57:17 -0800554 pexpect.TIMEOUT,
555 'error: Your local changes to the following files' +
Jon Hallefbd9792015-03-05 16:11:36 -0800556 'would be overwritten by checkout:',
Jon Hall274b6642015-02-17 11:57:17 -0800557 'error: you need to resolve your current index first',
558 "You are in 'detached HEAD' state.",
559 "HEAD is now at " ],
kelvin-onlabd3b64892015-01-20 13:26:24 -0800560 timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -0800561 if i == 0:
562 main.log.error(
563 self.name +
564 ": Git checkout had some issue..." )
565 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400566 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800567 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800568 main.log.error(
569 self.name +
570 ": Git checkout asking for username." +
571 " Please configure your local git repository to be able " +
572 "to access your remote repository passwordlessly" )
Jon Hall274b6642015-02-17 11:57:17 -0800573 # TODO add support for authenticating
Jon Hallacabffd2014-10-09 12:36:53 -0400574 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800575 elif i == 2:
576 main.log.info(
577 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800578 ": Git Checkout %s : Already on this branch" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700579 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800580 # main.log.info( "DEBUG: after checkout cmd = "+
581 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400582 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800583 elif i == 3:
584 main.log.info(
585 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800586 ": Git checkout %s - Switched to this branch" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700587 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800588 # main.log.info( "DEBUG: after checkout cmd = "+
589 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400590 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800591 elif i == 4:
592 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
593 main.log.error(
Jon Hall274b6642015-02-17 11:57:17 -0800594 self.name + " Response was: " + str( self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400595 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800596 elif i == 5:
597 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800598 main.log.error(
599 self.name +
600 ": Git checkout error: \n" +
Jon Hall274b6642015-02-17 11:57:17 -0800601 "Your local changes to the following files would" +
602 " be overwritten by checkout:" +
603 str( self.handle.before ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700604 self.handle.expect( self.prompt )
Jon Hall81e29af2014-11-04 20:41:23 -0500605 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800606 elif i == 6:
Jon Hall274b6642015-02-17 11:57:17 -0800607 main.log.error(
608 self.name +
609 ": Git checkout error: \n" +
610 "You need to resolve your current index first:" +
611 str( self.handle.before ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700612 self.handle.expect( self.prompt )
Jon Hall81e29af2014-11-04 20:41:23 -0500613 return main.ERROR
Jon Hall274b6642015-02-17 11:57:17 -0800614 elif i == 7:
615 main.log.info(
616 self.name +
617 ": Git checkout " + str( branch ) +
618 " - You are in 'detached HEAD' state. HEAD is now at " +
619 str( branch ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700620 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800621 return main.TRUE
622 elif i == 8: # Already in detached HEAD on the specified commit
623 main.log.info(
624 self.name +
625 ": Git Checkout %s : Already on commit" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700626 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800627 return main.TRUE
Jon Hallacabffd2014-10-09 12:36:53 -0400628 else:
kelvin8ec71442015-01-15 16:57:00 -0800629 main.log.error(
630 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800631 ": Git Checkout - Unexpected response, " +
632 "check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800633 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400634 return main.ERROR
635
636 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800637 main.log.error( self.name + ": EOF exception found" )
638 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700639 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800640 except Exception:
641 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700642 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400643
pingping-lin6d23d9e2015-02-02 16:54:24 -0800644 def getBranchName( self ):
You Wang9cdf9a22017-05-01 13:44:18 -0700645 import re
646 try:
647 main.log.info( "self.home = " )
648 main.log.info( self.home )
649 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700650 self.handle.expect( self.prompt )
You Wang9cdf9a22017-05-01 13:44:18 -0700651 self.handle.sendline( "git name-rev --name-only HEAD" )
652 self.handle.expect( "git name-rev --name-only HEAD" )
Devin Limc20e79a2017-06-07 10:29:57 -0700653 self.handle.expect( self.prompt )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700654 lines = self.handle.before.splitlines()
655 if lines[ 1 ] == "master" or re.search( "^onos-\d+(\.\d+)+$", lines[ 1 ] ):
656 return lines[ 1 ]
You Wang9cdf9a22017-05-01 13:44:18 -0700657 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700658 main.log.info( lines[ 1 ] )
You Wang9cdf9a22017-05-01 13:44:18 -0700659 return "unexpected ONOS branch"
660 except pexpect.EOF:
661 main.log.error( self.name + ": EOF exception found" )
662 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700663 main.cleanAndExit()
You Wang9cdf9a22017-05-01 13:44:18 -0700664 except pexpect.TIMEOUT:
665 main.log.error( self.name + ": TIMEOUT exception found" )
666 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700667 main.cleanAndExit()
You Wang9cdf9a22017-05-01 13:44:18 -0700668 except Exception:
669 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700670 main.cleanAndExit()
pingping-lin6d23d9e2015-02-02 16:54:24 -0800671
kelvin-onlabd3b64892015-01-20 13:26:24 -0800672 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800673 """
Jon Hall274b6642015-02-17 11:57:17 -0800674 Writes the COMMIT number to the report to be parsed
Jon Hallefbd9792015-03-05 16:11:36 -0800675 by Jenkins data collector.
kelvin8ec71442015-01-15 16:57:00 -0800676 """
Jon Hall45ec0922014-10-10 19:33:49 -0400677 try:
kelvin8ec71442015-01-15 16:57:00 -0800678 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700679 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800680 self.handle.sendline(
681 "cd " +
682 self.home +
Jon Hall274b6642015-02-17 11:57:17 -0800683 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " +
684 " \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800685 # NOTE: for some reason there are backspaces inserted in this
686 # phrase when run from Jenkins on some tests
687 self.handle.expect( "never" )
Devin Limc20e79a2017-06-07 10:29:57 -0700688 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800689 response = ( self.name + ": \n" + str(
690 self.handle.before + self.handle.after ) )
691 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700692 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800693 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400694 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500695 print line
696 if report:
pingping-lin763ee042015-05-20 17:45:30 -0700697 main.log.wiki( "<blockquote>" )
kelvin8ec71442015-01-15 16:57:00 -0800698 for line in lines[ 2:-1 ]:
699 # Bracket replacement is for Wiki-compliant
700 # formatting. '<' or '>' are interpreted
701 # as xml specific tags that cause errors
702 line = line.replace( "<", "[" )
703 line = line.replace( ">", "]" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700704 # main.log.wiki( "\t" + line )
pingping-lin763ee042015-05-20 17:45:30 -0700705 main.log.wiki( line + "<br /> " )
706 main.log.summary( line )
707 main.log.wiki( "</blockquote>" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700708 main.log.summary( "\n" )
kelvin8ec71442015-01-15 16:57:00 -0800709 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400710 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800711 main.log.error( self.name + ": EOF exception found" )
712 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700713 main.cleanAndExit()
Jon Hall368769f2014-11-19 15:43:35 -0800714 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800715 main.log.error( self.name + ": TIMEOUT exception found" )
716 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700717 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800718 except Exception:
719 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700720 main.cleanAndExit()
Jon Hall45ec0922014-10-10 19:33:49 -0400721
kelvin-onlabd3b64892015-01-20 13:26:24 -0800722 def createCellFile( self, benchIp, fileName, mnIpAddrs,
Jon Hall810b67d2016-12-05 10:19:01 -0800723 appString, onosIpAddrs, onosUser="sdn", useSSH=True ):
kelvin8ec71442015-01-15 16:57:00 -0800724 """
andrewonlab94282092014-10-10 13:00:11 -0400725 Creates a cell file based on arguments
726 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800727 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400728 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800729 * File name of the cell file ( fileName )
730 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800731 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400732 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800733 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400734 - Must be passed in as last arguments
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000735 * ONOS USER (onosUser)
Flavio Castrocc38a542016-03-03 13:15:46 -0800736 - optional argument to set ONOS_USER environment variable
kelvin8ec71442015-01-15 16:57:00 -0800737
andrewonlab94282092014-10-10 13:00:11 -0400738 NOTE: Assumes cells are located at:
739 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800740 """
andrewonlab94282092014-10-10 13:00:11 -0400741 try:
Devin Lim461f0872017-06-05 16:49:33 -0700742
Jon Hall2c8959e2016-12-16 12:17:34 -0800743 # Variable initialization
744 cellDirectory = self.home + "/tools/test/cells/"
745 # We want to create the cell file in the dependencies directory
746 # of TestON first, then copy over to ONOS bench
747 tempDirectory = "/tmp/"
748 # Create the cell file in the directory for writing ( w+ )
749 cellFile = open( tempDirectory + fileName, 'w+' )
750 if isinstance( onosIpAddrs, types.StringType ):
751 onosIpAddrs = [ onosIpAddrs ]
752
753 # App string is hardcoded environment variables
754 # That you may wish to use by default on startup.
755 # Note that you may not want certain apps listed
756 # on here.
757 appString = "export ONOS_APPS=" + appString
758 onosGroup = "export ONOS_GROUP=" + onosUser
759 onosUser = "export ONOS_USER=" + onosUser
760 if useSSH:
761 onosUseSSH = "export ONOS_USE_SSH=true"
762 mnString = "export OCN="
763 if mnIpAddrs == "":
764 mnString = ""
765 onosString = "export OC"
766 tempCount = 1
767
768 # Create ONOSNIC ip address prefix
769 tempOnosIp = str( onosIpAddrs[ 0 ] )
770 tempList = []
771 tempList = tempOnosIp.split( "." )
772 # Omit last element of list to format for NIC
773 tempList = tempList[ :-1 ]
774 # Structure the nic string ip
775 nicAddr = ".".join( tempList ) + ".*"
776 self.nicAddr = nicAddr
777 onosNicString = "export ONOS_NIC=" + nicAddr
778
kelvin8ec71442015-01-15 16:57:00 -0800779 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800780 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400781
kelvin-onlabd3b64892015-01-20 13:26:24 -0800782 for arg in onosIpAddrs:
783 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800784 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400785 # export OC1="10.128.20.11"
786 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800787 cellFile.write( onosString + str( tempCount ) +
Jon Hall6f665652015-09-18 10:08:07 -0700788 "=\"" + arg + "\"\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800789 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800790
Jon Hall6f665652015-09-18 10:08:07 -0700791 cellFile.write( "export OCI=$OC1\n" )
792 cellFile.write( mnString + "\"" + mnIpAddrs + "\"\n" )
cameron@onlab.us75900962015-03-30 13:22:49 -0700793 cellFile.write( appString + "\n" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800794 cellFile.write( onosGroup + "\n" )
795 cellFile.write( onosUser + "\n" )
Pier88189b62016-09-07 17:01:53 -0700796 if useSSH:
797 cellFile.write( onosUseSSH + "\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800798 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400799
kelvin8ec71442015-01-15 16:57:00 -0800800 # We use os.system to send the command to TestON cluster
801 # to account for the case in which TestON is not located
802 # on the same cluster as the ONOS bench
803 # Note that even if TestON is located on the same cluster
804 # as ONOS bench, you must setup passwordless ssh
805 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabc2b79102015-07-14 11:41:20 -0700806 os.system( "scp " + tempDirectory + fileName + " " +
807 self.user_name + "@" + self.ip_address + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400808
andrewonlab2a6c9342014-10-16 13:40:15 -0400809 return main.TRUE
810
andrewonlab94282092014-10-10 13:00:11 -0400811 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800812 main.log.error( self.name + ": EOF exception found" )
813 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700814 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800815 except Exception:
816 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700817 main.cleanAndExit()
andrewonlab94282092014-10-10 13:00:11 -0400818
kelvin-onlabd3b64892015-01-20 13:26:24 -0800819 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800820 """
andrewonlab95ca1462014-10-09 14:04:24 -0400821 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800822 """
andrewonlab95ca1462014-10-09 14:04:24 -0400823 try:
824 if not cellname:
You Wang1cdc5f52017-12-19 16:47:51 -0800825 main.log.error( self.name + ": Must define cellname" )
Devin Lim44075962017-08-11 10:56:37 -0700826 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400827 else:
kelvin8ec71442015-01-15 16:57:00 -0800828 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800829 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800830 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400831 # and that this driver will have to change accordingly
Jon Hall3b489db2015-10-05 14:38:37 -0700832 self.handle.expect( str( cellname ) )
You Wang1cdc5f52017-12-19 16:47:51 -0800833 i = self.handle.expect( [ "No such cell",
834 self.prompt,
835 pexpect.TIMEOUT ], timeout=10 )
836 if i == 0:
837 main.log.error( self.name + ": No such cell. Response: " + str( self.handle.before ) )
838 main.cleanAndExit()
839 elif i == 1:
840 main.log.info( self.name + ": Successfully set cell: " + str( self.handle.before ) )
841 elif i == 2:
842 main.log.error( self.name + ": Set cell timed out. Response: " + str( self.handle.before ) )
843 main.cleanAndExit()
844 else:
845 main.log.error( self.name + ": Unexpected response: " + str( self.handle.before ) )
Devin Lim44075962017-08-11 10:56:37 -0700846 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400847 return main.TRUE
You Wang1cdc5f52017-12-19 16:47:51 -0800848 except pexpect.TIMEOUT:
849 main.log.error( self.name + ": TIMEOUT exception found" )
850 main.log.error( self.name + ": " + self.handle.before )
851 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400852 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 )
Devin Lim44075962017-08-11 10:56:37 -0700855 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800856 except Exception:
857 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700858 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400859
kelvin-onlabd3b64892015-01-20 13:26:24 -0800860 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800861 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400862 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800863 """
864 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400865
andrewonlabc03bf6c2014-10-09 14:56:18 -0400866 try:
kelvin8ec71442015-01-15 16:57:00 -0800867 # Clean handle by sending empty and expecting $
868 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700869 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800870 self.handle.sendline( "onos-verify-cell" )
Devin Limc20e79a2017-06-07 10:29:57 -0700871 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800872 handleBefore = self.handle.before
873 handleAfter = self.handle.after
kelvin-onlabd3b64892015-01-20 13:26:24 -0800874 main.log.info( "Verify cell returned: " + handleBefore +
Jon Hall3b489db2015-10-05 14:38:37 -0700875 handleAfter )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400876 return main.TRUE
Jon Halla5cb6172015-02-23 09:28:28 -0800877 except pexpect.ExceptionPexpect as e:
Jon Hall3b489db2015-10-05 14:38:37 -0700878 main.log.exception( self.name + ": Pexpect exception found: " )
kelvin8ec71442015-01-15 16:57:00 -0800879 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700880 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800881 except Exception:
882 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700883 main.cleanAndExit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400884
jenkins1e99e7b2015-04-02 18:15:39 -0700885 def onosCfgSet( self, ONOSIp, configName, configParam ):
886 """
887 Uses 'onos <node-ip> cfg set' to change a parameter value of an
Jon Hall4ba53f02015-07-29 13:07:41 -0700888 application.
889
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000890 ex)
jenkins1e99e7b2015-04-02 18:15:39 -0700891 onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1
jenkins1e99e7b2015-04-02 18:15:39 -0700892 ONOSIp = '10.0.0.1'
893 configName = 'org.onosproject.myapp'
894 configParam = 'appSetting 1'
jenkins1e99e7b2015-04-02 18:15:39 -0700895 """
Jon Hall72280bc2016-01-25 14:29:05 -0800896 try:
897 cfgStr = "onos {} cfg set {} {}".format( ONOSIp,
898 configName,
899 configParam )
900 self.handle.sendline( "" )
901 self.handle.expect( ":~" )
902 self.handle.sendline( cfgStr )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700903 self.handle.expect( "cfg set" )
Jon Hall72280bc2016-01-25 14:29:05 -0800904 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700905
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700906 paramValue = configParam.split( " " )[ 1 ]
907 paramName = configParam.split( " " )[ 0 ]
Jon Hall4ba53f02015-07-29 13:07:41 -0700908
Jon Hall72280bc2016-01-25 14:29:05 -0800909 checkStr = 'onos {} cfg get " {} {} " '.format( ONOSIp, configName, paramName )
Jon Hall4ba53f02015-07-29 13:07:41 -0700910
Jon Hall72280bc2016-01-25 14:29:05 -0800911 self.handle.sendline( checkStr )
912 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700913
Jon Hall72280bc2016-01-25 14:29:05 -0800914 if "value=" + paramValue + "," in self.handle.before:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700915 main.log.info( "cfg " + configName + " successfully set to " + configParam )
Jon Hall72280bc2016-01-25 14:29:05 -0800916 return main.TRUE
917 except pexpect.ExceptionPexpect as e:
918 main.log.exception( self.name + ": Pexpect exception found: " )
919 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700920 main.cleanAndExit()
Jon Hall72280bc2016-01-25 14:29:05 -0800921 except Exception:
922 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700923 main.cleanAndExit()
Jon Hall4ba53f02015-07-29 13:07:41 -0700924
kelvin-onlabd3b64892015-01-20 13:26:24 -0800925 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800926 """
andrewonlab05e362f2014-10-10 00:40:57 -0400927 Uses 'onos' command to send various ONOS CLI arguments.
928 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800929 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400930 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800931
932 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400933 CLI commands for ONOS. Try to use this function first
934 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800935 function.
936 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400937 by starting onos, and typing in 'onos' to enter the
938 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800939 available commands.
940 """
andrewonlab05e362f2014-10-10 00:40:57 -0400941 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800942 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800943 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400944 return main.FALSE
945 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800946 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400947 return main.FALSE
948
kelvin8ec71442015-01-15 16:57:00 -0800949 cmdstr = str( cmdstr )
950 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700951 self.handle.expect( self.prompt )
andrewonlab05e362f2014-10-10 00:40:57 -0400952
kelvin-onlabd3b64892015-01-20 13:26:24 -0800953 self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr )
Devin Limc20e79a2017-06-07 10:29:57 -0700954 self.handle.expect( self.prompt )
andrewonlab05e362f2014-10-10 00:40:57 -0400955
kelvin-onlabd3b64892015-01-20 13:26:24 -0800956 handleBefore = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800957 main.log.info( "Command sent successfully" )
kelvin8ec71442015-01-15 16:57:00 -0800958 # Obtain return handle that consists of result from
959 # the onos command. The string may need to be
960 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800961 returnString = handleBefore
kelvin-onlabd3b64892015-01-20 13:26:24 -0800962 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400963 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800964 main.log.error( self.name + ": EOF exception found" )
965 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700966 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800967 except Exception:
968 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700969 main.cleanAndExit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400970
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700971 def onosSecureSSH( self, userName="onos", userPWD="rocks", node="" ):
Pier88189b62016-09-07 17:01:53 -0700972 """
973 Enables secure access to ONOS console
974 by removing default users & keys.
975
976 onos-secure-ssh -u onos -p rocks node
977
978 Returns: main.TRUE on success and main.FALSE on failure
979 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000980
Pier88189b62016-09-07 17:01:53 -0700981 try:
Chiyu Chengef109502016-11-21 15:51:38 -0800982 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700983 self.handle.expect( self.prompt )
Pier88189b62016-09-07 17:01:53 -0700984 self.handle.sendline( " onos-secure-ssh -u " + userName + " -p " + userPWD + " " + node )
985
986 # NOTE: this timeout may need to change depending on the network
987 # and size of ONOS
988 # TODO: Handle the other possible error
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700989 i = self.handle.expect( [ "Network\sis\sunreachable",
990 self.prompt,
991 pexpect.TIMEOUT ], timeout=180 )
Pier88189b62016-09-07 17:01:53 -0700992 if i == 0:
993 # can't reach ONOS node
994 main.log.warn( "Network is unreachable" )
Devin Limc20e79a2017-06-07 10:29:57 -0700995 self.handle.expect( self.prompt )
Pier88189b62016-09-07 17:01:53 -0700996 return main.FALSE
997 elif i == 1:
998 # Process started
999 main.log.info(
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001000 "Secure SSH performed on " +
1001 node )
Pier88189b62016-09-07 17:01:53 -07001002 return main.TRUE
1003 except pexpect.EOF:
1004 main.log.error( self.name + ": EOF exception found" )
1005 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001006 main.cleanAndExit()
Pier88189b62016-09-07 17:01:53 -07001007 except Exception:
1008 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001009 main.cleanAndExit()
Pier88189b62016-09-07 17:01:53 -07001010
kelvin-onlabd3b64892015-01-20 13:26:24 -08001011 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001012 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001013 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -08001014 If -f option is provided, it also forces an uninstall.
1015 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -04001016 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -08001017 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -04001018 files to certain onos nodes
1019
1020 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -08001021 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001022 try:
andrewonlab114768a2014-11-14 12:44:44 -05001023 if options:
kelvin8ec71442015-01-15 16:57:00 -08001024 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -05001025 else:
kelvin8ec71442015-01-15 16:57:00 -08001026 self.handle.sendline( "onos-install " + node )
1027 self.handle.expect( "onos-install " )
1028 # NOTE: this timeout may need to change depending on the network
1029 # and size of ONOS
1030 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001031 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -08001032 "ONOS\sis\salready\sinstalled",
Jeremyc72b2582016-02-26 18:27:38 -08001033 "already\sup-to-date",
Jon Hall3576f572016-08-23 10:01:07 -07001034 "does not exist",
Devin Limc20e79a2017-06-07 10:29:57 -07001035 self.prompt,
Jon Hall6c44c0b2016-04-20 15:21:00 -07001036 pexpect.TIMEOUT ], timeout=180 )
Jon Hall7993bfc2014-10-09 16:30:14 -04001037 if i == 0:
Jon Hall3576f572016-08-23 10:01:07 -07001038 # can't reach ONOS node
kelvin8ec71442015-01-15 16:57:00 -08001039 main.log.warn( "Network is unreachable" )
Devin Limc20e79a2017-06-07 10:29:57 -07001040 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001041 return main.FALSE
1042 elif i == 1:
Jon Hall3576f572016-08-23 10:01:07 -07001043 # Process started
kelvin8ec71442015-01-15 16:57:00 -08001044 main.log.info(
1045 "ONOS was installed on " +
1046 node +
1047 " and started" )
Devin Limc20e79a2017-06-07 10:29:57 -07001048 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001049 return main.TRUE
Jon Hall3576f572016-08-23 10:01:07 -07001050 elif i == 2 or i == 3:
1051 # same bits are already on ONOS node
Jeremyc72b2582016-02-26 18:27:38 -08001052 main.log.info( "ONOS is already installed on " + node )
Devin Limc20e79a2017-06-07 10:29:57 -07001053 self.handle.expect( self.prompt )
Jeremyc72b2582016-02-26 18:27:38 -08001054 return main.TRUE
1055 elif i == 4:
Jon Hall3576f572016-08-23 10:01:07 -07001056 # onos not packaged
1057 main.log.error( "ONOS package not found." )
Devin Limc20e79a2017-06-07 10:29:57 -07001058 self.handle.expect( self.prompt )
Jon Hall3576f572016-08-23 10:01:07 -07001059 return main.FALSE
1060 elif i == 5:
1061 # prompt
Jeremyc72b2582016-02-26 18:27:38 -08001062 main.log.info( "ONOS was installed on " + node )
1063 return main.TRUE
Jon Hall3576f572016-08-23 10:01:07 -07001064 elif i == 6:
1065 # timeout
kelvin8ec71442015-01-15 16:57:00 -08001066 main.log.info(
1067 "Installation of ONOS on " +
1068 node +
1069 " timed out" )
Devin Limc20e79a2017-06-07 10:29:57 -07001070 self.handle.expect( self.prompt )
Jon Hall53c5e662016-04-13 16:06:56 -07001071 main.log.warn( self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001072 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -04001073 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001074 main.log.error( self.name + ": EOF exception found" )
1075 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001076 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001077 except Exception:
1078 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001079 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -04001080
kelvin-onlabd3b64892015-01-20 13:26:24 -08001081 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001082 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001083 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001084 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001085 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001086 try:
kelvin8ec71442015-01-15 16:57:00 -08001087 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001088 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001089 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001090 " start" )
1091 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -04001092 "Job\sis\salready\srunning",
1093 "start/running",
Devin Limc20e79a2017-06-07 10:29:57 -07001094 self.prompt,
andrewonlab8d0d7d72014-10-09 16:33:15 -04001095 "Unknown\sinstance",
Jeremy Songster14c13572016-04-21 17:34:03 -07001096 pexpect.TIMEOUT ], timeout=180 )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001097 if i == 0:
Devin Limc20e79a2017-06-07 10:29:57 -07001098 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001099 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001100 return main.TRUE
1101 elif i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001102 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001103 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001104 return main.TRUE
Jeremyd0e9a6d2016-03-02 11:28:52 -08001105 elif i == 2:
1106 main.log.info( "ONOS service started" )
1107 return main.TRUE
andrewonlab8d0d7d72014-10-09 16:33:15 -04001108 else:
Devin Limc20e79a2017-06-07 10:29:57 -07001109 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001110 main.log.error( "ONOS service failed to start" )
Devin Lim44075962017-08-11 10:56:37 -07001111
1112 main.cleanAndExit()
andrewonlab8d0d7d72014-10-09 16:33:15 -04001113 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001114 main.log.error( self.name + ": EOF exception found" )
1115 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001116 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001117 except Exception:
1118 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001119 main.cleanAndExit()
andrewonlab8d0d7d72014-10-09 16:33:15 -04001120
kelvin-onlabd3b64892015-01-20 13:26:24 -08001121 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001122 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001123 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001124 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001125 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001126 try:
kelvin8ec71442015-01-15 16:57:00 -08001127 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001128 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001129 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001130 " stop" )
1131 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -04001132 "stop/waiting",
Jon Hall61282e32015-03-19 11:34:11 -07001133 "Could not resolve hostname",
andrewonlab2b30bd32014-10-09 16:48:55 -04001134 "Unknown\sinstance",
Devin Limc20e79a2017-06-07 10:29:57 -07001135 self.prompt,
Jeremy Songster14c13572016-04-21 17:34:03 -07001136 pexpect.TIMEOUT ], timeout=180 )
andrewonlab2b30bd32014-10-09 16:48:55 -04001137 if i == 0:
Devin Limc20e79a2017-06-07 10:29:57 -07001138 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001139 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001140 return main.TRUE
1141 elif i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001142 self.handle.expect( self.prompt )
Jon Hall65844a32015-03-09 19:09:37 -07001143 main.log.info( "onosStop() Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001144 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -04001145 return main.FALSE
Jon Hall61282e32015-03-19 11:34:11 -07001146 elif i == 2:
Devin Limc20e79a2017-06-07 10:29:57 -07001147 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -07001148 main.log.warn( "ONOS wasn't running" )
1149 return main.TRUE
YPZhang77badfc2016-03-09 10:28:59 -08001150 elif i == 3:
1151 main.log.info( "ONOS service stopped" )
1152 return main.TRUE
andrewonlab2b30bd32014-10-09 16:48:55 -04001153 else:
kelvin8ec71442015-01-15 16:57:00 -08001154 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001155 return main.FALSE
andrewonlab2b30bd32014-10-09 16:48:55 -04001156 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001157 main.log.error( self.name + ": EOF exception found" )
1158 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001159 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001160 except Exception:
1161 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001162 main.cleanAndExit()
kelvin8ec71442015-01-15 16:57:00 -08001163
kelvin-onlabd3b64892015-01-20 13:26:24 -08001164 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -08001165 """
andrewonlabc8d47972014-10-09 16:52:36 -04001166 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -08001167 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -04001168 if needed
kelvin8ec71442015-01-15 16:57:00 -08001169 """
andrewonlabc8d47972014-10-09 16:52:36 -04001170 try:
kelvin8ec71442015-01-15 16:57:00 -08001171 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001172 self.handle.expect( self.prompt, timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001173 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
Devin Limc20e79a2017-06-07 10:29:57 -07001174 self.handle.expect( self.prompt, timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001175 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
kelvin8ec71442015-01-15 16:57:00 -08001176 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -04001177 return main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -07001178 except pexpect.TIMEOUT:
1179 main.log.exception( self.name + ": Timeout in onosUninstall" )
1180 return main.FALSE
andrewonlabc8d47972014-10-09 16:52:36 -04001181 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001182 main.log.error( self.name + ": EOF exception found" )
1183 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001184 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001185 except Exception:
1186 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001187 main.cleanAndExit()
andrewonlab2b30bd32014-10-09 16:48:55 -04001188
kelvin-onlabd3b64892015-01-20 13:26:24 -08001189 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001190 """
andrewonlabaedc8332014-12-04 12:43:03 -05001191 Issues the command 'onos-die <node-ip>'
1192 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -08001193 """
andrewonlabaedc8332014-12-04 12:43:03 -05001194 try:
kelvin8ec71442015-01-15 16:57:00 -08001195 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001196 self.handle.expect( self.prompt )
Jeremyf0aecdb2016-03-30 13:19:57 -07001197 cmdStr = "onos-die " + str( nodeIp )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001198 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001199 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -05001200 "Killing\sONOS",
1201 "ONOS\sprocess\sis\snot\srunning",
Jeremy Songster14c13572016-04-21 17:34:03 -07001202 pexpect.TIMEOUT ], timeout=60 )
andrewonlabaedc8332014-12-04 12:43:03 -05001203 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001204 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001205 " was killed and stopped" )
Jon Hall53c5e662016-04-13 16:06:56 -07001206 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001207 self.handle.expect( self.prompt )
andrewonlabaedc8332014-12-04 12:43:03 -05001208 return main.TRUE
1209 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001210 main.log.info( "ONOS process was not running" )
Jon Hall53c5e662016-04-13 16:06:56 -07001211 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001212 self.handle.expect( self.prompt )
andrewonlabaedc8332014-12-04 12:43:03 -05001213 return main.FALSE
1214 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001215 main.log.error( self.name + ": EOF exception found" )
1216 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001217 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001218 except Exception:
1219 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001220 main.cleanAndExit()
andrewonlabaedc8332014-12-04 12:43:03 -05001221
kelvin-onlabd3b64892015-01-20 13:26:24 -08001222 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001223 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001224 Calls the command: 'onos-kill [<node-ip>]'
1225 "Remotely, and unceremoniously kills the ONOS instance running on
1226 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -08001227 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001228 try:
kelvin8ec71442015-01-15 16:57:00 -08001229 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001230 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001231 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -08001232 i = self.handle.expect( [
Devin Limc20e79a2017-06-07 10:29:57 -07001233 self.prompt,
andrewonlabe8e56fd2014-10-09 17:12:44 -04001234 "No\sroute\sto\shost",
1235 "password:",
Jeremy Songster14c13572016-04-21 17:34:03 -07001236 pexpect.TIMEOUT ], timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -08001237
andrewonlabe8e56fd2014-10-09 17:12:44 -04001238 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001239 main.log.info(
1240 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -08001241 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001242 return main.TRUE
1243 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001244 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001245 return main.FALSE
1246 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001247 main.log.info(
1248 "Passwordless login for host: " +
1249 str( nodeIp ) +
1250 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001251 return main.FALSE
1252 else:
Jon Hallefbd9792015-03-05 16:11:36 -08001253 main.log.info( "ONOS instance was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001254 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001255
andrewonlabe8e56fd2014-10-09 17:12:44 -04001256 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001257 main.log.error( self.name + ": EOF exception found" )
1258 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001259 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001260 except Exception:
1261 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001262 main.cleanAndExit()
andrewonlabe8e56fd2014-10-09 17:12:44 -04001263
kelvin-onlabd3b64892015-01-20 13:26:24 -08001264 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -08001265 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001266 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -05001267 a cleaner environment.
1268
andrewonlab19fbdca2014-11-14 12:55:59 -05001269 Description:
Jon Hallfcc88622014-11-25 13:09:54 -05001270 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -05001271 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -08001272 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001273 try:
kelvin8ec71442015-01-15 16:57:00 -08001274 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001275 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001276 self.handle.sendline( "onos-remove-raft-logs" )
1277 # Sometimes this command hangs
Devin Limc20e79a2017-06-07 10:29:57 -07001278 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
kelvin8ec71442015-01-15 16:57:00 -08001279 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001280 if i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001281 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
kelvin8ec71442015-01-15 16:57:00 -08001282 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001283 if i == 1:
1284 return main.FALSE
andrewonlab19fbdca2014-11-14 12:55:59 -05001285 return main.TRUE
andrewonlab19fbdca2014-11-14 12:55:59 -05001286 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001287 main.log.error( self.name + ": EOF exception found" )
1288 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001289 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001290 except Exception:
1291 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001292 main.cleanAndExit()
Jon Hallfcc88622014-11-25 13:09:54 -05001293
kelvin-onlabd3b64892015-01-20 13:26:24 -08001294 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -08001295 """
1296 Calls the command 'onos-start-network [ <mininet-topo> ]
1297 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -04001298 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -08001299 cell."
andrewonlab94282092014-10-10 13:00:11 -04001300 * Specify mininet topology file name for mntopo
1301 * Topo files should be placed at:
1302 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001303
andrewonlab94282092014-10-10 13:00:11 -04001304 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001305 """
andrewonlab94282092014-10-10 13:00:11 -04001306 try:
1307 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001308 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001309 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001310
kelvin8ec71442015-01-15 16:57:00 -08001311 mntopo = str( mntopo )
1312 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001313 self.handle.expect( self.prompt )
andrewonlab94282092014-10-10 13:00:11 -04001314
kelvin8ec71442015-01-15 16:57:00 -08001315 self.handle.sendline( "onos-start-network " + mntopo )
1316 self.handle.expect( "mininet>" )
1317 main.log.info( "Network started, entered mininet prompt" )
1318
1319 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001320
1321 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001322 main.log.error( self.name + ": EOF exception found" )
1323 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001324 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001325 except Exception:
1326 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001327 main.cleanAndExit()
andrewonlab94282092014-10-10 13:00:11 -04001328
Jeremy Songster14c13572016-04-21 17:34:03 -07001329 def isup( self, node="", timeout=240 ):
kelvin8ec71442015-01-15 16:57:00 -08001330 """
1331 Run's onos-wait-for-start which only returns once ONOS is at run
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001332 level 100(ready for use)
andrewonlab8d0d7d72014-10-09 16:33:15 -04001333
Jon Hall7993bfc2014-10-09 16:30:14 -04001334 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001335 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001336 try:
Jon Hall3b489db2015-10-05 14:38:37 -07001337 self.handle.sendline( "onos-wait-for-start " + node )
1338 self.handle.expect( "onos-wait-for-start" )
kelvin8ec71442015-01-15 16:57:00 -08001339 # NOTE: this timeout is arbitrary"
Jon Hallcababf72018-02-05 12:05:19 -08001340 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT, "Password:" ], timeout )
Jon Hall7993bfc2014-10-09 16:30:14 -04001341 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001342 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001343 return main.TRUE
Jon Hallcababf72018-02-05 12:05:19 -08001344 elif i == 1 or i == 2:
kelvin8ec71442015-01-15 16:57:00 -08001345 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001346 # we will kill it on timeout
Jon Hallcababf72018-02-05 12:05:19 -08001347 if i == 1:
1348 main.log.error( "ONOS has not started yet" )
1349 elif i == 2:
1350 main.log.error( "Cannot login to ONOS CLI, try using onos-secure-ssh" )
kelvin8ec71442015-01-15 16:57:00 -08001351 self.handle.send( "\x03" ) # Control-C
Devin Limc20e79a2017-06-07 10:29:57 -07001352 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001353 return main.FALSE
1354 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001355 main.log.error( self.name + ": EOF exception found" )
1356 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001357 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001358 except Exception:
1359 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001360 main.cleanAndExit()
andrewonlab05e362f2014-10-10 00:40:57 -04001361
Devin Lim142b5342017-07-20 15:22:39 -07001362 def preventAutoRespawn( self ):
1363 """
1364 Description:
1365 This will prevent ONOSservice to automatically
1366 respawn.
1367 """
1368 try:
1369 self.handle.sendline( "sed -i -e 's/^respawn$/#respawn/g' tools/package/init/onos.conf" )
1370 self.handle.expect( "\$" ) # $ from the command
1371 self.handle.sendline( "sed -i -e 's/^Restart=always/Restart=no/g' tools/package/init/onos.service" )
1372 self.handle.expect( "\$" ) # $ from the command
1373 self.handle.expect( "\$" ) # $ from the prompt
1374 except pexpect.EOF:
1375 main.log.error( self.name + ": EOF exception found" )
1376 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001377 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -07001378 except Exception:
1379 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001380 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -07001381
kelvin-onlabd3b64892015-01-20 13:26:24 -08001382 def pushTestIntentsShell(
1383 self,
1384 dpidSrc,
1385 dpidDst,
1386 numIntents,
1387 dirFile,
1388 onosIp,
1389 numMult="",
1390 appId="",
1391 report=True,
1392 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001393 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001394 Description:
kelvin8ec71442015-01-15 16:57:00 -08001395 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001396 better parallelize the results than the CLI
1397 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001398 * dpidSrc: specify source dpid
1399 * dpidDst: specify destination dpid
1400 * numIntents: specify number of intents to push
1401 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001402 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001403 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001404 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001405 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001406 """
1407 try:
1408 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001409 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001410 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001411 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001412 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001413 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001414
kelvin-onlabd3b64892015-01-20 13:26:24 -08001415 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1416 if not numMult:
1417 addIntents = addDpid + " " + str( numIntents )
1418 elif numMult:
1419 addIntents = addDpid + " " + str( numIntents ) + " " +\
1420 str( numMult )
1421 if appId:
1422 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001423 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001424 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001425
andrewonlabaedc8332014-12-04 12:43:03 -05001426 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001427 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001428 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001429 sendCmd = addApp + " &"
1430 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001431
kelvin-onlabd3b64892015-01-20 13:26:24 -08001432 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001433
1434 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001435 main.log.error( self.name + ": EOF exception found" )
1436 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001437 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001438 except Exception:
1439 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001440 main.cleanAndExit()
andrewonlab05e362f2014-10-10 00:40:57 -04001441
kelvin-onlabd3b64892015-01-20 13:26:24 -08001442 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001443 """
andrewonlab970399c2014-11-07 13:09:32 -05001444 Capture all packet activity and store in specified
1445 directory/file
1446
1447 Required:
1448 * interface: interface to capture
1449 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001450 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001451 try:
1452 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001453 self.handle.expect( self.prompt )
andrewonlab970399c2014-11-07 13:09:32 -05001454
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001455 self.handle.sendline( "tshark -i " + str( interface ) + " -t e -w " + str( dirFile ) + " &" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001456 self.handle.sendline( "\n" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001457 self.handle.expect( "Capturing on" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001458 self.handle.sendline( "\n" )
Devin Limc20e79a2017-06-07 10:29:57 -07001459 self.handle.expect( self.prompt )
andrewonlab970399c2014-11-07 13:09:32 -05001460
Jon Hallfebb1c72015-03-05 13:30:09 -08001461 main.log.info( "Tshark started capturing files on " +
1462 str( interface ) + " and saving to directory: " +
1463 str( dirFile ) )
1464 except pexpect.EOF:
1465 main.log.error( self.name + ": EOF exception found" )
1466 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001467 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001468 except Exception:
1469 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001470 main.cleanAndExit()
Shreya Shaha73aaad2014-10-27 18:03:09 -04001471
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001472 def onosTopoCfg( self, onosIp, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001473 """
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001474 Description:
1475 Execute onos-topo-cfg command
1476 Required:
1477 onosIp - IP of the onos node you want to send the json to
1478 jsonFile - File path of the json file
1479 Return:
1480 Returns main.TRUE if the command is successfull; Returns
1481 main.FALSE if there was an error
kelvin8ec71442015-01-15 16:57:00 -08001482 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001483 try:
kelvin8ec71442015-01-15 16:57:00 -08001484 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001485 self.handle.expect( self.prompt )
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001486 cmd = "onos-topo-cfg "
1487 self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile )
1488 handle = self.handle.before
1489 print handle
1490 if "Error" in handle:
1491 main.log.error( self.name + ": " + self.handle.before )
1492 return main.FALSE
1493 else:
Devin Limc20e79a2017-06-07 10:29:57 -07001494 self.handle.expect( self.prompt )
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001495 return main.TRUE
1496
Jon Hallfebb1c72015-03-05 13:30:09 -08001497 except pexpect.EOF:
1498 main.log.error( self.name + ": EOF exception found" )
1499 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001500 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001501 except Exception:
1502 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001503 main.cleanAndExit()
kelvin8ec71442015-01-15 16:57:00 -08001504
jenkins1e99e7b2015-04-02 18:15:39 -07001505 def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ):
kelvin8ec71442015-01-15 16:57:00 -08001506 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001507 Required:
kelvin8ec71442015-01-15 16:57:00 -08001508 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001509 * directory to store results
1510 Optional:
1511 * interface - default: eth0
Jon Hall4ba53f02015-07-29 13:07:41 -07001512 * grepOptions - options for grep
andrewonlabba44bcf2014-10-16 16:54:41 -04001513 Description:
1514 Uses tshark command to grep specific group of packets
1515 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001516 The timestamp is hardcoded to be in epoch
1517 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001518 try:
1519 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001520 self.handle.expect( self.prompt )
Jon Hallfebb1c72015-03-05 13:30:09 -08001521 self.handle.sendline( "" )
jenkins1e99e7b2015-04-02 18:15:39 -07001522 if grepOptions:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001523 grepStr = "grep " + str( grepOptions )
jenkins1e99e7b2015-04-02 18:15:39 -07001524 else:
1525 grepStr = "grep"
Jon Hall4ba53f02015-07-29 13:07:41 -07001526
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001527 cmd = (
1528 "sudo tshark -i " +
Jon Hallfebb1c72015-03-05 13:30:09 -08001529 str( interface ) +
jenkins1e99e7b2015-04-02 18:15:39 -07001530 " -t e | " +
1531 grepStr + " --line-buffered \"" +
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001532 str( grep ) +
Jon Hallfebb1c72015-03-05 13:30:09 -08001533 "\" >" +
1534 directory +
1535 " &" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001536 self.handle.sendline( cmd )
1537 main.log.info( cmd )
Jon Hallfebb1c72015-03-05 13:30:09 -08001538 self.handle.expect( "Capturing on" )
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001539 self.handle.sendline( "\n" )
Devin Limc20e79a2017-06-07 10:29:57 -07001540 self.handle.expect( self.prompt )
Jon Hallfebb1c72015-03-05 13:30:09 -08001541 except pexpect.EOF:
1542 main.log.error( self.name + ": EOF exception found" )
1543 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001544 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001545 except Exception:
1546 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001547 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001548
kelvin-onlabd3b64892015-01-20 13:26:24 -08001549 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001550 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001551 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001552 """
1553 # Remove all pcap from previous captures
Jon Hallfebb1c72015-03-05 13:30:09 -08001554 try:
1555 self.execute( cmd="sudo rm /tmp/wireshark*" )
1556 self.handle.sendline( "" )
Jon Hallefbd9792015-03-05 16:11:36 -08001557 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" +
1558 " | grep -v grep | awk '{print $2}'`" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001559 self.handle.sendline( "" )
1560 main.log.info( "Tshark stopped" )
1561 except pexpect.EOF:
1562 main.log.error( self.name + ": EOF exception found" )
1563 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001564 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001565 except Exception:
1566 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001567 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001568
kelvin8ec71442015-01-15 16:57:00 -08001569 def ptpd( self, args ):
1570 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001571 Initiate ptp with user-specified args.
1572 Required:
1573 * args: specify string of args after command
1574 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001575 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001576 try:
kelvin8ec71442015-01-15 16:57:00 -08001577 self.handle.sendline( "sudo ptpd " + str( args ) )
1578 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001579 "Multiple",
1580 "Error",
Devin Limc20e79a2017-06-07 10:29:57 -07001581 self.prompt ] )
1582 self.handle.expect( self.prompt )
andrewonlabba44bcf2014-10-16 16:54:41 -04001583
andrewonlab0c38a4a2014-10-28 18:35:35 -04001584 if i == 0:
1585 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001586 main.log.info( "ptpd returned an error: " +
1587 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001588 return handle
1589 elif i == 1:
1590 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001591 main.log.error( "ptpd returned an error: " +
1592 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001593 return handle
1594 else:
1595 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001596
andrewonlab0c38a4a2014-10-28 18:35:35 -04001597 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001598 main.log.error( self.name + ": EOF exception found" )
1599 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001600 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001601 except Exception:
1602 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001603 main.cleanAndExit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001604
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001605 def dumpONOSCmd( self, ONOSIp, CMD, destDir, filename, options="" ):
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001606 """
Pier50f0bc62016-09-07 17:53:40 -07001607 Dump Cmd to a desired directory.
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001608 For debugging purposes, you may want to use
Pier50f0bc62016-09-07 17:53:40 -07001609 this function to capture Cmd at a given point in time.
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001610 Localtime will be attached to the filename
1611
1612 Required:
1613 * ONOSIp: the IP of the target ONOS instance
Pier50f0bc62016-09-07 17:53:40 -07001614 * CMD: the command to dump;
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001615 * destDir: specify directory to copy to.
1616 ex ) /tmp/
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001617 * fileName: Name of the file
Pier50f0bc62016-09-07 17:53:40 -07001618 * options: Options for ONOS command
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001619 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001620
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001621 localtime = time.strftime( '%x %X' )
1622 localtime = localtime.replace( "/", "" )
1623 localtime = localtime.replace( " ", "_" )
1624 localtime = localtime.replace( ":", "" )
1625 if destDir[ -1: ] != "/":
1626 destDir += "/"
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001627 cmd = CMD + " " + options + " > " + str( destDir ) + str( filename ) + localtime
1628 return self.onosCli( ONOSIp, cmd )
Flavio Castrob7718952016-05-18 08:53:41 -07001629
kelvin-onlabd3b64892015-01-20 13:26:24 -08001630 def cpLogsToDir( self, logToCopy,
Jon Hallefbd9792015-03-05 16:11:36 -08001631 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001632 """
1633 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001634 Current implementation of ONOS deletes its karaf
1635 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001636 you may want to use this function to capture
1637 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001638 Localtime will be attached to the filename
1639
1640 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001641 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001642 copy.
kelvin8ec71442015-01-15 16:57:00 -08001643 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001644 For copying multiple files, leave copyFileName
1645 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001646 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001647 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001648 ex ) /tmp/
1649 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001650 * copyFileName: If you want to rename the log
1651 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001652 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001653 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001654 try:
Flavio Castro09ab59d2016-05-25 17:01:35 -07001655 localtime = time.strftime( '%H %M' )
kelvin8ec71442015-01-15 16:57:00 -08001656 localtime = localtime.replace( "/", "" )
1657 localtime = localtime.replace( " ", "_" )
1658 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001659 if destDir[ -1: ] != "/":
1660 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001661
kelvin-onlabd3b64892015-01-20 13:26:24 -08001662 if copyFileName:
Jon Hallfebb1c72015-03-05 13:30:09 -08001663 self.handle.sendline( "cp " + str( logToCopy ) + " " +
1664 str( destDir ) + str( copyFileName ) +
1665 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001666 self.handle.expect( "cp" )
Devin Limc20e79a2017-06-07 10:29:57 -07001667 self.handle.expect( self.prompt )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001668 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001669 self.handle.sendline( "cp " + str( logToCopy ) +
1670 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001671 self.handle.expect( "cp" )
Devin Limc20e79a2017-06-07 10:29:57 -07001672 self.handle.expect( self.prompt )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001673
kelvin8ec71442015-01-15 16:57:00 -08001674 return self.handle.before
1675
1676 except pexpect.EOF:
1677 main.log.error( "Copying files failed" )
1678 main.log.error( self.name + ": EOF exception found" )
1679 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001680 except Exception:
1681 main.log.exception( "Copying files failed" )
1682
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001683 def checkLogs( self, onosIp, restart=False ):
kelvin8ec71442015-01-15 16:57:00 -08001684 """
Jon Hall94fd0472014-12-08 11:52:42 -08001685 runs onos-check-logs on the given onos node
Jon Hall80daded2015-05-27 16:07:00 -07001686 If restart is True, use the old version of onos-check-logs which
1687 does not print the full stacktrace, but shows the entire log file,
1688 including across restarts
Jon Hall94fd0472014-12-08 11:52:42 -08001689 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001690 """
Jon Hall94fd0472014-12-08 11:52:42 -08001691 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001692 cmd = "onos-check-logs " + str( onosIp )
Jon Hall16b72c42015-05-20 10:23:36 -07001693 if restart:
1694 cmd += " old"
kelvin8ec71442015-01-15 16:57:00 -08001695 self.handle.sendline( cmd )
1696 self.handle.expect( cmd )
Devin Limdc78e202017-06-09 18:30:07 -07001697 self.handle.expect( self.prompt + " " )
Jon Hall94fd0472014-12-08 11:52:42 -08001698 response = self.handle.before
1699 return response
1700 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001701 main.log.error( "Lost ssh connection" )
1702 main.log.error( self.name + ": EOF exception found" )
1703 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001704 except Exception:
1705 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001706 main.cleanAndExit()
Jon Hall94fd0472014-12-08 11:52:42 -08001707
kelvin-onlabd3b64892015-01-20 13:26:24 -08001708 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001709 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001710 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001711 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001712 try:
kelvin8ec71442015-01-15 16:57:00 -08001713 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001714 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001715 self.handle.sendline( "onos-service " + str( node ) +
1716 " status" )
1717 i = self.handle.expect( [
You Wangef1e6572016-03-08 12:53:18 -08001718 "start/running",
You Wang7bd83062016-03-01 11:50:00 -08001719 "Running ...",
You Wangef1e6572016-03-08 12:53:18 -08001720 "stop/waiting",
You Wang7bd83062016-03-01 11:50:00 -08001721 "Not Running ...",
kelvin8ec71442015-01-15 16:57:00 -08001722 pexpect.TIMEOUT ], timeout=120 )
YPZhangfebf7302016-05-24 16:45:56 -07001723 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001724 self.handle.expect( self.prompt )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001725
You Wangef1e6572016-03-08 12:53:18 -08001726 if i == 0 or i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001727 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001728 return main.TRUE
You Wangef1e6572016-03-08 12:53:18 -08001729 elif i == 2 or i == 3:
kelvin8ec71442015-01-15 16:57:00 -08001730 main.log.info( "ONOS is stopped" )
kelvin8ec71442015-01-15 16:57:00 -08001731 main.log.error( "ONOS service failed to check the status" )
Devin Lim44075962017-08-11 10:56:37 -07001732
1733 main.cleanAndExit()
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001734 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001735 main.log.error( self.name + ": EOF exception found" )
1736 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001737 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001738 except Exception:
1739 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001740 main.cleanAndExit()
Jon Hall21270ac2015-02-16 17:59:55 -08001741
Jon Hall63604932015-02-26 17:09:50 -08001742 def setIpTables( self, ip, port='', action='add', packet_type='',
1743 direction='INPUT', rule='DROP', states=True ):
Jon Hallefbd9792015-03-05 16:11:36 -08001744 """
Jon Hall21270ac2015-02-16 17:59:55 -08001745 Description:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001746 add or remove iptables rule to DROP (default) packets from
Jon Hall21270ac2015-02-16 17:59:55 -08001747 specific IP and PORT
1748 Usage:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001749 * specify action ('add' or 'remove')
Jon Hall21270ac2015-02-16 17:59:55 -08001750 when removing, pass in the same argument as you would add. It will
1751 delete that specific rule.
1752 * specify the ip to block
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001753 * specify the destination port to block (defaults to all ports)
1754 * optional packet type to block (default tcp)
1755 * optional iptables rule (default DROP)
1756 * optional direction to block (default 'INPUT')
Jon Hall63604932015-02-26 17:09:50 -08001757 * States boolean toggles adding all supported tcp states to the
1758 firewall rule
Jon Hall21270ac2015-02-16 17:59:55 -08001759 Returns:
1760 main.TRUE on success or
1761 main.FALSE if given invalid input or
1762 main.ERROR if there is an error in response from iptables
1763 WARNING:
1764 * This function uses root privilege iptables command which may result
1765 in unwanted network errors. USE WITH CAUTION
Jon Hallefbd9792015-03-05 16:11:36 -08001766 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001767
Jon Hall21270ac2015-02-16 17:59:55 -08001768 # NOTE*********
1769 # The strict checking methods of this driver function is intentional
1770 # to discourage any misuse or error of iptables, which can cause
1771 # severe network errors
1772 # *************
1773
1774 # NOTE: Sleep needed to give some time for rule to be added and
1775 # registered to the instance. If you are calling this function
1776 # multiple times this sleep will prevent any errors.
1777 # DO NOT REMOVE
Jon Hall63604932015-02-26 17:09:50 -08001778 # time.sleep( 5 )
Jon Hall21270ac2015-02-16 17:59:55 -08001779 try:
1780 # input validation
1781 action_type = action.lower()
1782 rule = rule.upper()
1783 direction = direction.upper()
1784 if action_type != 'add' and action_type != 'remove':
1785 main.log.error( "Invalid action type. Use 'add' or "
1786 "'remove' table rule" )
1787 if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
1788 # NOTE Currently only supports rules DROP, ACCEPT, and LOG
1789 main.log.error( "Invalid rule. Valid rules are 'DROP' or "
1790 "'ACCEPT' or 'LOG' only." )
1791 if direction != 'INPUT' and direction != 'OUTPUT':
1792 # NOTE currently only supports rules INPUT and OUPTUT
1793 main.log.error( "Invalid rule. Valid directions are"
1794 " 'OUTPUT' or 'INPUT'" )
1795 return main.FALSE
1796 return main.FALSE
1797 return main.FALSE
1798 if action_type == 'add':
1799 # -A is the 'append' action of iptables
1800 actionFlag = '-A'
1801 elif action_type == 'remove':
1802 # -D is the 'delete' rule of iptables
1803 actionFlag = '-D'
1804 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001805 self.handle.expect( self.prompt )
Jon Hall21270ac2015-02-16 17:59:55 -08001806 cmd = "sudo iptables " + actionFlag + " " +\
1807 direction +\
Jon Hall21270ac2015-02-16 17:59:55 -08001808 " -s " + str( ip )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001809 # " -p " + str( packet_type ) +\
Jon Hall63604932015-02-26 17:09:50 -08001810 if packet_type:
1811 cmd += " -p " + str( packet_type )
Jon Hall21270ac2015-02-16 17:59:55 -08001812 if port:
1813 cmd += " --dport " + str( port )
Jon Hall63604932015-02-26 17:09:50 -08001814 if states:
1815 cmd += " -m state --state="
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001816 # FIXME- Allow user to configure which states to block
Jon Hall63604932015-02-26 17:09:50 -08001817 cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED"
Jon Hall21270ac2015-02-16 17:59:55 -08001818 cmd += " -j " + str( rule )
1819
1820 self.handle.sendline( cmd )
Devin Limc20e79a2017-06-07 10:29:57 -07001821 self.handle.expect( self.prompt )
Jon Hall21270ac2015-02-16 17:59:55 -08001822 main.log.warn( self.handle.before )
1823
1824 info_string = "On " + str( self.name )
1825 info_string += " " + str( action_type )
1826 info_string += " iptable rule [ "
1827 info_string += " IP: " + str( ip )
1828 info_string += " Port: " + str( port )
1829 info_string += " Rule: " + str( rule )
1830 info_string += " Direction: " + str( direction ) + " ]"
1831 main.log.info( info_string )
1832 return main.TRUE
1833 except pexpect.TIMEOUT:
1834 main.log.exception( self.name + ": Timeout exception in "
1835 "setIpTables function" )
1836 return main.ERROR
1837 except pexpect.EOF:
1838 main.log.error( self.name + ": EOF exception found" )
1839 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001840 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001841 except Exception:
1842 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001843 main.cleanAndExit()
Jon Hall21270ac2015-02-16 17:59:55 -08001844
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001845 def detailed_status( self, log_filename ):
Jon Hallefbd9792015-03-05 16:11:36 -08001846 """
Jon Hall0468b042015-02-19 19:08:21 -08001847 This method is used by STS to check the status of the controller
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001848 Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
Jon Hallefbd9792015-03-05 16:11:36 -08001849 """
Jon Hall0468b042015-02-19 19:08:21 -08001850 import re
1851 try:
1852 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001853 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001854 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -07001855 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001856 self.handle.sendline( "service onos status" )
Devin Limc20e79a2017-06-07 10:29:57 -07001857 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001858 response = self.handle.before
1859 if re.search( "onos start/running", response ):
1860 # onos start/running, process 10457
1861 return 'RUNNING'
1862 # FIXME: Implement this case
1863 # elif re.search( pattern, response ):
1864 # return 'STARTING'
1865 elif re.search( "onos stop/", response ):
1866 # onos stop/waiting
1867 # FIXME handle this differently?: onos stop/pre-stop
1868 return 'STOPPED'
1869 # FIXME: Implement this case
1870 # elif re.search( pattern, response ):
1871 # return 'FROZEN'
1872 else:
1873 main.log.warn( self.name +
Jon Hallefbd9792015-03-05 16:11:36 -08001874 " WARNING: status received unknown response" )
Jon Hall0468b042015-02-19 19:08:21 -08001875 main.log.warn( response )
1876 return 'ERROR', "Unknown response: %s" % response
1877 except pexpect.TIMEOUT:
1878 main.log.exception( self.name + ": Timeout exception in "
1879 "setIpTables function" )
1880 return 'ERROR', "Pexpect Timeout"
1881 except pexpect.EOF:
1882 main.log.error( self.name + ": EOF exception found" )
1883 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001884 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001885 except Exception:
1886 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001887 main.cleanAndExit()
Jon Hall0468b042015-02-19 19:08:21 -08001888
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001889 def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001890 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07001891 Create/formats the LinkGraph.cfg file based on arguments
1892 -only creates a linear topology and connects islands
1893 -evenly distributes devices
andrew@onlab.us3b087132015-03-11 15:00:08 -07001894 -must be called by ONOSbench
1895
Jon Hall4ba53f02015-07-29 13:07:41 -07001896 ONOSIpList - list of all of the node IPs to be used
1897
1898 deviceCount - number of switches to be assigned
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001899 '''
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001900 main.log.info( "Creating link graph configuration file." )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001901 linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg"
Jon Hall4ba53f02015-07-29 13:07:41 -07001902 tempFile = "/tmp/linkGraph.cfg"
andrew@onlab.us3b087132015-03-11 15:00:08 -07001903
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001904 linkGraph = open( tempFile, 'w+' )
1905 linkGraph.write( "# NullLinkProvider topology description (config file).\n" )
1906 linkGraph.write( "# The NodeId is only added if the destination is another node's device.\n" )
1907 linkGraph.write( "# Bugs: Comments cannot be appended to a line to be read.\n" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001908
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001909 clusterCount = len( ONOSIpList )
Jon Hall4ba53f02015-07-29 13:07:41 -07001910
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001911 if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
1912 deviceCount = int( deviceCount )
1913 switchList = [ 0 ]*( clusterCount+1 )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001914 baselineSwitchCount = deviceCount/clusterCount
Jon Hall4ba53f02015-07-29 13:07:41 -07001915
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001916 for node in range( 1, clusterCount + 1 ):
1917 switchList[ node ] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001918
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001919 for node in range( 1, ( deviceCount % clusterCount )+1 ):
1920 switchList[ node ] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001921
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001922 if isinstance( deviceCount, list ):
1923 main.log.info( "Using provided device distribution" )
1924 switchList = [ 0 ]
andrew@onlab.us3b087132015-03-11 15:00:08 -07001925 for i in deviceCount:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001926 switchList.append( int( i ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001927
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001928 tempList = [ '0' ]
1929 tempList.extend( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001930 ONOSIpList = tempList
1931
1932 myPort = 6
1933 lastSwitch = 0
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001934 for node in range( 1, clusterCount+1 ):
1935 if switchList[ node ] == 0:
andrew@onlab.us3b087132015-03-11 15:00:08 -07001936 continue
1937
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001938 linkGraph.write( "graph " + ONOSIpList[ node ] + " {\n" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001939
andrew@onlab.us3b087132015-03-11 15:00:08 -07001940 if node > 1:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001941 # connect to last device on previous node
1942 line = ( "\t0:5 -> " + str( lastSwitch ) + ":6:" + lastIp + "\n" ) # ONOSIpList[node-1]
1943 linkGraph.write( line )
Jon Hall4ba53f02015-07-29 13:07:41 -07001944
1945 lastSwitch = 0
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001946 for switch in range( 0, switchList[ node ]-1 ):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001947 line = ""
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001948 line = ( "\t" + str( switch ) + ":" + str( myPort ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001949 line += " -- "
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001950 line += ( str( switch+1 ) + ":" + str( myPort-1 ) + "\n" )
1951 linkGraph.write( line )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001952 lastSwitch = switch+1
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001953 lastIp = ONOSIpList[ node ]
Jon Hall4ba53f02015-07-29 13:07:41 -07001954
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001955 # lastSwitch += 1
1956 if node < ( clusterCount ):
1957 # connect to first device on the next node
1958 line = ( "\t" + str( lastSwitch ) + ":6 -> 0:5:" + ONOSIpList[ node+1 ] + "\n" )
1959 linkGraph.write( line )
Jon Hall4ba53f02015-07-29 13:07:41 -07001960
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001961 linkGraph.write( "}\n" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001962 linkGraph.close()
1963
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001964 # SCP
1965 os.system( "scp " + tempFile + " " + self.user_name + "@" + benchIp + ":" + linkGraphPath )
1966 main.log.info( "linkGraph.cfg creation complete" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001967
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001968 def configNullDev( self, ONOSIpList, deviceCount, numPorts=10 ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001969 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07001970 ONOSIpList = list of Ip addresses of nodes switches will be devided amongst
1971 deviceCount = number of switches to distribute, or list of values to use as custom distribution
cameron@onlab.us75900962015-03-30 13:22:49 -07001972 numPorts = number of ports per device. Defaults to 10 both in this function and in ONOS. Optional arg
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001973 '''
1974
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001975 main.log.info( "Configuring Null Device Provider" )
1976 clusterCount = len( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001977
Jon Hall4ba53f02015-07-29 13:07:41 -07001978 try:
1979
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001980 if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
1981 main.log.info( "Creating device distribution" )
1982 deviceCount = int( deviceCount )
1983 switchList = [ 0 ]*( clusterCount+1 )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001984 baselineSwitchCount = deviceCount/clusterCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001985
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001986 for node in range( 1, clusterCount + 1 ):
1987 switchList[ node ] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001988
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001989 for node in range( 1, ( deviceCount % clusterCount )+1 ):
1990 switchList[ node ] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001991
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001992 if isinstance( deviceCount, list ):
1993 main.log.info( "Using provided device distribution" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001994
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001995 if len( deviceCount ) == clusterCount:
1996 switchList = [ '0' ]
1997 switchList.extend( deviceCount )
Jon Hall4ba53f02015-07-29 13:07:41 -07001998
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001999 if len( deviceCount ) == ( clusterCount + 1 ):
2000 if deviceCount[ 0 ] == '0' or deviceCount[ 0 ] == 0:
cameron@onlab.us75900962015-03-30 13:22:49 -07002001 switchList = deviceCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07002002
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002003 assert len( switchList ) == ( clusterCount + 1 )
Jon Hall4ba53f02015-07-29 13:07:41 -07002004
cameron@onlab.us75900962015-03-30 13:22:49 -07002005 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002006 main.log.error( "Bad device/Ip list match" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002007 except TypeError:
2008 main.log.exception( self.name + ": Object not as expected" )
2009 return None
Jon Hall77ba41c2015-04-06 10:25:40 -07002010 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002011 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002012 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002013
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002014 ONOSIp = [ 0 ]
2015 ONOSIp.extend( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002016
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002017 devicesString = "devConfigs = "
2018 for node in range( 1, len( ONOSIp ) ):
2019 devicesString += ( ONOSIp[ node ] + ":" + str( switchList[ node ] ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002020 if node < clusterCount:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002021 devicesString += ( "," )
Jon Hall4ba53f02015-07-29 13:07:41 -07002022
2023 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002024 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString )
2025 self.handle.expect( ":~" )
2026 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str( numPorts ) )
2027 self.handle.expect( ":~" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002028
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002029 for i in range( 10 ):
2030 self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider" )
2031 self.handle.expect( ":~" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002032 verification = self.handle.before
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002033 if ( " value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification:
cameron@onlab.us75900962015-03-30 13:22:49 -07002034 break
2035 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002036 time.sleep( 1 )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002037
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002038 assert ( "value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07002039
cameron@onlab.us75900962015-03-30 13:22:49 -07002040 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002041 main.log.error( "Incorrect Config settings: " + verification )
Jon Hall77ba41c2015-04-06 10:25:40 -07002042 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002043 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002044 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002045
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002046 def configNullLink( self, fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0 ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002047 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002048 fileName default is currently the same as the default on ONOS, specify alternate file if
cameron@onlab.us75900962015-03-30 13:22:49 -07002049 you want to use a different topology file than linkGraph.cfg
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002050 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002051
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002052 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002053 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str( eventRate ) )
2054 self.handle.expect( ":~" )
2055 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName )
2056 self.handle.expect( ":~" )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002057
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002058 for i in range( 10 ):
2059 self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider" )
2060 self.handle.expect( ":~" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002061 verification = self.handle.before
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002062 if ( " value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification:
cameron@onlab.us75900962015-03-30 13:22:49 -07002063 break
Jon Hall4ba53f02015-07-29 13:07:41 -07002064 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002065 time.sleep( 1 )
Jon Hall4ba53f02015-07-29 13:07:41 -07002066
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002067 assert ( "value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07002068
cameron@onlab.us75900962015-03-30 13:22:49 -07002069 except pexpect.EOF:
2070 main.log.error( self.name + ": EOF exception found" )
2071 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002072 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002073 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002074 main.log.info( "Settings did not post to ONOS" )
2075 main.log.error( varification )
Jon Hall77ba41c2015-04-06 10:25:40 -07002076 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002077 main.log.exception( self.name + ": Uncaught exception!" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002078 main.log.error( varification )
Devin Lim44075962017-08-11 10:56:37 -07002079 main.cleanAndExit()
andrew@onlab.us3b087132015-03-11 15:00:08 -07002080
kelvin-onlaba4074292015-07-09 15:19:49 -07002081 def getOnosIps( self ):
2082 """
2083 Get all onos IPs stored in
2084 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002085
kelvin-onlaba4074292015-07-09 15:19:49 -07002086 return sorted( self.onosIps.values() )
cameron@onlab.us59d29d92015-05-11 14:31:54 -07002087
Chiyu Chengec63bde2016-11-17 18:11:36 -08002088 def listLog( self, nodeIp ):
2089 """
2090 Get a list of all the karaf log names
2091 """
2092 try:
2093 cmd = "onos-ssh " + nodeIp + " ls -tr /opt/onos/log"
2094 self.handle.sendline( cmd )
2095 self.handle.expect( ":~" )
2096 before = self.handle.before.splitlines()
2097 logNames = []
2098 for word in before:
2099 if 'karaf.log' in word:
2100 logNames.append( word )
2101 return logNames
2102 except pexpect.EOF:
2103 main.log.error( self.name + ": EOF exception found" )
2104 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002105 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002106 except pexpect.TIMEOUT:
2107 main.log.error( self.name + ": TIMEOUT exception found" )
2108 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002109 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002110 except Exception:
2111 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002112 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002113
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002114 def logReport( self, nodeIp, searchTerms, outputMode="s", startStr=None, endStr=None ):
Jon Hallb4242222016-01-25 17:07:04 -08002115 """
2116 Searches the latest ONOS log file for the given search terms and
2117 prints the total occurances of each term. Returns to combined total of
2118 all occurances.
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002119
Jon Hallb4242222016-01-25 17:07:04 -08002120 Arguments:
2121 * nodeIp - The ip of the ONOS node where the log is located
2122 * searchTerms - A string to grep for or a list of strings to grep
2123 for in the ONOS log. Will print out the number of
2124 occurances for each term.
2125 Optional Arguments:
2126 * outputMode - 's' or 'd'. If 'd' will print the last 5 lines
2127 containing each search term as well as the total
2128 number of occurances of each term. Defaults to 's',
2129 which prints the simple output of just the number
2130 of occurances for each term.
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002131 * startStr - the start string to be given to stream editor command
2132 as the start point for extraction of data
2133 * endStr - the end string to be given to stream editor command as
2134 the end point for extraction of data
Jon Hallb4242222016-01-25 17:07:04 -08002135 """
2136 try:
2137 main.log.info( " Log Report for {} ".format( nodeIp ).center( 70, '=' ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002138 if isinstance( searchTerms, str ):
2139 searchTerms = [ searchTerms ]
Jon Hallb4242222016-01-25 17:07:04 -08002140 numTerms = len( searchTerms )
2141 outputMode = outputMode.lower()
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002142
Jon Hallb4242222016-01-25 17:07:04 -08002143 totalHits = 0
2144 logLines = []
2145 for termIndex in range( numTerms ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002146 term = searchTerms[ termIndex ]
2147 logLines.append( [ term ] )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002148 if startStr and endStr:
2149 cmd = "onos-ssh {} \"sed -n '/{}/,/{}/p' /opt/onos/log/karaf.log | grep {}\"".format( nodeIp,
2150 startStr,
2151 endStr,
2152 term )
2153 else:
2154 cmd = "onos-ssh {} cat /opt/onos/log/karaf.log | grep {}".format( nodeIp,
2155 term )
Jon Hallb4242222016-01-25 17:07:04 -08002156 self.handle.sendline( cmd )
2157 self.handle.expect( ":~" )
2158 before = self.handle.before.splitlines()
2159 count = 0
2160 for line in before:
2161 if term in line and "grep" not in line:
2162 count += 1
2163 if before.index( line ) > ( len( before ) - 7 ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002164 logLines[ termIndex ].append( line )
Jon Hallb4242222016-01-25 17:07:04 -08002165 main.log.info( "{}: {}".format( term, count ) )
2166 totalHits += count
2167 if termIndex == numTerms - 1:
2168 print "\n"
2169 if outputMode != "s":
2170 outputString = ""
2171 for term in logLines:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002172 outputString = term[ 0 ] + ": \n"
Jon Hallb4242222016-01-25 17:07:04 -08002173 for line in range( 1, len( term ) ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002174 outputString += ( "\t" + term[ line ] + "\n" )
2175 if outputString != ( term[ 0 ] + ": \n" ):
Jon Hallb4242222016-01-25 17:07:04 -08002176 main.log.info( outputString )
2177 main.log.info( "=" * 70 )
2178 return totalHits
2179 except pexpect.EOF:
2180 main.log.error( self.name + ": EOF exception found" )
2181 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002182 main.cleanAndExit()
Jon Hallb4242222016-01-25 17:07:04 -08002183 except pexpect.TIMEOUT:
2184 main.log.error( self.name + ": TIMEOUT exception found" )
2185 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002186 main.cleanAndExit()
Jon Hallb4242222016-01-25 17:07:04 -08002187 except Exception:
2188 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002189 main.cleanAndExit()
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002190
2191 def copyMininetFile( self, fileName, localPath, userName, ip,
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002192 mnPath='~/mininet/custom/', timeout = 60 ):
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002193 """
2194 Description:
2195 Copy mininet topology file from dependency folder in the test folder
2196 and paste it to the mininet machine's mininet/custom folder
2197 Required:
2198 fileName - Name of the topology file to copy
2199 localPath - File path of the mininet topology file
2200 userName - User name of the mininet machine to send the file to
2201 ip - Ip address of the mininet machine
2202 Optional:
2203 mnPath - of the mininet directory to send the file to
2204 Return:
2205 Return main.TRUE if successfully copied the file otherwise
2206 return main.FALSE
2207 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002208
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002209 try:
2210 cmd = "scp " + localPath + fileName + " " + userName + "@" + \
2211 str( ip ) + ":" + mnPath + fileName
2212
2213 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07002214 self.handle.expect( self.prompt )
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002215
2216 main.log.info( self.name + ": Execute: " + cmd )
2217
2218 self.handle.sendline( cmd )
2219
2220 i = self.handle.expect( [ 'No such file',
2221 "100%",
2222 pexpect.TIMEOUT ] )
2223
2224 if i == 0:
2225 main.log.error( self.name + ": File " + fileName +
2226 " does not exist!" )
2227 return main.FALSE
2228
2229 if i == 1:
2230 main.log.info( self.name + ": File " + fileName +
2231 " has been copied!" )
2232 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07002233 self.handle.expect( self.prompt )
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002234 return main.TRUE
2235
2236 except pexpect.EOF:
2237 main.log.error( self.name + ": EOF exception found" )
2238 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002239 main.cleanAndExit()
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002240 except pexpect.TIMEOUT:
2241 main.log.error( self.name + ": TIMEOUT exception found" )
2242 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002243 main.cleanAndExit()
cameron@onlab.us78b89652015-07-08 15:21:03 -07002244
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002245 def jvmSet( self, memory=8 ):
Jon Hall4ba53f02015-07-29 13:07:41 -07002246
cameron@onlab.us78b89652015-07-08 15:21:03 -07002247 import os
2248
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002249 homeDir = os.path.expanduser( '~' )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002250 filename = "/onos/tools/package/bin/onos-service"
2251
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002252 serviceConfig = open( homeDir + filename, 'w+' )
2253 serviceConfig.write( "#!/bin/bash\n " )
2254 serviceConfig.write( "#------------------------------------- \n " )
2255 serviceConfig.write( "# Starts ONOS Apache Karaf container\n " )
2256 serviceConfig.write( "#------------------------------------- \n " )
2257 serviceConfig.write( "#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n " )
2258 serviceConfig.write( """export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str( memory ) + "G -Xmx" + str( memory ) + """G}" \n """ )
2259 serviceConfig.write( "[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n" )
2260 serviceConfig.write( """${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """ )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002261 serviceConfig.close()
2262
Jon Hall6c44c0b2016-04-20 15:21:00 -07002263 def createDBFile( self, testData ):
Jon Hall4ba53f02015-07-29 13:07:41 -07002264
cameron@onlab.us78b89652015-07-08 15:21:03 -07002265 filename = main.TEST + "DB"
2266 DBString = ""
Jon Hall4ba53f02015-07-29 13:07:41 -07002267
cameron@onlab.us78b89652015-07-08 15:21:03 -07002268 for item in testData:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002269 if isinstance( item, string ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002270 item = "'" + item + "'"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002271 if testData.index( item ) < len( testData - 1 ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002272 item += ","
Jon Hall6c44c0b2016-04-20 15:21:00 -07002273 DBString += str( item )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002274
Jon Hall6c44c0b2016-04-20 15:21:00 -07002275 DBFile = open( filename, "a" )
2276 DBFile.write( DBString )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002277 DBFile.close()
2278
Jon Hall6c44c0b2016-04-20 15:21:00 -07002279 def verifySummary( self, ONOSIp, *deviceCount ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002280
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002281 self.handle.sendline( "onos " + ONOSIp + " summary" )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002282 self.handle.expect( ":~" )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002283
2284 summaryStr = self.handle.before
2285 print "\nSummary\n==============\n" + summaryStr + "\n\n"
2286
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002287 # passed = "SCC(s)=1" in summaryStr
2288 # if deviceCount:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002289 # passed = "devices=" + str(deviceCount) + "," not in summaryStr
cameron@onlab.us78b89652015-07-08 15:21:03 -07002290
GlennRC772363b2015-08-25 13:05:57 -07002291 passed = False
cameron@onlab.us78b89652015-07-08 15:21:03 -07002292 if "SCC(s)=1," in summaryStr:
2293 passed = True
Jon Hall6c44c0b2016-04-20 15:21:00 -07002294 print "Summary is verifed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002295 else:
Jon Hall6c44c0b2016-04-20 15:21:00 -07002296 print "Summary failed"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002297
2298 if deviceCount:
2299 print" ============================="
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002300 checkStr = "devices=" + str( deviceCount[ 0 ] ) + ","
cameron@onlab.us78b89652015-07-08 15:21:03 -07002301 print "Checkstr: " + checkStr
2302 if checkStr not in summaryStr:
2303 passed = False
Jon Hall6c44c0b2016-04-20 15:21:00 -07002304 print "Device count failed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002305 else:
2306 print "device count verified"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002307
2308 return passed
Jon Hall6c44c0b2016-04-20 15:21:00 -07002309
Jon Hall8f6d4622016-05-23 15:27:18 -07002310 def getIpAddr( self, iface=None ):
Jon Hall6c44c0b2016-04-20 15:21:00 -07002311 """
2312 Update self.ip_address with numerical ip address. If multiple IP's are
2313 located on the device, will attempt to use self.nicAddr to choose the
2314 right one. Defaults to 127.0.0.1 if no other address is found or cannot
2315 determine the correct address.
2316
2317 ONLY WORKS WITH IPV4 ADDRESSES
2318 """
2319 try:
Jon Hall8f6d4622016-05-23 15:27:18 -07002320 LOCALHOST = "127.0.0.1"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002321 ipPat = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
2322 pattern = re.compile( ipPat )
2323 match = re.search( pattern, self.ip_address )
2324 if self.nicAddr:
2325 nicPat = self.nicAddr.replace( ".", "\." ).replace( "\*", r"\d{1,3}" )
2326 nicPat = re.compile( nicPat )
2327 else:
2328 nicPat = None
2329 # IF self.ip_address is an ip address and matches
2330 # self.nicAddr: return self.ip_address
2331 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002332 curIp = match.group( 0 )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002333 if nicPat:
2334 nicMatch = re.search( nicPat, curIp )
2335 if nicMatch:
2336 return self.ip_address
Jon Hall8f6d4622016-05-23 15:27:18 -07002337 # ELSE: IF iface, return ip of interface
2338 cmd = "ifconfig"
2339 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2340 if iface:
2341 cmd += " " + str( iface )
2342 raw = subprocess.check_output( cmd.split() )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002343 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2344 ips = re.findall( ifPat, raw )
Jon Hall8f6d4622016-05-23 15:27:18 -07002345 if iface:
2346 if ips:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002347 ip = ips[ 0 ]
Jon Hall8f6d4622016-05-23 15:27:18 -07002348 self.ip_address = ip
2349 return ip
2350 else:
2351 main.log.error( "Error finding ip, ifconfig output:".format( raw ) )
2352 # ELSE: attempt to get address matching nicPat.
Jon Hall6c44c0b2016-04-20 15:21:00 -07002353 if nicPat:
2354 for ip in ips:
2355 curMatch = re.search( nicPat, ip )
2356 if curMatch:
2357 self.ip_address = ip
2358 return ip
Jon Hall8f6d4622016-05-23 15:27:18 -07002359 else: # If only one non-localhost ip, return that
2360 tmpList = [ ip for ip in ips if ip is not LOCALHOST ]
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002361 if len( tmpList ) == 1:
2362 curIp = tmpList[ 0 ]
Jon Hall6c44c0b2016-04-20 15:21:00 -07002363 self.ip_address = curIp
2364 return curIp
Jon Hall8f6d4622016-05-23 15:27:18 -07002365 # Either no non-localhost IPs, or more than 1
Jon Hallebccd352016-05-20 15:17:17 -07002366 main.log.warn( "getIpAddr failed to find a public IP address" )
Jon Hall8f6d4622016-05-23 15:27:18 -07002367 return LOCALHOST
Jon Halle1790952016-05-23 15:51:46 -07002368 except subprocess.CalledProcessError:
Jon Hall8f6d4622016-05-23 15:27:18 -07002369 main.log.exception( "Error executing ifconfig" )
2370 except IndexError:
2371 main.log.exception( "Error getting IP Address" )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002372 except Exception:
2373 main.log.exception( "Uncaught exception" )
suibin zhang116647a2016-05-06 16:30:09 -07002374
Devin Lim461f0872017-06-05 16:49:33 -07002375 def startBasicONOS( self, nodeList, opSleep=60, onosStartupSleep=30, onosUser="sdn" ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002376 '''
suibin zhang116647a2016-05-06 16:30:09 -07002377 Start onos cluster with defined nodes, but only with drivers app
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002378 '''
suibin zhang116647a2016-05-06 16:30:09 -07002379 import time
2380
2381 self.createCellFile( self.ip_address,
2382 "temp",
2383 self.ip_address,
2384 "drivers",
Devin Lim461f0872017-06-05 16:49:33 -07002385 nodeList, onosUser )
suibin zhang116647a2016-05-06 16:30:09 -07002386
2387 main.log.info( self.name + ": Apply cell to environment" )
2388 cellResult = self.setCell( "temp" )
2389 verifyResult = self.verifyCell()
2390
2391 main.log.info( self.name + ": Creating ONOS package" )
You Wangd1bcaca2016-10-24 15:23:26 -07002392 packageResult = self.buckBuild( timeout=opSleep )
suibin zhang116647a2016-05-06 16:30:09 -07002393
You Wangc669d212017-01-25 11:09:48 -08002394 main.log.info( self.name + ": Uninstalling ONOS" )
2395 for nd in nodeList:
2396 self.onosUninstall( nodeIp=nd )
2397
suibin zhang116647a2016-05-06 16:30:09 -07002398 main.log.info( self.name + ": Installing ONOS package" )
2399 for nd in nodeList:
You Wangc669d212017-01-25 11:09:48 -08002400 self.onosInstall( node=nd )
2401
2402 main.log.info( self.name + ": Set up ONOS secure SSH" )
2403 for nd in nodeList:
2404 self.onosSecureSSH( node=nd )
suibin zhang116647a2016-05-06 16:30:09 -07002405
2406 main.log.info( self.name + ": Starting ONOS service" )
2407 time.sleep( onosStartupSleep )
2408
2409 onosStatus = True
2410 for nd in nodeList:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002411 onosStatus = onosStatus & self.isup( node = nd )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002412 # print "onosStatus is: " + str( onosStatus )
suibin zhang116647a2016-05-06 16:30:09 -07002413
2414 return main.TRUE if onosStatus else main.FALSE
2415
Devin Lim02075272017-07-10 15:33:21 -07002416 def onosNetCfg( self, controllerIp, path, fileName ):
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002417 """
2418 Push a specified json file to ONOS through the onos-netcfg service
2419
2420 Required:
Devin Lim02075272017-07-10 15:33:21 -07002421 controllerIp - the Ip of the ONOS node in the cluster
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002422 path - the location of the file to be sent
2423 fileName - name of the json file to be sent
2424
2425 Returns main.TRUE on successfully sending json file, and main.FALSE if
2426 there is an error.
2427 """
2428 try:
Devin Lim02075272017-07-10 15:33:21 -07002429 cmd = "onos-netcfg {0} {1}{2}".format( controllerIp, path, fileName )
2430 main.log.info( "Sending: " + cmd )
2431 main.ONOSbench.handle.sendline( cmd )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -07002432 main.ONOSbench.handle.expect( self.prompt )
Devin Lim02075272017-07-10 15:33:21 -07002433 handle = self.handle.before
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -07002434 if "Error" in handle or "No such file or directory" in handle or "curl: " in handle:
2435 main.log.error( self.name + ": " + handle + self.handle.after )
Devin Lim02075272017-07-10 15:33:21 -07002436 return main.FALSE
Devin Lim752dd7b2017-06-27 14:40:03 -07002437 return main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002438 except pexpect.EOF:
2439 main.log.error( self.name + ": EOF exception found" )
2440 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002441 main.cleanAndExit()
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002442 except Exception:
2443 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002444 main.cleanAndExit()
Devin Lim3ebd5e72017-11-14 10:38:00 -08002445
2446 def formCluster( self, onosIPs ):
2447 """
2448 From ONOS cluster for IP addresses in onosIPs list
2449 """
2450 try:
2451 onosIPs = " ".join( onosIPs )
2452 command = "onos-form-cluster {}".format( onosIPs )
2453 main.log.info( "Sending: " + command )
2454 self.handle.sendline( "" )
2455 self.handle.expect( self.prompt )
2456 self.handle.sendline( command )
2457 self.handle.expect( self.prompt )
2458 handle = self.handle.before
2459 main.log.debug( handle )
2460 assert handle is not None, "Error in sendline"
2461 assert "Command not found:" not in handle, handle
2462 assert "Error" not in handle, handle
2463 assert "Exception:" not in handle, handle
2464 assert "curl:" not in handle, handle
2465 return main.TRUE
2466 except AssertionError:
2467 main.log.exception( "{} Error in onos-form-cluster output:".format( self.name ) )
2468 return main.FALSE
2469 except TypeError:
2470 main.log.exception( self.name + ": Object not as expected" )
2471 return main.FALSE
2472 except pexpect.EOF:
2473 main.log.error( self.name + ": EOF exception found" )
2474 main.log.error( self.name + ": " + self.handle.before )
2475 main.cleanAndExit()
2476 except Exception:
2477 main.log.exception( self.name + ": Uncaught exception!" )
2478 main.cleanAndExit()
Jon Hall7ce46ea2018-02-05 12:20:59 -08002479
2480 def backupData( self, location ):
2481 """
2482 Backs up ONOS data and logs to a given location. Returns main.FALSE
2483 if there is an error executing the command, and main.TRUE otherwise.
2484 required arguments:
2485 loaction - The file path to save the backup to
2486 """
2487 try:
2488 cmd = "/opt/onos/bin/onos-backup " + str( location )
2489 self.handle.sendline( cmd )
2490 self.handle.expect( self.prompt )
2491 handle = self.handle.before
2492 main.log.debug( handle )
2493 assert handle is not None, "Error in sendline"
2494 assert "Command not found:" not in handle, handle
2495 assert "Error" not in handle, handle
2496 assert "Exception:" not in handle, handle
2497 return main.TRUE
2498 except AssertionError:
2499 main.log.exception( "{} Error in onos-backup output:".format( self.name ) )
2500 return main.FALSE
2501 except TypeError:
2502 main.log.exception( self.name + ": Object not as expected" )
2503 return main.FALSE
2504 except pexpect.EOF:
2505 main.log.error( self.name + ": EOF exception found" )
2506 main.log.error( self.name + ": " + self.handle.before )
2507 main.cleanAndExit()
2508 except Exception:
2509 main.log.exception( self.name + ": Uncaught exception!" )
2510 main.cleanAndExit()
2511
2512 def restoreData( self, location ):
2513 """
2514 Restores ONOS data and logs from a given location. Returns main.FALSE
2515 if there is an error executing the command, and main.TRUE otherwise.
2516 required arguments:
2517 loaction - The file path of a backup file
2518 """
2519 try:
2520 cmd = "/opt/onos/bin/onos-restore " + str( location )
2521 self.handle.sendline( cmd )
2522 self.handle.expect( self.prompt )
2523 handle = self.handle.before
2524 main.log.debug( handle )
2525 assert handle is not None, "Error in sendline"
2526 assert "Command not found:" not in handle, handle
2527 assert "Error" not in handle, handle
2528 assert "Exception:" not in handle, handle
2529 return main.TRUE
2530 except AssertionError:
2531 main.log.exception( "{} Error in onos-restore output:".format( self.name ) )
2532 return main.FALSE
2533 except TypeError:
2534 main.log.exception( self.name + ": Object not as expected" )
2535 return main.FALSE
2536 except pexpect.EOF:
2537 main.log.error( self.name + ": EOF exception found" )
2538 main.log.error( self.name + ": " + self.handle.before )
2539 main.cleanAndExit()
2540 except Exception:
2541 main.log.exception( self.name + ": Uncaught exception!" )
2542 main.cleanAndExit()