blob: 89dc363af3b1b12039519a83f1b90f54e53fbc92 [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 )
You Wang141b43b2018-06-26 16:50:18 -0700235 self.handle.send( "\x03" ) # Control-C
236 self.handle.expect( self.prompt )
Jon Hall64af8502015-12-15 10:09:33 -0800237 return main.FALSE
andrewonlab7735d852014-10-09 13:02:47 -0400238 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800239 main.log.error( self.name + ": EOF exception found" )
240 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700241 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800242 except Exception:
243 main.log.exception( "Failed to package ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700244 main.cleanAndExit()
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400245
kelvin-onlabd3b64892015-01-20 13:26:24 -0800246 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800247 """
andrewonlab8790abb2014-11-06 13:51:54 -0500248 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800249 """
andrewonlab8790abb2014-11-06 13:51:54 -0500250 try:
kelvin8ec71442015-01-15 16:57:00 -0800251 self.handle.sendline( "onos-build" )
252 self.handle.expect( "onos-build" )
253 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800254 "BUILD SUCCESS",
255 "ERROR",
256 "BUILD FAILED" ],
257 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800258 handle = str( self.handle.before )
Devin Limc20e79a2017-06-07 10:29:57 -0700259 self.handle.expect( self.prompt )
andrewonlab8790abb2014-11-06 13:51:54 -0500260
kelvin8ec71442015-01-15 16:57:00 -0800261 main.log.info( "onos-build command returned: " +
262 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500263
264 if i == 0:
265 return main.TRUE
266 else:
267 return handle
268
269 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800270 main.log.error( self.name + ": EOF exception found" )
271 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800272 except Exception:
273 main.log.exception( "Failed to build ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700274 main.cleanAndExit()
andrewonlab8790abb2014-11-06 13:51:54 -0500275
shahshreya9f531fe2015-06-10 12:03:51 -0700276 def cleanInstall( self, skipTest=False, mciTimeout=600 ):
kelvin8ec71442015-01-15 16:57:00 -0800277 """
278 Runs mvn clean install in the root of the ONOS directory.
279 This will clean all ONOS artifacts then compile each module
shahshreya9f531fe2015-06-10 12:03:51 -0700280 Optional:
281 skipTest - Does "-DskipTests -Dcheckstyle.skip -U -T 1C" which
282 skip the test. This will make the building faster.
283 Disregarding the credibility of the build
kelvin8ec71442015-01-15 16:57:00 -0800284 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400285 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800286 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400287 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800288 main.log.info( "Running 'mvn clean install' on " +
289 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800290 ". This may take some time." )
291 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700292 self.handle.expect( self.prompt )
Jon Hallea7818b2014-10-09 14:30:59 -0400293
kelvin8ec71442015-01-15 16:57:00 -0800294 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700295 self.handle.expect( self.prompt )
shahshreya9f531fe2015-06-10 12:03:51 -0700296
297 if not skipTest:
298 self.handle.sendline( "mvn clean install" )
299 self.handle.expect( "mvn clean install" )
300 else:
301 self.handle.sendline( "mvn clean install -DskipTests" +
302 " -Dcheckstyle.skip -U -T 1C" )
303 self.handle.expect( "mvn clean install -DskipTests" +
304 " -Dcheckstyle.skip -U -T 1C" )
kelvin8ec71442015-01-15 16:57:00 -0800305 while True:
306 i = self.handle.expect( [
Jon Hall274b6642015-02-17 11:57:17 -0800307 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' +
Jon Hallefbd9792015-03-05 16:11:36 -0800308 'Runtime\sEnvironment\sto\scontinue',
Jon Hallde9d9aa2014-10-08 20:36:02 -0400309 'BUILD\sFAILURE',
310 'BUILD\sSUCCESS',
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700311 'onos' + self.prompt, # TODO: fix this to be more generic?
Devin Limdc78e202017-06-09 18:30:07 -0700312 'ONOS' + self.prompt,
pingping-lin57a56ce2015-05-20 16:43:48 -0700313 pexpect.TIMEOUT ], mciTimeout )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400314 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800315 main.log.error( self.name + ":There is insufficient memory \
316 for the Java Runtime Environment to continue." )
317 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700318
319 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400320 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800321 main.log.error( self.name + ": Build failure!" )
322 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700323
324 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400325 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800326 main.log.info( self.name + ": Build success!" )
Jon Halle94919c2015-03-23 11:42:57 -0700327 elif i == 3 or i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800328 main.log.info( self.name + ": Build complete" )
329 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400330 for line in self.handle.before.splitlines():
331 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800332 main.log.info( line )
333 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700334 self.handle.expect( self.prompt, timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400335 return main.TRUE
Jon Halle94919c2015-03-23 11:42:57 -0700336 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800337 main.log.error(
338 self.name +
339 ": mvn clean install TIMEOUT!" )
340 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700341
342 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400343 else:
Jon Hall274b6642015-02-17 11:57:17 -0800344 main.log.error( self.name + ": unexpected response from " +
Jon Hallefbd9792015-03-05 16:11:36 -0800345 "mvn clean install" )
kelvin8ec71442015-01-15 16:57:00 -0800346 # return main.FALSE
Devin Lim44075962017-08-11 10:56:37 -0700347
348 main.cleanAndExit()
Jon Hallde9d9aa2014-10-08 20:36:02 -0400349 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800350 main.log.error( self.name + ": EOF exception found" )
351 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700352 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800353 except Exception:
354 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700355 main.cleanAndExit()
Jon Hallacabffd2014-10-09 12:36:53 -0400356
Jon Hall3576f572016-08-23 10:01:07 -0700357 def buckBuild( self, timeout=180 ):
358 """
359 Build onos using buck.
360 """
361 try:
362 ret = main.TRUE
363 self.handle.sendline( "buck build onos" )
364 self.handle.expect( "buck build onos" )
365 output = ""
366 while True:
367 i = self.handle.expect( [ "This does not appear to be the root of a Buck project.",
368 "\n",
369 "BUILD FAILED",
Jon Halld9066132018-03-01 14:52:53 -0800370 "no buck in",
Devin Limc20e79a2017-06-07 10:29:57 -0700371 self.prompt ],
Jon Hall3576f572016-08-23 10:01:07 -0700372 timeout=timeout )
373 output += str( self.handle.before + self.handle.after )
374 if i == 0:
375 main.log.error( "Wrong location" )
376 ret = main.FALSE
377 elif i == 1:
378 # end of a line, buck is still printing output
379 pass
380 elif i == 2:
381 # Build failed
382 main.log.error( "Build failed" )
383 ret = main.FALSE
384 elif i == 3:
Jon Halld9066132018-03-01 14:52:53 -0800385 main.log.error( "Could not find buck in your PATH." )
386 ret = main.FALSE
387 elif i == 4:
Jon Hall3576f572016-08-23 10:01:07 -0700388 # Prompt returned
389 break
390 main.log.debug( output )
391 return ret
392 except pexpect.TIMEOUT:
393 main.log.exception( self.name + ": TIMEOUT exception found" )
394 main.log.error( self.name + ": " + self.handle.before )
You Wang141b43b2018-06-26 16:50:18 -0700395 self.handle.send( "\x03" ) # Control-C
396 self.handle.expect( self.prompt )
Jon Hall3576f572016-08-23 10:01:07 -0700397 return main.FALSE
398 except pexpect.EOF:
399 main.log.error( self.name + ": EOF exception found" )
400 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700401 main.cleanAndExit()
Jon Hall3576f572016-08-23 10:01:07 -0700402 except Exception:
403 main.log.exception( "Failed to build and package ONOS" )
Devin Lim44075962017-08-11 10:56:37 -0700404 main.cleanAndExit()
Jon Hall3576f572016-08-23 10:01:07 -0700405
Jon Hall61282e32015-03-19 11:34:11 -0700406 def gitPull( self, comp1="", fastForward=True ):
kelvin8ec71442015-01-15 16:57:00 -0800407 """
Jon Hallacabffd2014-10-09 12:36:53 -0400408 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800409
Jon Hall61282e32015-03-19 11:34:11 -0700410 If the fastForward boolean is set to true, only git pulls that can
411 be fast forwarded will be performed. IE if you have not local commits
412 in your branch.
413
Jon Hallacabffd2014-10-09 12:36:53 -0400414 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800415 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400416 for the purpose of pulling from other nodes if necessary.
417
Jon Hall47a93fb2015-01-06 16:46:06 -0800418 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400419 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800420 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400421 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400422
kelvin8ec71442015-01-15 16:57:00 -0800423 """
Jon Hallacabffd2014-10-09 12:36:53 -0400424 try:
kelvin8ec71442015-01-15 16:57:00 -0800425 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700426 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700427 cmd = "git pull"
428 if comp1 != "":
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700429 cmd += ' ' + comp1
Jon Hall61282e32015-03-19 11:34:11 -0700430 if fastForward:
431 cmd += ' ' + " --ff-only"
432 self.handle.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800433 i = self.handle.expect(
434 [
435 'fatal',
436 'Username\sfor\s(.*):\s',
437 '\sfile(s*) changed,\s',
438 'Already up-to-date',
439 'Aborting',
440 'You\sare\snot\scurrently\son\sa\sbranch',
Jon Hall274b6642015-02-17 11:57:17 -0800441 'You asked me to pull without telling me which branch you',
442 'Pull is not possible because you have unmerged files',
Jon Hall61282e32015-03-19 11:34:11 -0700443 'Please enter a commit message to explain why this merge',
444 'Found a swap file by the name',
445 'Please, commit your changes before you can merge.',
kelvin-onlabd3b64892015-01-20 13:26:24 -0800446 pexpect.TIMEOUT ],
447 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800448 if i == 0:
Jon Hall61282e32015-03-19 11:34:11 -0700449 main.log.error( self.name + ": Git pull had some issue" )
450 output = self.handle.after
Devin Limdc78e202017-06-09 18:30:07 -0700451 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700452 output += self.handle.before
453 main.log.warn( output )
Jon Hallacabffd2014-10-09 12:36:53 -0400454 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800455 elif i == 1:
456 main.log.error(
457 self.name +
458 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400459 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800460 elif i == 2:
461 main.log.info(
462 self.name +
463 ": Git Pull - pulling repository now" )
Devin Limc20e79a2017-06-07 10:29:57 -0700464 self.handle.expect( self.prompt, 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800465 # So that only when git pull is done, we do mvn clean compile
466 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800467 elif i == 3:
468 main.log.info( self.name + ": Git Pull - Already up to date" )
Devin Limc20e79a2017-06-07 10:29:57 -0700469 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800470 elif i == 4:
471 main.log.info(
472 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800473 ": Git Pull - Aborting..." +
474 "Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400475 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800476 elif i == 5:
477 main.log.info(
478 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800479 ": Git Pull - You are not currently " +
480 "on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400481 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800482 elif i == 6:
483 main.log.info(
484 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800485 ": Git Pull - You have not configured an upstream " +
486 "branch to pull from. Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400487 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800488 elif i == 7:
489 main.log.info(
490 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800491 ": Git Pull - Pull is not possible because " +
492 "you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400493 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800494 elif i == 8:
Jon Hall61282e32015-03-19 11:34:11 -0700495 # NOTE: abandoning test since we can't reliably handle this
496 # there could be different default text editors and we
497 # also don't know if we actually want to make the commit
498 main.log.error( "Git pull resulted in a merge commit message" +
499 ". Exiting test!" )
Devin Lim44075962017-08-11 10:56:37 -0700500
501 main.cleanAndExit()
Jon Hall61282e32015-03-19 11:34:11 -0700502 elif i == 9: # Merge commit message but swap file exists
503 main.log.error( "Git pull resulted in a merge commit message" +
504 " but a swap file exists." )
505 try:
506 self.handle.send( 'A' ) # Abort
Devin Limc20e79a2017-06-07 10:29:57 -0700507 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700508 return main.ERROR
509 except Exception:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700510 main.log.exception( "Couldn't exit editor prompt!" )
Devin Lim44075962017-08-11 10:56:37 -0700511
512 main.cleanAndExit()
Jon Hall61282e32015-03-19 11:34:11 -0700513 elif i == 10: # In the middle of a merge commit
514 main.log.error( "Git branch is in the middle of a merge. " )
515 main.log.warn( self.handle.before + self.handle.after )
516 return main.ERROR
517 elif i == 11:
kelvin8ec71442015-01-15 16:57:00 -0800518 main.log.error( self.name + ": Git Pull - TIMEOUT" )
519 main.log.error(
520 self.name + " Response was: " + str(
521 self.handle.before ) )
You Wang141b43b2018-06-26 16:50:18 -0700522 self.handle.send( "\x03" ) # Control-C
523 self.handle.expect( self.prompt )
Jon Hallacabffd2014-10-09 12:36:53 -0400524 return main.ERROR
525 else:
kelvin8ec71442015-01-15 16:57:00 -0800526 main.log.error(
527 self.name +
528 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400529 return main.ERROR
530 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800531 main.log.error( self.name + ": EOF exception found" )
532 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700533 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800534 except Exception:
535 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700536 main.cleanAndExit()
Jon Hallacabffd2014-10-09 12:36:53 -0400537
kelvin-onlabd3b64892015-01-20 13:26:24 -0800538 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800539 """
Jon Hallacabffd2014-10-09 12:36:53 -0400540 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800541
Jon Hallacabffd2014-10-09 12:36:53 -0400542 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800543 If used as gitCheckout( "branch" ) it will do git checkout
544 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400545
546 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800547 branch of the ONOS repository. If it has any problems, it will return
548 main.ERROR.
549 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400550 successful then the function will return main.TRUE.
551
kelvin8ec71442015-01-15 16:57:00 -0800552 """
Jon Hallacabffd2014-10-09 12:36:53 -0400553 try:
kelvin8ec71442015-01-15 16:57:00 -0800554 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700555 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800556 main.log.info( self.name +
557 ": Checking out git branch/ref: " + branch + "..." )
kelvin8ec71442015-01-15 16:57:00 -0800558 cmd = "git checkout " + branch
559 self.handle.sendline( cmd )
560 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800561 i = self.handle.expect(
Jon Hall274b6642015-02-17 11:57:17 -0800562 [ 'fatal',
Jon Hall61282e32015-03-19 11:34:11 -0700563 'Username for (.*): ',
564 'Already on \'',
Jon Hall7a8354f2015-06-10 15:37:00 -0700565 'Switched to (a new )?branch \'' + str( branch ),
Jon Hall274b6642015-02-17 11:57:17 -0800566 pexpect.TIMEOUT,
567 'error: Your local changes to the following files' +
Jon Hallefbd9792015-03-05 16:11:36 -0800568 'would be overwritten by checkout:',
Jon Hall274b6642015-02-17 11:57:17 -0800569 'error: you need to resolve your current index first',
570 "You are in 'detached HEAD' state.",
571 "HEAD is now at " ],
kelvin-onlabd3b64892015-01-20 13:26:24 -0800572 timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -0800573 if i == 0:
574 main.log.error(
575 self.name +
576 ": Git checkout had some issue..." )
577 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400578 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800579 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800580 main.log.error(
581 self.name +
582 ": Git checkout asking for username." +
583 " Please configure your local git repository to be able " +
584 "to access your remote repository passwordlessly" )
Jon Hall274b6642015-02-17 11:57:17 -0800585 # TODO add support for authenticating
Jon Hallacabffd2014-10-09 12:36:53 -0400586 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800587 elif i == 2:
588 main.log.info(
589 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800590 ": Git Checkout %s : Already on this branch" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700591 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800592 # main.log.info( "DEBUG: after checkout cmd = "+
593 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400594 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800595 elif i == 3:
596 main.log.info(
597 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800598 ": Git checkout %s - Switched to this branch" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700599 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800600 # main.log.info( "DEBUG: after checkout cmd = "+
601 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400602 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800603 elif i == 4:
604 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
605 main.log.error(
Jon Hall274b6642015-02-17 11:57:17 -0800606 self.name + " Response was: " + str( self.handle.before ) )
You Wang141b43b2018-06-26 16:50:18 -0700607 self.handle.send( "\x03" ) # Control-C
608 self.handle.expect( self.prompt )
Jon Hallacabffd2014-10-09 12:36:53 -0400609 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800610 elif i == 5:
611 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800612 main.log.error(
613 self.name +
614 ": Git checkout error: \n" +
Jon Hall274b6642015-02-17 11:57:17 -0800615 "Your local changes to the following files would" +
616 " be overwritten by checkout:" +
617 str( self.handle.before ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700618 self.handle.expect( self.prompt )
Jon Hall81e29af2014-11-04 20:41:23 -0500619 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800620 elif i == 6:
Jon Hall274b6642015-02-17 11:57:17 -0800621 main.log.error(
622 self.name +
623 ": Git checkout error: \n" +
624 "You need to resolve your current index first:" +
625 str( self.handle.before ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700626 self.handle.expect( self.prompt )
Jon Hall81e29af2014-11-04 20:41:23 -0500627 return main.ERROR
Jon Hall274b6642015-02-17 11:57:17 -0800628 elif i == 7:
629 main.log.info(
630 self.name +
631 ": Git checkout " + str( branch ) +
632 " - You are in 'detached HEAD' state. HEAD is now at " +
633 str( branch ) )
Devin Limc20e79a2017-06-07 10:29:57 -0700634 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800635 return main.TRUE
636 elif i == 8: # Already in detached HEAD on the specified commit
637 main.log.info(
638 self.name +
639 ": Git Checkout %s : Already on commit" % branch )
Devin Limc20e79a2017-06-07 10:29:57 -0700640 self.handle.expect( self.prompt )
Jon Hall274b6642015-02-17 11:57:17 -0800641 return main.TRUE
Jon Hallacabffd2014-10-09 12:36:53 -0400642 else:
kelvin8ec71442015-01-15 16:57:00 -0800643 main.log.error(
644 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800645 ": Git Checkout - Unexpected response, " +
646 "check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800647 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400648 return main.ERROR
649
650 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800651 main.log.error( self.name + ": EOF exception found" )
652 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700653 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800654 except Exception:
655 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700656 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400657
pingping-lin6d23d9e2015-02-02 16:54:24 -0800658 def getBranchName( self ):
You Wang9cdf9a22017-05-01 13:44:18 -0700659 import re
660 try:
661 main.log.info( "self.home = " )
662 main.log.info( self.home )
663 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700664 self.handle.expect( self.prompt )
You Wang9cdf9a22017-05-01 13:44:18 -0700665 self.handle.sendline( "git name-rev --name-only HEAD" )
666 self.handle.expect( "git name-rev --name-only HEAD" )
Devin Limc20e79a2017-06-07 10:29:57 -0700667 self.handle.expect( self.prompt )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700668 lines = self.handle.before.splitlines()
669 if lines[ 1 ] == "master" or re.search( "^onos-\d+(\.\d+)+$", lines[ 1 ] ):
670 return lines[ 1 ]
You Wang9cdf9a22017-05-01 13:44:18 -0700671 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700672 main.log.info( lines[ 1 ] )
You Wang9cdf9a22017-05-01 13:44:18 -0700673 return "unexpected ONOS branch"
674 except pexpect.EOF:
675 main.log.error( self.name + ": EOF exception found" )
676 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700677 main.cleanAndExit()
You Wang9cdf9a22017-05-01 13:44:18 -0700678 except pexpect.TIMEOUT:
679 main.log.error( self.name + ": TIMEOUT exception found" )
680 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700681 main.cleanAndExit()
You Wang9cdf9a22017-05-01 13:44:18 -0700682 except Exception:
683 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700684 main.cleanAndExit()
pingping-lin6d23d9e2015-02-02 16:54:24 -0800685
kelvin-onlabd3b64892015-01-20 13:26:24 -0800686 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800687 """
Jon Hall274b6642015-02-17 11:57:17 -0800688 Writes the COMMIT number to the report to be parsed
Jon Hallefbd9792015-03-05 16:11:36 -0800689 by Jenkins data collector.
kelvin8ec71442015-01-15 16:57:00 -0800690 """
Jon Hall45ec0922014-10-10 19:33:49 -0400691 try:
kelvin8ec71442015-01-15 16:57:00 -0800692 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700693 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800694 self.handle.sendline(
695 "cd " +
696 self.home +
Jon Hall274b6642015-02-17 11:57:17 -0800697 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " +
698 " \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800699 # NOTE: for some reason there are backspaces inserted in this
700 # phrase when run from Jenkins on some tests
701 self.handle.expect( "never" )
Devin Limc20e79a2017-06-07 10:29:57 -0700702 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800703 response = ( self.name + ": \n" + str(
704 self.handle.before + self.handle.after ) )
705 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -0700706 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800707 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400708 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500709 print line
710 if report:
pingping-lin763ee042015-05-20 17:45:30 -0700711 main.log.wiki( "<blockquote>" )
kelvin8ec71442015-01-15 16:57:00 -0800712 for line in lines[ 2:-1 ]:
713 # Bracket replacement is for Wiki-compliant
714 # formatting. '<' or '>' are interpreted
715 # as xml specific tags that cause errors
716 line = line.replace( "<", "[" )
717 line = line.replace( ">", "]" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700718 # main.log.wiki( "\t" + line )
pingping-lin763ee042015-05-20 17:45:30 -0700719 main.log.wiki( line + "<br /> " )
720 main.log.summary( line )
721 main.log.wiki( "</blockquote>" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700722 main.log.summary( "\n" )
kelvin8ec71442015-01-15 16:57:00 -0800723 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400724 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800725 main.log.error( self.name + ": EOF exception found" )
726 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700727 main.cleanAndExit()
Jon Hall368769f2014-11-19 15:43:35 -0800728 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800729 main.log.error( self.name + ": TIMEOUT exception found" )
730 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700731 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800732 except Exception:
733 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700734 main.cleanAndExit()
Jon Hall45ec0922014-10-10 19:33:49 -0400735
kelvin-onlabd3b64892015-01-20 13:26:24 -0800736 def createCellFile( self, benchIp, fileName, mnIpAddrs,
Jon Hall810b67d2016-12-05 10:19:01 -0800737 appString, onosIpAddrs, onosUser="sdn", useSSH=True ):
kelvin8ec71442015-01-15 16:57:00 -0800738 """
andrewonlab94282092014-10-10 13:00:11 -0400739 Creates a cell file based on arguments
740 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800741 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400742 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800743 * File name of the cell file ( fileName )
744 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800745 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400746 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800747 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400748 - Must be passed in as last arguments
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000749 * ONOS USER (onosUser)
Flavio Castrocc38a542016-03-03 13:15:46 -0800750 - optional argument to set ONOS_USER environment variable
kelvin8ec71442015-01-15 16:57:00 -0800751
andrewonlab94282092014-10-10 13:00:11 -0400752 NOTE: Assumes cells are located at:
753 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800754 """
andrewonlab94282092014-10-10 13:00:11 -0400755 try:
Devin Lim461f0872017-06-05 16:49:33 -0700756
Jon Hall2c8959e2016-12-16 12:17:34 -0800757 # Variable initialization
758 cellDirectory = self.home + "/tools/test/cells/"
759 # We want to create the cell file in the dependencies directory
760 # of TestON first, then copy over to ONOS bench
761 tempDirectory = "/tmp/"
762 # Create the cell file in the directory for writing ( w+ )
763 cellFile = open( tempDirectory + fileName, 'w+' )
764 if isinstance( onosIpAddrs, types.StringType ):
765 onosIpAddrs = [ onosIpAddrs ]
766
767 # App string is hardcoded environment variables
768 # That you may wish to use by default on startup.
769 # Note that you may not want certain apps listed
770 # on here.
771 appString = "export ONOS_APPS=" + appString
772 onosGroup = "export ONOS_GROUP=" + onosUser
773 onosUser = "export ONOS_USER=" + onosUser
774 if useSSH:
775 onosUseSSH = "export ONOS_USE_SSH=true"
776 mnString = "export OCN="
777 if mnIpAddrs == "":
778 mnString = ""
779 onosString = "export OC"
780 tempCount = 1
781
782 # Create ONOSNIC ip address prefix
783 tempOnosIp = str( onosIpAddrs[ 0 ] )
784 tempList = []
785 tempList = tempOnosIp.split( "." )
786 # Omit last element of list to format for NIC
787 tempList = tempList[ :-1 ]
788 # Structure the nic string ip
789 nicAddr = ".".join( tempList ) + ".*"
790 self.nicAddr = nicAddr
791 onosNicString = "export ONOS_NIC=" + nicAddr
792
kelvin8ec71442015-01-15 16:57:00 -0800793 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800794 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400795
kelvin-onlabd3b64892015-01-20 13:26:24 -0800796 for arg in onosIpAddrs:
797 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800798 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400799 # export OC1="10.128.20.11"
800 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800801 cellFile.write( onosString + str( tempCount ) +
Jon Hall6f665652015-09-18 10:08:07 -0700802 "=\"" + arg + "\"\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800803 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800804
Jon Hall6f665652015-09-18 10:08:07 -0700805 cellFile.write( "export OCI=$OC1\n" )
Jon Hallab611372018-02-21 15:26:05 -0800806 if mnString:
807 cellFile.write( mnString + "\"" + str( mnIpAddrs ) + "\"\n" )
cameron@onlab.us75900962015-03-30 13:22:49 -0700808 cellFile.write( appString + "\n" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800809 cellFile.write( onosGroup + "\n" )
810 cellFile.write( onosUser + "\n" )
Pier88189b62016-09-07 17:01:53 -0700811 if useSSH:
812 cellFile.write( onosUseSSH + "\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800813 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400814
kelvin8ec71442015-01-15 16:57:00 -0800815 # We use os.system to send the command to TestON cluster
816 # to account for the case in which TestON is not located
817 # on the same cluster as the ONOS bench
818 # Note that even if TestON is located on the same cluster
819 # as ONOS bench, you must setup passwordless ssh
820 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabc2b79102015-07-14 11:41:20 -0700821 os.system( "scp " + tempDirectory + fileName + " " +
822 self.user_name + "@" + self.ip_address + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400823
andrewonlab2a6c9342014-10-16 13:40:15 -0400824 return main.TRUE
825
andrewonlab94282092014-10-10 13:00:11 -0400826 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800827 main.log.error( self.name + ": EOF exception found" )
828 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700829 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800830 except Exception:
831 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700832 main.cleanAndExit()
andrewonlab94282092014-10-10 13:00:11 -0400833
kelvin-onlabd3b64892015-01-20 13:26:24 -0800834 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800835 """
andrewonlab95ca1462014-10-09 14:04:24 -0400836 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800837 """
andrewonlab95ca1462014-10-09 14:04:24 -0400838 try:
839 if not cellname:
You Wang1cdc5f52017-12-19 16:47:51 -0800840 main.log.error( self.name + ": Must define cellname" )
Devin Lim44075962017-08-11 10:56:37 -0700841 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400842 else:
kelvin8ec71442015-01-15 16:57:00 -0800843 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800844 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800845 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400846 # and that this driver will have to change accordingly
Jon Hall3b489db2015-10-05 14:38:37 -0700847 self.handle.expect( str( cellname ) )
Jon Hallab611372018-02-21 15:26:05 -0800848 response = self.handle.before + self.handle.after
You Wang1cdc5f52017-12-19 16:47:51 -0800849 i = self.handle.expect( [ "No such cell",
Jon Hallab611372018-02-21 15:26:05 -0800850 "command not found",
851 self.prompt ], timeout=10 )
852 response += self.handle.before + self.handle.after
You Wang1cdc5f52017-12-19 16:47:51 -0800853 if i == 0:
Jon Hallab611372018-02-21 15:26:05 -0800854 main.log.error( self.name + ": No such cell. Response: " + str( response ) )
You Wang1cdc5f52017-12-19 16:47:51 -0800855 main.cleanAndExit()
856 elif i == 1:
Jon Hallab611372018-02-21 15:26:05 -0800857 main.log.error( self.name + ": Error setting cell. Response: " + str( response ) )
858 main.cleanAndExit()
You Wang1cdc5f52017-12-19 16:47:51 -0800859 elif i == 2:
Jon Hallab611372018-02-21 15:26:05 -0800860 main.log.info( self.name + ": Successfully set cell: " + str( response ) )
andrewonlab95ca1462014-10-09 14:04:24 -0400861 return main.TRUE
You Wang1cdc5f52017-12-19 16:47:51 -0800862 except pexpect.TIMEOUT:
863 main.log.error( self.name + ": TIMEOUT exception found" )
864 main.log.error( self.name + ": " + self.handle.before )
865 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400866 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800867 main.log.error( self.name + ": EOF exception found" )
868 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700869 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800870 except Exception:
871 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700872 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -0400873
kelvin-onlabd3b64892015-01-20 13:26:24 -0800874 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800875 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400876 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800877 """
878 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400879
andrewonlabc03bf6c2014-10-09 14:56:18 -0400880 try:
kelvin8ec71442015-01-15 16:57:00 -0800881 # Clean handle by sending empty and expecting $
882 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700883 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -0800884 self.handle.sendline( "onos-verify-cell" )
Devin Limc20e79a2017-06-07 10:29:57 -0700885 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800886 handleBefore = self.handle.before
887 handleAfter = self.handle.after
kelvin-onlabd3b64892015-01-20 13:26:24 -0800888 main.log.info( "Verify cell returned: " + handleBefore +
Jon Hall3b489db2015-10-05 14:38:37 -0700889 handleAfter )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400890 return main.TRUE
Jon Halla5cb6172015-02-23 09:28:28 -0800891 except pexpect.ExceptionPexpect as e:
Jon Hall3b489db2015-10-05 14:38:37 -0700892 main.log.exception( self.name + ": Pexpect exception found: " )
kelvin8ec71442015-01-15 16:57:00 -0800893 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700894 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800895 except Exception:
896 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700897 main.cleanAndExit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400898
jenkins1e99e7b2015-04-02 18:15:39 -0700899 def onosCfgSet( self, ONOSIp, configName, configParam ):
900 """
901 Uses 'onos <node-ip> cfg set' to change a parameter value of an
Jon Hall4ba53f02015-07-29 13:07:41 -0700902 application.
903
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000904 ex)
jenkins1e99e7b2015-04-02 18:15:39 -0700905 onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1
jenkins1e99e7b2015-04-02 18:15:39 -0700906 ONOSIp = '10.0.0.1'
907 configName = 'org.onosproject.myapp'
908 configParam = 'appSetting 1'
jenkins1e99e7b2015-04-02 18:15:39 -0700909 """
Jon Hall72280bc2016-01-25 14:29:05 -0800910 try:
911 cfgStr = "onos {} cfg set {} {}".format( ONOSIp,
912 configName,
913 configParam )
914 self.handle.sendline( "" )
915 self.handle.expect( ":~" )
916 self.handle.sendline( cfgStr )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700917 self.handle.expect( "cfg set" )
Jon Hall72280bc2016-01-25 14:29:05 -0800918 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700919
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700920 paramValue = configParam.split( " " )[ 1 ]
921 paramName = configParam.split( " " )[ 0 ]
Jon Hall4ba53f02015-07-29 13:07:41 -0700922
Jon Hall72280bc2016-01-25 14:29:05 -0800923 checkStr = 'onos {} cfg get " {} {} " '.format( ONOSIp, configName, paramName )
Jon Hall4ba53f02015-07-29 13:07:41 -0700924
Jon Hall72280bc2016-01-25 14:29:05 -0800925 self.handle.sendline( checkStr )
926 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700927
Jon Hall72280bc2016-01-25 14:29:05 -0800928 if "value=" + paramValue + "," in self.handle.before:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700929 main.log.info( "cfg " + configName + " successfully set to " + configParam )
Jon Hall72280bc2016-01-25 14:29:05 -0800930 return main.TRUE
931 except pexpect.ExceptionPexpect as e:
932 main.log.exception( self.name + ": Pexpect exception found: " )
933 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700934 main.cleanAndExit()
Jon Hall72280bc2016-01-25 14:29:05 -0800935 except Exception:
936 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700937 main.cleanAndExit()
Jon Hall4ba53f02015-07-29 13:07:41 -0700938
You Wang54b1d672018-06-11 16:44:13 -0700939 def onosCli( self, ONOSIp, cmdstr, timeout=60 ):
kelvin8ec71442015-01-15 16:57:00 -0800940 """
andrewonlab05e362f2014-10-10 00:40:57 -0400941 Uses 'onos' command to send various ONOS CLI arguments.
942 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800943 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400944 * cmdstr: specify the command string to send
You Wang54b1d672018-06-11 16:44:13 -0700945 Optional:
946 * timeout: pexpect timeout for running the command
kelvin8ec71442015-01-15 16:57:00 -0800947
948 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400949 CLI commands for ONOS. Try to use this function first
950 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800951 function.
952 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400953 by starting onos, and typing in 'onos' to enter the
954 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800955 available commands.
956 """
andrewonlab05e362f2014-10-10 00:40:57 -0400957 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800958 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800959 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400960 return main.FALSE
961 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800962 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400963 return main.FALSE
964
kelvin8ec71442015-01-15 16:57:00 -0800965 cmdstr = str( cmdstr )
966 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -0700967 self.handle.expect( self.prompt )
andrewonlab05e362f2014-10-10 00:40:57 -0400968
You Wangdd3dae52018-02-15 13:31:25 -0800969 self.handle.sendline( "onos-wait-for-start " + ONOSIp )
970 self.handle.expect( self.prompt )
971
972 self.handle.sendline( "onos " + ONOSIp + " " + cmdstr )
You Wang54b1d672018-06-11 16:44:13 -0700973 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ], timeout=timeout )
974 if i == 0:
975 handleBefore = self.handle.before
976 main.log.info( "Command sent successfully" )
977 # Obtain return handle that consists of result from
978 # the onos command. The string may need to be
979 # configured further.
980 returnString = handleBefore
981 return returnString
982 elif i == 1:
983 main.log.error( self.name + ": Timeout when sending " + cmdstr )
You Wang141b43b2018-06-26 16:50:18 -0700984 self.handle.send( "\x03" ) # Control-C
You Wang54b1d672018-06-11 16:44:13 -0700985 self.handle.expect( self.prompt )
986 return main.FALSE
You Wangd66de192018-04-30 17:30:12 -0700987 except pexpect.TIMEOUT:
988 main.log.exception( self.name + ": Timeout when sending " + cmdstr )
989 return main.FALSE
andrewonlab05e362f2014-10-10 00:40:57 -0400990 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800991 main.log.error( self.name + ": EOF exception found" )
992 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700993 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800994 except Exception:
995 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700996 main.cleanAndExit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400997
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700998 def onosSecureSSH( self, userName="onos", userPWD="rocks", node="" ):
Pier88189b62016-09-07 17:01:53 -0700999 """
1000 Enables secure access to ONOS console
1001 by removing default users & keys.
1002
1003 onos-secure-ssh -u onos -p rocks node
1004
1005 Returns: main.TRUE on success and main.FALSE on failure
1006 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001007
Pier88189b62016-09-07 17:01:53 -07001008 try:
Chiyu Chengef109502016-11-21 15:51:38 -08001009 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001010 self.handle.expect( self.prompt )
Pier88189b62016-09-07 17:01:53 -07001011 self.handle.sendline( " onos-secure-ssh -u " + userName + " -p " + userPWD + " " + node )
1012
1013 # NOTE: this timeout may need to change depending on the network
1014 # and size of ONOS
1015 # TODO: Handle the other possible error
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001016 i = self.handle.expect( [ "Network\sis\sunreachable",
1017 self.prompt,
1018 pexpect.TIMEOUT ], timeout=180 )
Pier88189b62016-09-07 17:01:53 -07001019 if i == 0:
1020 # can't reach ONOS node
1021 main.log.warn( "Network is unreachable" )
Devin Limc20e79a2017-06-07 10:29:57 -07001022 self.handle.expect( self.prompt )
Pier88189b62016-09-07 17:01:53 -07001023 return main.FALSE
1024 elif i == 1:
1025 # Process started
1026 main.log.info(
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001027 "Secure SSH performed on " +
1028 node )
Pier88189b62016-09-07 17:01:53 -07001029 return main.TRUE
1030 except pexpect.EOF:
1031 main.log.error( self.name + ": EOF exception found" )
1032 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001033 main.cleanAndExit()
Pier88189b62016-09-07 17:01:53 -07001034 except Exception:
1035 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001036 main.cleanAndExit()
Pier88189b62016-09-07 17:01:53 -07001037
kelvin-onlabd3b64892015-01-20 13:26:24 -08001038 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001039 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001040 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -08001041 If -f option is provided, it also forces an uninstall.
1042 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -04001043 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -08001044 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -04001045 files to certain onos nodes
1046
1047 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -08001048 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001049 try:
andrewonlab114768a2014-11-14 12:44:44 -05001050 if options:
kelvin8ec71442015-01-15 16:57:00 -08001051 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -05001052 else:
kelvin8ec71442015-01-15 16:57:00 -08001053 self.handle.sendline( "onos-install " + node )
1054 self.handle.expect( "onos-install " )
1055 # NOTE: this timeout may need to change depending on the network
1056 # and size of ONOS
1057 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001058 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -08001059 "ONOS\sis\salready\sinstalled",
Jeremyc72b2582016-02-26 18:27:38 -08001060 "already\sup-to-date",
Jon Hall3576f572016-08-23 10:01:07 -07001061 "does not exist",
Devin Limc20e79a2017-06-07 10:29:57 -07001062 self.prompt,
Jon Hall6c44c0b2016-04-20 15:21:00 -07001063 pexpect.TIMEOUT ], timeout=180 )
Jon Hall7993bfc2014-10-09 16:30:14 -04001064 if i == 0:
Jon Hall3576f572016-08-23 10:01:07 -07001065 # can't reach ONOS node
kelvin8ec71442015-01-15 16:57:00 -08001066 main.log.warn( "Network is unreachable" )
Devin Limc20e79a2017-06-07 10:29:57 -07001067 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001068 return main.FALSE
1069 elif i == 1:
Jon Hall3576f572016-08-23 10:01:07 -07001070 # Process started
kelvin8ec71442015-01-15 16:57:00 -08001071 main.log.info(
1072 "ONOS was installed on " +
1073 node +
1074 " and started" )
Devin Limc20e79a2017-06-07 10:29:57 -07001075 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001076 return main.TRUE
Jon Hall3576f572016-08-23 10:01:07 -07001077 elif i == 2 or i == 3:
1078 # same bits are already on ONOS node
Jeremyc72b2582016-02-26 18:27:38 -08001079 main.log.info( "ONOS is already installed on " + node )
Devin Limc20e79a2017-06-07 10:29:57 -07001080 self.handle.expect( self.prompt )
Jeremyc72b2582016-02-26 18:27:38 -08001081 return main.TRUE
1082 elif i == 4:
Jon Hall3576f572016-08-23 10:01:07 -07001083 # onos not packaged
1084 main.log.error( "ONOS package not found." )
Devin Limc20e79a2017-06-07 10:29:57 -07001085 self.handle.expect( self.prompt )
Jon Hall3576f572016-08-23 10:01:07 -07001086 return main.FALSE
1087 elif i == 5:
1088 # prompt
Jeremyc72b2582016-02-26 18:27:38 -08001089 main.log.info( "ONOS was installed on " + node )
1090 return main.TRUE
Jon Hall3576f572016-08-23 10:01:07 -07001091 elif i == 6:
1092 # timeout
kelvin8ec71442015-01-15 16:57:00 -08001093 main.log.info(
1094 "Installation of ONOS on " +
1095 node +
1096 " timed out" )
Devin Limc20e79a2017-06-07 10:29:57 -07001097 self.handle.expect( self.prompt )
Jon Hall53c5e662016-04-13 16:06:56 -07001098 main.log.warn( self.handle.before )
You Wang141b43b2018-06-26 16:50:18 -07001099 self.handle.send( "\x03" ) # Control-C
1100 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001101 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -04001102 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001103 main.log.error( self.name + ": EOF exception found" )
1104 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001105 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001106 except Exception:
1107 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001108 main.cleanAndExit()
andrewonlab95ca1462014-10-09 14:04:24 -04001109
kelvin-onlabd3b64892015-01-20 13:26:24 -08001110 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001111 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001112 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001113 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001114 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001115 try:
kelvin8ec71442015-01-15 16:57:00 -08001116 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001117 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001118 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001119 " start" )
1120 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -04001121 "Job\sis\salready\srunning",
1122 "start/running",
Devin Limc20e79a2017-06-07 10:29:57 -07001123 self.prompt,
andrewonlab8d0d7d72014-10-09 16:33:15 -04001124 "Unknown\sinstance",
Jeremy Songster14c13572016-04-21 17:34:03 -07001125 pexpect.TIMEOUT ], timeout=180 )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001126 if i == 0:
Devin Limc20e79a2017-06-07 10:29:57 -07001127 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001128 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001129 return main.TRUE
1130 elif i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001131 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001132 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001133 return main.TRUE
Jeremyd0e9a6d2016-03-02 11:28:52 -08001134 elif i == 2:
1135 main.log.info( "ONOS service started" )
1136 return main.TRUE
andrewonlab8d0d7d72014-10-09 16:33:15 -04001137 else:
Devin Limc20e79a2017-06-07 10:29:57 -07001138 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001139 main.log.error( "ONOS service failed to start" )
Devin Lim44075962017-08-11 10:56:37 -07001140
1141 main.cleanAndExit()
andrewonlab8d0d7d72014-10-09 16:33:15 -04001142 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001143 main.log.error( self.name + ": EOF exception found" )
1144 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001145 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001146 except Exception:
1147 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001148 main.cleanAndExit()
andrewonlab8d0d7d72014-10-09 16:33:15 -04001149
kelvin-onlabd3b64892015-01-20 13:26:24 -08001150 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001151 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001152 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001153 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001154 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001155 try:
kelvin8ec71442015-01-15 16:57:00 -08001156 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001157 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001158 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001159 " stop" )
1160 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -04001161 "stop/waiting",
Jon Hall61282e32015-03-19 11:34:11 -07001162 "Could not resolve hostname",
andrewonlab2b30bd32014-10-09 16:48:55 -04001163 "Unknown\sinstance",
Devin Limc20e79a2017-06-07 10:29:57 -07001164 self.prompt,
Jeremy Songster14c13572016-04-21 17:34:03 -07001165 pexpect.TIMEOUT ], timeout=180 )
andrewonlab2b30bd32014-10-09 16:48:55 -04001166 if i == 0:
Devin Limc20e79a2017-06-07 10:29:57 -07001167 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001168 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001169 return main.TRUE
1170 elif i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001171 self.handle.expect( self.prompt )
Jon Hall65844a32015-03-09 19:09:37 -07001172 main.log.info( "onosStop() Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001173 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -04001174 return main.FALSE
Jon Hall61282e32015-03-19 11:34:11 -07001175 elif i == 2:
Devin Limc20e79a2017-06-07 10:29:57 -07001176 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -07001177 main.log.warn( "ONOS wasn't running" )
1178 return main.TRUE
YPZhang77badfc2016-03-09 10:28:59 -08001179 elif i == 3:
1180 main.log.info( "ONOS service stopped" )
1181 return main.TRUE
andrewonlab2b30bd32014-10-09 16:48:55 -04001182 else:
kelvin8ec71442015-01-15 16:57:00 -08001183 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001184 return main.FALSE
andrewonlab2b30bd32014-10-09 16:48:55 -04001185 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001186 main.log.error( self.name + ": EOF exception found" )
1187 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001188 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001189 except Exception:
1190 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001191 main.cleanAndExit()
kelvin8ec71442015-01-15 16:57:00 -08001192
kelvin-onlabd3b64892015-01-20 13:26:24 -08001193 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -08001194 """
andrewonlabc8d47972014-10-09 16:52:36 -04001195 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -08001196 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -04001197 if needed
kelvin8ec71442015-01-15 16:57:00 -08001198 """
andrewonlabc8d47972014-10-09 16:52:36 -04001199 try:
kelvin8ec71442015-01-15 16:57:00 -08001200 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001201 self.handle.expect( self.prompt, timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001202 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
Devin Limc20e79a2017-06-07 10:29:57 -07001203 self.handle.expect( self.prompt, timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001204 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
kelvin8ec71442015-01-15 16:57:00 -08001205 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -04001206 return main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -07001207 except pexpect.TIMEOUT:
1208 main.log.exception( self.name + ": Timeout in onosUninstall" )
You Wang141b43b2018-06-26 16:50:18 -07001209 self.handle.send( "\x03" ) # Control-C
1210 self.handle.expect( self.prompt )
pingping-lin763ee042015-05-20 17:45:30 -07001211 return main.FALSE
andrewonlabc8d47972014-10-09 16:52:36 -04001212 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001213 main.log.error( self.name + ": EOF exception found" )
1214 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001215 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001216 except Exception:
1217 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001218 main.cleanAndExit()
andrewonlab2b30bd32014-10-09 16:48:55 -04001219
kelvin-onlabd3b64892015-01-20 13:26:24 -08001220 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001221 """
andrewonlabaedc8332014-12-04 12:43:03 -05001222 Issues the command 'onos-die <node-ip>'
1223 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -08001224 """
andrewonlabaedc8332014-12-04 12:43:03 -05001225 try:
kelvin8ec71442015-01-15 16:57:00 -08001226 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001227 self.handle.expect( self.prompt )
Jeremyf0aecdb2016-03-30 13:19:57 -07001228 cmdStr = "onos-die " + str( nodeIp )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001229 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001230 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -05001231 "Killing\sONOS",
1232 "ONOS\sprocess\sis\snot\srunning",
Jeremy Songster14c13572016-04-21 17:34:03 -07001233 pexpect.TIMEOUT ], timeout=60 )
andrewonlabaedc8332014-12-04 12:43:03 -05001234 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001235 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001236 " was killed and stopped" )
Jon Hall53c5e662016-04-13 16:06:56 -07001237 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001238 self.handle.expect( self.prompt )
andrewonlabaedc8332014-12-04 12:43:03 -05001239 return main.TRUE
1240 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001241 main.log.info( "ONOS process was not running" )
Jon Hall53c5e662016-04-13 16:06:56 -07001242 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001243 self.handle.expect( self.prompt )
andrewonlabaedc8332014-12-04 12:43:03 -05001244 return main.FALSE
1245 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001246 main.log.error( self.name + ": EOF exception found" )
1247 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001248 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001249 except Exception:
1250 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001251 main.cleanAndExit()
andrewonlabaedc8332014-12-04 12:43:03 -05001252
kelvin-onlabd3b64892015-01-20 13:26:24 -08001253 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001254 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001255 Calls the command: 'onos-kill [<node-ip>]'
1256 "Remotely, and unceremoniously kills the ONOS instance running on
1257 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -08001258 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001259 try:
kelvin8ec71442015-01-15 16:57:00 -08001260 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001261 self.handle.expect( self.prompt )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001262 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -08001263 i = self.handle.expect( [
Devin Limc20e79a2017-06-07 10:29:57 -07001264 self.prompt,
andrewonlabe8e56fd2014-10-09 17:12:44 -04001265 "No\sroute\sto\shost",
1266 "password:",
Jeremy Songster14c13572016-04-21 17:34:03 -07001267 pexpect.TIMEOUT ], timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -08001268
andrewonlabe8e56fd2014-10-09 17:12:44 -04001269 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001270 main.log.info(
1271 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -08001272 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001273 return main.TRUE
1274 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001275 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001276 return main.FALSE
1277 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001278 main.log.info(
1279 "Passwordless login for host: " +
1280 str( nodeIp ) +
1281 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001282 return main.FALSE
1283 else:
Jon Hallefbd9792015-03-05 16:11:36 -08001284 main.log.info( "ONOS instance was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001285 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001286
andrewonlabe8e56fd2014-10-09 17:12:44 -04001287 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001288 main.log.error( self.name + ": EOF exception found" )
1289 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001290 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001291 except Exception:
1292 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001293 main.cleanAndExit()
andrewonlabe8e56fd2014-10-09 17:12:44 -04001294
kelvin-onlabd3b64892015-01-20 13:26:24 -08001295 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -08001296 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001297 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -05001298 a cleaner environment.
1299
andrewonlab19fbdca2014-11-14 12:55:59 -05001300 Description:
Jon Hallfcc88622014-11-25 13:09:54 -05001301 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -05001302 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -08001303 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001304 try:
kelvin8ec71442015-01-15 16:57:00 -08001305 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001306 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001307 self.handle.sendline( "onos-remove-raft-logs" )
1308 # Sometimes this command hangs
Devin Limc20e79a2017-06-07 10:29:57 -07001309 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
kelvin8ec71442015-01-15 16:57:00 -08001310 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001311 if i == 1:
Devin Limc20e79a2017-06-07 10:29:57 -07001312 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
kelvin8ec71442015-01-15 16:57:00 -08001313 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001314 if i == 1:
1315 return main.FALSE
andrewonlab19fbdca2014-11-14 12:55:59 -05001316 return main.TRUE
andrewonlab19fbdca2014-11-14 12:55:59 -05001317 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001318 main.log.error( self.name + ": EOF exception found" )
1319 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001320 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001321 except Exception:
1322 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001323 main.cleanAndExit()
Jon Hallfcc88622014-11-25 13:09:54 -05001324
kelvin-onlabd3b64892015-01-20 13:26:24 -08001325 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -08001326 """
1327 Calls the command 'onos-start-network [ <mininet-topo> ]
1328 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -04001329 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -08001330 cell."
andrewonlab94282092014-10-10 13:00:11 -04001331 * Specify mininet topology file name for mntopo
1332 * Topo files should be placed at:
1333 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001334
andrewonlab94282092014-10-10 13:00:11 -04001335 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001336 """
andrewonlab94282092014-10-10 13:00:11 -04001337 try:
1338 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001339 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001340 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001341
kelvin8ec71442015-01-15 16:57:00 -08001342 mntopo = str( mntopo )
1343 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001344 self.handle.expect( self.prompt )
andrewonlab94282092014-10-10 13:00:11 -04001345
kelvin8ec71442015-01-15 16:57:00 -08001346 self.handle.sendline( "onos-start-network " + mntopo )
1347 self.handle.expect( "mininet>" )
1348 main.log.info( "Network started, entered mininet prompt" )
1349
1350 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001351
1352 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001353 main.log.error( self.name + ": EOF exception found" )
1354 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001355 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001356 except Exception:
1357 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001358 main.cleanAndExit()
andrewonlab94282092014-10-10 13:00:11 -04001359
Jeremy Songster14c13572016-04-21 17:34:03 -07001360 def isup( self, node="", timeout=240 ):
kelvin8ec71442015-01-15 16:57:00 -08001361 """
1362 Run's onos-wait-for-start which only returns once ONOS is at run
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001363 level 100(ready for use)
andrewonlab8d0d7d72014-10-09 16:33:15 -04001364
Jon Hall7993bfc2014-10-09 16:30:14 -04001365 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001366 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001367 try:
Jon Hall3b489db2015-10-05 14:38:37 -07001368 self.handle.sendline( "onos-wait-for-start " + node )
1369 self.handle.expect( "onos-wait-for-start" )
kelvin8ec71442015-01-15 16:57:00 -08001370 # NOTE: this timeout is arbitrary"
Jon Hallcababf72018-02-05 12:05:19 -08001371 i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT, "Password:" ], timeout )
Jon Hall7993bfc2014-10-09 16:30:14 -04001372 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001373 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001374 return main.TRUE
Jon Hallcababf72018-02-05 12:05:19 -08001375 elif i == 1 or i == 2:
kelvin8ec71442015-01-15 16:57:00 -08001376 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001377 # we will kill it on timeout
Jon Hallcababf72018-02-05 12:05:19 -08001378 if i == 1:
1379 main.log.error( "ONOS has not started yet" )
1380 elif i == 2:
1381 main.log.error( "Cannot login to ONOS CLI, try using onos-secure-ssh" )
kelvin8ec71442015-01-15 16:57:00 -08001382 self.handle.send( "\x03" ) # Control-C
Devin Limc20e79a2017-06-07 10:29:57 -07001383 self.handle.expect( self.prompt )
Jon Hall7993bfc2014-10-09 16:30:14 -04001384 return main.FALSE
1385 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001386 main.log.error( self.name + ": EOF exception found" )
1387 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001388 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001389 except Exception:
1390 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001391 main.cleanAndExit()
andrewonlab05e362f2014-10-10 00:40:57 -04001392
Devin Lim142b5342017-07-20 15:22:39 -07001393 def preventAutoRespawn( self ):
1394 """
1395 Description:
1396 This will prevent ONOSservice to automatically
1397 respawn.
1398 """
1399 try:
1400 self.handle.sendline( "sed -i -e 's/^respawn$/#respawn/g' tools/package/init/onos.conf" )
1401 self.handle.expect( "\$" ) # $ from the command
1402 self.handle.sendline( "sed -i -e 's/^Restart=always/Restart=no/g' tools/package/init/onos.service" )
1403 self.handle.expect( "\$" ) # $ from the command
1404 self.handle.expect( "\$" ) # $ from the prompt
1405 except pexpect.EOF:
1406 main.log.error( self.name + ": EOF exception found" )
1407 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001408 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -07001409 except Exception:
1410 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001411 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -07001412
kelvin-onlabd3b64892015-01-20 13:26:24 -08001413 def pushTestIntentsShell(
1414 self,
1415 dpidSrc,
1416 dpidDst,
1417 numIntents,
1418 dirFile,
1419 onosIp,
1420 numMult="",
1421 appId="",
1422 report=True,
1423 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001424 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001425 Description:
kelvin8ec71442015-01-15 16:57:00 -08001426 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001427 better parallelize the results than the CLI
1428 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001429 * dpidSrc: specify source dpid
1430 * dpidDst: specify destination dpid
1431 * numIntents: specify number of intents to push
1432 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001433 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001434 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001435 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001436 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001437 """
1438 try:
1439 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001440 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001441 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001442 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001443 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001444 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001445
kelvin-onlabd3b64892015-01-20 13:26:24 -08001446 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1447 if not numMult:
1448 addIntents = addDpid + " " + str( numIntents )
1449 elif numMult:
1450 addIntents = addDpid + " " + str( numIntents ) + " " +\
1451 str( numMult )
1452 if appId:
1453 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001454 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001455 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001456
andrewonlabaedc8332014-12-04 12:43:03 -05001457 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001458 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001459 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001460 sendCmd = addApp + " &"
1461 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001462
kelvin-onlabd3b64892015-01-20 13:26:24 -08001463 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001464
1465 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001466 main.log.error( self.name + ": EOF exception found" )
1467 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001468 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001469 except Exception:
1470 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001471 main.cleanAndExit()
andrewonlab05e362f2014-10-10 00:40:57 -04001472
kelvin-onlabd3b64892015-01-20 13:26:24 -08001473 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001474 """
andrewonlab970399c2014-11-07 13:09:32 -05001475 Capture all packet activity and store in specified
1476 directory/file
1477
1478 Required:
1479 * interface: interface to capture
1480 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001481 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001482 try:
1483 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001484 self.handle.expect( self.prompt )
andrewonlab970399c2014-11-07 13:09:32 -05001485
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001486 self.handle.sendline( "tshark -i " + str( interface ) + " -t e -w " + str( dirFile ) + " &" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001487 self.handle.sendline( "\n" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001488 self.handle.expect( "Capturing on" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001489 self.handle.sendline( "\n" )
Devin Limc20e79a2017-06-07 10:29:57 -07001490 self.handle.expect( self.prompt )
andrewonlab970399c2014-11-07 13:09:32 -05001491
Jon Hallfebb1c72015-03-05 13:30:09 -08001492 main.log.info( "Tshark started capturing files on " +
1493 str( interface ) + " and saving to directory: " +
1494 str( dirFile ) )
1495 except pexpect.EOF:
1496 main.log.error( self.name + ": EOF exception found" )
1497 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001498 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001499 except Exception:
1500 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001501 main.cleanAndExit()
Shreya Shaha73aaad2014-10-27 18:03:09 -04001502
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001503 def onosTopoCfg( self, onosIp, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001504 """
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001505 Description:
1506 Execute onos-topo-cfg command
1507 Required:
1508 onosIp - IP of the onos node you want to send the json to
1509 jsonFile - File path of the json file
1510 Return:
1511 Returns main.TRUE if the command is successfull; Returns
1512 main.FALSE if there was an error
kelvin8ec71442015-01-15 16:57:00 -08001513 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001514 try:
kelvin8ec71442015-01-15 16:57:00 -08001515 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001516 self.handle.expect( self.prompt )
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001517 cmd = "onos-topo-cfg "
1518 self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile )
1519 handle = self.handle.before
1520 print handle
1521 if "Error" in handle:
1522 main.log.error( self.name + ": " + self.handle.before )
1523 return main.FALSE
1524 else:
Devin Limc20e79a2017-06-07 10:29:57 -07001525 self.handle.expect( self.prompt )
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001526 return main.TRUE
1527
Jon Hallfebb1c72015-03-05 13:30:09 -08001528 except pexpect.EOF:
1529 main.log.error( self.name + ": EOF exception found" )
1530 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001531 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001532 except Exception:
1533 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001534 main.cleanAndExit()
kelvin8ec71442015-01-15 16:57:00 -08001535
jenkins1e99e7b2015-04-02 18:15:39 -07001536 def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ):
kelvin8ec71442015-01-15 16:57:00 -08001537 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001538 Required:
kelvin8ec71442015-01-15 16:57:00 -08001539 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001540 * directory to store results
1541 Optional:
1542 * interface - default: eth0
Jon Hall4ba53f02015-07-29 13:07:41 -07001543 * grepOptions - options for grep
andrewonlabba44bcf2014-10-16 16:54:41 -04001544 Description:
1545 Uses tshark command to grep specific group of packets
1546 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001547 The timestamp is hardcoded to be in epoch
1548 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001549 try:
1550 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001551 self.handle.expect( self.prompt )
Jon Hallfebb1c72015-03-05 13:30:09 -08001552 self.handle.sendline( "" )
jenkins1e99e7b2015-04-02 18:15:39 -07001553 if grepOptions:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001554 grepStr = "grep " + str( grepOptions )
jenkins1e99e7b2015-04-02 18:15:39 -07001555 else:
1556 grepStr = "grep"
Jon Hall4ba53f02015-07-29 13:07:41 -07001557
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001558 cmd = (
1559 "sudo tshark -i " +
Jon Hallfebb1c72015-03-05 13:30:09 -08001560 str( interface ) +
jenkins1e99e7b2015-04-02 18:15:39 -07001561 " -t e | " +
1562 grepStr + " --line-buffered \"" +
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001563 str( grep ) +
Jon Hallfebb1c72015-03-05 13:30:09 -08001564 "\" >" +
1565 directory +
1566 " &" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001567 self.handle.sendline( cmd )
1568 main.log.info( cmd )
Jon Hallfebb1c72015-03-05 13:30:09 -08001569 self.handle.expect( "Capturing on" )
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001570 self.handle.sendline( "\n" )
Devin Limc20e79a2017-06-07 10:29:57 -07001571 self.handle.expect( self.prompt )
Jon Hallfebb1c72015-03-05 13:30:09 -08001572 except pexpect.EOF:
1573 main.log.error( self.name + ": EOF exception found" )
1574 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001575 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001576 except Exception:
1577 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001578 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001579
kelvin-onlabd3b64892015-01-20 13:26:24 -08001580 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001581 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001582 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001583 """
1584 # Remove all pcap from previous captures
Jon Hallfebb1c72015-03-05 13:30:09 -08001585 try:
1586 self.execute( cmd="sudo rm /tmp/wireshark*" )
1587 self.handle.sendline( "" )
Jon Hallefbd9792015-03-05 16:11:36 -08001588 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" +
1589 " | grep -v grep | awk '{print $2}'`" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001590 self.handle.sendline( "" )
1591 main.log.info( "Tshark stopped" )
1592 except pexpect.EOF:
1593 main.log.error( self.name + ": EOF exception found" )
1594 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001595 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001596 except Exception:
1597 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001598 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001599
kelvin8ec71442015-01-15 16:57:00 -08001600 def ptpd( self, args ):
1601 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001602 Initiate ptp with user-specified args.
1603 Required:
1604 * args: specify string of args after command
1605 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001606 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001607 try:
kelvin8ec71442015-01-15 16:57:00 -08001608 self.handle.sendline( "sudo ptpd " + str( args ) )
1609 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001610 "Multiple",
1611 "Error",
Devin Limc20e79a2017-06-07 10:29:57 -07001612 self.prompt ] )
1613 self.handle.expect( self.prompt )
andrewonlabba44bcf2014-10-16 16:54:41 -04001614
andrewonlab0c38a4a2014-10-28 18:35:35 -04001615 if i == 0:
1616 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001617 main.log.info( "ptpd returned an error: " +
1618 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001619 return handle
1620 elif i == 1:
1621 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001622 main.log.error( "ptpd returned an error: " +
1623 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001624 return handle
1625 else:
1626 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001627
andrewonlab0c38a4a2014-10-28 18:35:35 -04001628 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001629 main.log.error( self.name + ": EOF exception found" )
1630 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001631 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001632 except Exception:
1633 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001634 main.cleanAndExit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001635
You Wang54b1d672018-06-11 16:44:13 -07001636 def dumpONOSCmd( self, ONOSIp, CMD, destDir, filename, options="", timeout=60 ):
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001637 """
Pier50f0bc62016-09-07 17:53:40 -07001638 Dump Cmd to a desired directory.
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001639 For debugging purposes, you may want to use
Pier50f0bc62016-09-07 17:53:40 -07001640 this function to capture Cmd at a given point in time.
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001641 Localtime will be attached to the filename
1642
1643 Required:
1644 * ONOSIp: the IP of the target ONOS instance
Pier50f0bc62016-09-07 17:53:40 -07001645 * CMD: the command to dump;
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001646 * destDir: specify directory to copy to.
1647 ex ) /tmp/
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001648 * fileName: Name of the file
You Wang54b1d672018-06-11 16:44:13 -07001649 Optional:
Pier50f0bc62016-09-07 17:53:40 -07001650 * options: Options for ONOS command
You Wang54b1d672018-06-11 16:44:13 -07001651 * timeout: pexpect timeout for running the ONOS command
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001652 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001653
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001654 localtime = time.strftime( '%x %X' )
1655 localtime = localtime.replace( "/", "" )
1656 localtime = localtime.replace( " ", "_" )
1657 localtime = localtime.replace( ":", "" )
1658 if destDir[ -1: ] != "/":
1659 destDir += "/"
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001660 cmd = CMD + " " + options + " > " + str( destDir ) + str( filename ) + localtime
You Wang54b1d672018-06-11 16:44:13 -07001661 return self.onosCli( ONOSIp, cmd, timeout=timeout )
Flavio Castrob7718952016-05-18 08:53:41 -07001662
kelvin-onlabd3b64892015-01-20 13:26:24 -08001663 def cpLogsToDir( self, logToCopy,
Jon Hallefbd9792015-03-05 16:11:36 -08001664 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001665 """
1666 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001667 Current implementation of ONOS deletes its karaf
1668 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001669 you may want to use this function to capture
1670 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001671 Localtime will be attached to the filename
1672
1673 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001674 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001675 copy.
kelvin8ec71442015-01-15 16:57:00 -08001676 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001677 For copying multiple files, leave copyFileName
1678 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001679 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001680 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001681 ex ) /tmp/
1682 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001683 * copyFileName: If you want to rename the log
1684 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001685 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001686 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001687 try:
Flavio Castro09ab59d2016-05-25 17:01:35 -07001688 localtime = time.strftime( '%H %M' )
kelvin8ec71442015-01-15 16:57:00 -08001689 localtime = localtime.replace( "/", "" )
1690 localtime = localtime.replace( " ", "_" )
1691 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001692 if destDir[ -1: ] != "/":
1693 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001694
kelvin-onlabd3b64892015-01-20 13:26:24 -08001695 if copyFileName:
Jon Hallfebb1c72015-03-05 13:30:09 -08001696 self.handle.sendline( "cp " + str( logToCopy ) + " " +
1697 str( destDir ) + str( copyFileName ) +
1698 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001699 self.handle.expect( "cp" )
Devin Limc20e79a2017-06-07 10:29:57 -07001700 self.handle.expect( self.prompt )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001701 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001702 self.handle.sendline( "cp " + str( logToCopy ) +
1703 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001704 self.handle.expect( "cp" )
Devin Limc20e79a2017-06-07 10:29:57 -07001705 self.handle.expect( self.prompt )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001706
kelvin8ec71442015-01-15 16:57:00 -08001707 return self.handle.before
1708
1709 except pexpect.EOF:
1710 main.log.error( "Copying files failed" )
1711 main.log.error( self.name + ": EOF exception found" )
1712 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001713 except Exception:
1714 main.log.exception( "Copying files failed" )
1715
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001716 def checkLogs( self, onosIp, restart=False ):
kelvin8ec71442015-01-15 16:57:00 -08001717 """
Jon Hall94fd0472014-12-08 11:52:42 -08001718 runs onos-check-logs on the given onos node
Jon Hall80daded2015-05-27 16:07:00 -07001719 If restart is True, use the old version of onos-check-logs which
1720 does not print the full stacktrace, but shows the entire log file,
1721 including across restarts
Jon Hall94fd0472014-12-08 11:52:42 -08001722 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001723 """
Jon Hall94fd0472014-12-08 11:52:42 -08001724 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001725 cmd = "onos-check-logs " + str( onosIp )
Jon Hall16b72c42015-05-20 10:23:36 -07001726 if restart:
1727 cmd += " old"
kelvin8ec71442015-01-15 16:57:00 -08001728 self.handle.sendline( cmd )
1729 self.handle.expect( cmd )
Devin Limdc78e202017-06-09 18:30:07 -07001730 self.handle.expect( self.prompt + " " )
Jon Hall94fd0472014-12-08 11:52:42 -08001731 response = self.handle.before
1732 return response
1733 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001734 main.log.error( "Lost ssh connection" )
1735 main.log.error( self.name + ": EOF exception found" )
1736 main.log.error( self.name + ": " + self.handle.before )
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 Hall94fd0472014-12-08 11:52:42 -08001740
kelvin-onlabd3b64892015-01-20 13:26:24 -08001741 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001742 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001743 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001744 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001745 try:
kelvin8ec71442015-01-15 16:57:00 -08001746 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001747 self.handle.expect( self.prompt )
kelvin8ec71442015-01-15 16:57:00 -08001748 self.handle.sendline( "onos-service " + str( node ) +
1749 " status" )
1750 i = self.handle.expect( [
You Wangef1e6572016-03-08 12:53:18 -08001751 "start/running",
You Wang7bd83062016-03-01 11:50:00 -08001752 "Running ...",
You Wangef1e6572016-03-08 12:53:18 -08001753 "stop/waiting",
You Wang7bd83062016-03-01 11:50:00 -08001754 "Not Running ...",
kelvin8ec71442015-01-15 16:57:00 -08001755 pexpect.TIMEOUT ], timeout=120 )
YPZhangfebf7302016-05-24 16:45:56 -07001756 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001757 self.handle.expect( self.prompt )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001758
You Wangef1e6572016-03-08 12:53:18 -08001759 if i == 0 or i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001760 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001761 return main.TRUE
You Wangef1e6572016-03-08 12:53:18 -08001762 elif i == 2 or i == 3:
kelvin8ec71442015-01-15 16:57:00 -08001763 main.log.info( "ONOS is stopped" )
kelvin8ec71442015-01-15 16:57:00 -08001764 main.log.error( "ONOS service failed to check the status" )
Devin Lim44075962017-08-11 10:56:37 -07001765
1766 main.cleanAndExit()
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001767 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001768 main.log.error( self.name + ": EOF exception found" )
1769 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001770 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001771 except Exception:
1772 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001773 main.cleanAndExit()
Jon Hall21270ac2015-02-16 17:59:55 -08001774
Jon Hall63604932015-02-26 17:09:50 -08001775 def setIpTables( self, ip, port='', action='add', packet_type='',
1776 direction='INPUT', rule='DROP', states=True ):
Jon Hallefbd9792015-03-05 16:11:36 -08001777 """
Jon Hall21270ac2015-02-16 17:59:55 -08001778 Description:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001779 add or remove iptables rule to DROP (default) packets from
Jon Hall21270ac2015-02-16 17:59:55 -08001780 specific IP and PORT
1781 Usage:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001782 * specify action ('add' or 'remove')
Jon Hall21270ac2015-02-16 17:59:55 -08001783 when removing, pass in the same argument as you would add. It will
1784 delete that specific rule.
1785 * specify the ip to block
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001786 * specify the destination port to block (defaults to all ports)
1787 * optional packet type to block (default tcp)
1788 * optional iptables rule (default DROP)
1789 * optional direction to block (default 'INPUT')
Jon Hall63604932015-02-26 17:09:50 -08001790 * States boolean toggles adding all supported tcp states to the
1791 firewall rule
Jon Hall21270ac2015-02-16 17:59:55 -08001792 Returns:
1793 main.TRUE on success or
1794 main.FALSE if given invalid input or
1795 main.ERROR if there is an error in response from iptables
1796 WARNING:
1797 * This function uses root privilege iptables command which may result
1798 in unwanted network errors. USE WITH CAUTION
Jon Hallefbd9792015-03-05 16:11:36 -08001799 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001800
Jon Hall21270ac2015-02-16 17:59:55 -08001801 # NOTE*********
1802 # The strict checking methods of this driver function is intentional
1803 # to discourage any misuse or error of iptables, which can cause
1804 # severe network errors
1805 # *************
1806
1807 # NOTE: Sleep needed to give some time for rule to be added and
1808 # registered to the instance. If you are calling this function
1809 # multiple times this sleep will prevent any errors.
1810 # DO NOT REMOVE
Jon Hall63604932015-02-26 17:09:50 -08001811 # time.sleep( 5 )
Jon Hall21270ac2015-02-16 17:59:55 -08001812 try:
1813 # input validation
1814 action_type = action.lower()
1815 rule = rule.upper()
1816 direction = direction.upper()
1817 if action_type != 'add' and action_type != 'remove':
1818 main.log.error( "Invalid action type. Use 'add' or "
1819 "'remove' table rule" )
1820 if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
1821 # NOTE Currently only supports rules DROP, ACCEPT, and LOG
1822 main.log.error( "Invalid rule. Valid rules are 'DROP' or "
1823 "'ACCEPT' or 'LOG' only." )
1824 if direction != 'INPUT' and direction != 'OUTPUT':
1825 # NOTE currently only supports rules INPUT and OUPTUT
1826 main.log.error( "Invalid rule. Valid directions are"
1827 " 'OUTPUT' or 'INPUT'" )
1828 return main.FALSE
1829 return main.FALSE
1830 return main.FALSE
1831 if action_type == 'add':
1832 # -A is the 'append' action of iptables
1833 actionFlag = '-A'
1834 elif action_type == 'remove':
1835 # -D is the 'delete' rule of iptables
1836 actionFlag = '-D'
1837 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001838 self.handle.expect( self.prompt )
Jon Hall21270ac2015-02-16 17:59:55 -08001839 cmd = "sudo iptables " + actionFlag + " " +\
1840 direction +\
Jon Hall21270ac2015-02-16 17:59:55 -08001841 " -s " + str( ip )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001842 # " -p " + str( packet_type ) +\
Jon Hall63604932015-02-26 17:09:50 -08001843 if packet_type:
1844 cmd += " -p " + str( packet_type )
Jon Hall21270ac2015-02-16 17:59:55 -08001845 if port:
1846 cmd += " --dport " + str( port )
Jon Hall63604932015-02-26 17:09:50 -08001847 if states:
1848 cmd += " -m state --state="
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001849 # FIXME- Allow user to configure which states to block
Jon Hall63604932015-02-26 17:09:50 -08001850 cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED"
Jon Hall21270ac2015-02-16 17:59:55 -08001851 cmd += " -j " + str( rule )
1852
1853 self.handle.sendline( cmd )
Devin Limc20e79a2017-06-07 10:29:57 -07001854 self.handle.expect( self.prompt )
Jon Hall21270ac2015-02-16 17:59:55 -08001855 main.log.warn( self.handle.before )
1856
1857 info_string = "On " + str( self.name )
1858 info_string += " " + str( action_type )
1859 info_string += " iptable rule [ "
1860 info_string += " IP: " + str( ip )
1861 info_string += " Port: " + str( port )
1862 info_string += " Rule: " + str( rule )
1863 info_string += " Direction: " + str( direction ) + " ]"
1864 main.log.info( info_string )
1865 return main.TRUE
1866 except pexpect.TIMEOUT:
1867 main.log.exception( self.name + ": Timeout exception in "
1868 "setIpTables function" )
You Wang141b43b2018-06-26 16:50:18 -07001869 self.handle.send( "\x03" ) # Control-C
1870 self.handle.expect( self.prompt )
Jon Hall21270ac2015-02-16 17:59:55 -08001871 return main.ERROR
1872 except pexpect.EOF:
1873 main.log.error( self.name + ": EOF exception found" )
1874 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001875 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001876 except Exception:
1877 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001878 main.cleanAndExit()
Jon Hall21270ac2015-02-16 17:59:55 -08001879
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001880 def detailed_status( self, log_filename ):
Jon Hallefbd9792015-03-05 16:11:36 -08001881 """
Jon Hall0468b042015-02-19 19:08:21 -08001882 This method is used by STS to check the status of the controller
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001883 Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
Jon Hallefbd9792015-03-05 16:11:36 -08001884 """
Jon Hall0468b042015-02-19 19:08:21 -08001885 import re
1886 try:
1887 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07001888 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001889 self.handle.sendline( "cd " + self.home )
Devin Limc20e79a2017-06-07 10:29:57 -07001890 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001891 self.handle.sendline( "service onos status" )
Devin Limc20e79a2017-06-07 10:29:57 -07001892 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001893 response = self.handle.before
1894 if re.search( "onos start/running", response ):
1895 # onos start/running, process 10457
1896 return 'RUNNING'
1897 # FIXME: Implement this case
1898 # elif re.search( pattern, response ):
1899 # return 'STARTING'
1900 elif re.search( "onos stop/", response ):
1901 # onos stop/waiting
1902 # FIXME handle this differently?: onos stop/pre-stop
1903 return 'STOPPED'
1904 # FIXME: Implement this case
1905 # elif re.search( pattern, response ):
1906 # return 'FROZEN'
1907 else:
1908 main.log.warn( self.name +
Jon Hallefbd9792015-03-05 16:11:36 -08001909 " WARNING: status received unknown response" )
Jon Hall0468b042015-02-19 19:08:21 -08001910 main.log.warn( response )
1911 return 'ERROR', "Unknown response: %s" % response
1912 except pexpect.TIMEOUT:
1913 main.log.exception( self.name + ": Timeout exception in "
1914 "setIpTables function" )
You Wang141b43b2018-06-26 16:50:18 -07001915 self.handle.send( "\x03" ) # Control-C
1916 self.handle.expect( self.prompt )
Jon Hall0468b042015-02-19 19:08:21 -08001917 return 'ERROR', "Pexpect Timeout"
1918 except pexpect.EOF:
1919 main.log.error( self.name + ": EOF exception found" )
1920 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001921 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001922 except Exception:
1923 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001924 main.cleanAndExit()
Jon Hall0468b042015-02-19 19:08:21 -08001925
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001926 def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001927 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07001928 Create/formats the LinkGraph.cfg file based on arguments
1929 -only creates a linear topology and connects islands
1930 -evenly distributes devices
andrew@onlab.us3b087132015-03-11 15:00:08 -07001931 -must be called by ONOSbench
1932
Jon Hall4ba53f02015-07-29 13:07:41 -07001933 ONOSIpList - list of all of the node IPs to be used
1934
1935 deviceCount - number of switches to be assigned
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001936 '''
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001937 main.log.info( "Creating link graph configuration file." )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001938 linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg"
Jon Hall4ba53f02015-07-29 13:07:41 -07001939 tempFile = "/tmp/linkGraph.cfg"
andrew@onlab.us3b087132015-03-11 15:00:08 -07001940
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001941 linkGraph = open( tempFile, 'w+' )
1942 linkGraph.write( "# NullLinkProvider topology description (config file).\n" )
1943 linkGraph.write( "# The NodeId is only added if the destination is another node's device.\n" )
1944 linkGraph.write( "# Bugs: Comments cannot be appended to a line to be read.\n" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001945
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001946 clusterCount = len( ONOSIpList )
Jon Hall4ba53f02015-07-29 13:07:41 -07001947
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001948 if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
1949 deviceCount = int( deviceCount )
1950 switchList = [ 0 ]*( clusterCount+1 )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001951 baselineSwitchCount = deviceCount/clusterCount
Jon Hall4ba53f02015-07-29 13:07:41 -07001952
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001953 for node in range( 1, clusterCount + 1 ):
1954 switchList[ node ] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001955
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001956 for node in range( 1, ( deviceCount % clusterCount )+1 ):
1957 switchList[ node ] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001958
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001959 if isinstance( deviceCount, list ):
1960 main.log.info( "Using provided device distribution" )
1961 switchList = [ 0 ]
andrew@onlab.us3b087132015-03-11 15:00:08 -07001962 for i in deviceCount:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001963 switchList.append( int( i ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001964
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001965 tempList = [ '0' ]
1966 tempList.extend( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001967 ONOSIpList = tempList
1968
1969 myPort = 6
1970 lastSwitch = 0
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001971 for node in range( 1, clusterCount+1 ):
1972 if switchList[ node ] == 0:
andrew@onlab.us3b087132015-03-11 15:00:08 -07001973 continue
1974
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001975 linkGraph.write( "graph " + ONOSIpList[ node ] + " {\n" )
Jon Hall4ba53f02015-07-29 13:07:41 -07001976
andrew@onlab.us3b087132015-03-11 15:00:08 -07001977 if node > 1:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001978 # connect to last device on previous node
1979 line = ( "\t0:5 -> " + str( lastSwitch ) + ":6:" + lastIp + "\n" ) # ONOSIpList[node-1]
1980 linkGraph.write( line )
Jon Hall4ba53f02015-07-29 13:07:41 -07001981
1982 lastSwitch = 0
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001983 for switch in range( 0, switchList[ node ]-1 ):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001984 line = ""
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001985 line = ( "\t" + str( switch ) + ":" + str( myPort ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001986 line += " -- "
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001987 line += ( str( switch+1 ) + ":" + str( myPort-1 ) + "\n" )
1988 linkGraph.write( line )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00001989 lastSwitch = switch+1
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001990 lastIp = ONOSIpList[ node ]
Jon Hall4ba53f02015-07-29 13:07:41 -07001991
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001992 # lastSwitch += 1
1993 if node < ( clusterCount ):
1994 # connect to first device on the next node
1995 line = ( "\t" + str( lastSwitch ) + ":6 -> 0:5:" + ONOSIpList[ node+1 ] + "\n" )
1996 linkGraph.write( line )
Jon Hall4ba53f02015-07-29 13:07:41 -07001997
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001998 linkGraph.write( "}\n" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001999 linkGraph.close()
2000
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002001 # SCP
2002 os.system( "scp " + tempFile + " " + self.user_name + "@" + benchIp + ":" + linkGraphPath )
2003 main.log.info( "linkGraph.cfg creation complete" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002004
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002005 def configNullDev( self, ONOSIpList, deviceCount, numPorts=10 ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002006 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002007 ONOSIpList = list of Ip addresses of nodes switches will be devided amongst
2008 deviceCount = number of switches to distribute, or list of values to use as custom distribution
cameron@onlab.us75900962015-03-30 13:22:49 -07002009 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 +00002010 '''
2011
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002012 main.log.info( "Configuring Null Device Provider" )
2013 clusterCount = len( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002014
Jon Hall4ba53f02015-07-29 13:07:41 -07002015 try:
2016
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002017 if isinstance( deviceCount, int ) or isinstance( deviceCount, str ):
2018 main.log.info( "Creating device distribution" )
2019 deviceCount = int( deviceCount )
2020 switchList = [ 0 ]*( clusterCount+1 )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002021 baselineSwitchCount = deviceCount/clusterCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07002022
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002023 for node in range( 1, clusterCount + 1 ):
2024 switchList[ node ] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07002025
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002026 for node in range( 1, ( deviceCount % clusterCount )+1 ):
2027 switchList[ node ] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07002028
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002029 if isinstance( deviceCount, list ):
2030 main.log.info( "Using provided device distribution" )
Jon Hall4ba53f02015-07-29 13:07:41 -07002031
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002032 if len( deviceCount ) == clusterCount:
2033 switchList = [ '0' ]
2034 switchList.extend( deviceCount )
Jon Hall4ba53f02015-07-29 13:07:41 -07002035
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002036 if len( deviceCount ) == ( clusterCount + 1 ):
2037 if deviceCount[ 0 ] == '0' or deviceCount[ 0 ] == 0:
cameron@onlab.us75900962015-03-30 13:22:49 -07002038 switchList = deviceCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07002039
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002040 assert len( switchList ) == ( clusterCount + 1 )
Jon Hall4ba53f02015-07-29 13:07:41 -07002041
cameron@onlab.us75900962015-03-30 13:22:49 -07002042 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002043 main.log.error( "Bad device/Ip list match" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002044 except TypeError:
2045 main.log.exception( self.name + ": Object not as expected" )
2046 return None
Jon Hall77ba41c2015-04-06 10:25:40 -07002047 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002048 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002049 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002050
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002051 ONOSIp = [ 0 ]
2052 ONOSIp.extend( ONOSIpList )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002053
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002054 devicesString = "devConfigs = "
2055 for node in range( 1, len( ONOSIp ) ):
2056 devicesString += ( ONOSIp[ node ] + ":" + str( switchList[ node ] ) )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002057 if node < clusterCount:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002058 devicesString += ( "," )
Jon Hall4ba53f02015-07-29 13:07:41 -07002059
2060 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002061 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString )
2062 self.handle.expect( ":~" )
2063 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str( numPorts ) )
2064 self.handle.expect( ":~" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002065
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002066 for i in range( 10 ):
2067 self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider" )
2068 self.handle.expect( ":~" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002069 verification = self.handle.before
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002070 if ( " value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification:
cameron@onlab.us75900962015-03-30 13:22:49 -07002071 break
2072 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002073 time.sleep( 1 )
andrew@onlab.us3b087132015-03-11 15:00:08 -07002074
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002075 assert ( "value=" + str( numPorts ) ) in verification and ( " value=" + devicesString ) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07002076
cameron@onlab.us75900962015-03-30 13:22:49 -07002077 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002078 main.log.error( "Incorrect Config settings: " + verification )
Jon Hall77ba41c2015-04-06 10:25:40 -07002079 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002080 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002081 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002082
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002083 def configNullLink( self, fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0 ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002084 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002085 fileName default is currently the same as the default on ONOS, specify alternate file if
cameron@onlab.us75900962015-03-30 13:22:49 -07002086 you want to use a different topology file than linkGraph.cfg
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002087 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002088
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002089 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002090 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str( eventRate ) )
2091 self.handle.expect( ":~" )
2092 self.handle.sendline( "onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName )
2093 self.handle.expect( ":~" )
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002094
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002095 for i in range( 10 ):
2096 self.handle.sendline( "onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider" )
2097 self.handle.expect( ":~" )
cameron@onlab.us75900962015-03-30 13:22:49 -07002098 verification = self.handle.before
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002099 if ( " value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification:
cameron@onlab.us75900962015-03-30 13:22:49 -07002100 break
Jon Hall4ba53f02015-07-29 13:07:41 -07002101 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002102 time.sleep( 1 )
Jon Hall4ba53f02015-07-29 13:07:41 -07002103
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002104 assert ( "value=" + str( eventRate ) ) in verification and ( " value=" + fileName ) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07002105
cameron@onlab.us75900962015-03-30 13:22:49 -07002106 except pexpect.EOF:
2107 main.log.error( self.name + ": EOF exception found" )
2108 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002109 main.cleanAndExit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002110 except AssertionError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002111 main.log.info( "Settings did not post to ONOS" )
2112 main.log.error( varification )
Jon Hall77ba41c2015-04-06 10:25:40 -07002113 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002114 main.log.exception( self.name + ": Uncaught exception!" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002115 main.log.error( varification )
Devin Lim44075962017-08-11 10:56:37 -07002116 main.cleanAndExit()
andrew@onlab.us3b087132015-03-11 15:00:08 -07002117
kelvin-onlaba4074292015-07-09 15:19:49 -07002118 def getOnosIps( self ):
2119 """
2120 Get all onos IPs stored in
2121 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002122
kelvin-onlaba4074292015-07-09 15:19:49 -07002123 return sorted( self.onosIps.values() )
cameron@onlab.us59d29d92015-05-11 14:31:54 -07002124
Chiyu Chengec63bde2016-11-17 18:11:36 -08002125 def listLog( self, nodeIp ):
2126 """
2127 Get a list of all the karaf log names
2128 """
2129 try:
2130 cmd = "onos-ssh " + nodeIp + " ls -tr /opt/onos/log"
2131 self.handle.sendline( cmd )
2132 self.handle.expect( ":~" )
2133 before = self.handle.before.splitlines()
2134 logNames = []
2135 for word in before:
2136 if 'karaf.log' in word:
2137 logNames.append( word )
2138 return logNames
2139 except pexpect.EOF:
2140 main.log.error( self.name + ": EOF exception found" )
2141 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002142 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002143 except pexpect.TIMEOUT:
2144 main.log.error( self.name + ": TIMEOUT exception found" )
2145 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002146 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002147 except Exception:
2148 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002149 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08002150
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002151 def logReport( self, nodeIp, searchTerms, outputMode="s", startStr=None, endStr=None ):
Jon Hallb4242222016-01-25 17:07:04 -08002152 """
2153 Searches the latest ONOS log file for the given search terms and
2154 prints the total occurances of each term. Returns to combined total of
2155 all occurances.
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002156
Jon Hallb4242222016-01-25 17:07:04 -08002157 Arguments:
2158 * nodeIp - The ip of the ONOS node where the log is located
2159 * searchTerms - A string to grep for or a list of strings to grep
2160 for in the ONOS log. Will print out the number of
2161 occurances for each term.
2162 Optional Arguments:
2163 * outputMode - 's' or 'd'. If 'd' will print the last 5 lines
2164 containing each search term as well as the total
2165 number of occurances of each term. Defaults to 's',
2166 which prints the simple output of just the number
2167 of occurances for each term.
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002168 * startStr - the start string to be given to stream editor command
2169 as the start point for extraction of data
2170 * endStr - the end string to be given to stream editor command as
2171 the end point for extraction of data
Jon Hallb4242222016-01-25 17:07:04 -08002172 """
2173 try:
2174 main.log.info( " Log Report for {} ".format( nodeIp ).center( 70, '=' ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002175 if isinstance( searchTerms, str ):
2176 searchTerms = [ searchTerms ]
Jon Hallb4242222016-01-25 17:07:04 -08002177 numTerms = len( searchTerms )
2178 outputMode = outputMode.lower()
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002179
Jon Hallb4242222016-01-25 17:07:04 -08002180 totalHits = 0
2181 logLines = []
2182 for termIndex in range( numTerms ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002183 term = searchTerms[ termIndex ]
2184 logLines.append( [ term ] )
Pratik Parab3b2ab5a2017-02-14 13:15:14 -08002185 if startStr and endStr:
2186 cmd = "onos-ssh {} \"sed -n '/{}/,/{}/p' /opt/onos/log/karaf.log | grep {}\"".format( nodeIp,
2187 startStr,
2188 endStr,
2189 term )
2190 else:
2191 cmd = "onos-ssh {} cat /opt/onos/log/karaf.log | grep {}".format( nodeIp,
2192 term )
Jon Hallb4242222016-01-25 17:07:04 -08002193 self.handle.sendline( cmd )
2194 self.handle.expect( ":~" )
2195 before = self.handle.before.splitlines()
2196 count = 0
2197 for line in before:
2198 if term in line and "grep" not in line:
2199 count += 1
2200 if before.index( line ) > ( len( before ) - 7 ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002201 logLines[ termIndex ].append( line )
Jon Hallb4242222016-01-25 17:07:04 -08002202 main.log.info( "{}: {}".format( term, count ) )
2203 totalHits += count
2204 if termIndex == numTerms - 1:
2205 print "\n"
2206 if outputMode != "s":
2207 outputString = ""
2208 for term in logLines:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002209 outputString = term[ 0 ] + ": \n"
Jon Hallb4242222016-01-25 17:07:04 -08002210 for line in range( 1, len( term ) ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002211 outputString += ( "\t" + term[ line ] + "\n" )
2212 if outputString != ( term[ 0 ] + ": \n" ):
Jon Hallb4242222016-01-25 17:07:04 -08002213 main.log.info( outputString )
2214 main.log.info( "=" * 70 )
2215 return totalHits
2216 except pexpect.EOF:
2217 main.log.error( self.name + ": EOF exception found" )
2218 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002219 main.cleanAndExit()
Jon Hallb4242222016-01-25 17:07:04 -08002220 except pexpect.TIMEOUT:
2221 main.log.error( self.name + ": TIMEOUT exception found" )
2222 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002223 main.cleanAndExit()
Jon Hallb4242222016-01-25 17:07:04 -08002224 except Exception:
2225 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002226 main.cleanAndExit()
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002227
2228 def copyMininetFile( self, fileName, localPath, userName, ip,
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002229 mnPath='~/mininet/custom/', timeout = 60 ):
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002230 """
2231 Description:
2232 Copy mininet topology file from dependency folder in the test folder
2233 and paste it to the mininet machine's mininet/custom folder
2234 Required:
2235 fileName - Name of the topology file to copy
2236 localPath - File path of the mininet topology file
2237 userName - User name of the mininet machine to send the file to
2238 ip - Ip address of the mininet machine
2239 Optional:
2240 mnPath - of the mininet directory to send the file to
2241 Return:
2242 Return main.TRUE if successfully copied the file otherwise
2243 return main.FALSE
2244 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002245
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002246 try:
2247 cmd = "scp " + localPath + fileName + " " + userName + "@" + \
2248 str( ip ) + ":" + mnPath + fileName
2249
2250 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07002251 self.handle.expect( self.prompt )
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002252
2253 main.log.info( self.name + ": Execute: " + cmd )
2254
2255 self.handle.sendline( cmd )
2256
2257 i = self.handle.expect( [ 'No such file',
2258 "100%",
2259 pexpect.TIMEOUT ] )
2260
2261 if i == 0:
2262 main.log.error( self.name + ": File " + fileName +
2263 " does not exist!" )
2264 return main.FALSE
2265
2266 if i == 1:
2267 main.log.info( self.name + ": File " + fileName +
2268 " has been copied!" )
2269 self.handle.sendline( "" )
Devin Limc20e79a2017-06-07 10:29:57 -07002270 self.handle.expect( self.prompt )
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002271 return main.TRUE
2272
2273 except pexpect.EOF:
2274 main.log.error( self.name + ": EOF exception found" )
2275 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002276 main.cleanAndExit()
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002277 except pexpect.TIMEOUT:
2278 main.log.error( self.name + ": TIMEOUT exception found" )
2279 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002280 main.cleanAndExit()
cameron@onlab.us78b89652015-07-08 15:21:03 -07002281
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002282 def jvmSet( self, memory=8 ):
Jon Hall4ba53f02015-07-29 13:07:41 -07002283
cameron@onlab.us78b89652015-07-08 15:21:03 -07002284 import os
2285
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002286 homeDir = os.path.expanduser( '~' )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002287 filename = "/onos/tools/package/bin/onos-service"
2288
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002289 serviceConfig = open( homeDir + filename, 'w+' )
2290 serviceConfig.write( "#!/bin/bash\n " )
2291 serviceConfig.write( "#------------------------------------- \n " )
2292 serviceConfig.write( "# Starts ONOS Apache Karaf container\n " )
2293 serviceConfig.write( "#------------------------------------- \n " )
2294 serviceConfig.write( "#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n " )
2295 serviceConfig.write( """export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str( memory ) + "G -Xmx" + str( memory ) + """G}" \n """ )
2296 serviceConfig.write( "[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n" )
2297 serviceConfig.write( """${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """ )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002298 serviceConfig.close()
2299
Jon Hall6c44c0b2016-04-20 15:21:00 -07002300 def createDBFile( self, testData ):
Jon Hall4ba53f02015-07-29 13:07:41 -07002301
cameron@onlab.us78b89652015-07-08 15:21:03 -07002302 filename = main.TEST + "DB"
2303 DBString = ""
Jon Hall4ba53f02015-07-29 13:07:41 -07002304
cameron@onlab.us78b89652015-07-08 15:21:03 -07002305 for item in testData:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002306 if isinstance( item, string ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002307 item = "'" + item + "'"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002308 if testData.index( item ) < len( testData - 1 ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002309 item += ","
Jon Hall6c44c0b2016-04-20 15:21:00 -07002310 DBString += str( item )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002311
Jon Hall6c44c0b2016-04-20 15:21:00 -07002312 DBFile = open( filename, "a" )
2313 DBFile.write( DBString )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002314 DBFile.close()
2315
Jon Hall6c44c0b2016-04-20 15:21:00 -07002316 def verifySummary( self, ONOSIp, *deviceCount ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002317
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002318 self.handle.sendline( "onos " + ONOSIp + " summary" )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002319 self.handle.expect( ":~" )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002320
2321 summaryStr = self.handle.before
2322 print "\nSummary\n==============\n" + summaryStr + "\n\n"
2323
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002324 # passed = "SCC(s)=1" in summaryStr
2325 # if deviceCount:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002326 # passed = "devices=" + str(deviceCount) + "," not in summaryStr
cameron@onlab.us78b89652015-07-08 15:21:03 -07002327
GlennRC772363b2015-08-25 13:05:57 -07002328 passed = False
cameron@onlab.us78b89652015-07-08 15:21:03 -07002329 if "SCC(s)=1," in summaryStr:
2330 passed = True
Jon Hall6c44c0b2016-04-20 15:21:00 -07002331 print "Summary is verifed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002332 else:
Jon Hall6c44c0b2016-04-20 15:21:00 -07002333 print "Summary failed"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002334
2335 if deviceCount:
2336 print" ============================="
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002337 checkStr = "devices=" + str( deviceCount[ 0 ] ) + ","
cameron@onlab.us78b89652015-07-08 15:21:03 -07002338 print "Checkstr: " + checkStr
2339 if checkStr not in summaryStr:
2340 passed = False
Jon Hall6c44c0b2016-04-20 15:21:00 -07002341 print "Device count failed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002342 else:
2343 print "device count verified"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002344
2345 return passed
Jon Hall6c44c0b2016-04-20 15:21:00 -07002346
Jon Hall8f6d4622016-05-23 15:27:18 -07002347 def getIpAddr( self, iface=None ):
Jon Hall6c44c0b2016-04-20 15:21:00 -07002348 """
2349 Update self.ip_address with numerical ip address. If multiple IP's are
2350 located on the device, will attempt to use self.nicAddr to choose the
2351 right one. Defaults to 127.0.0.1 if no other address is found or cannot
2352 determine the correct address.
2353
2354 ONLY WORKS WITH IPV4 ADDRESSES
2355 """
2356 try:
Jon Hall8f6d4622016-05-23 15:27:18 -07002357 LOCALHOST = "127.0.0.1"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002358 ipPat = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
2359 pattern = re.compile( ipPat )
2360 match = re.search( pattern, self.ip_address )
2361 if self.nicAddr:
2362 nicPat = self.nicAddr.replace( ".", "\." ).replace( "\*", r"\d{1,3}" )
2363 nicPat = re.compile( nicPat )
2364 else:
2365 nicPat = None
2366 # IF self.ip_address is an ip address and matches
2367 # self.nicAddr: return self.ip_address
2368 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002369 curIp = match.group( 0 )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002370 if nicPat:
2371 nicMatch = re.search( nicPat, curIp )
2372 if nicMatch:
2373 return self.ip_address
Jon Hall8f6d4622016-05-23 15:27:18 -07002374 # ELSE: IF iface, return ip of interface
2375 cmd = "ifconfig"
2376 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2377 if iface:
2378 cmd += " " + str( iface )
2379 raw = subprocess.check_output( cmd.split() )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002380 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2381 ips = re.findall( ifPat, raw )
Jon Hall8f6d4622016-05-23 15:27:18 -07002382 if iface:
2383 if ips:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002384 ip = ips[ 0 ]
Jon Hall8f6d4622016-05-23 15:27:18 -07002385 self.ip_address = ip
2386 return ip
2387 else:
2388 main.log.error( "Error finding ip, ifconfig output:".format( raw ) )
2389 # ELSE: attempt to get address matching nicPat.
Jon Hall6c44c0b2016-04-20 15:21:00 -07002390 if nicPat:
2391 for ip in ips:
2392 curMatch = re.search( nicPat, ip )
2393 if curMatch:
2394 self.ip_address = ip
2395 return ip
Jon Hall8f6d4622016-05-23 15:27:18 -07002396 else: # If only one non-localhost ip, return that
2397 tmpList = [ ip for ip in ips if ip is not LOCALHOST ]
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002398 if len( tmpList ) == 1:
2399 curIp = tmpList[ 0 ]
Jon Hall6c44c0b2016-04-20 15:21:00 -07002400 self.ip_address = curIp
2401 return curIp
Jon Hall8f6d4622016-05-23 15:27:18 -07002402 # Either no non-localhost IPs, or more than 1
Jon Hallebccd352016-05-20 15:17:17 -07002403 main.log.warn( "getIpAddr failed to find a public IP address" )
Jon Hall8f6d4622016-05-23 15:27:18 -07002404 return LOCALHOST
Jon Halle1790952016-05-23 15:51:46 -07002405 except subprocess.CalledProcessError:
Jon Hall8f6d4622016-05-23 15:27:18 -07002406 main.log.exception( "Error executing ifconfig" )
2407 except IndexError:
2408 main.log.exception( "Error getting IP Address" )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002409 except Exception:
2410 main.log.exception( "Uncaught exception" )
suibin zhang116647a2016-05-06 16:30:09 -07002411
Devin Lim461f0872017-06-05 16:49:33 -07002412 def startBasicONOS( self, nodeList, opSleep=60, onosStartupSleep=30, onosUser="sdn" ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002413 '''
suibin zhang116647a2016-05-06 16:30:09 -07002414 Start onos cluster with defined nodes, but only with drivers app
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002415 '''
suibin zhang116647a2016-05-06 16:30:09 -07002416 import time
2417
2418 self.createCellFile( self.ip_address,
2419 "temp",
2420 self.ip_address,
2421 "drivers",
Devin Lim461f0872017-06-05 16:49:33 -07002422 nodeList, onosUser )
suibin zhang116647a2016-05-06 16:30:09 -07002423
2424 main.log.info( self.name + ": Apply cell to environment" )
2425 cellResult = self.setCell( "temp" )
2426 verifyResult = self.verifyCell()
2427
2428 main.log.info( self.name + ": Creating ONOS package" )
You Wangd1bcaca2016-10-24 15:23:26 -07002429 packageResult = self.buckBuild( timeout=opSleep )
suibin zhang116647a2016-05-06 16:30:09 -07002430
You Wangc669d212017-01-25 11:09:48 -08002431 main.log.info( self.name + ": Uninstalling ONOS" )
2432 for nd in nodeList:
2433 self.onosUninstall( nodeIp=nd )
2434
suibin zhang116647a2016-05-06 16:30:09 -07002435 main.log.info( self.name + ": Installing ONOS package" )
2436 for nd in nodeList:
You Wangc669d212017-01-25 11:09:48 -08002437 self.onosInstall( node=nd )
2438
2439 main.log.info( self.name + ": Set up ONOS secure SSH" )
2440 for nd in nodeList:
2441 self.onosSecureSSH( node=nd )
suibin zhang116647a2016-05-06 16:30:09 -07002442
2443 main.log.info( self.name + ": Starting ONOS service" )
2444 time.sleep( onosStartupSleep )
2445
2446 onosStatus = True
2447 for nd in nodeList:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002448 onosStatus = onosStatus & self.isup( node = nd )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002449 # print "onosStatus is: " + str( onosStatus )
suibin zhang116647a2016-05-06 16:30:09 -07002450
2451 return main.TRUE if onosStatus else main.FALSE
2452
Devin Lim02075272017-07-10 15:33:21 -07002453 def onosNetCfg( self, controllerIp, path, fileName ):
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002454 """
2455 Push a specified json file to ONOS through the onos-netcfg service
2456
2457 Required:
Devin Lim02075272017-07-10 15:33:21 -07002458 controllerIp - the Ip of the ONOS node in the cluster
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002459 path - the location of the file to be sent
2460 fileName - name of the json file to be sent
2461
2462 Returns main.TRUE on successfully sending json file, and main.FALSE if
2463 there is an error.
2464 """
2465 try:
Devin Lim02075272017-07-10 15:33:21 -07002466 cmd = "onos-netcfg {0} {1}{2}".format( controllerIp, path, fileName )
2467 main.log.info( "Sending: " + cmd )
2468 main.ONOSbench.handle.sendline( cmd )
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -07002469 main.ONOSbench.handle.expect( self.prompt )
Devin Lim02075272017-07-10 15:33:21 -07002470 handle = self.handle.before
Jeremy Ronquillo3008aa32017-07-07 15:38:57 -07002471 if "Error" in handle or "No such file or directory" in handle or "curl: " in handle:
2472 main.log.error( self.name + ": " + handle + self.handle.after )
Devin Lim02075272017-07-10 15:33:21 -07002473 return main.FALSE
Devin Lim752dd7b2017-06-27 14:40:03 -07002474 return main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002475 except pexpect.EOF:
2476 main.log.error( self.name + ": EOF exception found" )
2477 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002478 main.cleanAndExit()
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002479 except Exception:
2480 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002481 main.cleanAndExit()
Devin Lim3ebd5e72017-11-14 10:38:00 -08002482
2483 def formCluster( self, onosIPs ):
2484 """
2485 From ONOS cluster for IP addresses in onosIPs list
2486 """
2487 try:
2488 onosIPs = " ".join( onosIPs )
2489 command = "onos-form-cluster {}".format( onosIPs )
2490 main.log.info( "Sending: " + command )
2491 self.handle.sendline( "" )
2492 self.handle.expect( self.prompt )
2493 self.handle.sendline( command )
2494 self.handle.expect( self.prompt )
2495 handle = self.handle.before
2496 main.log.debug( handle )
2497 assert handle is not None, "Error in sendline"
2498 assert "Command not found:" not in handle, handle
2499 assert "Error" not in handle, handle
2500 assert "Exception:" not in handle, handle
2501 assert "curl:" not in handle, handle
2502 return main.TRUE
2503 except AssertionError:
2504 main.log.exception( "{} Error in onos-form-cluster output:".format( self.name ) )
2505 return main.FALSE
2506 except TypeError:
2507 main.log.exception( self.name + ": Object not as expected" )
2508 return main.FALSE
2509 except pexpect.EOF:
2510 main.log.error( self.name + ": EOF exception found" )
2511 main.log.error( self.name + ": " + self.handle.before )
2512 main.cleanAndExit()
2513 except Exception:
2514 main.log.exception( self.name + ": Uncaught exception!" )
2515 main.cleanAndExit()
Jon Hall7ce46ea2018-02-05 12:20:59 -08002516
2517 def backupData( self, location ):
2518 """
2519 Backs up ONOS data and logs to a given location. Returns main.FALSE
2520 if there is an error executing the command, and main.TRUE otherwise.
2521 required arguments:
2522 loaction - The file path to save the backup to
2523 """
2524 try:
2525 cmd = "/opt/onos/bin/onos-backup " + str( location )
2526 self.handle.sendline( cmd )
2527 self.handle.expect( self.prompt )
2528 handle = self.handle.before
2529 main.log.debug( handle )
2530 assert handle is not None, "Error in sendline"
2531 assert "Command not found:" not in handle, handle
2532 assert "Error" not in handle, handle
2533 assert "Exception:" not in handle, handle
2534 return main.TRUE
2535 except AssertionError:
2536 main.log.exception( "{} Error in onos-backup output:".format( self.name ) )
2537 return main.FALSE
2538 except TypeError:
2539 main.log.exception( self.name + ": Object not as expected" )
2540 return main.FALSE
2541 except pexpect.EOF:
2542 main.log.error( self.name + ": EOF exception found" )
2543 main.log.error( self.name + ": " + self.handle.before )
2544 main.cleanAndExit()
2545 except Exception:
2546 main.log.exception( self.name + ": Uncaught exception!" )
2547 main.cleanAndExit()
2548
2549 def restoreData( self, location ):
2550 """
2551 Restores ONOS data and logs from a given location. Returns main.FALSE
2552 if there is an error executing the command, and main.TRUE otherwise.
2553 required arguments:
2554 loaction - The file path of a backup file
2555 """
2556 try:
2557 cmd = "/opt/onos/bin/onos-restore " + str( location )
2558 self.handle.sendline( cmd )
2559 self.handle.expect( self.prompt )
2560 handle = self.handle.before
2561 main.log.debug( handle )
2562 assert handle is not None, "Error in sendline"
2563 assert "Command not found:" not in handle, handle
2564 assert "Error" not in handle, handle
2565 assert "Exception:" not in handle, handle
2566 return main.TRUE
2567 except AssertionError:
2568 main.log.exception( "{} Error in onos-restore output:".format( self.name ) )
2569 return main.FALSE
2570 except TypeError:
2571 main.log.exception( self.name + ": Object not as expected" )
2572 return main.FALSE
2573 except pexpect.EOF:
2574 main.log.error( self.name + ": EOF exception found" )
2575 main.log.error( self.name + ": " + self.handle.before )
2576 main.cleanAndExit()
2577 except Exception:
2578 main.log.exception( self.name + ": Uncaught exception!" )
2579 main.cleanAndExit()
You Wang5df1c6d2018-04-06 18:02:02 -07002580
You Wang5ac7db72018-07-17 11:17:52 -07002581 def onosDiagnostics( self, onosIPs, dstDir, suffix, timeout=300 ):
You Wang5df1c6d2018-04-06 18:02:02 -07002582 """
2583 Run onos-diagnostics with given ONOS instance IPs and save output to dstDir
2584 with suffix specified E.g. onos-diags-suffix.tar.gz
Jon Hall0e240372018-05-02 11:21:57 -07002585 required arguments:
You Wang5df1c6d2018-04-06 18:02:02 -07002586 onosIPs - list of ONOS IPs for collecting diags
2587 dstDir - diags file will be saved under the directory specified
2588 suffix - diags file will be named with the suffix specified
2589 returns:
2590 main.FALSE if there's an error executing the command, and main.TRUE otherwise
2591 """
2592 try:
2593 cmd = "onos-diagnostics"
2594 assert isinstance( onosIPs, list )
2595 for ip in onosIPs:
2596 cmd += " " + str( ip )
2597 self.handle.sendline( cmd )
You Wang5ac7db72018-07-17 11:17:52 -07002598 self.handle.expect( self.prompt, timeout=timeout )
You Wang5df1c6d2018-04-06 18:02:02 -07002599 handle = self.handle.before
2600 main.log.debug( handle )
2601 assert handle is not None, "Error in sendline"
2602 assert "Command not found:" not in handle, handle
2603 assert "Exception:" not in handle, handle
2604 # Rename and move diags file to dstDir from /tmp
2605 if dstDir[ -1: ] != "/":
2606 dstDir += "/"
2607 self.handle.sendline( "mv /tmp/onos-diags.tar.gz " + str( dstDir ) + "onos-diags" + str( suffix ) + ".tar.gz" )
2608 self.handle.expect( self.prompt )
2609 handle = self.handle.before
2610 main.log.debug( handle )
2611 assert handle is not None, "Error in sendline"
2612 assert "No such file or directory" not in handle, handle
2613 return main.TRUE
2614 except AssertionError:
2615 main.log.exception( "{} Error in onos-diagnostics output:".format( self.name ) )
2616 return main.FALSE
2617 except TypeError:
2618 main.log.exception( self.name + ": Object not as expected" )
2619 return main.FALSE
You Wang223faa32018-06-21 10:45:47 -07002620 except pexpect.TIMEOUT:
2621 main.log.exception( self.name + ": TIMEOUT exception found in onosDiagnostics" )
2622 main.log.error( self.name + ": " + self.handle.before )
You Wang141b43b2018-06-26 16:50:18 -07002623 self.handle.send( "\x03" ) # Control-C
2624 self.handle.expect( self.prompt )
You Wang223faa32018-06-21 10:45:47 -07002625 return main.FALSE
You Wang5df1c6d2018-04-06 18:02:02 -07002626 except pexpect.EOF:
2627 main.log.error( self.name + ": EOF exception found" )
2628 main.log.error( self.name + ": " + self.handle.before )
2629 main.cleanAndExit()
2630 except Exception:
2631 main.log.exception( self.name + ": Uncaught exception!" )
2632 main.cleanAndExit()
Jon Hall0e240372018-05-02 11:21:57 -07002633
2634 def onosPower( self, onosIP, toggle, userName=None ):
2635 """
2636 Run onos-power script to tell the cell warden to simulate a power faulure
2637 for the given container.
2638 required :
2639 onosIP - ONOS node IP
2640 toggle - either "off" or "on", used to indicate whether
2641 the node should be powered off or on
2642 returns:
2643 main.FALSE if there's an error executing the command, and main.TRUE otherwise
2644 """
2645 try:
2646 cmd = "onos-power {} {}".format( onosIP, toggle )
2647 if userName:
2648 cmd += " {}".format( userName )
2649 self.handle.sendline( cmd )
2650 self.handle.expect( self.prompt )
2651 handle = self.handle.before
2652 main.log.debug( handle )
2653 assert handle is not None, "Error in sendline"
2654 assert "Command not found:" not in handle, handle
2655 assert "Exception:" not in handle, handle
2656 assert "usage:" not in handle, handle
2657 return main.TRUE
2658 except AssertionError:
2659 main.log.exception( "{} Error in onos-power output:".format( self.name ) )
2660 return main.FALSE
2661 except TypeError:
2662 main.log.exception( self.name + ": Object not as expected" )
2663 return main.FALSE
2664 except pexpect.EOF:
2665 main.log.error( self.name + ": EOF exception found" )
2666 main.log.error( self.name + ": " + self.handle.before )
2667 main.cleanAndExit()
2668 except Exception:
2669 main.log.exception( self.name + ": Uncaught exception!" )
2670 main.cleanAndExit()