blob: 7e580fdc890cc57a9e5be0b2a2de428419e4590c [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"""
Jeremy Ronquilloec916a42018-02-02 13:05:57 -08004Copyright 2014 Open Networking Foundation (ONF)
5
kelvin8ec71442015-01-15 16:57:00 -08006This driver interacts with ONOS bench, the OSGi platform
7that configures the ONOS nodes. ( aka ONOS-next )
andrewonlabe8e56fd2014-10-09 17:12:44 -04008
kelvin8ec71442015-01-15 16:57:00 -08009Please follow the coding style demonstrated by existing
andrewonlabe8e56fd2014-10-09 17:12:44 -040010functions and document properly.
11
12If you are a contributor to the driver, please
13list your email here for future contact:
14
15jhall@onlab.us
16andrew@onlab.us
17
18OCT 9 2014
Jeremy Songsterae01bba2016-07-11 15:39:17 -070019Modified 2016 by ON.Lab
20
21Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
22the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
23or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
andrewonlabe8e56fd2014-10-09 17:12:44 -040024
kelvin8ec71442015-01-15 16:57:00 -080025"""
Jon Hall05b2b432014-10-08 19:53:25 -040026import time
Jon Hall6801cda2015-07-15 14:13:45 -070027import types
Jon Hall05b2b432014-10-08 19:53:25 -040028import pexpect
kelvin-onlaba4074292015-07-09 15:19:49 -070029import os
Jon Hall6c44c0b2016-04-20 15:21:00 -070030import re
31import subprocess
pingping-lin6d23d9e2015-02-02 16:54:24 -080032from requests.models import Response
Jon Hall05b2b432014-10-08 19:53:25 -040033from drivers.common.clidriver import CLI
34
kelvin8ec71442015-01-15 16:57:00 -080035class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040036
kelvin8ec71442015-01-15 16:57:00 -080037 def __init__( self ):
38 """
39 Initialize client
40 """
Jon Hallefbd9792015-03-05 16:11:36 -080041 self.name = None
42 self.home = None
43 self.handle = None
Jon Hall6c44c0b2016-04-20 15:21:00 -070044 self.nicAddr = None
Devin Limdc78e202017-06-09 18:30:07 -070045 super( OnosDriver, self ).__init__()
kelvin8ec71442015-01-15 16:57:00 -080046
47 def connect( self, **connectargs ):
48 """
Jon Hall05b2b432014-10-08 19:53:25 -040049 Creates ssh handle for ONOS "bench".
kelvin-onlaba4074292015-07-09 15:19:49 -070050 NOTE:
51 The ip_address would come from the topo file using the host tag, the
52 value can be an environment variable as well as a "localhost" to get
53 the ip address needed to ssh to the "bench"
kelvin8ec71442015-01-15 16:57:00 -080054 """
Jon Hall05b2b432014-10-08 19:53:25 -040055 try:
Devin Limdc78e202017-06-09 18:30:07 -070056
Jon Hall05b2b432014-10-08 19:53:25 -040057 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080058 vars( self )[ key ] = connectargs[ key ]
andrew@onlab.us3b087132015-03-11 15:00:08 -070059 self.home = "~/onos"
Jon Hall05b2b432014-10-08 19:53:25 -040060 for key in self.options:
61 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080062 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040063 break
Jon Hall274b6642015-02-17 11:57:17 -080064 if self.home is None or self.home == "":
Jon Halle94919c2015-03-23 11:42:57 -070065 self.home = "~/onos"
Jon Hall21270ac2015-02-16 17:59:55 -080066
kelvin8ec71442015-01-15 16:57:00 -080067 self.name = self.options[ 'name' ]
kelvin-onlaba4074292015-07-09 15:19:49 -070068
kelvin-onlabc2b79102015-07-14 11:41:20 -070069 # The 'nodes' tag is optional and it is not required in .topo file
kelvin-onlaba4074292015-07-09 15:19:49 -070070 for key in self.options:
71 if key == "nodes":
kelvin-onlabc2b79102015-07-14 11:41:20 -070072 # Maximum number of ONOS nodes to run, if there is any
kelvin-onlaba4074292015-07-09 15:19:49 -070073 self.maxNodes = int( self.options[ 'nodes' ] )
74 break
75 self.maxNodes = None
76
Jeremy Ronquillo82705492017-10-18 14:19:55 -070077 if self.maxNodes is None or self.maxNodes == "":
kelvin-onlabc2b79102015-07-14 11:41:20 -070078 self.maxNodes = 100
kelvin-onlaba4074292015-07-09 15:19:49 -070079
kelvin-onlabc2b79102015-07-14 11:41:20 -070080 # Grabs all OC environment variables based on max number of nodes
kelvin-onlaba4074292015-07-09 15:19:49 -070081 self.onosIps = {} # Dictionary of all possible ONOS ip
82
83 try:
84 if self.maxNodes:
kelvin-onlaba4074292015-07-09 15:19:49 -070085 for i in range( self.maxNodes ):
86 envString = "OC" + str( i + 1 )
kelvin-onlabc2b79102015-07-14 11:41:20 -070087 # If there is no more OC# then break the loop
88 if os.getenv( envString ):
89 self.onosIps[ envString ] = os.getenv( envString )
90 else:
91 self.maxNodes = len( self.onosIps )
92 main.log.info( self.name +
93 ": Created cluster data with " +
94 str( self.maxNodes ) +
95 " maximum number" +
96 " of nodes" )
97 break
kelvin-onlaba4074292015-07-09 15:19:49 -070098
99 if not self.onosIps:
100 main.log.info( "Could not read any environment variable"
101 + " please load a cell file with all" +
102 " onos IP" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700103 self.maxNodes = None
kelvin-onlaba4074292015-07-09 15:19:49 -0700104 else:
105 main.log.info( self.name + ": Found " +
106 str( self.onosIps.values() ) +
107 " ONOS IPs" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700108 except KeyError:
109 main.log.info( "Invalid environment variable" )
110 except Exception as inst:
111 main.log.error( "Uncaught exception: " + str( inst ) )
112
113 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700114 if os.getenv( str( self.ip_address ) ) is not None:
kelvin-onlaba4074292015-07-09 15:19:49 -0700115 self.ip_address = os.getenv( str( self.ip_address ) )
116 else:
117 main.log.info( self.name +
118 ": Trying to connect to " +
119 self.ip_address )
kelvin-onlaba4074292015-07-09 15:19:49 -0700120 except KeyError:
121 main.log.info( "Invalid host name," +
122 " connecting to local host instead" )
123 self.ip_address = 'localhost'
124 except Exception as inst:
125 main.log.error( "Uncaught exception: " + str( inst ) )
126
kelvin8ec71442015-01-15 16:57:00 -0800127 self.handle = super( OnosDriver, self ).connect(
128 user_name=self.user_name,
kelvin-onlab08679eb2015-01-21 16:11:48 -0800129 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800130 port=self.port,
131 pwd=self.pwd,
132 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -0400133
Jon Hall05b2b432014-10-08 19:53:25 -0400134 if self.handle:
Jon Hall0fc0d452015-07-14 09:49:58 -0700135 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700136 self.handle.expect( self.prompt )
Jon Hall05b2b432014-10-08 19:53:25 -0400137 return self.handle
kelvin8ec71442015-01-15 16:57:00 -0800138 else:
Jon Hall0fc0d452015-07-14 09:49:58 -0700139 main.log.info( "Failed to create ONOS handle" )
Jon Hall05b2b432014-10-08 19:53:25 -0400140 return main.FALSE
141 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800142 main.log.error( self.name + ": EOF exception found" )
143 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700144 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800145 except Exception:
146 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700147 main.cleanAndExit()
Jon Hall05b2b432014-10-08 19:53:25 -0400148
kelvin8ec71442015-01-15 16:57:00 -0800149 def disconnect( self ):
150 """
Jon Hall05b2b432014-10-08 19:53:25 -0400151 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -0800152 """
Jon Halld61331b2015-02-17 16:35:47 -0800153 response = main.TRUE
Jon Hall05b2b432014-10-08 19:53:25 -0400154 try:
Jon Hall61282e32015-03-19 11:34:11 -0700155 if self.handle:
156 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700157 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700158 self.handle.sendline( "exit" )
159 self.handle.expect( "closed" )
Jon Hall05b2b432014-10-08 19:53:25 -0400160 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800161 main.log.error( self.name + ": EOF exception found" )
162 main.log.error( self.name + ": " + self.handle.before )
Jon Hall61282e32015-03-19 11:34:11 -0700163 except ValueError:
Jon Hall1a77a1e2015-04-06 10:41:13 -0700164 main.log.exception( "Exception in disconnect of " + self.name )
Jon Hall61282e32015-03-19 11:34:11 -0700165 response = main.TRUE
Jon Hallfebb1c72015-03-05 13:30:09 -0800166 except Exception:
167 main.log.exception( self.name + ": Connection failed to the host" )
Jon Hall05b2b432014-10-08 19:53:25 -0400168 response = main.FALSE
169 return response
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400170
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400171 def getEpochMs( self ):
172 """
173 Returns milliseconds since epoch
Jon Hall4ba53f02015-07-29 13:07:41 -0700174
175 When checking multiple nodes in a for loop,
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000176 around a hundred milliseconds of difference (ascending) is
Jon Hall4ba53f02015-07-29 13:07:41 -0700177 generally acceptable due to calltime of the function.
178 Few seconds, however, is not and it means clocks
179 are off sync.
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400180 """
181 try:
182 self.handle.sendline( 'date +%s.%N' )
183 self.handle.expect( 'date \+\%s\.\%N' )
Devin Limdc78e202017-06-09 18:30:07 -0700184 self.handle.expect( self.prompt )
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400185 epochMs = self.handle.before
186 return epochMs
187 except Exception:
188 main.log.exception( 'Uncaught exception getting epoch time' )
Devin Lim44075962017-08-11 10:56:37 -0700189 main.cleanAndExit()
andrew@onlab.usaee415a2015-06-05 14:38:58 -0400190
Jon Hall6c44c0b2016-04-20 15:21:00 -0700191 def onosPackage( self, opTimeout=180 ):
kelvin8ec71442015-01-15 16:57:00 -0800192 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400193 Produce a self-contained tar.gz file that can be deployed
Jon Hall64af8502015-12-15 10:09:33 -0800194 and executed on any platform with Java 8 JRE.
kelvin8ec71442015-01-15 16:57:00 -0800195 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400196 try:
Jon Hall64af8502015-12-15 10:09:33 -0800197 ret = main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800198 self.handle.sendline( "onos-package" )
199 self.handle.expect( "onos-package" )
Jon Hall96451092016-05-04 09:42:30 -0700200 while True:
201 i = self.handle.expect( [ "Downloading",
202 "Unknown options",
203 "No such file or directory",
204 "tar.gz",
Devin Limc20e79a2017-06-07 10:29:57 -0700205 self.prompt ],
Jon Hall96451092016-05-04 09:42:30 -0700206 opTimeout )
207 handle = str( self.handle.before + self.handle.after )
208 if i == 0:
209 # Give more time to download the file
210 continue # expect again
211 elif i == 1:
212 # Incorrect usage
213 main.log.error( "onos-package does not recognize the given options" )
214 ret = main.FALSE
215 continue # expect again
216 elif i == 2:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000217 # File(s) not found
Jon Hall96451092016-05-04 09:42:30 -0700218 main.log.error( "onos-package could not find a file or directory" )
219 ret = main.FALSE
220 continue # expect again
221 elif i == 3:
222 # tar.gz
223 continue # expect again
224 elif i == 4:
225 # Prompt returned
226 break
Jon Hallc6793552016-01-19 14:18:37 -0800227 main.log.info( "onos-package command returned: " + handle )
kelvin8ec71442015-01-15 16:57:00 -0800228 # As long as the sendline does not time out,
229 # return true. However, be careful to interpret
230 # the results of the onos-package command return
Jon Hall64af8502015-12-15 10:09:33 -0800231 return ret
232 except pexpect.TIMEOUT:
233 main.log.exception( self.name + ": TIMEOUT exception found in onosPackage" )
234 main.log.error( self.name + ": " + self.handle.before )
235 return main.FALSE
andrewonlab7735d852014-10-09 13:02:47 -0400236 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800237 main.log.error( self.name + ": EOF exception found" )
238 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700239 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800240 except Exception:
241 main.log.exception( "Failed to package ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700242 main.cleanAndExit()
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400243
kelvin-onlabd3b64892015-01-20 13:26:24 -0800244 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800245 """
andrewonlab8790abb2014-11-06 13:51:54 -0500246 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800247 """
andrewonlab8790abb2014-11-06 13:51:54 -0500248 try:
kelvin8ec71442015-01-15 16:57:00 -0800249 self.handle.sendline( "onos-build" )
250 self.handle.expect( "onos-build" )
251 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800252 "BUILD SUCCESS",
253 "ERROR",
254 "BUILD FAILED" ],
255 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800256 handle = str( self.handle.before )
Devin Limc20e79a2017-06-07 10:29:57 -0700257 self.handle.expect( self.prompt )
andrewonlab8790abb2014-11-06 13:51:54 -0500258
kelvin8ec71442015-01-15 16:57:00 -0800259 main.log.info( "onos-build command returned: " +
260 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500261
262 if i == 0:
263 return main.TRUE
264 else:
265 return handle
266
267 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800268 main.log.error( self.name + ": EOF exception found" )
269 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800270 except Exception:
271 main.log.exception( "Failed to build ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700272 main.cleanAndExit()
andrewonlab8790abb2014-11-06 13:51:54 -0500273
shahshreya9f531fe2015-06-10 12:03:51 -0700274 def cleanInstall( self, skipTest=False, mciTimeout=600 ):
kelvin8ec71442015-01-15 16:57:00 -0800275 """
276 Runs mvn clean install in the root of the ONOS directory.
277 This will clean all ONOS artifacts then compile each module
shahshreya9f531fe2015-06-10 12:03:51 -0700278 Optional:
279 skipTest - Does "-DskipTests -Dcheckstyle.skip -U -T 1C" which
280 skip the test. This will make the building faster.
281 Disregarding the credibility of the build
kelvin8ec71442015-01-15 16:57:00 -0800282 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400283 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800284 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400285 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800286 main.log.info( "Running 'mvn clean install' on " +
287 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800288 ". This may take some time." )
289 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700290 self.handle.expect( self.prompt )
Jon Hallea7818b2014-10-09 14:30:59 -0400291
kelvin8ec71442015-01-15 16:57:00 -0800292 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700293 self.handle.expect( self.prompt )
shahshreya9f531fe2015-06-10 12:03:51 -0700294
295 if not skipTest:
296 self.handle.sendline( "mvn clean install" )
297 self.handle.expect( "mvn clean install" )
298 else:
299 self.handle.sendline( "mvn clean install -DskipTests" +
300 " -Dcheckstyle.skip -U -T 1C" )
301 self.handle.expect( "mvn clean install -DskipTests" +
302 " -Dcheckstyle.skip -U -T 1C" )
kelvin8ec71442015-01-15 16:57:00 -0800303 while True:
304 i = self.handle.expect( [
Jon Hall274b6642015-02-17 11:57:17 -0800305 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' +
Jon Hallefbd9792015-03-05 16:11:36 -0800306 'Runtime\sEnvironment\sto\scontinue',
Jon Hallde9d9aa2014-10-08 20:36:02 -0400307 'BUILD\sFAILURE',
308 'BUILD\sSUCCESS',
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700309 'onos' + self.prompt, # TODO: fix this to be more generic?
Devin Limdc78e202017-06-09 18:30:07 -0700310 'ONOS' + self.prompt,
pingping-lin57a56ce2015-05-20 16:43:48 -0700311 pexpect.TIMEOUT ], mciTimeout )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400312 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800313 main.log.error( self.name + ":There is insufficient memory \
314 for the Java Runtime Environment to continue." )
315 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700316
317 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400318 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800319 main.log.error( self.name + ": Build failure!" )
320 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700321
322 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400323 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800324 main.log.info( self.name + ": Build success!" )
Jon Halle94919c2015-03-23 11:42:57 -0700325 elif i == 3 or i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800326 main.log.info( self.name + ": Build complete" )
327 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400328 for line in self.handle.before.splitlines():
329 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800330 main.log.info( line )
331 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700332 self.handle.expect( self.prompt, timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400333 return main.TRUE
Jon Halle94919c2015-03-23 11:42:57 -0700334 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800335 main.log.error(
336 self.name +
337 ": mvn clean install TIMEOUT!" )
338 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700339
340 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400341 else:
Jon Hall274b6642015-02-17 11:57:17 -0800342 main.log.error( self.name + ": unexpected response from " +
Jon Hallefbd9792015-03-05 16:11:36 -0800343 "mvn clean install" )
kelvin8ec71442015-01-15 16:57:00 -0800344 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700345
346 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400347 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800348 main.log.error( self.name + ": EOF exception found" )
349 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700350 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800351 except Exception:
352 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700353 main.cleanAndExit()
Jon Hallacabffd2014-10-09 12:36:53 -0400354
Jon Hall3576f572016-08-23 10:01:07 -0700355 def buckBuild( self, timeout=180 ):
356 """
357 Build onos using buck.
358 """
359 try:
360 ret = main.TRUE
361 self.handle.sendline( "buck build onos" )
362 self.handle.expect( "buck build onos" )
363 output = ""
364 while True:
365 i = self.handle.expect( [ "This does not appear to be the root of a Buck project.",
366 "\n",
367 "BUILD FAILED",
Devin Limc20e79a2017-06-07 10:29:57 -0700368 self.prompt ],
Jon Hall3576f572016-08-23 10:01:07 -0700369 timeout=timeout )
370 output += str( self.handle.before + self.handle.after )
371 if i == 0:
372 main.log.error( "Wrong location" )
373 ret = main.FALSE
374 elif i == 1:
375 # end of a line, buck is still printing output
376 pass
377 elif i == 2:
378 # Build failed
379 main.log.error( "Build failed" )
380 ret = main.FALSE
381 elif i == 3:
382 # Prompt returned
383 break
384 main.log.debug( output )
385 return ret
386 except pexpect.TIMEOUT:
387 main.log.exception( self.name + ": TIMEOUT exception found" )
388 main.log.error( self.name + ": " + self.handle.before )
389 return main.FALSE
390 except pexpect.EOF:
391 main.log.error( self.name + ": EOF exception found" )
392 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700393 main.cleanAndExit()
Jon Hall3576f572016-08-23 10:01:07 -0700394 except Exception:
395 main.log.exception( "Failed to build and package ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700396 main.cleanAndExit()
Jon Hall3576f572016-08-23 10:01:07 -0700397
Jon Hall61282e32015-03-19 11:34:11 -0700398 def gitPull( self, comp1="", fastForward=True ):
kelvin8ec71442015-01-15 16:57:00 -0800399 """
Jon Hallacabffd2014-10-09 12:36:53 -0400400 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800401
Jon Hall61282e32015-03-19 11:34:11 -0700402 If the fastForward boolean is set to true, only git pulls that can
403 be fast forwarded will be performed. IE if you have not local commits
404 in your branch.
405
Jon Hallacabffd2014-10-09 12:36:53 -0400406 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800407 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400408 for the purpose of pulling from other nodes if necessary.
409
Jon Hall47a93fb2015-01-06 16:46:06 -0800410 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400411 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800412 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400413 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400414
kelvin8ec71442015-01-15 16:57:00 -0800415 """
Jon Hallacabffd2014-10-09 12:36:53 -0400416 try:
kelvin8ec71442015-01-15 16:57:00 -0800417 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700418 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700419 cmd = "git pull"
420 if comp1 != "":
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700421 cmd += ' ' + comp1
Jon Hall61282e32015-03-19 11:34:11 -0700422 if fastForward:
423 cmd += ' ' + " --ff-only"
424 self.handle.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800425 i = self.handle.expect(
426 [
427 'fatal',
428 'Username\sfor\s(.*):\s',
429 '\sfile(s*) changed,\s',
430 'Already up-to-date',
431 'Aborting',
432 'You\sare\snot\scurrently\son\sa\sbranch',
Jon Hall274b6642015-02-17 11:57:17 -0800433 'You asked me to pull without telling me which branch you',
434 'Pull is not possible because you have unmerged files',
Jon Hall61282e32015-03-19 11:34:11 -0700435 'Please enter a commit message to explain why this merge',
436 'Found a swap file by the name',
437 'Please, commit your changes before you can merge.',
kelvin-onlabd3b64892015-01-20 13:26:24 -0800438 pexpect.TIMEOUT ],
439 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800440 if i == 0:
Jon Hall61282e32015-03-19 11:34:11 -0700441 main.log.error( self.name + ": Git pull had some issue" )
442 output = self.handle.after
Devin Limdc78e202017-06-09 18:30:07 -0700443 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700444 output += self.handle.before
445 main.log.warn( output )
Jon Hallacabffd2014-10-09 12:36:53 -0400446 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800447 elif i == 1:
448 main.log.error(
449 self.name +
450 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400451 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800452 elif i == 2:
453 main.log.info(
454 self.name +
455 ": Git Pull - pulling repository now" )
Devin Limc20e79a2017-06-07 10:29:57 -0700456 self.handle.expect( self.prompt, 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800457 # So that only when git pull is done, we do mvn clean compile
458 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800459 elif i == 3:
460 main.log.info( self.name + ": Git Pull - Already up to date" )
Devin Limc20e79a2017-06-07 10:29:57 -0700461 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800462 elif i == 4:
463 main.log.info(
464 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800465 ": Git Pull - Aborting..." +
466 "Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400467 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800468 elif i == 5:
469 main.log.info(
470 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800471 ": Git Pull - You are not currently " +
472 "on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400473 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800474 elif i == 6:
475 main.log.info(
476 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800477 ": Git Pull - You have not configured an upstream " +
478 "branch to pull from. Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400479 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800480 elif i == 7:
481 main.log.info(
482 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800483 ": Git Pull - Pull is not possible because " +
484 "you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400485 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800486 elif i == 8:
Jon Hall61282e32015-03-19 11:34:11 -0700487 # NOTE: abandoning test since we can't reliably handle this
488 # there could be different default text editors and we
489 # also don't know if we actually want to make the commit
490 main.log.error( "Git pull resulted in a merge commit message" +
491 ". Exiting test!" )
Devin Lim44075962017-08-11 10:56:37 -0700492
493 main.cleanAndExit()
Jon Hall61282e32015-03-19 11:34:11 -0700494 elif i == 9: # Merge commit message but swap file exists
495 main.log.error( "Git pull resulted in a merge commit message" +
496 " but a swap file exists." )
497 try:
498 self.handle.send( 'A' ) # Abort
Devin Limc20e79a2017-06-07 10:29:57 -0700499 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700500 return main.ERROR
501 except Exception:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700502 main.log.exception( "Couldn't exit editor prompt!" )
Devin Lim44075962017-08-11 10:56:37 -0700503
504 main.cleanAndExit()
Jon Hall61282e32015-03-19 11:34:11 -0700505 elif i == 10: # In the middle of a merge commit
506 main.log.error( "Git branch is in the middle of a merge. " )
507 main.log.warn( self.handle.before + self.handle.after )
508 return main.ERROR
509 elif i == 11:
kelvin8ec71442015-01-15 16:57:00 -0800510 main.log.error( self.name + ": Git Pull - TIMEOUT" )
511 main.log.error(
512 self.name + " Response was: " + str(
513 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400514 return main.ERROR
515 else:
kelvin8ec71442015-01-15 16:57:00 -0800516 main.log.error(
517 self.name +
518 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400519 return main.ERROR
520 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800521 main.log.error( self.name + ": EOF exception found" )
522 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700523 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800524 except Exception:
525 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700526 main.cleanAndExit()
Jon Hallacabffd2014-10-09 12:36:53 -0400527
kelvin-onlabd3b64892015-01-20 13:26:24 -0800528 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800529 """
Jon Hallacabffd2014-10-09 12:36:53 -0400530 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800531
Jon Hallacabffd2014-10-09 12:36:53 -0400532 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800533 If used as gitCheckout( "branch" ) it will do git checkout
534 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400535
536 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800537 branch of the ONOS repository. If it has any problems, it will return
538 main.ERROR.
539 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400540 successful then the function will return main.TRUE.
541
kelvin8ec71442015-01-15 16:57:00 -0800542 """
Jon Hallacabffd2014-10-09 12:36:53 -0400543 try:
kelvin8ec71442015-01-15 16:57:00 -0800544 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700545 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800546 main.log.info( self.name +
547 ": Checking out git branch/ref: " + branch + "..." )
kelvin8ec71442015-01-15 16:57:00 -0800548 cmd = "git checkout " + branch
549 self.handle.sendline( cmd )
550 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800551 i = self.handle.expect(
Jon Hall274b6642015-02-17 11:57:17 -0800552 [ 'fatal',
Jon Hall61282e32015-03-19 11:34:11 -0700553 'Username for (.*): ',
554 'Already on \'',
Jon Hall7a8354f2015-06-10 15:37:00 -0700555 'Switched to (a new )?branch \'' + str( branch ),
Jon Hall274b6642015-02-17 11:57:17 -0800556 pexpect.TIMEOUT,
557 'error: Your local changes to the following files' +
Jon Hallefbd9792015-03-05 16:11:36 -0800558 'would be overwritten by checkout:',
Jon Hall274b6642015-02-17 11:57:17 -0800559 'error: you need to resolve your current index first',
560 "You are in 'detached HEAD' state.",
561 "HEAD is now at " ],
kelvin-onlabd3b64892015-01-20 13:26:24 -0800562 timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -0800563 if i == 0:
564 main.log.error(
565 self.name +
566 ": Git checkout had some issue..." )
567 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400568 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800569 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800570 main.log.error(
571 self.name +
572 ": Git checkout asking for username." +
573 " Please configure your local git repository to be able " +
574 "to access your remote repository passwordlessly" )
Jon Hall274b6642015-02-17 11:57:17 -0800575 # TODO add support for authenticating
Jon Hallacabffd2014-10-09 12:36:53 -0400576 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800577 elif i == 2:
578 main.log.info(
579 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800580 ": Git Checkout %s : Already on this branch" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700581 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800582 # main.log.info( "DEBUG: after checkout cmd = "+
583 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400584 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800585 elif i == 3:
586 main.log.info(
587 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800588 ": Git checkout %s - Switched to this branch" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700589 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800590 # main.log.info( "DEBUG: after checkout cmd = "+
591 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400592 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800593 elif i == 4:
594 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
595 main.log.error(
Jon Hall274b6642015-02-17 11:57:17 -0800596 self.name + " Response was: " + str( self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400597 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800598 elif i == 5:
599 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800600 main.log.error(
601 self.name +
602 ": Git checkout error: \n" +
Jon Hall274b6642015-02-17 11:57:17 -0800603 "Your local changes to the following files would" +
604 " be overwritten by checkout:" +
605 str( self.handle.before ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700606 self.handle.expect( self.prompt )
Jon Hall81e29af2014-11-04 20:41:23 -0500607 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800608 elif i == 6:
Jon Hall274b6642015-02-17 11:57:17 -0800609 main.log.error(
610 self.name +
611 ": Git checkout error: \n" +
612 "You need to resolve your current index first:" +
613 str( self.handle.before ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700614 self.handle.expect( self.prompt )
Jon Hall81e29af2014-11-04 20:41:23 -0500615 return main.ERROR
Jon Hall274b6642015-02-17 11:57:17 -0800616 elif i == 7:
617 main.log.info(
618 self.name +
619 ": Git checkout " + str( branch ) +
620 " - You are in 'detached HEAD' state. HEAD is now at " +
621 str( branch ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700622 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800623 return main.TRUE
624 elif i == 8: # Already in detached HEAD on the specified commit
625 main.log.info(
626 self.name +
627 ": Git Checkout %s : Already on commit" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700628 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800629 return main.TRUE
Jon Hallacabffd2014-10-09 12:36:53 -0400630 else:
kelvin8ec71442015-01-15 16:57:00 -0800631 main.log.error(
632 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800633 ": Git Checkout - Unexpected response, " +
634 "check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800635 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400636 return main.ERROR
637
638 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800639 main.log.error( self.name + ": EOF exception found" )
640 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700641 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800642 except Exception:
643 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700644 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400645
pingping-lin6d23d9e2015-02-02 16:54:24 -0800646 def getBranchName( self ):
You Wang9cdf9a22017-05-01 13:44:18 -0700647 import re
648 try:
649 main.log.info( "self.home = " )
650 main.log.info( self.home )
651 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700652 self.handle.expect( self.prompt )
You Wang9cdf9a22017-05-01 13:44:18 -0700653 self.handle.sendline( "git name-rev --name-only HEAD" )
654 self.handle.expect( "git name-rev --name-only HEAD" )
Devin Limc20e79a2017-06-07 10:29:57 -0700655 self.handle.expect( self.prompt )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700656 lines = self.handle.before.splitlines()
657 if lines[ 1 ] == "master" or re.search( "^onos-\d+(\.\d+)+$", lines[ 1 ] ):
658 return lines[ 1 ]
You Wang9cdf9a22017-05-01 13:44:18 -0700659 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700660 main.log.info( lines[ 1 ] )
You Wang9cdf9a22017-05-01 13:44:18 -0700661 return "unexpected ONOS branch"
662 except pexpect.EOF:
663 main.log.error( self.name + ": EOF exception found" )
664 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700665 main.cleanAndExit()
You Wang9cdf9a22017-05-01 13:44:18 -0700666 except pexpect.TIMEOUT:
667 main.log.error( self.name + ": TIMEOUT exception found" )
668 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700669 main.cleanAndExit()
You Wang9cdf9a22017-05-01 13:44:18 -0700670 except Exception:
671 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700672 main.cleanAndExit()
pingping-lin6d23d9e2015-02-02 16:54:24 -0800673
kelvin-onlabd3b64892015-01-20 13:26:24 -0800674 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800675 """
Jon Hall274b6642015-02-17 11:57:17 -0800676 Writes the COMMIT number to the report to be parsed
Jon Hallefbd9792015-03-05 16:11:36 -0800677 by Jenkins data collector.
kelvin8ec71442015-01-15 16:57:00 -0800678 """
Jon Hall45ec0922014-10-10 19:33:49 -0400679 try:
kelvin8ec71442015-01-15 16:57:00 -0800680 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700681 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800682 self.handle.sendline(
683 "cd " +
684 self.home +
Jon Hall274b6642015-02-17 11:57:17 -0800685 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " +
686 " \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800687 # NOTE: for some reason there are backspaces inserted in this
688 # phrase when run from Jenkins on some tests
689 self.handle.expect( "never" )
Devin Limc20e79a2017-06-07 10:29:57 -0700690 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800691 response = ( self.name + ": \n" + str(
692 self.handle.before + self.handle.after ) )
693 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700694 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800695 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400696 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500697 print line
698 if report:
pingping-lin763ee042015-05-20 17:45:30 -0700699 main.log.wiki( "<blockquote>" )
kelvin8ec71442015-01-15 16:57:00 -0800700 for line in lines[ 2:-1 ]:
701 # Bracket replacement is for Wiki-compliant
702 # formatting. '<' or '>' are interpreted
703 # as xml specific tags that cause errors
704 line = line.replace( "<", "[" )
705 line = line.replace( ">", "]" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700706 # main.log.wiki( "\t" + line )
pingping-lin763ee042015-05-20 17:45:30 -0700707 main.log.wiki( line + "<br /> " )
708 main.log.summary( line )
709 main.log.wiki( "</blockquote>" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700710 main.log.summary( "\n" )
kelvin8ec71442015-01-15 16:57:00 -0800711 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400712 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800713 main.log.error( self.name + ": EOF exception found" )
714 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700715 main.cleanAndExit()
Jon Hall368769f2014-11-19 15:43:35 -0800716 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800717 main.log.error( self.name + ": TIMEOUT exception found" )
718 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700719 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800720 except Exception:
721 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700722 main.cleanAndExit()
Jon Hall45ec0922014-10-10 19:33:49 -0400723
kelvin-onlabd3b64892015-01-20 13:26:24 -0800724 def createCellFile( self, benchIp, fileName, mnIpAddrs,
Jon Hall810b67d2016-12-05 10:19:01 -0800725 appString, onosIpAddrs, onosUser="sdn", useSSH=True ):
kelvin8ec71442015-01-15 16:57:00 -0800726 """
andrewonlab94282092014-10-10 13:00:11 -0400727 Creates a cell file based on arguments
728 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800729 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400730 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800731 * File name of the cell file ( fileName )
732 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800733 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400734 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800735 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400736 - Must be passed in as last arguments
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000737 * ONOS USER (onosUser)
Flavio Castrocc38a542016-03-03 13:15:46 -0800738 - optional argument to set ONOS_USER environment variable
kelvin8ec71442015-01-15 16:57:00 -0800739
andrewonlab94282092014-10-10 13:00:11 -0400740 NOTE: Assumes cells are located at:
741 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800742 """
andrewonlab94282092014-10-10 13:00:11 -0400743 try:
Devin Lim461f0872017-06-05 16:49:33 -0700744
Jon Hall2c8959e2016-12-16 12:17:34 -0800745 # Variable initialization
746 cellDirectory = self.home + "/tools/test/cells/"
747 # We want to create the cell file in the dependencies directory
748 # of TestON first, then copy over to ONOS bench
749 tempDirectory = "/tmp/"
750 # Create the cell file in the directory for writing ( w+ )
751 cellFile = open( tempDirectory + fileName, 'w+' )
752 if isinstance( onosIpAddrs, types.StringType ):
753 onosIpAddrs = [ onosIpAddrs ]
754
755 # App string is hardcoded environment variables
756 # That you may wish to use by default on startup.
757 # Note that you may not want certain apps listed
758 # on here.
759 appString = "export ONOS_APPS=" + appString
760 onosGroup = "export ONOS_GROUP=" + onosUser
761 onosUser = "export ONOS_USER=" + onosUser
762 if useSSH:
763 onosUseSSH = "export ONOS_USE_SSH=true"
764 mnString = "export OCN="
765 if mnIpAddrs == "":
766 mnString = ""
767 onosString = "export OC"
768 tempCount = 1
769
770 # Create ONOSNIC ip address prefix
771 tempOnosIp = str( onosIpAddrs[ 0 ] )
772 tempList = []
773 tempList = tempOnosIp.split( "." )
774 # Omit last element of list to format for NIC
775 tempList = tempList[ :-1 ]
776 # Structure the nic string ip
777 nicAddr = ".".join( tempList ) + ".*"
778 self.nicAddr = nicAddr
779 onosNicString = "export ONOS_NIC=" + nicAddr
780
kelvin8ec71442015-01-15 16:57:00 -0800781 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800782 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400783
kelvin-onlabd3b64892015-01-20 13:26:24 -0800784 for arg in onosIpAddrs:
785 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800786 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400787 # export OC1="10.128.20.11"
788 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800789 cellFile.write( onosString + str( tempCount ) +
Jon Hall6f665652015-09-18 10:08:07 -0700790 "=\"" + arg + "\"\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800791 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800792
Jon Hall6f665652015-09-18 10:08:07 -0700793 cellFile.write( "export OCI=$OC1\n" )
794 cellFile.write( mnString + "\"" + mnIpAddrs + "\"\n" )
cameron@onlab.us75900962015-03-30 13:22:49 -0700795 cellFile.write( appString + "\n" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800796 cellFile.write( onosGroup + "\n" )
797 cellFile.write( onosUser + "\n" )
Pier88189b62016-09-07 17:01:53 -0700798 if useSSH:
799 cellFile.write( onosUseSSH + "\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800800 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400801
kelvin8ec71442015-01-15 16:57:00 -0800802 # We use os.system to send the command to TestON cluster
803 # to account for the case in which TestON is not located
804 # on the same cluster as the ONOS bench
805 # Note that even if TestON is located on the same cluster
806 # as ONOS bench, you must setup passwordless ssh
807 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabc2b79102015-07-14 11:41:20 -0700808 os.system( "scp " + tempDirectory + fileName + " " +
809 self.user_name + "@" + self.ip_address + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400810
andrewonlab2a6c9342014-10-16 13:40:15 -0400811 return main.TRUE
812
andrewonlab94282092014-10-10 13:00:11 -0400813 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800814 main.log.error( self.name + ": EOF exception found" )
815 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700816 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800817 except Exception:
818 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700819 main.cleanAndExit()
andrewonlab94282092014-10-10 13:00:11 -0400820
kelvin-onlabd3b64892015-01-20 13:26:24 -0800821 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800822 """
andrewonlab95ca1462014-10-09 14:04:24 -0400823 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800824 """
andrewonlab95ca1462014-10-09 14:04:24 -0400825 try:
826 if not cellname:
You Wang1cdc5f52017-12-19 16:47:51 -0800827 main.log.error( self.name + ": Must define cellname" )
Devin Lim44075962017-08-11 10:56:37 -0700828 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400829 else:
kelvin8ec71442015-01-15 16:57:00 -0800830 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800831 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800832 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400833 # and that this driver will have to change accordingly
Jon Hall3b489db2015-10-05 14:38:37 -0700834 self.handle.expect( str( cellname ) )
You Wang1cdc5f52017-12-19 16:47:51 -0800835 i = self.handle.expect( [ "No such cell",
836 self.prompt,
837 pexpect.TIMEOUT ], timeout=10 )
838 if i == 0:
839 main.log.error( self.name + ": No such cell. Response: " + str( self.handle.before ) )
840 main.cleanAndExit()
841 elif i == 1:
842 main.log.info( self.name + ": Successfully set cell: " + str( self.handle.before ) )
843 elif i == 2:
844 main.log.error( self.name + ": Set cell timed out. Response: " + str( self.handle.before ) )
845 main.cleanAndExit()
846 else:
847 main.log.error( self.name + ": Unexpected response: " + str( self.handle.before ) )
Devin Lim44075962017-08-11 10:56:37 -0700848 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400849 return main.TRUE
You Wang1cdc5f52017-12-19 16:47:51 -0800850 except pexpect.TIMEOUT:
851 main.log.error( self.name + ": TIMEOUT exception found" )
852 main.log.error( self.name + ": " + self.handle.before )
853 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400854 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800855 main.log.error( self.name + ": EOF exception found" )
856 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700857 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800858 except Exception:
859 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700860 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400861
kelvin-onlabd3b64892015-01-20 13:26:24 -0800862 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800863 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400864 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800865 """
866 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400867
andrewonlabc03bf6c2014-10-09 14:56:18 -0400868 try:
kelvin8ec71442015-01-15 16:57:00 -0800869 # Clean handle by sending empty and expecting $
870 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700871 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800872 self.handle.sendline( "onos-verify-cell" )
Devin Limc20e79a2017-06-07 10:29:57 -0700873 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800874 handleBefore = self.handle.before
875 handleAfter = self.handle.after
kelvin-onlabd3b64892015-01-20 13:26:24 -0800876 main.log.info( "Verify cell returned: " + handleBefore +
Jon Hall3b489db2015-10-05 14:38:37 -0700877 handleAfter )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400878 return main.TRUE
Jon Halla5cb6172015-02-23 09:28:28 -0800879 except pexpect.ExceptionPexpect as e:
Jon Hall3b489db2015-10-05 14:38:37 -0700880 main.log.exception( self.name + ": Pexpect exception found: " )
kelvin8ec71442015-01-15 16:57:00 -0800881 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700882 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800883 except Exception:
884 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700885 main.cleanAndExit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400886
jenkins1e99e7b2015-04-02 18:15:39 -0700887 def onosCfgSet( self, ONOSIp, configName, configParam ):
888 """
889 Uses 'onos <node-ip> cfg set' to change a parameter value of an
Jon Hall4ba53f02015-07-29 13:07:41 -0700890 application.
891
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000892 ex)
jenkins1e99e7b2015-04-02 18:15:39 -0700893 onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1
jenkins1e99e7b2015-04-02 18:15:39 -0700894 ONOSIp = '10.0.0.1'
895 configName = 'org.onosproject.myapp'
896 configParam = 'appSetting 1'
jenkins1e99e7b2015-04-02 18:15:39 -0700897 """
Jon Hall72280bc2016-01-25 14:29:05 -0800898 try:
899 cfgStr = "onos {} cfg set {} {}".format( ONOSIp,
900 configName,
901 configParam )
902 self.handle.sendline( "" )
903 self.handle.expect( ":~" )
904 self.handle.sendline( cfgStr )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700905 self.handle.expect( "cfg set" )
Jon Hall72280bc2016-01-25 14:29:05 -0800906 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700907
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700908 paramValue = configParam.split( " " )[ 1 ]
909 paramName = configParam.split( " " )[ 0 ]
Jon Hall4ba53f02015-07-29 13:07:41 -0700910
Jon Hall72280bc2016-01-25 14:29:05 -0800911 checkStr = 'onos {} cfg get " {} {} " '.format( ONOSIp, configName, paramName )
Jon Hall4ba53f02015-07-29 13:07:41 -0700912
Jon Hall72280bc2016-01-25 14:29:05 -0800913 self.handle.sendline( checkStr )
914 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700915
Jon Hall72280bc2016-01-25 14:29:05 -0800916 if "value=" + paramValue + "," in self.handle.before:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700917 main.log.info( "cfg " + configName + " successfully set to " + configParam )
Jon Hall72280bc2016-01-25 14:29:05 -0800918 return main.TRUE
919 except pexpect.ExceptionPexpect as e:
920 main.log.exception( self.name + ": Pexpect exception found: " )
921 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700922 main.cleanAndExit()
Jon Hall72280bc2016-01-25 14:29:05 -0800923 except Exception:
924 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700925 main.cleanAndExit()
Jon Hall4ba53f02015-07-29 13:07:41 -0700926
kelvin-onlabd3b64892015-01-20 13:26:24 -0800927 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800928 """
andrewonlab05e362f2014-10-10 00:40:57 -0400929 Uses 'onos' command to send various ONOS CLI arguments.
930 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800931 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400932 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800933
934 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400935 CLI commands for ONOS. Try to use this function first
936 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800937 function.
938 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400939 by starting onos, and typing in 'onos' to enter the
940 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800941 available commands.
942 """
andrewonlab05e362f2014-10-10 00:40:57 -0400943 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800944 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800945 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400946 return main.FALSE
947 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800948 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400949 return main.FALSE
950
kelvin8ec71442015-01-15 16:57:00 -0800951 cmdstr = str( cmdstr )
952 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700953 self.handle.expect( self.prompt )
andrewonlab05e362f2014-10-10 00:40:57 -0400954
Jeremy Ronquilloec916a42018-02-02 13:05:57 -0800955 self.handle.sendline( "onos-wait-for-start " + ONOSIp + " " + cmdstr )
Devin Limc20e79a2017-06-07 10:29:57 -0700956 self.handle.expect( self.prompt )
andrewonlab05e362f2014-10-10 00:40:57 -0400957
kelvin-onlabd3b64892015-01-20 13:26:24 -0800958 handleBefore = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800959 main.log.info( "Command sent successfully" )
kelvin8ec71442015-01-15 16:57:00 -0800960 # Obtain return handle that consists of result from
961 # the onos command. The string may need to be
962 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800963 returnString = handleBefore
kelvin-onlabd3b64892015-01-20 13:26:24 -0800964 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400965 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800966 main.log.error( self.name + ": EOF exception found" )
967 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700968 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800969 except Exception:
970 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700971 main.cleanAndExit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400972
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700973 def onosSecureSSH( self, userName="onos", userPWD="rocks", node="" ):
Pier88189b62016-09-07 17:01:53 -0700974 """
975 Enables secure access to ONOS console
976 by removing default users & keys.
977
978 onos-secure-ssh -u onos -p rocks node
979
980 Returns: main.TRUE on success and main.FALSE on failure
981 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000982
Pier88189b62016-09-07 17:01:53 -0700983 try:
Chiyu Chengef109502016-11-21 15:51:38 -0800984 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700985 self.handle.expect( self.prompt )
Pier88189b62016-09-07 17:01:53 -0700986 self.handle.sendline( " onos-secure-ssh -u " + userName + " -p " + userPWD + " " + node )
987
988 # NOTE: this timeout may need to change depending on the network
989 # and size of ONOS
990 # TODO: Handle the other possible error
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700991 i = self.handle.expect( [ "Network\sis\sunreachable",
992 self.prompt,
993 pexpect.TIMEOUT ], timeout=180 )
Pier88189b62016-09-07 17:01:53 -0700994 if i == 0:
995 # can't reach ONOS node
996 main.log.warn( "Network is unreachable" )
Devin Limc20e79a2017-06-07 10:29:57 -0700997 self.handle.expect( self.prompt )
Pier88189b62016-09-07 17:01:53 -0700998 return main.FALSE
999 elif i == 1:
1000 # Process started
1001 main.log.info(
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001002 "Secure SSH performed on " +
1003 node )
Pier88189b62016-09-07 17:01:53 -07001004 return main.TRUE
1005 except pexpect.EOF:
1006 main.log.error( self.name + ": EOF exception found" )
1007 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001008 main.cleanAndExit()
Pier88189b62016-09-07 17:01:53 -07001009 except Exception:
1010 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001011 main.cleanAndExit()
Pier88189b62016-09-07 17:01:53 -07001012
kelvin-onlabd3b64892015-01-20 13:26:24 -08001013 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001014 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001015 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -08001016 If -f option is provided, it also forces an uninstall.
1017 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -04001018 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -08001019 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -04001020 files to certain onos nodes
1021
1022 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -08001023 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001024 try:
andrewonlab114768a2014-11-14 12:44:44 -05001025 if options:
kelvin8ec71442015-01-15 16:57:00 -08001026 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -05001027 else:
kelvin8ec71442015-01-15 16:57:00 -08001028 self.handle.sendline( "onos-install " + node )
1029 self.handle.expect( "onos-install " )
1030 # NOTE: this timeout may need to change depending on the network
1031 # and size of ONOS
1032 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001033 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -08001034 "ONOS\sis\salready\sinstalled",
Jeremyc72b2582016-02-26 18:27:38 -08001035 "already\sup-to-date",
Jon Hall3576f572016-08-23 10:01:07 -07001036 "does not exist",
Devin Limc20e79a2017-06-07 10:29:57 -07001037 self.prompt,
Jon Hall6c44c0b2016-04-20 15:21:00 -07001038 pexpect.TIMEOUT ], timeout=180 )
Jon Hall7993bfc2014-10-09 16:30:14 -04001039 if i == 0:
Jon Hall3576f572016-08-23 10:01:07 -07001040 # can't reach ONOS node
kelvin8ec71442015-01-15 16:57:00 -08001041 main.log.warn( "Network is unreachable" )
Devin Limc20e79a2017-06-07 10:29:57 -07001042 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001043 return main.FALSE
1044 elif i == 1:
Jon Hall3576f572016-08-23 10:01:07 -07001045 # Process started
kelvin8ec71442015-01-15 16:57:00 -08001046 main.log.info(
1047 "ONOS was installed on " +
1048 node +
1049 " and started" )
Devin Limc20e79a2017-06-07 10:29:57 -07001050 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001051 return main.TRUE
Jon Hall3576f572016-08-23 10:01:07 -07001052 elif i == 2 or i == 3:
1053 # same bits are already on ONOS node
Jeremyc72b2582016-02-26 18:27:38 -08001054 main.log.info( "ONOS is already installed on " + node )
Devin Limc20e79a2017-06-07 10:29:57 -07001055 self.handle.expect( self.prompt )
Jeremyc72b2582016-02-26 18:27:38 -08001056 return main.TRUE
1057 elif i == 4:
Jon Hall3576f572016-08-23 10:01:07 -07001058 # onos not packaged
1059 main.log.error( "ONOS package not found." )
Devin Limc20e79a2017-06-07 10:29:57 -07001060 self.handle.expect( self.prompt )
Jon Hall3576f572016-08-23 10:01:07 -07001061 return main.FALSE
1062 elif i == 5:
1063 # prompt
Jeremyc72b2582016-02-26 18:27:38 -08001064 main.log.info( "ONOS was installed on " + node )
1065 return main.TRUE
Jon Hall3576f572016-08-23 10:01:07 -07001066 elif i == 6:
1067 # timeout
kelvin8ec71442015-01-15 16:57:00 -08001068 main.log.info(
1069 "Installation of ONOS on " +
1070 node +
1071 " timed out" )
Devin Limc20e79a2017-06-07 10:29:57 -07001072 self.handle.expect( self.prompt )
Jon Hall53c5e662016-04-13 16:06:56 -07001073 main.log.warn( self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001074 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -04001075 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001076 main.log.error( self.name + ": EOF exception found" )
1077 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001078 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001079 except Exception:
1080 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001081 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -04001082
kelvin-onlabd3b64892015-01-20 13:26:24 -08001083 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001084 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001085 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001086 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001087 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001088 try:
kelvin8ec71442015-01-15 16:57:00 -08001089 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001090 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001091 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001092 " start" )
1093 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -04001094 "Job\sis\salready\srunning",
1095 "start/running",
Devin Limc20e79a2017-06-07 10:29:57 -07001096 self.prompt,
andrewonlab8d0d7d72014-10-09 16:33:15 -04001097 "Unknown\sinstance",
Jeremy Songster14c13572016-04-21 17:34:03 -07001098 pexpect.TIMEOUT ], timeout=180 )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001099 if i == 0:
Devin Limc20e79a2017-06-07 10:29:57 -07001100 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001101 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001102 return main.TRUE
1103 elif i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001104 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001105 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001106 return main.TRUE
Jeremyd0e9a6d2016-03-02 11:28:52 -08001107 elif i == 2:
1108 main.log.info( "ONOS service started" )
1109 return main.TRUE
andrewonlab8d0d7d72014-10-09 16:33:15 -04001110 else:
Devin Limc20e79a2017-06-07 10:29:57 -07001111 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001112 main.log.error( "ONOS service failed to start" )
Devin Lim44075962017-08-11 10:56:37 -07001113
1114 main.cleanAndExit()
andrewonlab8d0d7d72014-10-09 16:33:15 -04001115 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001116 main.log.error( self.name + ": EOF exception found" )
1117 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001118 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001119 except Exception:
1120 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001121 main.cleanAndExit()
andrewonlab8d0d7d72014-10-09 16:33:15 -04001122
kelvin-onlabd3b64892015-01-20 13:26:24 -08001123 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001124 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001125 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001126 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001127 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001128 try:
kelvin8ec71442015-01-15 16:57:00 -08001129 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001130 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001131 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001132 " stop" )
1133 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -04001134 "stop/waiting",
Jon Hall61282e32015-03-19 11:34:11 -07001135 "Could not resolve hostname",
andrewonlab2b30bd32014-10-09 16:48:55 -04001136 "Unknown\sinstance",
Devin Limc20e79a2017-06-07 10:29:57 -07001137 self.prompt,
Jeremy Songster14c13572016-04-21 17:34:03 -07001138 pexpect.TIMEOUT ], timeout=180 )
andrewonlab2b30bd32014-10-09 16:48:55 -04001139 if i == 0:
Devin Limc20e79a2017-06-07 10:29:57 -07001140 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001141 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001142 return main.TRUE
1143 elif i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001144 self.handle.expect( self.prompt )
Jon Hall65844a32015-03-09 19:09:37 -07001145 main.log.info( "onosStop() Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001146 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -04001147 return main.FALSE
Jon Hall61282e32015-03-19 11:34:11 -07001148 elif i == 2:
Devin Limc20e79a2017-06-07 10:29:57 -07001149 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -07001150 main.log.warn( "ONOS wasn't running" )
1151 return main.TRUE
YPZhang77badfc2016-03-09 10:28:59 -08001152 elif i == 3:
1153 main.log.info( "ONOS service stopped" )
1154 return main.TRUE
andrewonlab2b30bd32014-10-09 16:48:55 -04001155 else:
kelvin8ec71442015-01-15 16:57:00 -08001156 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001157 return main.FALSE
andrewonlab2b30bd32014-10-09 16:48:55 -04001158 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001159 main.log.error( self.name + ": EOF exception found" )
1160 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001161 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001162 except Exception:
1163 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001164 main.cleanAndExit()
kelvin8ec71442015-01-15 16:57:00 -08001165
kelvin-onlabd3b64892015-01-20 13:26:24 -08001166 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -08001167 """
andrewonlabc8d47972014-10-09 16:52:36 -04001168 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -08001169 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -04001170 if needed
kelvin8ec71442015-01-15 16:57:00 -08001171 """
andrewonlabc8d47972014-10-09 16:52:36 -04001172 try:
kelvin8ec71442015-01-15 16:57:00 -08001173 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001174 self.handle.expect( self.prompt, timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001175 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
Devin Limc20e79a2017-06-07 10:29:57 -07001176 self.handle.expect( self.prompt, timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001177 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
kelvin8ec71442015-01-15 16:57:00 -08001178 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -04001179 return main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -07001180 except pexpect.TIMEOUT:
1181 main.log.exception( self.name + ": Timeout in onosUninstall" )
1182 return main.FALSE
andrewonlabc8d47972014-10-09 16:52:36 -04001183 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001184 main.log.error( self.name + ": EOF exception found" )
1185 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001186 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001187 except Exception:
1188 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001189 main.cleanAndExit()
andrewonlab2b30bd32014-10-09 16:48:55 -04001190
kelvin-onlabd3b64892015-01-20 13:26:24 -08001191 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001192 """
andrewonlabaedc8332014-12-04 12:43:03 -05001193 Issues the command 'onos-die <node-ip>'
1194 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -08001195 """
andrewonlabaedc8332014-12-04 12:43:03 -05001196 try:
kelvin8ec71442015-01-15 16:57:00 -08001197 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001198 self.handle.expect( self.prompt )
Jeremyf0aecdb2016-03-30 13:19:57 -07001199 cmdStr = "onos-die " + str( nodeIp )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001200 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001201 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -05001202 "Killing\sONOS",
1203 "ONOS\sprocess\sis\snot\srunning",
Jeremy Songster14c13572016-04-21 17:34:03 -07001204 pexpect.TIMEOUT ], timeout=60 )
andrewonlabaedc8332014-12-04 12:43:03 -05001205 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001206 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001207 " was killed and stopped" )
Jon Hall53c5e662016-04-13 16:06:56 -07001208 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001209 self.handle.expect( self.prompt )
andrewonlabaedc8332014-12-04 12:43:03 -05001210 return main.TRUE
1211 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001212 main.log.info( "ONOS process was not running" )
Jon Hall53c5e662016-04-13 16:06:56 -07001213 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001214 self.handle.expect( self.prompt )
andrewonlabaedc8332014-12-04 12:43:03 -05001215 return main.FALSE
1216 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001217 main.log.error( self.name + ": EOF exception found" )
1218 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001219 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001220 except Exception:
1221 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001222 main.cleanAndExit()
andrewonlabaedc8332014-12-04 12:43:03 -05001223
kelvin-onlabd3b64892015-01-20 13:26:24 -08001224 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001225 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001226 Calls the command: 'onos-kill [<node-ip>]'
1227 "Remotely, and unceremoniously kills the ONOS instance running on
1228 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -08001229 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001230 try:
kelvin8ec71442015-01-15 16:57:00 -08001231 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001232 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001233 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -08001234 i = self.handle.expect( [
Devin Limc20e79a2017-06-07 10:29:57 -07001235 self.prompt,
andrewonlabe8e56fd2014-10-09 17:12:44 -04001236 "No\sroute\sto\shost",
1237 "password:",
Jeremy Songster14c13572016-04-21 17:34:03 -07001238 pexpect.TIMEOUT ], timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -08001239
andrewonlabe8e56fd2014-10-09 17:12:44 -04001240 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001241 main.log.info(
1242 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -08001243 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001244 return main.TRUE
1245 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001246 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001247 return main.FALSE
1248 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001249 main.log.info(
1250 "Passwordless login for host: " +
1251 str( nodeIp ) +
1252 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001253 return main.FALSE
1254 else:
Jon Hallefbd9792015-03-05 16:11:36 -08001255 main.log.info( "ONOS instance was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001256 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001257
andrewonlabe8e56fd2014-10-09 17:12:44 -04001258 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001259 main.log.error( self.name + ": EOF exception found" )
1260 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001261 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001262 except Exception:
1263 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001264 main.cleanAndExit()
andrewonlabe8e56fd2014-10-09 17:12:44 -04001265
kelvin-onlabd3b64892015-01-20 13:26:24 -08001266 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -08001267 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001268 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -05001269 a cleaner environment.
1270
andrewonlab19fbdca2014-11-14 12:55:59 -05001271 Description:
Jon Hallfcc88622014-11-25 13:09:54 -05001272 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -05001273 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -08001274 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001275 try:
kelvin8ec71442015-01-15 16:57:00 -08001276 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001277 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001278 self.handle.sendline( "onos-remove-raft-logs" )
1279 # Sometimes this command hangs
Devin Limc20e79a2017-06-07 10:29:57 -07001280 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
kelvin8ec71442015-01-15 16:57:00 -08001281 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001282 if i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001283 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
kelvin8ec71442015-01-15 16:57:00 -08001284 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001285 if i == 1:
1286 return main.FALSE
andrewonlab19fbdca2014-11-14 12:55:59 -05001287 return main.TRUE
andrewonlab19fbdca2014-11-14 12:55:59 -05001288 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001289 main.log.error( self.name + ": EOF exception found" )
1290 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001291 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001292 except Exception:
1293 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001294 main.cleanAndExit()
Jon Hallfcc88622014-11-25 13:09:54 -05001295
kelvin-onlabd3b64892015-01-20 13:26:24 -08001296 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -08001297 """
1298 Calls the command 'onos-start-network [ <mininet-topo> ]
1299 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -04001300 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -08001301 cell."
andrewonlab94282092014-10-10 13:00:11 -04001302 * Specify mininet topology file name for mntopo
1303 * Topo files should be placed at:
1304 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001305
andrewonlab94282092014-10-10 13:00:11 -04001306 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001307 """
andrewonlab94282092014-10-10 13:00:11 -04001308 try:
1309 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001310 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001311 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001312
kelvin8ec71442015-01-15 16:57:00 -08001313 mntopo = str( mntopo )
1314 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001315 self.handle.expect( self.prompt )
andrewonlab94282092014-10-10 13:00:11 -04001316
kelvin8ec71442015-01-15 16:57:00 -08001317 self.handle.sendline( "onos-start-network " + mntopo )
1318 self.handle.expect( "mininet>" )
1319 main.log.info( "Network started, entered mininet prompt" )
1320
1321 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001322
1323 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001324 main.log.error( self.name + ": EOF exception found" )
1325 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001326 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001327 except Exception:
1328 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001329 main.cleanAndExit()
andrewonlab94282092014-10-10 13:00:11 -04001330
Jeremy Songster14c13572016-04-21 17:34:03 -07001331 def isup( self, node="", timeout=240 ):
kelvin8ec71442015-01-15 16:57:00 -08001332 """
1333 Run's onos-wait-for-start which only returns once ONOS is at run
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001334 level 100(ready for use)
andrewonlab8d0d7d72014-10-09 16:33:15 -04001335
Jon Hall7993bfc2014-10-09 16:30:14 -04001336 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001337 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001338 try:
Jon Hall3b489db2015-10-05 14:38:37 -07001339 self.handle.sendline( "onos-wait-for-start " + node )
1340 self.handle.expect( "onos-wait-for-start" )
kelvin8ec71442015-01-15 16:57:00 -08001341 # NOTE: this timeout is arbitrary"
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001342 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ], timeout )
Jon Hall7993bfc2014-10-09 16:30:14 -04001343 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001344 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001345 return main.TRUE
1346 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001347 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001348 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001349 main.log.error( "ONOS has not started yet" )
1350 self.handle.send( "\x03" ) # Control-C
Devin Limc20e79a2017-06-07 10:29:57 -07001351 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001352 return main.FALSE
1353 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001354 main.log.error( self.name + ": EOF exception found" )
1355 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001356 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001357 except Exception:
1358 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001359 main.cleanAndExit()
andrewonlab05e362f2014-10-10 00:40:57 -04001360
Devin Lim142b5342017-07-20 15:22:39 -07001361 def preventAutoRespawn( self ):
1362 """
1363 Description:
1364 This will prevent ONOSservice to automatically
1365 respawn.
1366 """
1367 try:
1368 self.handle.sendline( "sed -i -e 's/^respawn$/#respawn/g' tools/package/init/onos.conf" )
1369 self.handle.expect( "\$" ) # $ from the command
1370 self.handle.sendline( "sed -i -e 's/^Restart=always/Restart=no/g' tools/package/init/onos.service" )
1371 self.handle.expect( "\$" ) # $ from the command
1372 self.handle.expect( "\$" ) # $ from the prompt
1373 except pexpect.EOF:
1374 main.log.error( self.name + ": EOF exception found" )
1375 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001376 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -07001377 except Exception:
1378 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001379 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -07001380
kelvin-onlabd3b64892015-01-20 13:26:24 -08001381 def pushTestIntentsShell(
1382 self,
1383 dpidSrc,
1384 dpidDst,
1385 numIntents,
1386 dirFile,
1387 onosIp,
1388 numMult="",
1389 appId="",
1390 report=True,
1391 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001392 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001393 Description:
kelvin8ec71442015-01-15 16:57:00 -08001394 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001395 better parallelize the results than the CLI
1396 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001397 * dpidSrc: specify source dpid
1398 * dpidDst: specify destination dpid
1399 * numIntents: specify number of intents to push
1400 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001401 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001402 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001403 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001404 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001405 """
1406 try:
1407 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001408 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001409 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001410 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001411 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001412 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001413
kelvin-onlabd3b64892015-01-20 13:26:24 -08001414 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1415 if not numMult:
1416 addIntents = addDpid + " " + str( numIntents )
1417 elif numMult:
1418 addIntents = addDpid + " " + str( numIntents ) + " " +\
1419 str( numMult )
1420 if appId:
1421 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001422 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001423 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001424
andrewonlabaedc8332014-12-04 12:43:03 -05001425 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001426 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001427 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001428 sendCmd = addApp + " &"
1429 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001430
kelvin-onlabd3b64892015-01-20 13:26:24 -08001431 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001432
1433 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001434 main.log.error( self.name + ": EOF exception found" )
1435 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001436 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001437 except Exception:
1438 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001439 main.cleanAndExit()
andrewonlab05e362f2014-10-10 00:40:57 -04001440
kelvin-onlabd3b64892015-01-20 13:26:24 -08001441 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001442 """
andrewonlab970399c2014-11-07 13:09:32 -05001443 Capture all packet activity and store in specified
1444 directory/file
1445
1446 Required:
1447 * interface: interface to capture
1448 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001449 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001450 try:
1451 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001452 self.handle.expect( self.prompt )
andrewonlab970399c2014-11-07 13:09:32 -05001453
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001454 self.handle.sendline( "tshark -i " + str( interface ) + " -t e -w " + str( dirFile ) + " &" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001455 self.handle.sendline( "\n" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001456 self.handle.expect( "Capturing on" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001457 self.handle.sendline( "\n" )
Devin Limc20e79a2017-06-07 10:29:57 -07001458 self.handle.expect( self.prompt )
andrewonlab970399c2014-11-07 13:09:32 -05001459
Jon Hallfebb1c72015-03-05 13:30:09 -08001460 main.log.info( "Tshark started capturing files on " +
1461 str( interface ) + " and saving to directory: " +
1462 str( dirFile ) )
1463 except pexpect.EOF:
1464 main.log.error( self.name + ": EOF exception found" )
1465 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001466 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001467 except Exception:
1468 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001469 main.cleanAndExit()
Shreya Shaha73aaad2014-10-27 18:03:09 -04001470
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001471 def onosTopoCfg( self, onosIp, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001472 """
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001473 Description:
1474 Execute onos-topo-cfg command
1475 Required:
1476 onosIp - IP of the onos node you want to send the json to
1477 jsonFile - File path of the json file
1478 Return:
1479 Returns main.TRUE if the command is successfull; Returns
1480 main.FALSE if there was an error
kelvin8ec71442015-01-15 16:57:00 -08001481 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001482 try:
kelvin8ec71442015-01-15 16:57:00 -08001483 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001484 self.handle.expect( self.prompt )
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001485 cmd = "onos-topo-cfg "
1486 self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile )
1487 handle = self.handle.before
1488 print handle
1489 if "Error" in handle:
1490 main.log.error( self.name + ": " + self.handle.before )
1491 return main.FALSE
1492 else:
Devin Limc20e79a2017-06-07 10:29:57 -07001493 self.handle.expect( self.prompt )
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001494 return main.TRUE
1495
Jon Hallfebb1c72015-03-05 13:30:09 -08001496 except pexpect.EOF:
1497 main.log.error( self.name + ": EOF exception found" )
1498 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001499 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001500 except Exception:
1501 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001502 main.cleanAndExit()
kelvin8ec71442015-01-15 16:57:00 -08001503
jenkins1e99e7b2015-04-02 18:15:39 -07001504 def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ):
kelvin8ec71442015-01-15 16:57:00 -08001505 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001506 Required:
kelvin8ec71442015-01-15 16:57:00 -08001507 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001508 * directory to store results
1509 Optional:
1510 * interface - default: eth0
Jon Hall4ba53f02015-07-29 13:07:41 -07001511 * grepOptions - options for grep
andrewonlabba44bcf2014-10-16 16:54:41 -04001512 Description:
1513 Uses tshark command to grep specific group of packets
1514 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001515 The timestamp is hardcoded to be in epoch
1516 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001517 try:
1518 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001519 self.handle.expect( self.prompt )
Jon Hallfebb1c72015-03-05 13:30:09 -08001520 self.handle.sendline( "" )
jenkins1e99e7b2015-04-02 18:15:39 -07001521 if grepOptions:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001522 grepStr = "grep " + str( grepOptions )
jenkins1e99e7b2015-04-02 18:15:39 -07001523 else:
1524 grepStr = "grep"
Jon Hall4ba53f02015-07-29 13:07:41 -07001525
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001526 cmd = (
1527 "sudo tshark -i " +
Jon Hallfebb1c72015-03-05 13:30:09 -08001528 str( interface ) +
jenkins1e99e7b2015-04-02 18:15:39 -07001529 " -t e | " +
1530 grepStr + " --line-buffered \"" +
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001531 str( grep ) +
Jon Hallfebb1c72015-03-05 13:30:09 -08001532 "\" >" +
1533 directory +
1534 " &" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001535 self.handle.sendline( cmd )
1536 main.log.info( cmd )
Jon Hallfebb1c72015-03-05 13:30:09 -08001537 self.handle.expect( "Capturing on" )
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001538 self.handle.sendline( "\n" )
Devin Limc20e79a2017-06-07 10:29:57 -07001539 self.handle.expect( self.prompt )
Jon Hallfebb1c72015-03-05 13:30:09 -08001540 except pexpect.EOF:
1541 main.log.error( self.name + ": EOF exception found" )
1542 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001543 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001544 except Exception:
1545 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001546 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001547
kelvin-onlabd3b64892015-01-20 13:26:24 -08001548 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001549 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001550 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001551 """
1552 # Remove all pcap from previous captures
Jon Hallfebb1c72015-03-05 13:30:09 -08001553 try:
1554 self.execute( cmd="sudo rm /tmp/wireshark*" )
1555 self.handle.sendline( "" )
Jon Hallefbd9792015-03-05 16:11:36 -08001556 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" +
1557 " | grep -v grep | awk '{print $2}'`" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001558 self.handle.sendline( "" )
1559 main.log.info( "Tshark stopped" )
1560 except pexpect.EOF:
1561 main.log.error( self.name + ": EOF exception found" )
1562 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001563 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001564 except Exception:
1565 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001566 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001567
kelvin8ec71442015-01-15 16:57:00 -08001568 def ptpd( self, args ):
1569 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001570 Initiate ptp with user-specified args.
1571 Required:
1572 * args: specify string of args after command
1573 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001574 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001575 try:
kelvin8ec71442015-01-15 16:57:00 -08001576 self.handle.sendline( "sudo ptpd " + str( args ) )
1577 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001578 "Multiple",
1579 "Error",
Devin Limc20e79a2017-06-07 10:29:57 -07001580 self.prompt ] )
1581 self.handle.expect( self.prompt )
andrewonlabba44bcf2014-10-16 16:54:41 -04001582
andrewonlab0c38a4a2014-10-28 18:35:35 -04001583 if i == 0:
1584 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001585 main.log.info( "ptpd returned an error: " +
1586 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001587 return handle
1588 elif i == 1:
1589 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001590 main.log.error( "ptpd returned an error: " +
1591 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001592 return handle
1593 else:
1594 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001595
andrewonlab0c38a4a2014-10-28 18:35:35 -04001596 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001597 main.log.error( self.name + ": EOF exception found" )
1598 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001599 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001600 except Exception:
1601 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001602 main.cleanAndExit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001603
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001604 def dumpONOSCmd( self, ONOSIp, CMD, destDir, filename, options="" ):
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001605 """
Pier50f0bc62016-09-07 17:53:40 -07001606 Dump Cmd to a desired directory.
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001607 For debugging purposes, you may want to use
Pier50f0bc62016-09-07 17:53:40 -07001608 this function to capture Cmd at a given point in time.
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001609 Localtime will be attached to the filename
1610
1611 Required:
1612 * ONOSIp: the IP of the target ONOS instance
Pier50f0bc62016-09-07 17:53:40 -07001613 * CMD: the command to dump;
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001614 * destDir: specify directory to copy to.
1615 ex ) /tmp/
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001616 * fileName: Name of the file
Pier50f0bc62016-09-07 17:53:40 -07001617 * options: Options for ONOS command
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001618 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001619
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001620 localtime = time.strftime( '%x %X' )
1621 localtime = localtime.replace( "/", "" )
1622 localtime = localtime.replace( " ", "_" )
1623 localtime = localtime.replace( ":", "" )
1624 if destDir[ -1: ] != "/":
1625 destDir += "/"
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001626 cmd = CMD + " " + options + " > " + str( destDir ) + str( filename ) + localtime
1627 return self.onosCli( ONOSIp, cmd )
Flavio Castrob7718952016-05-18 08:53:41 -07001628
kelvin-onlabd3b64892015-01-20 13:26:24 -08001629 def cpLogsToDir( self, logToCopy,
Jon Hallefbd9792015-03-05 16:11:36 -08001630 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001631 """
1632 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001633 Current implementation of ONOS deletes its karaf
1634 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001635 you may want to use this function to capture
1636 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001637 Localtime will be attached to the filename
1638
1639 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001640 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001641 copy.
kelvin8ec71442015-01-15 16:57:00 -08001642 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001643 For copying multiple files, leave copyFileName
1644 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001645 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001646 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001647 ex ) /tmp/
1648 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001649 * copyFileName: If you want to rename the log
1650 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001651 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001652 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001653 try:
Flavio Castro09ab59d2016-05-25 17:01:35 -07001654 localtime = time.strftime( '%H %M' )
kelvin8ec71442015-01-15 16:57:00 -08001655 localtime = localtime.replace( "/", "" )
1656 localtime = localtime.replace( " ", "_" )
1657 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001658 if destDir[ -1: ] != "/":
1659 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001660
kelvin-onlabd3b64892015-01-20 13:26:24 -08001661 if copyFileName:
Jon Hallfebb1c72015-03-05 13:30:09 -08001662 self.handle.sendline( "cp " + str( logToCopy ) + " " +
1663 str( destDir ) + str( copyFileName ) +
1664 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001665 self.handle.expect( "cp" )
Devin Limc20e79a2017-06-07 10:29:57 -07001666 self.handle.expect( self.prompt )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001667 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001668 self.handle.sendline( "cp " + str( logToCopy ) +
1669 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001670 self.handle.expect( "cp" )
Devin Limc20e79a2017-06-07 10:29:57 -07001671 self.handle.expect( self.prompt )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001672
kelvin8ec71442015-01-15 16:57:00 -08001673 return self.handle.before
1674
1675 except pexpect.EOF:
1676 main.log.error( "Copying files failed" )
1677 main.log.error( self.name + ": EOF exception found" )
1678 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001679 except Exception:
1680 main.log.exception( "Copying files failed" )
1681
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001682 def checkLogs( self, onosIp, restart=False ):
kelvin8ec71442015-01-15 16:57:00 -08001683 """
Jon Hall94fd0472014-12-08 11:52:42 -08001684 runs onos-check-logs on the given onos node
Jon Hall80daded2015-05-27 16:07:00 -07001685 If restart is True, use the old version of onos-check-logs which
1686 does not print the full stacktrace, but shows the entire log file,
1687 including across restarts
Jon Hall94fd0472014-12-08 11:52:42 -08001688 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001689 """
Jon Hall94fd0472014-12-08 11:52:42 -08001690 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001691 cmd = "onos-check-logs " + str( onosIp )
Jon Hall16b72c42015-05-20 10:23:36 -07001692 if restart:
1693 cmd += " old"
kelvin8ec71442015-01-15 16:57:00 -08001694 self.handle.sendline( cmd )
1695 self.handle.expect( cmd )
Devin Limdc78e202017-06-09 18:30:07 -07001696 self.handle.expect( self.prompt + " " )
Jon Hall94fd0472014-12-08 11:52:42 -08001697 response = self.handle.before
1698 return response
1699 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001700 main.log.error( "Lost ssh connection" )
1701 main.log.error( self.name + ": EOF exception found" )
1702 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001703 except Exception:
1704 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001705 main.cleanAndExit()
Jon Hall94fd0472014-12-08 11:52:42 -08001706
kelvin-onlabd3b64892015-01-20 13:26:24 -08001707 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001708 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001709 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001710 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001711 try:
kelvin8ec71442015-01-15 16:57:00 -08001712 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001713 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001714 self.handle.sendline( "onos-service " + str( node ) +
1715 " status" )
1716 i = self.handle.expect( [
You Wangef1e6572016-03-08 12:53:18 -08001717 "start/running",
You Wang7bd83062016-03-01 11:50:00 -08001718 "Running ...",
You Wangef1e6572016-03-08 12:53:18 -08001719 "stop/waiting",
You Wang7bd83062016-03-01 11:50:00 -08001720 "Not Running ...",
kelvin8ec71442015-01-15 16:57:00 -08001721 pexpect.TIMEOUT ], timeout=120 )
YPZhangfebf7302016-05-24 16:45:56 -07001722 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001723 self.handle.expect( self.prompt )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001724
You Wangef1e6572016-03-08 12:53:18 -08001725 if i == 0 or i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001726 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001727 return main.TRUE
You Wangef1e6572016-03-08 12:53:18 -08001728 elif i == 2 or i == 3:
kelvin8ec71442015-01-15 16:57:00 -08001729 main.log.info( "ONOS is stopped" )
kelvin8ec71442015-01-15 16:57:00 -08001730 main.log.error( "ONOS service failed to check the status" )
Devin Lim44075962017-08-11 10:56:37 -07001731
1732 main.cleanAndExit()
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001733 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001734 main.log.error( self.name + ": EOF exception found" )
1735 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001736 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001737 except Exception:
1738 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001739 main.cleanAndExit()
Jon Hall21270ac2015-02-16 17:59:55 -08001740
Jon Hall63604932015-02-26 17:09:50 -08001741 def setIpTables( self, ip, port='', action='add', packet_type='',
1742 direction='INPUT', rule='DROP', states=True ):
Jon Hallefbd9792015-03-05 16:11:36 -08001743 """
Jon Hall21270ac2015-02-16 17:59:55 -08001744 Description:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001745 add or remove iptables rule to DROP (default) packets from
Jon Hall21270ac2015-02-16 17:59:55 -08001746 specific IP and PORT
1747 Usage:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001748 * specify action ('add' or 'remove')
Jon Hall21270ac2015-02-16 17:59:55 -08001749 when removing, pass in the same argument as you would add. It will
1750 delete that specific rule.
1751 * specify the ip to block
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001752 * specify the destination port to block (defaults to all ports)
1753 * optional packet type to block (default tcp)
1754 * optional iptables rule (default DROP)
1755 * optional direction to block (default 'INPUT')
Jon Hall63604932015-02-26 17:09:50 -08001756 * States boolean toggles adding all supported tcp states to the
1757 firewall rule
Jon Hall21270ac2015-02-16 17:59:55 -08001758 Returns:
1759 main.TRUE on success or
1760 main.FALSE if given invalid input or
1761 main.ERROR if there is an error in response from iptables
1762 WARNING:
1763 * This function uses root privilege iptables command which may result
1764 in unwanted network errors. USE WITH CAUTION
Jon Hallefbd9792015-03-05 16:11:36 -08001765 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001766
Jon Hall21270ac2015-02-16 17:59:55 -08001767 # NOTE*********
1768 # The strict checking methods of this driver function is intentional
1769 # to discourage any misuse or error of iptables, which can cause
1770 # severe network errors
1771 # *************
1772
1773 # NOTE: Sleep needed to give some time for rule to be added and
1774 # registered to the instance. If you are calling this function
1775 # multiple times this sleep will prevent any errors.
1776 # DO NOT REMOVE
Jon Hall63604932015-02-26 17:09:50 -08001777 # time.sleep( 5 )
Jon Hall21270ac2015-02-16 17:59:55 -08001778 try:
1779 # input validation
1780 action_type = action.lower()
1781 rule = rule.upper()
1782 direction = direction.upper()
1783 if action_type != 'add' and action_type != 'remove':
1784 main.log.error( "Invalid action type. Use 'add' or "
1785 "'remove' table rule" )
1786 if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
1787 # NOTE Currently only supports rules DROP, ACCEPT, and LOG
1788 main.log.error( "Invalid rule. Valid rules are 'DROP' or "
1789 "'ACCEPT' or 'LOG' only." )
1790 if direction != 'INPUT' and direction != 'OUTPUT':
1791 # NOTE currently only supports rules INPUT and OUPTUT
1792 main.log.error( "Invalid rule. Valid directions are"
1793 " 'OUTPUT' or 'INPUT'" )
1794 return main.FALSE
1795 return main.FALSE
1796 return main.FALSE
1797 if action_type == 'add':
1798 # -A is the 'append' action of iptables
1799 actionFlag = '-A'
1800 elif action_type == 'remove':
1801 # -D is the 'delete' rule of iptables
1802 actionFlag = '-D'
1803 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001804 self.handle.expect( self.prompt )
Jon Hall21270ac2015-02-16 17:59:55 -08001805 cmd = "sudo iptables " + actionFlag + " " +\
1806 direction +\
Jon Hall21270ac2015-02-16 17:59:55 -08001807 " -s " + str( ip )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001808 # " -p " + str( packet_type ) +\
Jon Hall63604932015-02-26 17:09:50 -08001809 if packet_type:
1810 cmd += " -p " + str( packet_type )
Jon Hall21270ac2015-02-16 17:59:55 -08001811 if port:
1812 cmd += " --dport " + str( port )
Jon Hall63604932015-02-26 17:09:50 -08001813 if states:
1814 cmd += " -m state --state="
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001815 # FIXME- Allow user to configure which states to block
Jon Hall63604932015-02-26 17:09:50 -08001816 cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED"
Jon Hall21270ac2015-02-16 17:59:55 -08001817 cmd += " -j " + str( rule )
1818
1819 self.handle.sendline( cmd )
Devin Limc20e79a2017-06-07 10:29:57 -07001820 self.handle.expect( self.prompt )
Jon Hall21270ac2015-02-16 17:59:55 -08001821 main.log.warn( self.handle.before )
1822
1823 info_string = "On " + str( self.name )
1824 info_string += " " + str( action_type )
1825 info_string += " iptable rule [ "
1826 info_string += " IP: " + str( ip )
1827 info_string += " Port: " + str( port )
1828 info_string += " Rule: " + str( rule )
1829 info_string += " Direction: " + str( direction ) + " ]"
1830 main.log.info( info_string )
1831 return main.TRUE
1832 except pexpect.TIMEOUT:
1833 main.log.exception( self.name + ": Timeout exception in "
1834 "setIpTables function" )
1835 return main.ERROR
1836 except pexpect.EOF:
1837 main.log.error( self.name + ": EOF exception found" )
1838 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001839 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001840 except Exception:
1841 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001842 main.cleanAndExit()
Jon Hall21270ac2015-02-16 17:59:55 -08001843
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001844 def detailed_status( self, log_filename ):
Jon Hallefbd9792015-03-05 16:11:36 -08001845 """
Jon Hall0468b042015-02-19 19:08:21 -08001846 This method is used by STS to check the status of the controller
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001847 Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
Jon Hallefbd9792015-03-05 16:11:36 -08001848 """
Jon Hall0468b042015-02-19 19:08:21 -08001849 import re
1850 try:
1851 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001852 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001853 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -07001854 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001855 self.handle.sendline( "service onos status" )
Devin Limc20e79a2017-06-07 10:29:57 -07001856 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001857 response = self.handle.before
1858 if re.search( "onos start/running", response ):
1859 # onos start/running, process 10457
1860 return 'RUNNING'
1861 # FIXME: Implement this case
1862 # elif re.search( pattern, response ):
1863 # return 'STARTING'
1864 elif re.search( "onos stop/", response ):
1865 # onos stop/waiting
1866 # FIXME handle this differently?: onos stop/pre-stop
1867 return 'STOPPED'
1868 # FIXME: Implement this case
1869 # elif re.search( pattern, response ):
1870 # return 'FROZEN'
1871 else:
1872 main.log.warn( self.name +
Jon Hallefbd9792015-03-05 16:11:36 -08001873 " WARNING: status received unknown response" )
Jon Hall0468b042015-02-19 19:08:21 -08001874 main.log.warn( response )
1875 return 'ERROR', "Unknown response: %s" % response
1876 except pexpect.TIMEOUT:
1877 main.log.exception( self.name + ": Timeout exception in "
1878 "setIpTables function" )
1879 return 'ERROR', "Pexpect Timeout"
1880 except pexpect.EOF:
1881 main.log.error( self.name + ": EOF exception found" )
1882 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001883 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001884 except Exception:
1885 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001886 main.cleanAndExit()
Jon Hall0468b042015-02-19 19:08:21 -08001887
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001888 def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001889 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07001890 Create/formats the LinkGraph.cfg file based on arguments
1891 -only creates a linear topology and connects islands
1892 -evenly distributes devices
andrew@onlab.us3b087132015-03-11 15:00:08 -07001893 -must be called by ONOSbench
1894
Jon Hall4ba53f02015-07-29 13:07:41 -07001895 ONOSIpList - list of all of the node IPs to be used
1896
1897 deviceCount - number of switches to be assigned
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001898 '''
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001899 main.log.info( "Creating link graph configuration file." )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001900 linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg"
Jon Hall4ba53f02015-07-29 13:07:41 -07001901 tempFile = "/tmp/linkGraph.cfg"
andrew@onlab.us3b087132015-03-11 15:00:08 -07001902
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001903 linkGraph = open( tempFile, 'w+' )
1904 linkGraph.write( "# NullLinkProvider topology description (config file).\n" )
1905 linkGraph.write( "# The NodeId is only added if the destination is another node's device.\n" )
1906 linkGraph.write( "# Bugs: Comments cannot be appended to a line to be read.\n" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001907
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001908 clusterCount = len( ONOSIpList )
Jon Hall4ba53f02015-07-29 13:07:41 -07001909
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001910 if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
1911 deviceCount = int( deviceCount )
1912 switchList = [ 0 ]*( clusterCount+1 )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001913 baselineSwitchCount = deviceCount/clusterCount
Jon Hall4ba53f02015-07-29 13:07:41 -07001914
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001915 for node in range( 1, clusterCount + 1 ):
1916 switchList[ node ] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001917
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001918 for node in range( 1, ( deviceCount % clusterCount )+1 ):
1919 switchList[ node ] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001920
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001921 if isinstance( deviceCount, list ):
1922 main.log.info( "Using provided device distribution" )
1923 switchList = [ 0 ]
andrew@onlab.us3b087132015-03-11 15:00:08 -07001924 for i in deviceCount:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001925 switchList.append( int( i ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001926
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001927 tempList = [ '0' ]
1928 tempList.extend( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001929 ONOSIpList = tempList
1930
1931 myPort = 6
1932 lastSwitch = 0
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001933 for node in range( 1, clusterCount+1 ):
1934 if switchList[ node ] == 0:
andrew@onlab.us3b087132015-03-11 15:00:08 -07001935 continue
1936
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001937 linkGraph.write( "graph " + ONOSIpList[ node ] + " {\n" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001938
andrew@onlab.us3b087132015-03-11 15:00:08 -07001939 if node > 1:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001940 # connect to last device on previous node
1941 line = ( "\t0:5 -> " + str( lastSwitch ) + ":6:" + lastIp + "\n" ) # ONOSIpList[node-1]
1942 linkGraph.write( line )
Jon Hall4ba53f02015-07-29 13:07:41 -07001943
1944 lastSwitch = 0
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001945 for switch in range( 0, switchList[ node ]-1 ):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001946 line = ""
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001947 line = ( "\t" + str( switch ) + ":" + str( myPort ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001948 line += " -- "
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001949 line += ( str( switch+1 ) + ":" + str( myPort-1 ) + "\n" )
1950 linkGraph.write( line )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001951 lastSwitch = switch+1
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001952 lastIp = ONOSIpList[ node ]
Jon Hall4ba53f02015-07-29 13:07:41 -07001953
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001954 # lastSwitch += 1
1955 if node < ( clusterCount ):
1956 # connect to first device on the next node
1957 line = ( "\t" + str( lastSwitch ) + ":6 -> 0:5:" + ONOSIpList[ node+1 ] + "\n" )
1958 linkGraph.write( line )
Jon Hall4ba53f02015-07-29 13:07:41 -07001959
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001960 linkGraph.write( "}\n" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001961 linkGraph.close()
1962
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001963 # SCP
1964 os.system( "scp " + tempFile + " " + self.user_name + "@" + benchIp + ":" + linkGraphPath )
1965 main.log.info( "linkGraph.cfg creation complete" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001966
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001967 def configNullDev( self, ONOSIpList, deviceCount, numPorts=10 ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001968 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07001969 ONOSIpList = list of Ip addresses of nodes switches will be devided amongst
1970 deviceCount = number of switches to distribute, or list of values to use as custom distribution
cameron@onlab.us75900962015-03-30 13:22:49 -07001971 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 +00001972 '''
1973
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001974 main.log.info( "Configuring Null Device Provider" )
1975 clusterCount = len( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001976
Jon Hall4ba53f02015-07-29 13:07:41 -07001977 try:
1978
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001979 if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
1980 main.log.info( "Creating device distribution" )
1981 deviceCount = int( deviceCount )
1982 switchList = [ 0 ]*( clusterCount+1 )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001983 baselineSwitchCount = deviceCount/clusterCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001984
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001985 for node in range( 1, clusterCount + 1 ):
1986 switchList[ node ] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001987
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001988 for node in range( 1, ( deviceCount % clusterCount )+1 ):
1989 switchList[ node ] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001990
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001991 if isinstance( deviceCount, list ):
1992 main.log.info( "Using provided device distribution" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001993
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001994 if len( deviceCount ) == clusterCount:
1995 switchList = [ '0' ]
1996 switchList.extend( deviceCount )
Jon Hall4ba53f02015-07-29 13:07:41 -07001997
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001998 if len( deviceCount ) == ( clusterCount + 1 ):
1999 if deviceCount[ 0 ] == '0' or deviceCount[ 0 ] == 0:
cameron@onlab.us75900962015-03-30 13:22:49 -07002000 switchList = deviceCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07002001
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002002 assert len( switchList ) == ( clusterCount + 1 )
Jon Hall4ba53f02015-07-29 13:07:41 -07002003
cameron@onlab.us75900962015-03-30 13:22:49 -07002004 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002005 main.log.error( "Bad device/Ip list match" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002006 except TypeError:
2007 main.log.exception( self.name + ": Object not as expected" )
2008 return None
Jon Hall77ba41c2015-04-06 10:25:40 -07002009 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002010 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002011 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002012
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002013 ONOSIp = [ 0 ]
2014 ONOSIp.extend( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002015
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002016 devicesString = "devConfigs = "
2017 for node in range( 1, len( ONOSIp ) ):
2018 devicesString += ( ONOSIp[ node ] + ":" + str( switchList[ node ] ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002019 if node < clusterCount:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002020 devicesString += ( "," )
Jon Hall4ba53f02015-07-29 13:07:41 -07002021
2022 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002023 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString )
2024 self.handle.expect( ":~" )
2025 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str( numPorts ) )
2026 self.handle.expect( ":~" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002027
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002028 for i in range( 10 ):
2029 self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider" )
2030 self.handle.expect( ":~" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002031 verification = self.handle.before
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002032 if ( " value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification:
cameron@onlab.us75900962015-03-30 13:22:49 -07002033 break
2034 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002035 time.sleep( 1 )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002036
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002037 assert ( "value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07002038
cameron@onlab.us75900962015-03-30 13:22:49 -07002039 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002040 main.log.error( "Incorrect Config settings: " + verification )
Jon Hall77ba41c2015-04-06 10:25:40 -07002041 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002042 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002043 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002044
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002045 def configNullLink( self, fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0 ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002046 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002047 fileName default is currently the same as the default on ONOS, specify alternate file if
cameron@onlab.us75900962015-03-30 13:22:49 -07002048 you want to use a different topology file than linkGraph.cfg
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002049 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002050
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002051 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002052 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str( eventRate ) )
2053 self.handle.expect( ":~" )
2054 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName )
2055 self.handle.expect( ":~" )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002056
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002057 for i in range( 10 ):
2058 self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider" )
2059 self.handle.expect( ":~" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002060 verification = self.handle.before
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002061 if ( " value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification:
cameron@onlab.us75900962015-03-30 13:22:49 -07002062 break
Jon Hall4ba53f02015-07-29 13:07:41 -07002063 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002064 time.sleep( 1 )
Jon Hall4ba53f02015-07-29 13:07:41 -07002065
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002066 assert ( "value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07002067
cameron@onlab.us75900962015-03-30 13:22:49 -07002068 except pexpect.EOF:
2069 main.log.error( self.name + ": EOF exception found" )
2070 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002071 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002072 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002073 main.log.info( "Settings did not post to ONOS" )
2074 main.log.error( varification )
Jon Hall77ba41c2015-04-06 10:25:40 -07002075 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002076 main.log.exception( self.name + ": Uncaught exception!" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002077 main.log.error( varification )
Devin Lim44075962017-08-11 10:56:37 -07002078 main.cleanAndExit()
andrew@onlab.us3b087132015-03-11 15:00:08 -07002079
kelvin-onlaba4074292015-07-09 15:19:49 -07002080 def getOnosIps( self ):
2081 """
2082 Get all onos IPs stored in
2083 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002084
kelvin-onlaba4074292015-07-09 15:19:49 -07002085 return sorted( self.onosIps.values() )
cameron@onlab.us59d29d92015-05-11 14:31:54 -07002086
Chiyu Chengec63bde2016-11-17 18:11:36 -08002087 def listLog( self, nodeIp ):
2088 """
2089 Get a list of all the karaf log names
2090 """
2091 try:
2092 cmd = "onos-ssh " + nodeIp + " ls -tr /opt/onos/log"
2093 self.handle.sendline( cmd )
2094 self.handle.expect( ":~" )
2095 before = self.handle.before.splitlines()
2096 logNames = []
2097 for word in before:
2098 if 'karaf.log' in word:
2099 logNames.append( word )
2100 return logNames
2101 except pexpect.EOF:
2102 main.log.error( self.name + ": EOF exception found" )
2103 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002104 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002105 except pexpect.TIMEOUT:
2106 main.log.error( self.name + ": TIMEOUT exception found" )
2107 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002108 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002109 except Exception:
2110 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002111 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002112
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002113 def logReport( self, nodeIp, searchTerms, outputMode="s", startStr=None, endStr=None ):
Jon Hallb4242222016-01-25 17:07:04 -08002114 """
2115 Searches the latest ONOS log file for the given search terms and
2116 prints the total occurances of each term. Returns to combined total of
2117 all occurances.
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002118
Jon Hallb4242222016-01-25 17:07:04 -08002119 Arguments:
2120 * nodeIp - The ip of the ONOS node where the log is located
2121 * searchTerms - A string to grep for or a list of strings to grep
2122 for in the ONOS log. Will print out the number of
2123 occurances for each term.
2124 Optional Arguments:
2125 * outputMode - 's' or 'd'. If 'd' will print the last 5 lines
2126 containing each search term as well as the total
2127 number of occurances of each term. Defaults to 's',
2128 which prints the simple output of just the number
2129 of occurances for each term.
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002130 * startStr - the start string to be given to stream editor command
2131 as the start point for extraction of data
2132 * endStr - the end string to be given to stream editor command as
2133 the end point for extraction of data
Jon Hallb4242222016-01-25 17:07:04 -08002134 """
2135 try:
2136 main.log.info( " Log Report for {} ".format( nodeIp ).center( 70, '=' ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002137 if isinstance( searchTerms, str ):
2138 searchTerms = [ searchTerms ]
Jon Hallb4242222016-01-25 17:07:04 -08002139 numTerms = len( searchTerms )
2140 outputMode = outputMode.lower()
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002141
Jon Hallb4242222016-01-25 17:07:04 -08002142 totalHits = 0
2143 logLines = []
2144 for termIndex in range( numTerms ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002145 term = searchTerms[ termIndex ]
2146 logLines.append( [ term ] )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002147 if startStr and endStr:
2148 cmd = "onos-ssh {} \"sed -n '/{}/,/{}/p' /opt/onos/log/karaf.log | grep {}\"".format( nodeIp,
2149 startStr,
2150 endStr,
2151 term )
2152 else:
2153 cmd = "onos-ssh {} cat /opt/onos/log/karaf.log | grep {}".format( nodeIp,
2154 term )
Jon Hallb4242222016-01-25 17:07:04 -08002155 self.handle.sendline( cmd )
2156 self.handle.expect( ":~" )
2157 before = self.handle.before.splitlines()
2158 count = 0
2159 for line in before:
2160 if term in line and "grep" not in line:
2161 count += 1
2162 if before.index( line ) > ( len( before ) - 7 ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002163 logLines[ termIndex ].append( line )
Jon Hallb4242222016-01-25 17:07:04 -08002164 main.log.info( "{}: {}".format( term, count ) )
2165 totalHits += count
2166 if termIndex == numTerms - 1:
2167 print "\n"
2168 if outputMode != "s":
2169 outputString = ""
2170 for term in logLines:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002171 outputString = term[ 0 ] + ": \n"
Jon Hallb4242222016-01-25 17:07:04 -08002172 for line in range( 1, len( term ) ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002173 outputString += ( "\t" + term[ line ] + "\n" )
2174 if outputString != ( term[ 0 ] + ": \n" ):
Jon Hallb4242222016-01-25 17:07:04 -08002175 main.log.info( outputString )
2176 main.log.info( "=" * 70 )
2177 return totalHits
2178 except pexpect.EOF:
2179 main.log.error( self.name + ": EOF exception found" )
2180 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002181 main.cleanAndExit()
Jon Hallb4242222016-01-25 17:07:04 -08002182 except pexpect.TIMEOUT:
2183 main.log.error( self.name + ": TIMEOUT exception found" )
2184 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002185 main.cleanAndExit()
Jon Hallb4242222016-01-25 17:07:04 -08002186 except Exception:
2187 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002188 main.cleanAndExit()
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002189
2190 def copyMininetFile( self, fileName, localPath, userName, ip,
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002191 mnPath='~/mininet/custom/', timeout = 60 ):
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002192 """
2193 Description:
2194 Copy mininet topology file from dependency folder in the test folder
2195 and paste it to the mininet machine's mininet/custom folder
2196 Required:
2197 fileName - Name of the topology file to copy
2198 localPath - File path of the mininet topology file
2199 userName - User name of the mininet machine to send the file to
2200 ip - Ip address of the mininet machine
2201 Optional:
2202 mnPath - of the mininet directory to send the file to
2203 Return:
2204 Return main.TRUE if successfully copied the file otherwise
2205 return main.FALSE
2206 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002207
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002208 try:
2209 cmd = "scp " + localPath + fileName + " " + userName + "@" + \
2210 str( ip ) + ":" + mnPath + fileName
2211
2212 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07002213 self.handle.expect( self.prompt )
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002214
2215 main.log.info( self.name + ": Execute: " + cmd )
2216
2217 self.handle.sendline( cmd )
2218
2219 i = self.handle.expect( [ 'No such file',
2220 "100%",
2221 pexpect.TIMEOUT ] )
2222
2223 if i == 0:
2224 main.log.error( self.name + ": File " + fileName +
2225 " does not exist!" )
2226 return main.FALSE
2227
2228 if i == 1:
2229 main.log.info( self.name + ": File " + fileName +
2230 " has been copied!" )
2231 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07002232 self.handle.expect( self.prompt )
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002233 return main.TRUE
2234
2235 except pexpect.EOF:
2236 main.log.error( self.name + ": EOF exception found" )
2237 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002238 main.cleanAndExit()
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002239 except pexpect.TIMEOUT:
2240 main.log.error( self.name + ": TIMEOUT exception found" )
2241 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002242 main.cleanAndExit()
cameron@onlab.us78b89652015-07-08 15:21:03 -07002243
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002244 def jvmSet( self, memory=8 ):
Jon Hall4ba53f02015-07-29 13:07:41 -07002245
cameron@onlab.us78b89652015-07-08 15:21:03 -07002246 import os
2247
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002248 homeDir = os.path.expanduser( '~' )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002249 filename = "/onos/tools/package/bin/onos-service"
2250
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002251 serviceConfig = open( homeDir + filename, 'w+' )
2252 serviceConfig.write( "#!/bin/bash\n " )
2253 serviceConfig.write( "#------------------------------------- \n " )
2254 serviceConfig.write( "# Starts ONOS Apache Karaf container\n " )
2255 serviceConfig.write( "#------------------------------------- \n " )
2256 serviceConfig.write( "#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n " )
2257 serviceConfig.write( """export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str( memory ) + "G -Xmx" + str( memory ) + """G}" \n """ )
2258 serviceConfig.write( "[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n" )
2259 serviceConfig.write( """${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """ )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002260 serviceConfig.close()
2261
Jon Hall6c44c0b2016-04-20 15:21:00 -07002262 def createDBFile( self, testData ):
Jon Hall4ba53f02015-07-29 13:07:41 -07002263
cameron@onlab.us78b89652015-07-08 15:21:03 -07002264 filename = main.TEST + "DB"
2265 DBString = ""
Jon Hall4ba53f02015-07-29 13:07:41 -07002266
cameron@onlab.us78b89652015-07-08 15:21:03 -07002267 for item in testData:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002268 if isinstance( item, string ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002269 item = "'" + item + "'"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002270 if testData.index( item ) < len( testData - 1 ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002271 item += ","
Jon Hall6c44c0b2016-04-20 15:21:00 -07002272 DBString += str( item )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002273
Jon Hall6c44c0b2016-04-20 15:21:00 -07002274 DBFile = open( filename, "a" )
2275 DBFile.write( DBString )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002276 DBFile.close()
2277
Jon Hall6c44c0b2016-04-20 15:21:00 -07002278 def verifySummary( self, ONOSIp, *deviceCount ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002279
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002280 self.handle.sendline( "onos " + ONOSIp + " summary" )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002281 self.handle.expect( ":~" )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002282
2283 summaryStr = self.handle.before
2284 print "\nSummary\n==============\n" + summaryStr + "\n\n"
2285
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002286 # passed = "SCC(s)=1" in summaryStr
2287 # if deviceCount:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002288 # passed = "devices=" + str(deviceCount) + "," not in summaryStr
cameron@onlab.us78b89652015-07-08 15:21:03 -07002289
GlennRC772363b2015-08-25 13:05:57 -07002290 passed = False
cameron@onlab.us78b89652015-07-08 15:21:03 -07002291 if "SCC(s)=1," in summaryStr:
2292 passed = True
Jon Hall6c44c0b2016-04-20 15:21:00 -07002293 print "Summary is verifed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002294 else:
Jon Hall6c44c0b2016-04-20 15:21:00 -07002295 print "Summary failed"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002296
2297 if deviceCount:
2298 print" ============================="
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002299 checkStr = "devices=" + str( deviceCount[ 0 ] ) + ","
cameron@onlab.us78b89652015-07-08 15:21:03 -07002300 print "Checkstr: " + checkStr
2301 if checkStr not in summaryStr:
2302 passed = False
Jon Hall6c44c0b2016-04-20 15:21:00 -07002303 print "Device count failed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002304 else:
2305 print "device count verified"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002306
2307 return passed
Jon Hall6c44c0b2016-04-20 15:21:00 -07002308
Jon Hall8f6d4622016-05-23 15:27:18 -07002309 def getIpAddr( self, iface=None ):
Jon Hall6c44c0b2016-04-20 15:21:00 -07002310 """
2311 Update self.ip_address with numerical ip address. If multiple IP's are
2312 located on the device, will attempt to use self.nicAddr to choose the
2313 right one. Defaults to 127.0.0.1 if no other address is found or cannot
2314 determine the correct address.
2315
2316 ONLY WORKS WITH IPV4 ADDRESSES
2317 """
2318 try:
Jon Hall8f6d4622016-05-23 15:27:18 -07002319 LOCALHOST = "127.0.0.1"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002320 ipPat = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
2321 pattern = re.compile( ipPat )
2322 match = re.search( pattern, self.ip_address )
2323 if self.nicAddr:
2324 nicPat = self.nicAddr.replace( ".", "\." ).replace( "\*", r"\d{1,3}" )
2325 nicPat = re.compile( nicPat )
2326 else:
2327 nicPat = None
2328 # IF self.ip_address is an ip address and matches
2329 # self.nicAddr: return self.ip_address
2330 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002331 curIp = match.group( 0 )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002332 if nicPat:
2333 nicMatch = re.search( nicPat, curIp )
2334 if nicMatch:
2335 return self.ip_address
Jon Hall8f6d4622016-05-23 15:27:18 -07002336 # ELSE: IF iface, return ip of interface
2337 cmd = "ifconfig"
2338 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2339 if iface:
2340 cmd += " " + str( iface )
2341 raw = subprocess.check_output( cmd.split() )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002342 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2343 ips = re.findall( ifPat, raw )
Jon Hall8f6d4622016-05-23 15:27:18 -07002344 if iface:
2345 if ips:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002346 ip = ips[ 0 ]
Jon Hall8f6d4622016-05-23 15:27:18 -07002347 self.ip_address = ip
2348 return ip
2349 else:
2350 main.log.error( "Error finding ip, ifconfig output:".format( raw ) )
2351 # ELSE: attempt to get address matching nicPat.
Jon Hall6c44c0b2016-04-20 15:21:00 -07002352 if nicPat:
2353 for ip in ips:
2354 curMatch = re.search( nicPat, ip )
2355 if curMatch:
2356 self.ip_address = ip
2357 return ip
Jon Hall8f6d4622016-05-23 15:27:18 -07002358 else: # If only one non-localhost ip, return that
2359 tmpList = [ ip for ip in ips if ip is not LOCALHOST ]
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002360 if len( tmpList ) == 1:
2361 curIp = tmpList[ 0 ]
Jon Hall6c44c0b2016-04-20 15:21:00 -07002362 self.ip_address = curIp
2363 return curIp
Jon Hall8f6d4622016-05-23 15:27:18 -07002364 # Either no non-localhost IPs, or more than 1
Jon Hallebccd352016-05-20 15:17:17 -07002365 main.log.warn( "getIpAddr failed to find a public IP address" )
Jon Hall8f6d4622016-05-23 15:27:18 -07002366 return LOCALHOST
Jon Halle1790952016-05-23 15:51:46 -07002367 except subprocess.CalledProcessError:
Jon Hall8f6d4622016-05-23 15:27:18 -07002368 main.log.exception( "Error executing ifconfig" )
2369 except IndexError:
2370 main.log.exception( "Error getting IP Address" )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002371 except Exception:
2372 main.log.exception( "Uncaught exception" )
suibin zhang116647a2016-05-06 16:30:09 -07002373
Devin Lim461f0872017-06-05 16:49:33 -07002374 def startBasicONOS( self, nodeList, opSleep=60, onosStartupSleep=30, onosUser="sdn" ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002375 '''
suibin zhang116647a2016-05-06 16:30:09 -07002376 Start onos cluster with defined nodes, but only with drivers app
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002377 '''
suibin zhang116647a2016-05-06 16:30:09 -07002378 import time
2379
2380 self.createCellFile( self.ip_address,
2381 "temp",
2382 self.ip_address,
2383 "drivers",
Devin Lim461f0872017-06-05 16:49:33 -07002384 nodeList, onosUser )
suibin zhang116647a2016-05-06 16:30:09 -07002385
2386 main.log.info( self.name + ": Apply cell to environment" )
2387 cellResult = self.setCell( "temp" )
2388 verifyResult = self.verifyCell()
2389
2390 main.log.info( self.name + ": Creating ONOS package" )
You Wangd1bcaca2016-10-24 15:23:26 -07002391 packageResult = self.buckBuild( timeout=opSleep )
suibin zhang116647a2016-05-06 16:30:09 -07002392
You Wangc669d212017-01-25 11:09:48 -08002393 main.log.info( self.name + ": Uninstalling ONOS" )
2394 for nd in nodeList:
2395 self.onosUninstall( nodeIp=nd )
2396
suibin zhang116647a2016-05-06 16:30:09 -07002397 main.log.info( self.name + ": Installing ONOS package" )
2398 for nd in nodeList:
You Wangc669d212017-01-25 11:09:48 -08002399 self.onosInstall( node=nd )
2400
2401 main.log.info( self.name + ": Set up ONOS secure SSH" )
2402 for nd in nodeList:
2403 self.onosSecureSSH( node=nd )
suibin zhang116647a2016-05-06 16:30:09 -07002404
2405 main.log.info( self.name + ": Starting ONOS service" )
2406 time.sleep( onosStartupSleep )
2407
2408 onosStatus = True
2409 for nd in nodeList:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002410 onosStatus = onosStatus & self.isup( node = nd )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002411 # print "onosStatus is: " + str( onosStatus )
suibin zhang116647a2016-05-06 16:30:09 -07002412
2413 return main.TRUE if onosStatus else main.FALSE
2414
Devin Lim02075272017-07-10 15:33:21 -07002415 def onosNetCfg( self, controllerIp, path, fileName ):
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002416 """
2417 Push a specified json file to ONOS through the onos-netcfg service
2418
2419 Required:
Devin Lim02075272017-07-10 15:33:21 -07002420 controllerIp - the Ip of the ONOS node in the cluster
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002421 path - the location of the file to be sent
2422 fileName - name of the json file to be sent
2423
2424 Returns main.TRUE on successfully sending json file, and main.FALSE if
2425 there is an error.
2426 """
2427 try:
Devin Lim02075272017-07-10 15:33:21 -07002428 cmd = "onos-netcfg {0} {1}{2}".format( controllerIp, path, fileName )
2429 main.log.info( "Sending: " + cmd )
2430 main.ONOSbench.handle.sendline( cmd )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -07002431 main.ONOSbench.handle.expect( self.prompt )
Devin Lim02075272017-07-10 15:33:21 -07002432 handle = self.handle.before
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -07002433 if "Error" in handle or "No such file or directory" in handle or "curl: " in handle:
2434 main.log.error( self.name + ": " + handle + self.handle.after )
Devin Lim02075272017-07-10 15:33:21 -07002435 return main.FALSE
Devin Lim752dd7b2017-06-27 14:40:03 -07002436 return main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002437 except pexpect.EOF:
2438 main.log.error( self.name + ": EOF exception found" )
2439 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002440 main.cleanAndExit()
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002441 except Exception:
2442 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002443 main.cleanAndExit()
Devin Lim3ebd5e72017-11-14 10:38:00 -08002444
2445 def formCluster( self, onosIPs ):
2446 """
2447 From ONOS cluster for IP addresses in onosIPs list
2448 """
2449 try:
2450 onosIPs = " ".join( onosIPs )
2451 command = "onos-form-cluster {}".format( onosIPs )
2452 main.log.info( "Sending: " + command )
2453 self.handle.sendline( "" )
2454 self.handle.expect( self.prompt )
2455 self.handle.sendline( command )
2456 self.handle.expect( self.prompt )
2457 handle = self.handle.before
2458 main.log.debug( handle )
2459 assert handle is not None, "Error in sendline"
2460 assert "Command not found:" not in handle, handle
2461 assert "Error" not in handle, handle
2462 assert "Exception:" not in handle, handle
2463 assert "curl:" not in handle, handle
2464 return main.TRUE
2465 except AssertionError:
2466 main.log.exception( "{} Error in onos-form-cluster output:".format( self.name ) )
2467 return main.FALSE
2468 except TypeError:
2469 main.log.exception( self.name + ": Object not as expected" )
2470 return main.FALSE
2471 except pexpect.EOF:
2472 main.log.error( self.name + ": EOF exception found" )
2473 main.log.error( self.name + ": " + self.handle.before )
2474 main.cleanAndExit()
2475 except Exception:
2476 main.log.exception( self.name + ": Uncaught exception!" )
2477 main.cleanAndExit()