blob: 635178e5b4fbea16ee36de36a3ab6fc40bdbb524 [file] [log] [blame]
Jon Hall05b2b432014-10-08 19:53:25 -04001#!/usr/bin/env python
andrewonlabe8e56fd2014-10-09 17:12:44 -04002
kelvin8ec71442015-01-15 16:57:00 -08003"""
4This driver interacts with ONOS bench, the OSGi platform
5that configures the ONOS nodes. ( aka ONOS-next )
andrewonlabe8e56fd2014-10-09 17:12:44 -04006
kelvin8ec71442015-01-15 16:57:00 -08007Please follow the coding style demonstrated by existing
andrewonlabe8e56fd2014-10-09 17:12:44 -04008functions and document properly.
9
10If you are a contributor to the driver, please
11list your email here for future contact:
12
13jhall@onlab.us
14andrew@onlab.us
15
16OCT 9 2014
Jeremy Songsterae01bba2016-07-11 15:39:17 -070017Modified 2016 by ON.Lab
18
19Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
20the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
21or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
andrewonlabe8e56fd2014-10-09 17:12:44 -040022
kelvin8ec71442015-01-15 16:57:00 -080023"""
Jon Hall05b2b432014-10-08 19:53:25 -040024import time
Jon Hall6801cda2015-07-15 14:13:45 -070025import types
Jon Hall05b2b432014-10-08 19:53:25 -040026import pexpect
kelvin-onlaba4074292015-07-09 15:19:49 -070027import os
Jon Hall6c44c0b2016-04-20 15:21:00 -070028import re
29import subprocess
pingping-lin6d23d9e2015-02-02 16:54:24 -080030from requests.models import Response
Jon Hall05b2b432014-10-08 19:53:25 -040031from drivers.common.clidriver import CLI
32
kelvin8ec71442015-01-15 16:57:00 -080033class OnosDriver( CLI ):
Jon Hall05b2b432014-10-08 19:53:25 -040034
kelvin8ec71442015-01-15 16:57:00 -080035 def __init__( self ):
36 """
37 Initialize client
38 """
Jon Hallefbd9792015-03-05 16:11:36 -080039 self.name = None
40 self.home = None
41 self.handle = None
Jon Hall6c44c0b2016-04-20 15:21:00 -070042 self.nicAddr = None
kelvin8ec71442015-01-15 16:57:00 -080043 super( CLI, self ).__init__()
44
45 def connect( self, **connectargs ):
46 """
Jon Hall05b2b432014-10-08 19:53:25 -040047 Creates ssh handle for ONOS "bench".
kelvin-onlaba4074292015-07-09 15:19:49 -070048 NOTE:
49 The ip_address would come from the topo file using the host tag, the
50 value can be an environment variable as well as a "localhost" to get
51 the ip address needed to ssh to the "bench"
kelvin8ec71442015-01-15 16:57:00 -080052 """
Jon Hall05b2b432014-10-08 19:53:25 -040053 try:
54 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080055 vars( self )[ key ] = connectargs[ key ]
andrew@onlab.us3b087132015-03-11 15:00:08 -070056 self.home = "~/onos"
Jon Hall05b2b432014-10-08 19:53:25 -040057 for key in self.options:
58 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080059 self.home = self.options[ 'home' ]
Jon Hall05b2b432014-10-08 19:53:25 -040060 break
Jon Hall274b6642015-02-17 11:57:17 -080061 if self.home is None or self.home == "":
Jon Halle94919c2015-03-23 11:42:57 -070062 self.home = "~/onos"
Jon Hall21270ac2015-02-16 17:59:55 -080063
kelvin8ec71442015-01-15 16:57:00 -080064 self.name = self.options[ 'name' ]
kelvin-onlaba4074292015-07-09 15:19:49 -070065
kelvin-onlabc2b79102015-07-14 11:41:20 -070066 # The 'nodes' tag is optional and it is not required in .topo file
kelvin-onlaba4074292015-07-09 15:19:49 -070067 for key in self.options:
68 if key == "nodes":
kelvin-onlabc2b79102015-07-14 11:41:20 -070069 # Maximum number of ONOS nodes to run, if there is any
kelvin-onlaba4074292015-07-09 15:19:49 -070070 self.maxNodes = int( self.options[ 'nodes' ] )
71 break
72 self.maxNodes = None
73
kelvin-onlabc2b79102015-07-14 11:41:20 -070074 if self.maxNodes == None or self.maxNodes == "":
75 self.maxNodes = 100
kelvin-onlaba4074292015-07-09 15:19:49 -070076
kelvin-onlabc2b79102015-07-14 11:41:20 -070077
78 # Grabs all OC environment variables based on max number of nodes
kelvin-onlaba4074292015-07-09 15:19:49 -070079 self.onosIps = {} # Dictionary of all possible ONOS ip
80
81 try:
82 if self.maxNodes:
kelvin-onlaba4074292015-07-09 15:19:49 -070083 for i in range( self.maxNodes ):
84 envString = "OC" + str( i + 1 )
kelvin-onlabc2b79102015-07-14 11:41:20 -070085 # If there is no more OC# then break the loop
86 if os.getenv( envString ):
87 self.onosIps[ envString ] = os.getenv( envString )
88 else:
89 self.maxNodes = len( self.onosIps )
90 main.log.info( self.name +
91 ": Created cluster data with " +
92 str( self.maxNodes ) +
93 " maximum number" +
94 " of nodes" )
95 break
kelvin-onlaba4074292015-07-09 15:19:49 -070096
97 if not self.onosIps:
98 main.log.info( "Could not read any environment variable"
99 + " please load a cell file with all" +
100 " onos IP" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700101 self.maxNodes = None
kelvin-onlaba4074292015-07-09 15:19:49 -0700102 else:
103 main.log.info( self.name + ": Found " +
104 str( self.onosIps.values() ) +
105 " ONOS IPs" )
kelvin-onlaba4074292015-07-09 15:19:49 -0700106 except KeyError:
107 main.log.info( "Invalid environment variable" )
108 except Exception as inst:
109 main.log.error( "Uncaught exception: " + str( inst ) )
110
111 try:
112 if os.getenv( str( self.ip_address ) ) != None:
113 self.ip_address = os.getenv( str( self.ip_address ) )
114 else:
115 main.log.info( self.name +
116 ": Trying to connect to " +
117 self.ip_address )
kelvin-onlaba4074292015-07-09 15:19:49 -0700118 except KeyError:
119 main.log.info( "Invalid host name," +
120 " connecting to local host instead" )
121 self.ip_address = 'localhost'
122 except Exception as inst:
123 main.log.error( "Uncaught exception: " + str( inst ) )
124
kelvin8ec71442015-01-15 16:57:00 -0800125 self.handle = super( OnosDriver, self ).connect(
126 user_name=self.user_name,
kelvin-onlab08679eb2015-01-21 16:11:48 -0800127 ip_address=self.ip_address,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800128 port=self.port,
129 pwd=self.pwd,
130 home=self.home )
Jon Hall05b2b432014-10-08 19:53:25 -0400131
Jon Hall05b2b432014-10-08 19:53:25 -0400132 if self.handle:
Jon Hall0fc0d452015-07-14 09:49:58 -0700133 self.handle.sendline( "cd " + self.home )
134 self.handle.expect( "\$" )
Jon Hall05b2b432014-10-08 19:53:25 -0400135 return self.handle
kelvin8ec71442015-01-15 16:57:00 -0800136 else:
Jon Hall0fc0d452015-07-14 09:49:58 -0700137 main.log.info( "Failed to create ONOS handle" )
Jon Hall05b2b432014-10-08 19:53:25 -0400138 return main.FALSE
139 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800140 main.log.error( self.name + ": EOF exception found" )
141 main.log.error( self.name + ": " + self.handle.before )
Jon Hall05b2b432014-10-08 19:53:25 -0400142 main.cleanup()
143 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800144 except Exception:
145 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall05b2b432014-10-08 19:53:25 -0400146 main.cleanup()
147 main.exit()
148
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( "" )
157 self.handle.expect( "\$" )
158 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,
176 around a hundred milliseconds of difference (ascending) is
177 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' )
184 self.handle.expect( '\$' )
185 epochMs = self.handle.before
186 return epochMs
187 except Exception:
188 main.log.exception( 'Uncaught exception getting epoch time' )
189 main.cleanup()
190 main.exit()
191
Jon Hall6c44c0b2016-04-20 15:21:00 -0700192 def onosPackage( self, opTimeout=180 ):
kelvin8ec71442015-01-15 16:57:00 -0800193 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400194 Produce a self-contained tar.gz file that can be deployed
Jon Hall64af8502015-12-15 10:09:33 -0800195 and executed on any platform with Java 8 JRE.
kelvin8ec71442015-01-15 16:57:00 -0800196 """
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400197 try:
Jon Hall64af8502015-12-15 10:09:33 -0800198 ret = main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800199 self.handle.sendline( "onos-package" )
200 self.handle.expect( "onos-package" )
Jon Hall96451092016-05-04 09:42:30 -0700201 while True:
202 i = self.handle.expect( [ "Downloading",
203 "Unknown options",
204 "No such file or directory",
205 "tar.gz",
206 "\$" ],
207 opTimeout )
208 handle = str( self.handle.before + self.handle.after )
209 if i == 0:
210 # Give more time to download the file
211 continue # expect again
212 elif i == 1:
213 # Incorrect usage
214 main.log.error( "onos-package does not recognize the given options" )
215 ret = main.FALSE
216 continue # expect again
217 elif i == 2:
218 # File(s) not found
219 main.log.error( "onos-package could not find a file or directory" )
220 ret = main.FALSE
221 continue # expect again
222 elif i == 3:
223 # tar.gz
224 continue # expect again
225 elif i == 4:
226 # Prompt returned
227 break
Jon Hallc6793552016-01-19 14:18:37 -0800228 main.log.info( "onos-package command returned: " + handle )
kelvin8ec71442015-01-15 16:57:00 -0800229 # As long as the sendline does not time out,
230 # return true. However, be careful to interpret
231 # the results of the onos-package command return
Jon Hall64af8502015-12-15 10:09:33 -0800232 return ret
233 except pexpect.TIMEOUT:
234 main.log.exception( self.name + ": TIMEOUT exception found in onosPackage" )
235 main.log.error( self.name + ": " + self.handle.before )
236 return main.FALSE
andrewonlab7735d852014-10-09 13:02:47 -0400237 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800238 main.log.error( self.name + ": EOF exception found" )
239 main.log.error( self.name + ": " + self.handle.before )
Jon Hall64af8502015-12-15 10:09:33 -0800240 main.cleanup()
241 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800242 except Exception:
243 main.log.exception( "Failed to package ONOS" )
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400244 main.cleanup()
245 main.exit()
246
kelvin-onlabd3b64892015-01-20 13:26:24 -0800247 def onosBuild( self ):
kelvin8ec71442015-01-15 16:57:00 -0800248 """
andrewonlab8790abb2014-11-06 13:51:54 -0500249 Use the pre defined script to build onos via mvn
kelvin8ec71442015-01-15 16:57:00 -0800250 """
andrewonlab8790abb2014-11-06 13:51:54 -0500251 try:
kelvin8ec71442015-01-15 16:57:00 -0800252 self.handle.sendline( "onos-build" )
253 self.handle.expect( "onos-build" )
254 i = self.handle.expect( [
kelvin-onlabd3b64892015-01-20 13:26:24 -0800255 "BUILD SUCCESS",
256 "ERROR",
257 "BUILD FAILED" ],
258 timeout=120 )
kelvin8ec71442015-01-15 16:57:00 -0800259 handle = str( self.handle.before )
Jon Hall3b489db2015-10-05 14:38:37 -0700260 self.handle.expect( "\$" )
andrewonlab8790abb2014-11-06 13:51:54 -0500261
kelvin8ec71442015-01-15 16:57:00 -0800262 main.log.info( "onos-build command returned: " +
263 handle )
andrewonlab8790abb2014-11-06 13:51:54 -0500264
265 if i == 0:
266 return main.TRUE
267 else:
268 return handle
269
270 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800271 main.log.error( self.name + ": EOF exception found" )
272 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -0800273 except Exception:
274 main.log.exception( "Failed to build ONOS" )
andrewonlab8790abb2014-11-06 13:51:54 -0500275 main.cleanup()
276 main.exit()
277
shahshreya9f531fe2015-06-10 12:03:51 -0700278 def cleanInstall( self, skipTest=False, mciTimeout=600 ):
kelvin8ec71442015-01-15 16:57:00 -0800279 """
280 Runs mvn clean install in the root of the ONOS directory.
281 This will clean all ONOS artifacts then compile each module
shahshreya9f531fe2015-06-10 12:03:51 -0700282 Optional:
283 skipTest - Does "-DskipTests -Dcheckstyle.skip -U -T 1C" which
284 skip the test. This will make the building faster.
285 Disregarding the credibility of the build
kelvin8ec71442015-01-15 16:57:00 -0800286 Returns: main.TRUE on success
Jon Hallde9d9aa2014-10-08 20:36:02 -0400287 On Failure, exits the test
kelvin8ec71442015-01-15 16:57:00 -0800288 """
Jon Hallde9d9aa2014-10-08 20:36:02 -0400289 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800290 main.log.info( "Running 'mvn clean install' on " +
291 str( self.name ) +
kelvin8ec71442015-01-15 16:57:00 -0800292 ". This may take some time." )
293 self.handle.sendline( "cd " + self.home )
294 self.handle.expect( "\$" )
Jon Hallea7818b2014-10-09 14:30:59 -0400295
kelvin8ec71442015-01-15 16:57:00 -0800296 self.handle.sendline( "" )
297 self.handle.expect( "\$" )
shahshreya9f531fe2015-06-10 12:03:51 -0700298
299 if not skipTest:
300 self.handle.sendline( "mvn clean install" )
301 self.handle.expect( "mvn clean install" )
302 else:
303 self.handle.sendline( "mvn clean install -DskipTests" +
304 " -Dcheckstyle.skip -U -T 1C" )
305 self.handle.expect( "mvn clean install -DskipTests" +
306 " -Dcheckstyle.skip -U -T 1C" )
kelvin8ec71442015-01-15 16:57:00 -0800307 while True:
308 i = self.handle.expect( [
Jon Hall274b6642015-02-17 11:57:17 -0800309 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s' +
Jon Hallefbd9792015-03-05 16:11:36 -0800310 'Runtime\sEnvironment\sto\scontinue',
Jon Hallde9d9aa2014-10-08 20:36:02 -0400311 'BUILD\sFAILURE',
312 'BUILD\sSUCCESS',
Jon Halle94919c2015-03-23 11:42:57 -0700313 'onos\$', #TODO: fix this to be more generic?
Jon Hallde9d9aa2014-10-08 20:36:02 -0400314 'ONOS\$',
pingping-lin57a56ce2015-05-20 16:43:48 -0700315 pexpect.TIMEOUT ], mciTimeout )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400316 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800317 main.log.error( self.name + ":There is insufficient memory \
318 for the Java Runtime Environment to continue." )
319 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400320 main.cleanup()
321 main.exit()
322 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800323 main.log.error( self.name + ": Build failure!" )
324 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400325 main.cleanup()
326 main.exit()
327 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800328 main.log.info( self.name + ": Build success!" )
Jon Halle94919c2015-03-23 11:42:57 -0700329 elif i == 3 or i == 4:
kelvin8ec71442015-01-15 16:57:00 -0800330 main.log.info( self.name + ": Build complete" )
331 # Print the build time
Jon Hallf8ef52c2014-10-09 19:37:33 -0400332 for line in self.handle.before.splitlines():
333 if "Total time:" in line:
kelvin8ec71442015-01-15 16:57:00 -0800334 main.log.info( line )
335 self.handle.sendline( "" )
336 self.handle.expect( "\$", timeout=60 )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400337 return main.TRUE
Jon Halle94919c2015-03-23 11:42:57 -0700338 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800339 main.log.error(
340 self.name +
341 ": mvn clean install TIMEOUT!" )
342 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400343 main.cleanup()
344 main.exit()
345 else:
Jon Hall274b6642015-02-17 11:57:17 -0800346 main.log.error( self.name + ": unexpected response from " +
Jon Hallefbd9792015-03-05 16:11:36 -0800347 "mvn clean install" )
kelvin8ec71442015-01-15 16:57:00 -0800348 # return main.FALSE
Jon Hallde9d9aa2014-10-08 20:36:02 -0400349 main.cleanup()
350 main.exit()
351 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800352 main.log.error( self.name + ": EOF exception found" )
353 main.log.error( self.name + ": " + self.handle.before )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400354 main.cleanup()
355 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800356 except Exception:
357 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallde9d9aa2014-10-08 20:36:02 -0400358 main.cleanup()
359 main.exit()
Jon Hallacabffd2014-10-09 12:36:53 -0400360
Jon Hall61282e32015-03-19 11:34:11 -0700361 def gitPull( self, comp1="", fastForward=True ):
kelvin8ec71442015-01-15 16:57:00 -0800362 """
Jon Hallacabffd2014-10-09 12:36:53 -0400363 Assumes that "git pull" works without login
Jon Hall47a93fb2015-01-06 16:46:06 -0800364
Jon Hall61282e32015-03-19 11:34:11 -0700365 If the fastForward boolean is set to true, only git pulls that can
366 be fast forwarded will be performed. IE if you have not local commits
367 in your branch.
368
Jon Hallacabffd2014-10-09 12:36:53 -0400369 This function will perform a git pull on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800370 If used as gitPull( "NODE" ) it will do git pull + NODE. This is
Jon Hallacabffd2014-10-09 12:36:53 -0400371 for the purpose of pulling from other nodes if necessary.
372
Jon Hall47a93fb2015-01-06 16:46:06 -0800373 Otherwise, this function will perform a git pull in the
Jon Hallacabffd2014-10-09 12:36:53 -0400374 ONOS repository. If it has any problems, it will return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -0800375 If it successfully does a gitPull, it will return a 1 ( main.TRUE )
Shreya Shahee15f6c2014-10-28 18:12:30 -0400376 If it has no updates, it will return 3.
Jon Hallacabffd2014-10-09 12:36:53 -0400377
kelvin8ec71442015-01-15 16:57:00 -0800378 """
Jon Hallacabffd2014-10-09 12:36:53 -0400379 try:
kelvin8ec71442015-01-15 16:57:00 -0800380 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800381 self.handle.expect( self.home + "\$" )
Jon Hall61282e32015-03-19 11:34:11 -0700382 cmd = "git pull"
383 if comp1 != "":
384 cmd += ' ' + comp1
385 if fastForward:
386 cmd += ' ' + " --ff-only"
387 self.handle.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800388 i = self.handle.expect(
389 [
390 'fatal',
391 'Username\sfor\s(.*):\s',
392 '\sfile(s*) changed,\s',
393 'Already up-to-date',
394 'Aborting',
395 'You\sare\snot\scurrently\son\sa\sbranch',
Jon Hall274b6642015-02-17 11:57:17 -0800396 'You asked me to pull without telling me which branch you',
397 'Pull is not possible because you have unmerged files',
Jon Hall61282e32015-03-19 11:34:11 -0700398 'Please enter a commit message to explain why this merge',
399 'Found a swap file by the name',
400 'Please, commit your changes before you can merge.',
kelvin-onlabd3b64892015-01-20 13:26:24 -0800401 pexpect.TIMEOUT ],
402 timeout=300 )
kelvin8ec71442015-01-15 16:57:00 -0800403 if i == 0:
Jon Hall61282e32015-03-19 11:34:11 -0700404 main.log.error( self.name + ": Git pull had some issue" )
405 output = self.handle.after
406 self.handle.expect( '\$' )
407 output += self.handle.before
408 main.log.warn( output )
Jon Hallacabffd2014-10-09 12:36:53 -0400409 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800410 elif i == 1:
411 main.log.error(
412 self.name +
413 ": Git Pull Asking for username. " )
Jon Hallacabffd2014-10-09 12:36:53 -0400414 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800415 elif i == 2:
416 main.log.info(
417 self.name +
418 ": Git Pull - pulling repository now" )
kelvin-onlaba1484582015-02-02 15:46:20 -0800419 self.handle.expect( self.home + "\$", 120 )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800420 # So that only when git pull is done, we do mvn clean compile
421 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800422 elif i == 3:
423 main.log.info( self.name + ": Git Pull - Already up to date" )
Jon Hall47a93fb2015-01-06 16:46:06 -0800424 return i
kelvin8ec71442015-01-15 16:57:00 -0800425 elif i == 4:
426 main.log.info(
427 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800428 ": Git Pull - Aborting..." +
429 "Are there conflicting git files?" )
Jon Hallacabffd2014-10-09 12:36:53 -0400430 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800431 elif i == 5:
432 main.log.info(
433 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800434 ": Git Pull - You are not currently " +
435 "on a branch so git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400436 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800437 elif i == 6:
438 main.log.info(
439 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800440 ": Git Pull - You have not configured an upstream " +
441 "branch to pull from. Git pull failed!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400442 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800443 elif i == 7:
444 main.log.info(
445 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800446 ": Git Pull - Pull is not possible because " +
447 "you have unmerged files." )
Jon Hallacabffd2014-10-09 12:36:53 -0400448 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800449 elif i == 8:
Jon Hall61282e32015-03-19 11:34:11 -0700450 # NOTE: abandoning test since we can't reliably handle this
451 # there could be different default text editors and we
452 # also don't know if we actually want to make the commit
453 main.log.error( "Git pull resulted in a merge commit message" +
454 ". Exiting test!" )
455 main.cleanup()
456 main.exit()
457 elif i == 9: # Merge commit message but swap file exists
458 main.log.error( "Git pull resulted in a merge commit message" +
459 " but a swap file exists." )
460 try:
461 self.handle.send( 'A' ) # Abort
462 self.handle.expect( "\$" )
463 return main.ERROR
464 except Exception:
465 main.log.exception( "Couldn't exit editor prompt!")
466 main.cleanup()
467 main.exit()
468 elif i == 10: # In the middle of a merge commit
469 main.log.error( "Git branch is in the middle of a merge. " )
470 main.log.warn( self.handle.before + self.handle.after )
471 return main.ERROR
472 elif i == 11:
kelvin8ec71442015-01-15 16:57:00 -0800473 main.log.error( self.name + ": Git Pull - TIMEOUT" )
474 main.log.error(
475 self.name + " Response was: " + str(
476 self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400477 return main.ERROR
478 else:
kelvin8ec71442015-01-15 16:57:00 -0800479 main.log.error(
480 self.name +
481 ": Git Pull - Unexpected response, check for pull errors" )
Jon Hallacabffd2014-10-09 12:36:53 -0400482 return main.ERROR
483 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800484 main.log.error( self.name + ": EOF exception found" )
485 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400486 main.cleanup()
487 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800488 except Exception:
489 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400490 main.cleanup()
491 main.exit()
492
kelvin-onlabd3b64892015-01-20 13:26:24 -0800493 def gitCheckout( self, branch="master" ):
kelvin8ec71442015-01-15 16:57:00 -0800494 """
Jon Hallacabffd2014-10-09 12:36:53 -0400495 Assumes that "git pull" works without login
kelvin8ec71442015-01-15 16:57:00 -0800496
Jon Hallacabffd2014-10-09 12:36:53 -0400497 This function will perform a git git checkout on the ONOS instance.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800498 If used as gitCheckout( "branch" ) it will do git checkout
499 of the "branch".
Jon Hallacabffd2014-10-09 12:36:53 -0400500
501 Otherwise, this function will perform a git checkout of the master
kelvin8ec71442015-01-15 16:57:00 -0800502 branch of the ONOS repository. If it has any problems, it will return
503 main.ERROR.
504 If the branch was already the specified branch, or the git checkout was
Jon Hallacabffd2014-10-09 12:36:53 -0400505 successful then the function will return main.TRUE.
506
kelvin8ec71442015-01-15 16:57:00 -0800507 """
Jon Hallacabffd2014-10-09 12:36:53 -0400508 try:
kelvin8ec71442015-01-15 16:57:00 -0800509 self.handle.sendline( "cd " + self.home )
kelvin-onlaba1484582015-02-02 15:46:20 -0800510 self.handle.expect( self.home + "\$" )
Jon Hall274b6642015-02-17 11:57:17 -0800511 main.log.info( self.name +
512 ": Checking out git branch/ref: " + branch + "..." )
kelvin8ec71442015-01-15 16:57:00 -0800513 cmd = "git checkout " + branch
514 self.handle.sendline( cmd )
515 self.handle.expect( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800516 i = self.handle.expect(
Jon Hall274b6642015-02-17 11:57:17 -0800517 [ 'fatal',
Jon Hall61282e32015-03-19 11:34:11 -0700518 'Username for (.*): ',
519 'Already on \'',
Jon Hall7a8354f2015-06-10 15:37:00 -0700520 'Switched to (a new )?branch \'' + str( branch ),
Jon Hall274b6642015-02-17 11:57:17 -0800521 pexpect.TIMEOUT,
522 'error: Your local changes to the following files' +
Jon Hallefbd9792015-03-05 16:11:36 -0800523 'would be overwritten by checkout:',
Jon Hall274b6642015-02-17 11:57:17 -0800524 'error: you need to resolve your current index first',
525 "You are in 'detached HEAD' state.",
526 "HEAD is now at " ],
kelvin-onlabd3b64892015-01-20 13:26:24 -0800527 timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -0800528 if i == 0:
529 main.log.error(
530 self.name +
531 ": Git checkout had some issue..." )
532 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400533 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800534 elif i == 1:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800535 main.log.error(
536 self.name +
537 ": Git checkout asking for username." +
538 " Please configure your local git repository to be able " +
539 "to access your remote repository passwordlessly" )
Jon Hall274b6642015-02-17 11:57:17 -0800540 # TODO add support for authenticating
Jon Hallacabffd2014-10-09 12:36:53 -0400541 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800542 elif i == 2:
543 main.log.info(
544 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800545 ": Git Checkout %s : Already on this branch" % branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800546 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800547 # main.log.info( "DEBUG: after checkout cmd = "+
548 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400549 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800550 elif i == 3:
551 main.log.info(
552 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800553 ": Git checkout %s - Switched to this branch" % branch )
kelvin-onlaba1484582015-02-02 15:46:20 -0800554 self.handle.expect( self.home + "\$" )
kelvin8ec71442015-01-15 16:57:00 -0800555 # main.log.info( "DEBUG: after checkout cmd = "+
556 # self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400557 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800558 elif i == 4:
559 main.log.error( self.name + ": Git Checkout- TIMEOUT" )
560 main.log.error(
Jon Hall274b6642015-02-17 11:57:17 -0800561 self.name + " Response was: " + str( self.handle.before ) )
Jon Hallacabffd2014-10-09 12:36:53 -0400562 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800563 elif i == 5:
564 self.handle.expect( "Aborting" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800565 main.log.error(
566 self.name +
567 ": Git checkout error: \n" +
Jon Hall274b6642015-02-17 11:57:17 -0800568 "Your local changes to the following files would" +
569 " be overwritten by checkout:" +
570 str( self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800571 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500572 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -0800573 elif i == 6:
Jon Hall274b6642015-02-17 11:57:17 -0800574 main.log.error(
575 self.name +
576 ": Git checkout error: \n" +
577 "You need to resolve your current index first:" +
578 str( self.handle.before ) )
kelvin-onlaba1484582015-02-02 15:46:20 -0800579 self.handle.expect( self.home + "\$" )
Jon Hall81e29af2014-11-04 20:41:23 -0500580 return main.ERROR
Jon Hall274b6642015-02-17 11:57:17 -0800581 elif i == 7:
582 main.log.info(
583 self.name +
584 ": Git checkout " + str( branch ) +
585 " - You are in 'detached HEAD' state. HEAD is now at " +
586 str( branch ) )
587 self.handle.expect( self.home + "\$" )
588 return main.TRUE
589 elif i == 8: # Already in detached HEAD on the specified commit
590 main.log.info(
591 self.name +
592 ": Git Checkout %s : Already on commit" % branch )
593 self.handle.expect( self.home + "\$" )
594 return main.TRUE
Jon Hallacabffd2014-10-09 12:36:53 -0400595 else:
kelvin8ec71442015-01-15 16:57:00 -0800596 main.log.error(
597 self.name +
Jon Hall274b6642015-02-17 11:57:17 -0800598 ": Git Checkout - Unexpected response, " +
599 "check for pull errors" )
kelvin8ec71442015-01-15 16:57:00 -0800600 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400601 return main.ERROR
602
603 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800604 main.log.error( self.name + ": EOF exception found" )
605 main.log.error( self.name + ": " + self.handle.before )
Jon Hallacabffd2014-10-09 12:36:53 -0400606 main.cleanup()
607 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800608 except Exception:
609 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hallacabffd2014-10-09 12:36:53 -0400610 main.cleanup()
611 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400612
pingping-lin6d23d9e2015-02-02 16:54:24 -0800613 def getBranchName( self ):
pingping-linf30cf272015-05-29 15:54:07 -0700614 main.log.info( "self.home = " )
615 main.log.info( self.home )
pingping-lin6d23d9e2015-02-02 16:54:24 -0800616 self.handle.sendline( "cd " + self.home )
pingping-lin9bf3d8f2015-05-29 16:05:28 -0700617 self.handle.expect( self.home + "\$" )
pingping-lin6d23d9e2015-02-02 16:54:24 -0800618 self.handle.sendline( "git name-rev --name-only HEAD" )
619 self.handle.expect( "git name-rev --name-only HEAD" )
620 self.handle.expect( "\$" )
621
622 lines = self.handle.before.splitlines()
623 if lines[1] == "master":
624 return "master"
625 elif lines[1] == "onos-1.0":
626 return "onos-1.0"
627 else:
628 main.log.info( lines[1] )
629 return "unexpected ONOS branch for SDN-IP test"
630
kelvin-onlabd3b64892015-01-20 13:26:24 -0800631 def getVersion( self, report=False ):
kelvin8ec71442015-01-15 16:57:00 -0800632 """
Jon Hall274b6642015-02-17 11:57:17 -0800633 Writes the COMMIT number to the report to be parsed
Jon Hallefbd9792015-03-05 16:11:36 -0800634 by Jenkins data collector.
kelvin8ec71442015-01-15 16:57:00 -0800635 """
Jon Hall45ec0922014-10-10 19:33:49 -0400636 try:
kelvin8ec71442015-01-15 16:57:00 -0800637 self.handle.sendline( "" )
638 self.handle.expect( "\$" )
639 self.handle.sendline(
640 "cd " +
641 self.home +
Jon Hall274b6642015-02-17 11:57:17 -0800642 "; git log -1 --pretty=fuller --decorate=short | grep -A 6 " +
643 " \"commit\" --color=never" )
kelvin8ec71442015-01-15 16:57:00 -0800644 # NOTE: for some reason there are backspaces inserted in this
645 # phrase when run from Jenkins on some tests
646 self.handle.expect( "never" )
647 self.handle.expect( "\$" )
648 response = ( self.name + ": \n" + str(
649 self.handle.before + self.handle.after ) )
650 self.handle.sendline( "cd " + self.home )
651 self.handle.expect( "\$" )
652 lines = response.splitlines()
Jon Hall45ec0922014-10-10 19:33:49 -0400653 for line in lines:
Jon Hallfd191202014-11-07 18:36:09 -0500654 print line
655 if report:
pingping-lin763ee042015-05-20 17:45:30 -0700656 main.log.wiki( "<blockquote>" )
kelvin8ec71442015-01-15 16:57:00 -0800657 for line in lines[ 2:-1 ]:
658 # Bracket replacement is for Wiki-compliant
659 # formatting. '<' or '>' are interpreted
660 # as xml specific tags that cause errors
661 line = line.replace( "<", "[" )
662 line = line.replace( ">", "]" )
pingping-lin763ee042015-05-20 17:45:30 -0700663 #main.log.wiki( "\t" + line )
664 main.log.wiki( line + "<br /> " )
665 main.log.summary( line )
666 main.log.wiki( "</blockquote>" )
667 main.log.summary("\n")
kelvin8ec71442015-01-15 16:57:00 -0800668 return lines[ 2 ]
Jon Hall45ec0922014-10-10 19:33:49 -0400669 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800670 main.log.error( self.name + ": EOF exception found" )
671 main.log.error( self.name + ": " + self.handle.before )
Jon Hall45ec0922014-10-10 19:33:49 -0400672 main.cleanup()
673 main.exit()
Jon Hall368769f2014-11-19 15:43:35 -0800674 except pexpect.TIMEOUT:
kelvin8ec71442015-01-15 16:57:00 -0800675 main.log.error( self.name + ": TIMEOUT exception found" )
676 main.log.error( self.name + ": " + self.handle.before )
Jon Hall368769f2014-11-19 15:43:35 -0800677 main.cleanup()
678 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800679 except Exception:
680 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall45ec0922014-10-10 19:33:49 -0400681 main.cleanup()
682 main.exit()
683
kelvin-onlabd3b64892015-01-20 13:26:24 -0800684 def createCellFile( self, benchIp, fileName, mnIpAddrs,
Flavio Castrocc38a542016-03-03 13:15:46 -0800685 appString, onosIpAddrs, onosUser="sdn" ):
kelvin8ec71442015-01-15 16:57:00 -0800686 """
andrewonlab94282092014-10-10 13:00:11 -0400687 Creates a cell file based on arguments
688 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800689 * Bench IP address ( benchIp )
andrewonlab94282092014-10-10 13:00:11 -0400690 - Needed to copy the cell file over
kelvin-onlabd3b64892015-01-20 13:26:24 -0800691 * File name of the cell file ( fileName )
692 * Mininet IP address ( mnIpAddrs )
kelvin8ec71442015-01-15 16:57:00 -0800693 - Note that only 1 ip address is
andrewonlab94282092014-10-10 13:00:11 -0400694 supported currently
kelvin-onlabd3b64892015-01-20 13:26:24 -0800695 * ONOS IP addresses ( onosIpAddrs )
andrewonlab94282092014-10-10 13:00:11 -0400696 - Must be passed in as last arguments
Flavio Castrocc38a542016-03-03 13:15:46 -0800697 * ONOS USER (onosUser)
698 - optional argument to set ONOS_USER environment variable
kelvin8ec71442015-01-15 16:57:00 -0800699
andrewonlab94282092014-10-10 13:00:11 -0400700 NOTE: Assumes cells are located at:
701 ~/<self.home>/tools/test/cells/
kelvin8ec71442015-01-15 16:57:00 -0800702 """
703 # Variable initialization
Jon Hall6801cda2015-07-15 14:13:45 -0700704 cellDirectory = self.home + "/tools/test/cells/"
kelvin8ec71442015-01-15 16:57:00 -0800705 # We want to create the cell file in the dependencies directory
706 # of TestON first, then copy over to ONOS bench
kelvin-onlabd3b64892015-01-20 13:26:24 -0800707 tempDirectory = "/tmp/"
kelvin8ec71442015-01-15 16:57:00 -0800708 # Create the cell file in the directory for writing ( w+ )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800709 cellFile = open( tempDirectory + fileName, 'w+' )
Jon Hall6801cda2015-07-15 14:13:45 -0700710 if isinstance( onosIpAddrs, types.StringType ):
711 onosIpAddrs = [ onosIpAddrs ]
kelvin8ec71442015-01-15 16:57:00 -0800712
cameron@onlab.us75900962015-03-30 13:22:49 -0700713 # App string is hardcoded environment variables
kelvin8ec71442015-01-15 16:57:00 -0800714 # That you may wish to use by default on startup.
cameron@onlab.us75900962015-03-30 13:22:49 -0700715 # Note that you may not want certain apps listed
kelvin8ec71442015-01-15 16:57:00 -0800716 # on here.
cameron@onlab.us75900962015-03-30 13:22:49 -0700717 appString = "export ONOS_APPS=" + appString
Flavio Castrocc38a542016-03-03 13:15:46 -0800718 onosGroup = "export ONOS_GROUP=" + onosUser
719 onosUser = "export ONOS_USER=" + onosUser
kelvin-onlabd3b64892015-01-20 13:26:24 -0800720 mnString = "export OCN="
kelvin-onlabf70fd542015-05-07 18:41:40 -0700721 if mnIpAddrs == "":
722 mnString = ""
kelvin-onlabd3b64892015-01-20 13:26:24 -0800723 onosString = "export OC"
724 tempCount = 1
kelvin8ec71442015-01-15 16:57:00 -0800725
kelvin-onlabd3b64892015-01-20 13:26:24 -0800726 # Create ONOSNIC ip address prefix
kelvin-onlaba4074292015-07-09 15:19:49 -0700727 tempOnosIp = str( onosIpAddrs[ 0 ] )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800728 tempList = []
729 tempList = tempOnosIp.split( "." )
kelvin8ec71442015-01-15 16:57:00 -0800730 # Omit last element of list to format for NIC
kelvin-onlabd3b64892015-01-20 13:26:24 -0800731 tempList = tempList[ :-1 ]
kelvin8ec71442015-01-15 16:57:00 -0800732 # Structure the nic string ip
kelvin-onlabd3b64892015-01-20 13:26:24 -0800733 nicAddr = ".".join( tempList ) + ".*"
Jon Hall6c44c0b2016-04-20 15:21:00 -0700734 self.nicAddr = nicAddr
kelvin-onlabd3b64892015-01-20 13:26:24 -0800735 onosNicString = "export ONOS_NIC=" + nicAddr
andrewonlab94282092014-10-10 13:00:11 -0400736
737 try:
kelvin8ec71442015-01-15 16:57:00 -0800738 # Start writing to file
kelvin-onlabd3b64892015-01-20 13:26:24 -0800739 cellFile.write( onosNicString + "\n" )
andrewonlab94282092014-10-10 13:00:11 -0400740
kelvin-onlabd3b64892015-01-20 13:26:24 -0800741 for arg in onosIpAddrs:
742 # For each argument in onosIpAddrs, write to file
kelvin8ec71442015-01-15 16:57:00 -0800743 # Output should look like the following:
andrewonlabd4940492014-10-24 12:21:27 -0400744 # export OC1="10.128.20.11"
745 # export OC2="10.128.20.12"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800746 cellFile.write( onosString + str( tempCount ) +
Jon Hall6f665652015-09-18 10:08:07 -0700747 "=\"" + arg + "\"\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800748 tempCount = tempCount + 1
kelvin8ec71442015-01-15 16:57:00 -0800749
Jon Hall6f665652015-09-18 10:08:07 -0700750 cellFile.write( "export OCI=$OC1\n" )
751 cellFile.write( mnString + "\"" + mnIpAddrs + "\"\n" )
cameron@onlab.us75900962015-03-30 13:22:49 -0700752 cellFile.write( appString + "\n" )
Flavio Castrocc38a542016-03-03 13:15:46 -0800753 cellFile.write( onosGroup + "\n" )
754 cellFile.write( onosUser + "\n" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800755 cellFile.close()
andrewonlab94282092014-10-10 13:00:11 -0400756
kelvin8ec71442015-01-15 16:57:00 -0800757 # We use os.system to send the command to TestON cluster
758 # to account for the case in which TestON is not located
759 # on the same cluster as the ONOS bench
760 # Note that even if TestON is located on the same cluster
761 # as ONOS bench, you must setup passwordless ssh
762 # between TestON and ONOS bench in order to automate the test.
kelvin-onlabc2b79102015-07-14 11:41:20 -0700763 os.system( "scp " + tempDirectory + fileName + " " +
764 self.user_name + "@" + self.ip_address + ":" + cellDirectory )
andrewonlab94282092014-10-10 13:00:11 -0400765
andrewonlab2a6c9342014-10-16 13:40:15 -0400766 return main.TRUE
767
andrewonlab94282092014-10-10 13:00:11 -0400768 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800769 main.log.error( self.name + ": EOF exception found" )
770 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -0400771 main.cleanup()
772 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800773 except Exception:
774 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab94282092014-10-10 13:00:11 -0400775 main.cleanup()
776 main.exit()
777
kelvin-onlabd3b64892015-01-20 13:26:24 -0800778 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800779 """
andrewonlab95ca1462014-10-09 14:04:24 -0400780 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800781 """
Hari Krishna03f530e2015-07-10 17:28:27 -0700782 import re
andrewonlab95ca1462014-10-09 14:04:24 -0400783 try:
784 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800785 main.log.error( "Must define cellname" )
andrewonlab95ca1462014-10-09 14:04:24 -0400786 main.cleanup()
787 main.exit()
788 else:
kelvin8ec71442015-01-15 16:57:00 -0800789 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800790 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800791 # Note that this variable name is subject to change
andrewonlab95ca1462014-10-09 14:04:24 -0400792 # and that this driver will have to change accordingly
Jon Hall3b489db2015-10-05 14:38:37 -0700793 self.handle.expect( str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800794 handleBefore = self.handle.before
795 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800796 # Get the rest of the handle
Jon Hall3b489db2015-10-05 14:38:37 -0700797 self.handle.expect( "\$" )
Jon Hall439c8912016-04-15 02:22:03 -0700798 time.sleep(10)
kelvin-onlabd3b64892015-01-20 13:26:24 -0800799 handleMore = self.handle.before
andrewonlab95ca1462014-10-09 14:04:24 -0400800
Hari Krishna03f530e2015-07-10 17:28:27 -0700801 cell_result = handleBefore + handleAfter + handleMore
suibin zhang116647a2016-05-06 16:30:09 -0700802 #print cell_result
Hari Krishna03f530e2015-07-10 17:28:27 -0700803 if( re.search( "No such cell", cell_result ) ):
804 main.log.error( "Cell call returned: " + handleBefore +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800805 handleAfter + handleMore )
Hari Krishna03f530e2015-07-10 17:28:27 -0700806 main.cleanup()
807 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -0400808 return main.TRUE
andrewonlab95ca1462014-10-09 14:04:24 -0400809 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800810 main.log.error( self.name + ": EOF exception found" )
811 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ca1462014-10-09 14:04:24 -0400812 main.cleanup()
813 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800814 except Exception:
815 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab95ca1462014-10-09 14:04:24 -0400816 main.cleanup()
817 main.exit()
818
kelvin-onlabd3b64892015-01-20 13:26:24 -0800819 def verifyCell( self ):
kelvin8ec71442015-01-15 16:57:00 -0800820 """
andrewonlabc03bf6c2014-10-09 14:56:18 -0400821 Calls 'onos-verify-cell' to check for cell installation
kelvin8ec71442015-01-15 16:57:00 -0800822 """
823 # TODO: Add meaningful expect value
andrewonlab8d0d7d72014-10-09 16:33:15 -0400824
andrewonlabc03bf6c2014-10-09 14:56:18 -0400825 try:
kelvin8ec71442015-01-15 16:57:00 -0800826 # Clean handle by sending empty and expecting $
827 self.handle.sendline( "" )
828 self.handle.expect( "\$" )
829 self.handle.sendline( "onos-verify-cell" )
830 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800831 handleBefore = self.handle.before
832 handleAfter = self.handle.after
kelvin-onlabd3b64892015-01-20 13:26:24 -0800833 main.log.info( "Verify cell returned: " + handleBefore +
Jon Hall3b489db2015-10-05 14:38:37 -0700834 handleAfter )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400835 return main.TRUE
Jon Halla5cb6172015-02-23 09:28:28 -0800836 except pexpect.ExceptionPexpect as e:
Jon Hall3b489db2015-10-05 14:38:37 -0700837 main.log.exception( self.name + ": Pexpect exception found: " )
kelvin8ec71442015-01-15 16:57:00 -0800838 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400839 main.cleanup()
840 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800841 except Exception:
842 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400843 main.cleanup()
844 main.exit()
845
jenkins1e99e7b2015-04-02 18:15:39 -0700846 def onosCfgSet( self, ONOSIp, configName, configParam ):
847 """
848 Uses 'onos <node-ip> cfg set' to change a parameter value of an
Jon Hall4ba53f02015-07-29 13:07:41 -0700849 application.
850
jenkins1e99e7b2015-04-02 18:15:39 -0700851 ex)
852 onos 10.0.0.1 cfg set org.onosproject.myapp appSetting 1
jenkins1e99e7b2015-04-02 18:15:39 -0700853 ONOSIp = '10.0.0.1'
854 configName = 'org.onosproject.myapp'
855 configParam = 'appSetting 1'
jenkins1e99e7b2015-04-02 18:15:39 -0700856 """
Jon Hall72280bc2016-01-25 14:29:05 -0800857 try:
858 cfgStr = "onos {} cfg set {} {}".format( ONOSIp,
859 configName,
860 configParam )
861 self.handle.sendline( "" )
862 self.handle.expect( ":~" )
863 self.handle.sendline( cfgStr )
864 self.handle.expect("cfg set")
865 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700866
Jon Hall72280bc2016-01-25 14:29:05 -0800867 paramValue = configParam.split(" ")[1]
868 paramName = configParam.split(" ")[0]
Jon Hall4ba53f02015-07-29 13:07:41 -0700869
Jon Hall72280bc2016-01-25 14:29:05 -0800870 checkStr = 'onos {} cfg get " {} {} " '.format( ONOSIp, configName, paramName )
Jon Hall4ba53f02015-07-29 13:07:41 -0700871
Jon Hall72280bc2016-01-25 14:29:05 -0800872 self.handle.sendline( checkStr )
873 self.handle.expect( ":~" )
jenkins1e99e7b2015-04-02 18:15:39 -0700874
Jon Hall72280bc2016-01-25 14:29:05 -0800875 if "value=" + paramValue + "," in self.handle.before:
876 main.log.info("cfg " + configName + " successfully set to " + configParam)
877 return main.TRUE
878 except pexpect.ExceptionPexpect as e:
879 main.log.exception( self.name + ": Pexpect exception found: " )
880 main.log.error( self.name + ": " + self.handle.before )
881 main.cleanup()
882 main.exit()
883 except Exception:
884 main.log.exception( self.name + ": Uncaught exception!" )
885 main.cleanup()
886 main.exit()
Jon Hall4ba53f02015-07-29 13:07:41 -0700887
kelvin-onlabd3b64892015-01-20 13:26:24 -0800888 def onosCli( self, ONOSIp, cmdstr ):
kelvin8ec71442015-01-15 16:57:00 -0800889 """
andrewonlab05e362f2014-10-10 00:40:57 -0400890 Uses 'onos' command to send various ONOS CLI arguments.
891 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800892 * ONOSIp: specify the ip of the cell machine
andrewonlab94282092014-10-10 13:00:11 -0400893 * cmdstr: specify the command string to send
kelvin8ec71442015-01-15 16:57:00 -0800894
895 This function is intended to expose the entire karaf
andrewonlab6e20c342014-10-10 18:08:48 -0400896 CLI commands for ONOS. Try to use this function first
897 before attempting to write a ONOS CLI specific driver
kelvin8ec71442015-01-15 16:57:00 -0800898 function.
899 You can see a list of available 'cmdstr' arguments
andrewonlab6e20c342014-10-10 18:08:48 -0400900 by starting onos, and typing in 'onos' to enter the
901 onos> CLI. Then, type 'help' to see the list of
kelvin8ec71442015-01-15 16:57:00 -0800902 available commands.
903 """
andrewonlab05e362f2014-10-10 00:40:57 -0400904 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800905 if not ONOSIp:
kelvin8ec71442015-01-15 16:57:00 -0800906 main.log.error( "You must specify the IP address" )
andrewonlab05e362f2014-10-10 00:40:57 -0400907 return main.FALSE
908 if not cmdstr:
kelvin8ec71442015-01-15 16:57:00 -0800909 main.log.error( "You must specify the command string" )
andrewonlab05e362f2014-10-10 00:40:57 -0400910 return main.FALSE
911
kelvin8ec71442015-01-15 16:57:00 -0800912 cmdstr = str( cmdstr )
913 self.handle.sendline( "" )
914 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400915
kelvin-onlabd3b64892015-01-20 13:26:24 -0800916 self.handle.sendline( "onos -w " + ONOSIp + " " + cmdstr )
kelvin8ec71442015-01-15 16:57:00 -0800917 self.handle.expect( "\$" )
andrewonlab05e362f2014-10-10 00:40:57 -0400918
kelvin-onlabd3b64892015-01-20 13:26:24 -0800919 handleBefore = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -0800920 main.log.info( "Command sent successfully" )
kelvin8ec71442015-01-15 16:57:00 -0800921 # Obtain return handle that consists of result from
922 # the onos command. The string may need to be
923 # configured further.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800924 returnString = handleBefore
kelvin-onlabd3b64892015-01-20 13:26:24 -0800925 return returnString
andrewonlab05e362f2014-10-10 00:40:57 -0400926 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800927 main.log.error( self.name + ": EOF exception found" )
928 main.log.error( self.name + ": " + self.handle.before )
andrewonlab05e362f2014-10-10 00:40:57 -0400929 main.cleanup()
930 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800931 except Exception:
932 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab05e362f2014-10-10 00:40:57 -0400933 main.cleanup()
934 main.exit()
Jon Hall7993bfc2014-10-09 16:30:14 -0400935
kelvin-onlabd3b64892015-01-20 13:26:24 -0800936 def onosInstall( self, options="-f", node="" ):
kelvin8ec71442015-01-15 16:57:00 -0800937 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400938 Installs ONOS bits on the designated cell machine.
kelvin8ec71442015-01-15 16:57:00 -0800939 If -f option is provided, it also forces an uninstall.
940 Presently, install also includes onos-push-bits and
Jon Hall7993bfc2014-10-09 16:30:14 -0400941 onos-config within.
kelvin8ec71442015-01-15 16:57:00 -0800942 The node option allows you to selectively only push the jar
Jon Hall7993bfc2014-10-09 16:30:14 -0400943 files to certain onos nodes
944
945 Returns: main.TRUE on success and main.FALSE on failure
kelvin8ec71442015-01-15 16:57:00 -0800946 """
Jon Hall7993bfc2014-10-09 16:30:14 -0400947 try:
andrewonlab114768a2014-11-14 12:44:44 -0500948 if options:
kelvin8ec71442015-01-15 16:57:00 -0800949 self.handle.sendline( "onos-install " + options + " " + node )
andrewonlab114768a2014-11-14 12:44:44 -0500950 else:
kelvin8ec71442015-01-15 16:57:00 -0800951 self.handle.sendline( "onos-install " + node )
952 self.handle.expect( "onos-install " )
953 # NOTE: this timeout may need to change depending on the network
954 # and size of ONOS
955 i = self.handle.expect( [ "Network\sis\sunreachable",
kelvin-onlabd3b64892015-01-20 13:26:24 -0800956 "onos\sstart/running,\sprocess",
kelvin8ec71442015-01-15 16:57:00 -0800957 "ONOS\sis\salready\sinstalled",
Jeremyc72b2582016-02-26 18:27:38 -0800958 "already\sup-to-date",
959 "\$",
Jon Hall6c44c0b2016-04-20 15:21:00 -0700960 pexpect.TIMEOUT ], timeout=180 )
Jon Hall7993bfc2014-10-09 16:30:14 -0400961 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -0800962 main.log.warn( "Network is unreachable" )
Jon Hall3b489db2015-10-05 14:38:37 -0700963 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400964 return main.FALSE
965 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -0800966 main.log.info(
967 "ONOS was installed on " +
968 node +
969 " and started" )
Jon Hall3b489db2015-10-05 14:38:37 -0700970 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -0400971 return main.TRUE
andrewonlabd9a73a72014-11-14 17:28:21 -0500972 elif i == 2:
kelvin8ec71442015-01-15 16:57:00 -0800973 main.log.info( "ONOS is already installed on " + node )
Jon Hall3b489db2015-10-05 14:38:37 -0700974 self.handle.expect( "\$" )
andrewonlabd9a73a72014-11-14 17:28:21 -0500975 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -0800976 elif i == 3:
Jeremyc72b2582016-02-26 18:27:38 -0800977 main.log.info( "ONOS is already installed on " + node )
978 self.handle.expect( "\$" )
979 return main.TRUE
980 elif i == 4:
981 main.log.info( "ONOS was installed on " + node )
982 return main.TRUE
983 elif i == 5:
kelvin8ec71442015-01-15 16:57:00 -0800984 main.log.info(
985 "Installation of ONOS on " +
986 node +
987 " timed out" )
Jon Hall3b489db2015-10-05 14:38:37 -0700988 self.handle.expect( "\$" )
Jon Hall53c5e662016-04-13 16:06:56 -0700989 main.log.warn( self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -0400990 return main.FALSE
andrewonlabc03bf6c2014-10-09 14:56:18 -0400991 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800992 main.log.error( self.name + ": EOF exception found" )
993 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400994 main.cleanup()
995 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800996 except Exception:
997 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc03bf6c2014-10-09 14:56:18 -0400998 main.cleanup()
999 main.exit()
andrewonlab95ca1462014-10-09 14:04:24 -04001000
kelvin-onlabd3b64892015-01-20 13:26:24 -08001001 def onosStart( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001002 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001003 Calls onos command: 'onos-service [<node-ip>] start'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001004 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001005 """
andrewonlab8d0d7d72014-10-09 16:33:15 -04001006 try:
kelvin8ec71442015-01-15 16:57:00 -08001007 self.handle.sendline( "" )
1008 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001009 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001010 " start" )
1011 i = self.handle.expect( [
andrewonlab8d0d7d72014-10-09 16:33:15 -04001012 "Job\sis\salready\srunning",
1013 "start/running",
Jeremyd0e9a6d2016-03-02 11:28:52 -08001014 "\$",
andrewonlab8d0d7d72014-10-09 16:33:15 -04001015 "Unknown\sinstance",
Jeremy Songster14c13572016-04-21 17:34:03 -07001016 pexpect.TIMEOUT ], timeout=180 )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001017 if i == 0:
Jon Halleab7a242016-03-04 10:20:43 -08001018 self.handle.expect( "\$" )
kelvin8ec71442015-01-15 16:57:00 -08001019 main.log.info( "Service is already running" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001020 return main.TRUE
1021 elif i == 1:
Jon Halleab7a242016-03-04 10:20:43 -08001022 self.handle.expect( "\$" )
kelvin8ec71442015-01-15 16:57:00 -08001023 main.log.info( "ONOS service started" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001024 return main.TRUE
Jeremyd0e9a6d2016-03-02 11:28:52 -08001025 elif i == 2:
1026 main.log.info( "ONOS service started" )
1027 return main.TRUE
andrewonlab8d0d7d72014-10-09 16:33:15 -04001028 else:
Jon Halleab7a242016-03-04 10:20:43 -08001029 self.handle.expect( "\$" )
kelvin8ec71442015-01-15 16:57:00 -08001030 main.log.error( "ONOS service failed to start" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001031 main.cleanup()
1032 main.exit()
andrewonlab8d0d7d72014-10-09 16:33:15 -04001033 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001034 main.log.error( self.name + ": EOF exception found" )
1035 main.log.error( self.name + ": " + self.handle.before )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001036 main.cleanup()
1037 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001038 except Exception:
1039 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab8d0d7d72014-10-09 16:33:15 -04001040 main.cleanup()
1041 main.exit()
1042
kelvin-onlabd3b64892015-01-20 13:26:24 -08001043 def onosStop( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001044 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001045 Calls onos command: 'onos-service [<node-ip>] stop'
andrewonlabe8e56fd2014-10-09 17:12:44 -04001046 This command is a remote management of the ONOS upstart daemon
kelvin8ec71442015-01-15 16:57:00 -08001047 """
andrewonlab2b30bd32014-10-09 16:48:55 -04001048 try:
kelvin8ec71442015-01-15 16:57:00 -08001049 self.handle.sendline( "" )
1050 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001051 self.handle.sendline( "onos-service " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001052 " stop" )
1053 i = self.handle.expect( [
andrewonlab2b30bd32014-10-09 16:48:55 -04001054 "stop/waiting",
Jon Hall61282e32015-03-19 11:34:11 -07001055 "Could not resolve hostname",
andrewonlab2b30bd32014-10-09 16:48:55 -04001056 "Unknown\sinstance",
YPZhang77badfc2016-03-09 10:28:59 -08001057 "\$",
Jeremy Songster14c13572016-04-21 17:34:03 -07001058 pexpect.TIMEOUT ], timeout=180 )
andrewonlab2b30bd32014-10-09 16:48:55 -04001059 if i == 0:
YPZhang77badfc2016-03-09 10:28:59 -08001060 self.handle.expect( "\$" )
kelvin8ec71442015-01-15 16:57:00 -08001061 main.log.info( "ONOS service stopped" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001062 return main.TRUE
1063 elif i == 1:
YPZhang77badfc2016-03-09 10:28:59 -08001064 self.handle.expect( "\$" )
Jon Hall65844a32015-03-09 19:09:37 -07001065 main.log.info( "onosStop() Unknown ONOS instance specified: " +
kelvin-onlabd3b64892015-01-20 13:26:24 -08001066 str( nodeIp ) )
andrewonlab2b30bd32014-10-09 16:48:55 -04001067 return main.FALSE
Jon Hall61282e32015-03-19 11:34:11 -07001068 elif i == 2:
YPZhang77badfc2016-03-09 10:28:59 -08001069 self.handle.expect( "\$" )
Jon Hall61282e32015-03-19 11:34:11 -07001070 main.log.warn( "ONOS wasn't running" )
1071 return main.TRUE
YPZhang77badfc2016-03-09 10:28:59 -08001072 elif i == 3:
1073 main.log.info( "ONOS service stopped" )
1074 return main.TRUE
andrewonlab2b30bd32014-10-09 16:48:55 -04001075 else:
kelvin8ec71442015-01-15 16:57:00 -08001076 main.log.error( "ONOS service failed to stop" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001077 return main.FALSE
andrewonlab2b30bd32014-10-09 16:48:55 -04001078 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001079 main.log.error( self.name + ": EOF exception found" )
1080 main.log.error( self.name + ": " + self.handle.before )
andrewonlab2b30bd32014-10-09 16:48:55 -04001081 main.cleanup()
1082 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001083 except Exception:
1084 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab2b30bd32014-10-09 16:48:55 -04001085 main.cleanup()
1086 main.exit()
kelvin8ec71442015-01-15 16:57:00 -08001087
kelvin-onlabd3b64892015-01-20 13:26:24 -08001088 def onosUninstall( self, nodeIp="" ):
kelvin8ec71442015-01-15 16:57:00 -08001089 """
andrewonlabc8d47972014-10-09 16:52:36 -04001090 Calls the command: 'onos-uninstall'
kelvin8ec71442015-01-15 16:57:00 -08001091 Uninstalls ONOS from the designated cell machine, stopping
andrewonlabe8e56fd2014-10-09 17:12:44 -04001092 if needed
kelvin8ec71442015-01-15 16:57:00 -08001093 """
andrewonlabc8d47972014-10-09 16:52:36 -04001094 try:
kelvin8ec71442015-01-15 16:57:00 -08001095 self.handle.sendline( "" )
Jeremy Songster14c13572016-04-21 17:34:03 -07001096 self.handle.expect( "\$", timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001097 self.handle.sendline( "onos-uninstall " + str( nodeIp ) )
Jeremy Songster14c13572016-04-21 17:34:03 -07001098 self.handle.expect( "\$", timeout=180 )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001099 main.log.info( "ONOS " + nodeIp + " was uninstalled" )
kelvin8ec71442015-01-15 16:57:00 -08001100 # onos-uninstall command does not return any text
andrewonlabc8d47972014-10-09 16:52:36 -04001101 return main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -07001102 except pexpect.TIMEOUT:
1103 main.log.exception( self.name + ": Timeout in onosUninstall" )
1104 return main.FALSE
andrewonlabc8d47972014-10-09 16:52:36 -04001105 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001106 main.log.error( self.name + ": EOF exception found" )
1107 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc8d47972014-10-09 16:52:36 -04001108 main.cleanup()
1109 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001110 except Exception:
1111 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc8d47972014-10-09 16:52:36 -04001112 main.cleanup()
1113 main.exit()
andrewonlab2b30bd32014-10-09 16:48:55 -04001114
kelvin-onlabd3b64892015-01-20 13:26:24 -08001115 def onosDie( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001116 """
andrewonlabaedc8332014-12-04 12:43:03 -05001117 Issues the command 'onos-die <node-ip>'
1118 This command calls onos-kill and also stops the node
kelvin8ec71442015-01-15 16:57:00 -08001119 """
andrewonlabaedc8332014-12-04 12:43:03 -05001120 try:
kelvin8ec71442015-01-15 16:57:00 -08001121 self.handle.sendline( "" )
1122 self.handle.expect( "\$" )
Jeremyf0aecdb2016-03-30 13:19:57 -07001123 cmdStr = "onos-die " + str( nodeIp )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001124 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001125 i = self.handle.expect( [
andrewonlabaedc8332014-12-04 12:43:03 -05001126 "Killing\sONOS",
1127 "ONOS\sprocess\sis\snot\srunning",
Jeremy Songster14c13572016-04-21 17:34:03 -07001128 pexpect.TIMEOUT ], timeout=60 )
andrewonlabaedc8332014-12-04 12:43:03 -05001129 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001130 main.log.info( "ONOS instance " + str( nodeIp ) +
kelvin8ec71442015-01-15 16:57:00 -08001131 " was killed and stopped" )
Jon Hall53c5e662016-04-13 16:06:56 -07001132 self.handle.sendline( "" )
1133 self.handle.expect( "\$" )
andrewonlabaedc8332014-12-04 12:43:03 -05001134 return main.TRUE
1135 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001136 main.log.info( "ONOS process was not running" )
Jon Hall53c5e662016-04-13 16:06:56 -07001137 self.handle.sendline( "" )
1138 self.handle.expect( "\$" )
andrewonlabaedc8332014-12-04 12:43:03 -05001139 return main.FALSE
1140 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001141 main.log.error( self.name + ": EOF exception found" )
1142 main.log.error( self.name + ": " + self.handle.before )
andrewonlabaedc8332014-12-04 12:43:03 -05001143 main.cleanup()
1144 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001145 except Exception:
1146 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabaedc8332014-12-04 12:43:03 -05001147 main.cleanup()
1148 main.exit()
1149
kelvin-onlabd3b64892015-01-20 13:26:24 -08001150 def onosKill( self, nodeIp ):
kelvin8ec71442015-01-15 16:57:00 -08001151 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001152 Calls the command: 'onos-kill [<node-ip>]'
1153 "Remotely, and unceremoniously kills the ONOS instance running on
1154 the specified cell machine" - Tom V
kelvin8ec71442015-01-15 16:57:00 -08001155 """
andrewonlabe8e56fd2014-10-09 17:12:44 -04001156 try:
kelvin8ec71442015-01-15 16:57:00 -08001157 self.handle.sendline( "" )
1158 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001159 self.handle.sendline( "onos-kill " + str( nodeIp ) )
kelvin8ec71442015-01-15 16:57:00 -08001160 i = self.handle.expect( [
andrewonlabe8e56fd2014-10-09 17:12:44 -04001161 "\$",
1162 "No\sroute\sto\shost",
1163 "password:",
Jeremy Songster14c13572016-04-21 17:34:03 -07001164 pexpect.TIMEOUT ], timeout=60 )
kelvin8ec71442015-01-15 16:57:00 -08001165
andrewonlabe8e56fd2014-10-09 17:12:44 -04001166 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001167 main.log.info(
1168 "ONOS instance " + str(
kelvin-onlabd3b64892015-01-20 13:26:24 -08001169 nodeIp ) + " was killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001170 return main.TRUE
1171 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001172 main.log.info( "No route to host" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001173 return main.FALSE
1174 elif i == 2:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001175 main.log.info(
1176 "Passwordless login for host: " +
1177 str( nodeIp ) +
1178 " not configured" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001179 return main.FALSE
1180 else:
Jon Hallefbd9792015-03-05 16:11:36 -08001181 main.log.info( "ONOS instance was not killed" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001182 return main.FALSE
kelvin8ec71442015-01-15 16:57:00 -08001183
andrewonlabe8e56fd2014-10-09 17:12:44 -04001184 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001185 main.log.error( self.name + ": EOF exception found" )
1186 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001187 main.cleanup()
1188 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001189 except Exception:
1190 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabe8e56fd2014-10-09 17:12:44 -04001191 main.cleanup()
1192 main.exit()
1193
kelvin-onlabd3b64892015-01-20 13:26:24 -08001194 def onosRemoveRaftLogs( self ):
kelvin8ec71442015-01-15 16:57:00 -08001195 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001196 Removes Raft / Copy cat files from ONOS to ensure
Jon Hallfcc88622014-11-25 13:09:54 -05001197 a cleaner environment.
1198
andrewonlab19fbdca2014-11-14 12:55:59 -05001199 Description:
Jon Hallfcc88622014-11-25 13:09:54 -05001200 Stops all ONOS defined in the cell,
andrewonlab19fbdca2014-11-14 12:55:59 -05001201 wipes the raft / copycat log files
kelvin8ec71442015-01-15 16:57:00 -08001202 """
andrewonlab19fbdca2014-11-14 12:55:59 -05001203 try:
kelvin8ec71442015-01-15 16:57:00 -08001204 self.handle.sendline( "" )
1205 self.handle.expect( "\$" )
1206 self.handle.sendline( "onos-remove-raft-logs" )
1207 # Sometimes this command hangs
1208 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
1209 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001210 if i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001211 i = self.handle.expect( [ "\$", pexpect.TIMEOUT ],
1212 timeout=120 )
Jon Hallfcc88622014-11-25 13:09:54 -05001213 if i == 1:
1214 return main.FALSE
andrewonlab19fbdca2014-11-14 12:55:59 -05001215 return main.TRUE
andrewonlab19fbdca2014-11-14 12:55:59 -05001216 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001217 main.log.error( self.name + ": EOF exception found" )
1218 main.log.error( self.name + ": " + self.handle.before )
andrewonlab19fbdca2014-11-14 12:55:59 -05001219 main.cleanup()
1220 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001221 except Exception:
1222 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab19fbdca2014-11-14 12:55:59 -05001223 main.cleanup()
1224 main.exit()
Jon Hallfcc88622014-11-25 13:09:54 -05001225
kelvin-onlabd3b64892015-01-20 13:26:24 -08001226 def onosStartNetwork( self, mntopo ):
kelvin8ec71442015-01-15 16:57:00 -08001227 """
1228 Calls the command 'onos-start-network [ <mininet-topo> ]
1229 "remotely starts the specified topology on the cell's
andrewonlab94282092014-10-10 13:00:11 -04001230 mininet machine against all controllers configured in the
kelvin8ec71442015-01-15 16:57:00 -08001231 cell."
andrewonlab94282092014-10-10 13:00:11 -04001232 * Specify mininet topology file name for mntopo
1233 * Topo files should be placed at:
1234 ~/<your-onos-directory>/tools/test/topos
kelvin8ec71442015-01-15 16:57:00 -08001235
andrewonlab94282092014-10-10 13:00:11 -04001236 NOTE: This function will take you to the mininet prompt
kelvin8ec71442015-01-15 16:57:00 -08001237 """
andrewonlab94282092014-10-10 13:00:11 -04001238 try:
1239 if not mntopo:
kelvin8ec71442015-01-15 16:57:00 -08001240 main.log.error( "You must specify a topo file to execute" )
andrewonlab94282092014-10-10 13:00:11 -04001241 return main.FALSE
andrewonlab94282092014-10-10 13:00:11 -04001242
kelvin8ec71442015-01-15 16:57:00 -08001243 mntopo = str( mntopo )
1244 self.handle.sendline( "" )
1245 self.handle.expect( "\$" )
andrewonlab94282092014-10-10 13:00:11 -04001246
kelvin8ec71442015-01-15 16:57:00 -08001247 self.handle.sendline( "onos-start-network " + mntopo )
1248 self.handle.expect( "mininet>" )
1249 main.log.info( "Network started, entered mininet prompt" )
1250
1251 # TODO: Think about whether return is necessary or not
andrewonlab94282092014-10-10 13:00:11 -04001252
1253 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001254 main.log.error( self.name + ": EOF exception found" )
1255 main.log.error( self.name + ": " + self.handle.before )
andrewonlab94282092014-10-10 13:00:11 -04001256 main.cleanup()
1257 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001258 except Exception:
1259 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab94282092014-10-10 13:00:11 -04001260 main.cleanup()
1261 main.exit()
1262
Jeremy Songster14c13572016-04-21 17:34:03 -07001263 def isup( self, node="", timeout=240 ):
kelvin8ec71442015-01-15 16:57:00 -08001264 """
1265 Run's onos-wait-for-start which only returns once ONOS is at run
Cameron Franke9c94fb02015-01-21 10:20:20 -08001266 level 100(ready for use)
andrewonlab8d0d7d72014-10-09 16:33:15 -04001267
Jon Hall7993bfc2014-10-09 16:30:14 -04001268 Returns: main.TRUE if ONOS is running and main.FALSE on timeout
kelvin8ec71442015-01-15 16:57:00 -08001269 """
Jon Hall7993bfc2014-10-09 16:30:14 -04001270 try:
Jon Hall3b489db2015-10-05 14:38:37 -07001271 self.handle.sendline( "onos-wait-for-start " + node )
1272 self.handle.expect( "onos-wait-for-start" )
kelvin8ec71442015-01-15 16:57:00 -08001273 # NOTE: this timeout is arbitrary"
Cameron Franke9c94fb02015-01-21 10:20:20 -08001274 i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout)
Jon Hall7993bfc2014-10-09 16:30:14 -04001275 if i == 0:
kelvin8ec71442015-01-15 16:57:00 -08001276 main.log.info( self.name + ": " + node + " is up" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001277 return main.TRUE
1278 elif i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001279 # NOTE: since this function won't return until ONOS is ready,
Jon Hall7993bfc2014-10-09 16:30:14 -04001280 # we will kill it on timeout
kelvin8ec71442015-01-15 16:57:00 -08001281 main.log.error( "ONOS has not started yet" )
1282 self.handle.send( "\x03" ) # Control-C
1283 self.handle.expect( "\$" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001284 return main.FALSE
1285 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001286 main.log.error( self.name + ": EOF exception found" )
1287 main.log.error( self.name + ": " + self.handle.before )
Jon Hall7993bfc2014-10-09 16:30:14 -04001288 main.cleanup()
1289 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001290 except Exception:
1291 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall7993bfc2014-10-09 16:30:14 -04001292 main.cleanup()
1293 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001294
kelvin-onlabd3b64892015-01-20 13:26:24 -08001295 def pushTestIntentsShell(
1296 self,
1297 dpidSrc,
1298 dpidDst,
1299 numIntents,
1300 dirFile,
1301 onosIp,
1302 numMult="",
1303 appId="",
1304 report=True,
1305 options="" ):
kelvin8ec71442015-01-15 16:57:00 -08001306 """
andrewonlabb66dfa12014-12-02 15:51:10 -05001307 Description:
kelvin8ec71442015-01-15 16:57:00 -08001308 Use the linux prompt to push test intents to
andrewonlabb66dfa12014-12-02 15:51:10 -05001309 better parallelize the results than the CLI
1310 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001311 * dpidSrc: specify source dpid
1312 * dpidDst: specify destination dpid
1313 * numIntents: specify number of intents to push
1314 * dirFile: specify directory and file name to save
andrewonlabb66dfa12014-12-02 15:51:10 -05001315 results
kelvin-onlabd3b64892015-01-20 13:26:24 -08001316 * onosIp: specify the IP of ONOS to install on
kelvin8ec71442015-01-15 16:57:00 -08001317 NOTE:
andrewonlabb66dfa12014-12-02 15:51:10 -05001318 You must invoke this command at linux shell prompt
kelvin8ec71442015-01-15 16:57:00 -08001319 """
1320 try:
1321 # Create the string to sendline
andrewonlabaedc8332014-12-04 12:43:03 -05001322 if options:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001323 baseCmd = "onos " + str( onosIp ) + " push-test-intents " +\
kelvin8ec71442015-01-15 16:57:00 -08001324 options + " "
andrewonlabaedc8332014-12-04 12:43:03 -05001325 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001326 baseCmd = "onos " + str( onosIp ) + " push-test-intents "
kelvin8ec71442015-01-15 16:57:00 -08001327
kelvin-onlabd3b64892015-01-20 13:26:24 -08001328 addDpid = baseCmd + str( dpidSrc ) + " " + str( dpidDst )
1329 if not numMult:
1330 addIntents = addDpid + " " + str( numIntents )
1331 elif numMult:
1332 addIntents = addDpid + " " + str( numIntents ) + " " +\
1333 str( numMult )
1334 if appId:
1335 addApp = addIntents + " " + str( appId )
andrewonlabb66dfa12014-12-02 15:51:10 -05001336 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001337 addApp = addIntents
andrewonlabb66dfa12014-12-02 15:51:10 -05001338
andrewonlabaedc8332014-12-04 12:43:03 -05001339 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001340 sendCmd = addApp + " > " + str( dirFile ) + " &"
andrewonlabaedc8332014-12-04 12:43:03 -05001341 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001342 sendCmd = addApp + " &"
1343 main.log.info( "Send cmd: " + sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001344
kelvin-onlabd3b64892015-01-20 13:26:24 -08001345 self.handle.sendline( sendCmd )
andrewonlabb66dfa12014-12-02 15:51:10 -05001346
1347 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001348 main.log.error( self.name + ": EOF exception found" )
1349 main.log.error( self.name + ": " + self.handle.before )
andrewonlabb66dfa12014-12-02 15:51:10 -05001350 main.cleanup()
1351 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001352 except Exception:
1353 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabb66dfa12014-12-02 15:51:10 -05001354 main.cleanup()
kelvin8ec71442015-01-15 16:57:00 -08001355 main.exit()
andrewonlab05e362f2014-10-10 00:40:57 -04001356
kelvin-onlabd3b64892015-01-20 13:26:24 -08001357 def tsharkPcap( self, interface, dirFile ):
kelvin8ec71442015-01-15 16:57:00 -08001358 """
andrewonlab970399c2014-11-07 13:09:32 -05001359 Capture all packet activity and store in specified
1360 directory/file
1361
1362 Required:
1363 * interface: interface to capture
1364 * dir: directory/filename to store pcap
kelvin8ec71442015-01-15 16:57:00 -08001365 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001366 try:
1367 self.handle.sendline( "" )
1368 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001369
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001370 self.handle.sendline( "tshark -i " + str( interface ) + " -t e -w " + str( dirFile ) + " &" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001371 self.handle.sendline( "\n" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001372 self.handle.expect( "Capturing on" )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001373 self.handle.sendline( "\n" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001374 self.handle.expect( "\$" )
andrewonlab970399c2014-11-07 13:09:32 -05001375
Jon Hallfebb1c72015-03-05 13:30:09 -08001376 main.log.info( "Tshark started capturing files on " +
1377 str( interface ) + " and saving to directory: " +
1378 str( dirFile ) )
1379 except pexpect.EOF:
1380 main.log.error( self.name + ": EOF exception found" )
1381 main.log.error( self.name + ": " + self.handle.before )
1382 main.cleanup()
1383 main.exit()
1384 except Exception:
1385 main.log.exception( self.name + ": Uncaught exception!" )
1386 main.cleanup()
1387 main.exit()
Shreya Shaha73aaad2014-10-27 18:03:09 -04001388
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001389 def onosTopoCfg( self, onosIp, jsonFile ):
kelvin8ec71442015-01-15 16:57:00 -08001390 """
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001391 Description:
1392 Execute onos-topo-cfg command
1393 Required:
1394 onosIp - IP of the onos node you want to send the json to
1395 jsonFile - File path of the json file
1396 Return:
1397 Returns main.TRUE if the command is successfull; Returns
1398 main.FALSE if there was an error
kelvin8ec71442015-01-15 16:57:00 -08001399 """
shahshreyae6c7cf42014-11-26 16:39:01 -08001400 try:
kelvin8ec71442015-01-15 16:57:00 -08001401 self.handle.sendline( "" )
1402 self.handle.expect( "\$" )
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001403 cmd = "onos-topo-cfg "
1404 self.handle.sendline( cmd + str( onosIp ) + " " + jsonFile )
1405 handle = self.handle.before
1406 print handle
1407 if "Error" in handle:
1408 main.log.error( self.name + ": " + self.handle.before )
1409 return main.FALSE
1410 else:
1411 self.handle.expect( "\$" )
1412 return main.TRUE
1413
Jon Hallfebb1c72015-03-05 13:30:09 -08001414 except pexpect.EOF:
1415 main.log.error( self.name + ": EOF exception found" )
1416 main.log.error( self.name + ": " + self.handle.before )
1417 main.cleanup()
1418 main.exit()
1419 except Exception:
1420 main.log.exception( self.name + ": Uncaught exception!" )
1421 main.cleanup()
1422 main.exit()
kelvin8ec71442015-01-15 16:57:00 -08001423
jenkins1e99e7b2015-04-02 18:15:39 -07001424 def tsharkGrep( self, grep, directory, interface='eth0', grepOptions='' ):
kelvin8ec71442015-01-15 16:57:00 -08001425 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001426 Required:
kelvin8ec71442015-01-15 16:57:00 -08001427 * grep string
andrewonlabba44bcf2014-10-16 16:54:41 -04001428 * directory to store results
1429 Optional:
1430 * interface - default: eth0
Jon Hall4ba53f02015-07-29 13:07:41 -07001431 * grepOptions - options for grep
andrewonlabba44bcf2014-10-16 16:54:41 -04001432 Description:
1433 Uses tshark command to grep specific group of packets
1434 and stores the results to specified directory.
kelvin8ec71442015-01-15 16:57:00 -08001435 The timestamp is hardcoded to be in epoch
1436 """
Jon Hallfebb1c72015-03-05 13:30:09 -08001437 try:
1438 self.handle.sendline( "" )
1439 self.handle.expect( "\$" )
1440 self.handle.sendline( "" )
jenkins1e99e7b2015-04-02 18:15:39 -07001441 if grepOptions:
1442 grepStr = "grep "+str(grepOptions)
1443 else:
1444 grepStr = "grep"
Jon Hall4ba53f02015-07-29 13:07:41 -07001445
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001446 cmd = (
1447 "sudo tshark -i " +
Jon Hallfebb1c72015-03-05 13:30:09 -08001448 str( interface ) +
jenkins1e99e7b2015-04-02 18:15:39 -07001449 " -t e | " +
1450 grepStr + " --line-buffered \"" +
Jon Hallfebb1c72015-03-05 13:30:09 -08001451 str(grep) +
1452 "\" >" +
1453 directory +
1454 " &" )
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001455 self.handle.sendline(cmd)
1456 main.log.info(cmd)
Jon Hallfebb1c72015-03-05 13:30:09 -08001457 self.handle.expect( "Capturing on" )
cameron@onlab.us21106ea2015-07-23 15:32:51 -07001458 self.handle.sendline( "\n" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001459 self.handle.expect( "\$" )
1460 except pexpect.EOF:
1461 main.log.error( self.name + ": EOF exception found" )
1462 main.log.error( self.name + ": " + self.handle.before )
1463 main.cleanup()
1464 main.exit()
1465 except Exception:
1466 main.log.exception( self.name + ": Uncaught exception!" )
1467 main.cleanup()
1468 main.exit()
1469
kelvin-onlabd3b64892015-01-20 13:26:24 -08001470 def tsharkStop( self ):
kelvin8ec71442015-01-15 16:57:00 -08001471 """
andrewonlabba44bcf2014-10-16 16:54:41 -04001472 Removes wireshark files from /tmp and kills all tshark processes
kelvin8ec71442015-01-15 16:57:00 -08001473 """
1474 # Remove all pcap from previous captures
Jon Hallfebb1c72015-03-05 13:30:09 -08001475 try:
1476 self.execute( cmd="sudo rm /tmp/wireshark*" )
1477 self.handle.sendline( "" )
Jon Hallefbd9792015-03-05 16:11:36 -08001478 self.handle.sendline( "sudo kill -9 `ps -ef | grep \"tshark -i\"" +
1479 " | grep -v grep | awk '{print $2}'`" )
Jon Hallfebb1c72015-03-05 13:30:09 -08001480 self.handle.sendline( "" )
1481 main.log.info( "Tshark stopped" )
1482 except pexpect.EOF:
1483 main.log.error( self.name + ": EOF exception found" )
1484 main.log.error( self.name + ": " + self.handle.before )
1485 main.cleanup()
1486 main.exit()
1487 except Exception:
1488 main.log.exception( self.name + ": Uncaught exception!" )
1489 main.cleanup()
1490 main.exit()
1491
kelvin8ec71442015-01-15 16:57:00 -08001492 def ptpd( self, args ):
1493 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001494 Initiate ptp with user-specified args.
1495 Required:
1496 * args: specify string of args after command
1497 'sudo ptpd'
kelvin8ec71442015-01-15 16:57:00 -08001498 """
andrewonlab0c38a4a2014-10-28 18:35:35 -04001499 try:
kelvin8ec71442015-01-15 16:57:00 -08001500 self.handle.sendline( "sudo ptpd " + str( args ) )
1501 i = self.handle.expect( [
andrewonlab0c38a4a2014-10-28 18:35:35 -04001502 "Multiple",
1503 "Error",
kelvin8ec71442015-01-15 16:57:00 -08001504 "\$" ] )
1505 self.handle.expect( "\$" )
andrewonlabba44bcf2014-10-16 16:54:41 -04001506
andrewonlab0c38a4a2014-10-28 18:35:35 -04001507 if i == 0:
1508 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001509 main.log.info( "ptpd returned an error: " +
1510 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001511 return handle
1512 elif i == 1:
1513 handle = self.handle.before
kelvin8ec71442015-01-15 16:57:00 -08001514 main.log.error( "ptpd returned an error: " +
1515 str( handle ) )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001516 return handle
1517 else:
1518 return main.TRUE
kelvin8ec71442015-01-15 16:57:00 -08001519
andrewonlab0c38a4a2014-10-28 18:35:35 -04001520 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001521 main.log.error( self.name + ": EOF exception found" )
1522 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001523 main.cleanup()
1524 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001525 except Exception:
1526 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab0c38a4a2014-10-28 18:35:35 -04001527 main.cleanup()
1528 main.exit()
andrewonlabba44bcf2014-10-16 16:54:41 -04001529
Flavio Castrod2ffffa2016-04-26 15:56:56 -07001530 def dumpFlows(self,ONOSIp, destDir, filename="flows" ):
1531 """
1532 Dump Flow Tables to a desired directory.
1533 For debugging purposes, you may want to use
1534 this function to capture flows at a given point in time.
1535 Localtime will be attached to the filename
1536
1537 Required:
1538 * ONOSIp: the IP of the target ONOS instance
1539 * destDir: specify directory to copy to.
1540 ex ) /tmp/
1541 Optional:
1542 * fileName: Name of the file
1543 """
1544
1545 localtime = time.strftime( '%x %X' )
1546 localtime = localtime.replace( "/", "" )
1547 localtime = localtime.replace( " ", "_" )
1548 localtime = localtime.replace( ":", "" )
1549 if destDir[ -1: ] != "/":
1550 destDir += "/"
1551 cmd="flows > "+ str( destDir ) + str( filename ) + localtime
1552 return self.onosCli(ONOSIp,cmd)
1553
Flavio Castrob7718952016-05-18 08:53:41 -07001554 def dumpGroups(self,ONOSIp, destDir, filename="groups" ):
1555 """
1556 Dump Group Tables to a desired directory.
1557 For debugging purposes, you may want to use
1558 this function to capture groups at a given point in time.
1559 Localtime will be attached to the filename
1560
1561 Required:
1562 * ONOSIp: the IP of the target ONOS instance
1563 * destDir: specify directory to copy to.
1564 ex ) /tmp/
1565 Optional:
1566 * fileName: Name of the file
1567 """
1568
Flavio Castro09ab59d2016-05-25 17:01:35 -07001569 localtime = time.strftime( '%H %M' )
Flavio Castrob7718952016-05-18 08:53:41 -07001570 localtime = localtime.replace( "/", "" )
1571 localtime = localtime.replace( " ", "_" )
1572 localtime = localtime.replace( ":", "" )
1573 if destDir[ -1: ] != "/":
1574 destDir += "/"
1575 cmd="groups > "+ str( destDir ) + str( filename ) + localtime
1576 return self.onosCli(ONOSIp,cmd)
1577
kelvin-onlabd3b64892015-01-20 13:26:24 -08001578 def cpLogsToDir( self, logToCopy,
Jon Hallefbd9792015-03-05 16:11:36 -08001579 destDir, copyFileName="" ):
kelvin8ec71442015-01-15 16:57:00 -08001580 """
1581 Copies logs to a desired directory.
andrewonlab5d7a8f32014-11-10 13:07:56 -05001582 Current implementation of ONOS deletes its karaf
1583 logs on every iteration. For debugging purposes,
kelvin8ec71442015-01-15 16:57:00 -08001584 you may want to use this function to capture
1585 certain karaf logs. ( or any other logs if needed )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001586 Localtime will be attached to the filename
1587
1588 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001589 * logToCopy: specify directory and log name to
andrewonlab5d7a8f32014-11-10 13:07:56 -05001590 copy.
kelvin8ec71442015-01-15 16:57:00 -08001591 ex ) /opt/onos/log/karaf.log.1
kelvin-onlabd3b64892015-01-20 13:26:24 -08001592 For copying multiple files, leave copyFileName
1593 empty and only specify destDir -
kelvin8ec71442015-01-15 16:57:00 -08001594 ex ) /opt/onos/log/karaf*
kelvin-onlabd3b64892015-01-20 13:26:24 -08001595 * destDir: specify directory to copy to.
kelvin8ec71442015-01-15 16:57:00 -08001596 ex ) /tmp/
1597 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001598 * copyFileName: If you want to rename the log
1599 file, specify copyFileName. This will not work
andrewonlab5d7a8f32014-11-10 13:07:56 -05001600 with multiple file copying
kelvin8ec71442015-01-15 16:57:00 -08001601 """
andrewonlab5d7a8f32014-11-10 13:07:56 -05001602 try:
Flavio Castro09ab59d2016-05-25 17:01:35 -07001603 localtime = time.strftime( '%H %M' )
kelvin8ec71442015-01-15 16:57:00 -08001604 localtime = localtime.replace( "/", "" )
1605 localtime = localtime.replace( " ", "_" )
1606 localtime = localtime.replace( ":", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001607 if destDir[ -1: ] != "/":
1608 destDir += "/"
andrewonlab5d7a8f32014-11-10 13:07:56 -05001609
kelvin-onlabd3b64892015-01-20 13:26:24 -08001610 if copyFileName:
Jon Hallfebb1c72015-03-05 13:30:09 -08001611 self.handle.sendline( "cp " + str( logToCopy ) + " " +
1612 str( destDir ) + str( copyFileName ) +
1613 localtime )
kelvin8ec71442015-01-15 16:57:00 -08001614 self.handle.expect( "cp" )
1615 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001616 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001617 self.handle.sendline( "cp " + str( logToCopy ) +
1618 " " + str( destDir ) )
kelvin8ec71442015-01-15 16:57:00 -08001619 self.handle.expect( "cp" )
1620 self.handle.expect( "\$" )
andrewonlab5d7a8f32014-11-10 13:07:56 -05001621
kelvin8ec71442015-01-15 16:57:00 -08001622 return self.handle.before
1623
1624 except pexpect.EOF:
1625 main.log.error( "Copying files failed" )
1626 main.log.error( self.name + ": EOF exception found" )
1627 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001628 except Exception:
1629 main.log.exception( "Copying files failed" )
1630
Jon Hall16b72c42015-05-20 10:23:36 -07001631 def checkLogs( self, onosIp, restart=False):
kelvin8ec71442015-01-15 16:57:00 -08001632 """
Jon Hall94fd0472014-12-08 11:52:42 -08001633 runs onos-check-logs on the given onos node
Jon Hall80daded2015-05-27 16:07:00 -07001634 If restart is True, use the old version of onos-check-logs which
1635 does not print the full stacktrace, but shows the entire log file,
1636 including across restarts
Jon Hall94fd0472014-12-08 11:52:42 -08001637 returns the response
kelvin8ec71442015-01-15 16:57:00 -08001638 """
Jon Hall94fd0472014-12-08 11:52:42 -08001639 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001640 cmd = "onos-check-logs " + str( onosIp )
Jon Hall16b72c42015-05-20 10:23:36 -07001641 if restart:
1642 cmd += " old"
kelvin8ec71442015-01-15 16:57:00 -08001643 self.handle.sendline( cmd )
1644 self.handle.expect( cmd )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001645 self.handle.expect( "\$ " )
Jon Hall94fd0472014-12-08 11:52:42 -08001646 response = self.handle.before
1647 return response
1648 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001649 main.log.error( "Lost ssh connection" )
1650 main.log.error( self.name + ": EOF exception found" )
1651 main.log.error( self.name + ": " + self.handle.before )
Jon Hallfebb1c72015-03-05 13:30:09 -08001652 except Exception:
1653 main.log.exception( self.name + ": Uncaught exception!" )
1654 main.cleanup()
1655 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -08001656
kelvin-onlabd3b64892015-01-20 13:26:24 -08001657 def onosStatus( self, node="" ):
kelvin8ec71442015-01-15 16:57:00 -08001658 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001659 Calls onos command: 'onos-service [<node-ip>] status'
kelvin8ec71442015-01-15 16:57:00 -08001660 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001661 try:
kelvin8ec71442015-01-15 16:57:00 -08001662 self.handle.sendline( "" )
1663 self.handle.expect( "\$" )
1664 self.handle.sendline( "onos-service " + str( node ) +
1665 " status" )
1666 i = self.handle.expect( [
You Wangef1e6572016-03-08 12:53:18 -08001667 "start/running",
You Wang7bd83062016-03-01 11:50:00 -08001668 "Running ...",
You Wangef1e6572016-03-08 12:53:18 -08001669 "stop/waiting",
You Wang7bd83062016-03-01 11:50:00 -08001670 "Not Running ...",
kelvin8ec71442015-01-15 16:57:00 -08001671 pexpect.TIMEOUT ], timeout=120 )
YPZhangfebf7302016-05-24 16:45:56 -07001672 self.handle.sendline( "" )
1673 self.handle.expect( "\$" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001674
You Wangef1e6572016-03-08 12:53:18 -08001675 if i == 0 or i == 1:
kelvin8ec71442015-01-15 16:57:00 -08001676 main.log.info( "ONOS is running" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001677 return main.TRUE
You Wangef1e6572016-03-08 12:53:18 -08001678 elif i == 2 or i == 3:
kelvin8ec71442015-01-15 16:57:00 -08001679 main.log.info( "ONOS is stopped" )
kelvin8ec71442015-01-15 16:57:00 -08001680 main.log.error( "ONOS service failed to check the status" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001681 main.cleanup()
1682 main.exit()
1683 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001684 main.log.error( self.name + ": EOF exception found" )
1685 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001686 main.cleanup()
1687 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001688 except Exception:
1689 main.log.exception( self.name + ": Uncaught exception!" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001690 main.cleanup()
1691 main.exit()
Jon Hall21270ac2015-02-16 17:59:55 -08001692
Jon Hall63604932015-02-26 17:09:50 -08001693 def setIpTables( self, ip, port='', action='add', packet_type='',
1694 direction='INPUT', rule='DROP', states=True ):
Jon Hallefbd9792015-03-05 16:11:36 -08001695 """
Jon Hall21270ac2015-02-16 17:59:55 -08001696 Description:
1697 add or remove iptables rule to DROP (default) packets from
1698 specific IP and PORT
1699 Usage:
1700 * specify action ('add' or 'remove')
1701 when removing, pass in the same argument as you would add. It will
1702 delete that specific rule.
1703 * specify the ip to block
1704 * specify the destination port to block (defaults to all ports)
1705 * optional packet type to block (default tcp)
1706 * optional iptables rule (default DROP)
1707 * optional direction to block (default 'INPUT')
Jon Hall63604932015-02-26 17:09:50 -08001708 * States boolean toggles adding all supported tcp states to the
1709 firewall rule
Jon Hall21270ac2015-02-16 17:59:55 -08001710 Returns:
1711 main.TRUE on success or
1712 main.FALSE if given invalid input or
1713 main.ERROR if there is an error in response from iptables
1714 WARNING:
1715 * This function uses root privilege iptables command which may result
1716 in unwanted network errors. USE WITH CAUTION
Jon Hallefbd9792015-03-05 16:11:36 -08001717 """
Jon Hall21270ac2015-02-16 17:59:55 -08001718
1719 # NOTE*********
1720 # The strict checking methods of this driver function is intentional
1721 # to discourage any misuse or error of iptables, which can cause
1722 # severe network errors
1723 # *************
1724
1725 # NOTE: Sleep needed to give some time for rule to be added and
1726 # registered to the instance. If you are calling this function
1727 # multiple times this sleep will prevent any errors.
1728 # DO NOT REMOVE
Jon Hall63604932015-02-26 17:09:50 -08001729 # time.sleep( 5 )
Jon Hall21270ac2015-02-16 17:59:55 -08001730 try:
1731 # input validation
1732 action_type = action.lower()
1733 rule = rule.upper()
1734 direction = direction.upper()
1735 if action_type != 'add' and action_type != 'remove':
1736 main.log.error( "Invalid action type. Use 'add' or "
1737 "'remove' table rule" )
1738 if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
1739 # NOTE Currently only supports rules DROP, ACCEPT, and LOG
1740 main.log.error( "Invalid rule. Valid rules are 'DROP' or "
1741 "'ACCEPT' or 'LOG' only." )
1742 if direction != 'INPUT' and direction != 'OUTPUT':
1743 # NOTE currently only supports rules INPUT and OUPTUT
1744 main.log.error( "Invalid rule. Valid directions are"
1745 " 'OUTPUT' or 'INPUT'" )
1746 return main.FALSE
1747 return main.FALSE
1748 return main.FALSE
1749 if action_type == 'add':
1750 # -A is the 'append' action of iptables
1751 actionFlag = '-A'
1752 elif action_type == 'remove':
1753 # -D is the 'delete' rule of iptables
1754 actionFlag = '-D'
1755 self.handle.sendline( "" )
1756 self.handle.expect( "\$" )
1757 cmd = "sudo iptables " + actionFlag + " " +\
1758 direction +\
Jon Hall21270ac2015-02-16 17:59:55 -08001759 " -s " + str( ip )
Jon Hall63604932015-02-26 17:09:50 -08001760 # " -p " + str( packet_type ) +\
1761 if packet_type:
1762 cmd += " -p " + str( packet_type )
Jon Hall21270ac2015-02-16 17:59:55 -08001763 if port:
1764 cmd += " --dport " + str( port )
Jon Hall63604932015-02-26 17:09:50 -08001765 if states:
1766 cmd += " -m state --state="
1767 #FIXME- Allow user to configure which states to block
1768 cmd += "INVALID,ESTABLISHED,NEW,RELATED,UNTRACKED"
Jon Hall21270ac2015-02-16 17:59:55 -08001769 cmd += " -j " + str( rule )
1770
1771 self.handle.sendline( cmd )
1772 self.handle.expect( "\$" )
1773 main.log.warn( self.handle.before )
1774
1775 info_string = "On " + str( self.name )
1776 info_string += " " + str( action_type )
1777 info_string += " iptable rule [ "
1778 info_string += " IP: " + str( ip )
1779 info_string += " Port: " + str( port )
1780 info_string += " Rule: " + str( rule )
1781 info_string += " Direction: " + str( direction ) + " ]"
1782 main.log.info( info_string )
1783 return main.TRUE
1784 except pexpect.TIMEOUT:
1785 main.log.exception( self.name + ": Timeout exception in "
1786 "setIpTables function" )
1787 return main.ERROR
1788 except pexpect.EOF:
1789 main.log.error( self.name + ": EOF exception found" )
1790 main.log.error( self.name + ": " + self.handle.before )
1791 main.cleanup()
1792 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001793 except Exception:
1794 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall21270ac2015-02-16 17:59:55 -08001795 main.cleanup()
1796 main.exit()
1797
Jon Hall0468b042015-02-19 19:08:21 -08001798 def detailed_status(self, log_filename):
Jon Hallefbd9792015-03-05 16:11:36 -08001799 """
Jon Hall0468b042015-02-19 19:08:21 -08001800 This method is used by STS to check the status of the controller
1801 Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
Jon Hallefbd9792015-03-05 16:11:36 -08001802 """
Jon Hall0468b042015-02-19 19:08:21 -08001803 import re
1804 try:
1805 self.handle.sendline( "" )
1806 self.handle.expect( "\$" )
1807 self.handle.sendline( "cd " + self.home )
1808 self.handle.expect( "\$" )
1809 self.handle.sendline( "service onos status" )
1810 self.handle.expect( "\$" )
1811 response = self.handle.before
1812 if re.search( "onos start/running", response ):
1813 # onos start/running, process 10457
1814 return 'RUNNING'
1815 # FIXME: Implement this case
1816 # elif re.search( pattern, response ):
1817 # return 'STARTING'
1818 elif re.search( "onos stop/", response ):
1819 # onos stop/waiting
1820 # FIXME handle this differently?: onos stop/pre-stop
1821 return 'STOPPED'
1822 # FIXME: Implement this case
1823 # elif re.search( pattern, response ):
1824 # return 'FROZEN'
1825 else:
1826 main.log.warn( self.name +
Jon Hallefbd9792015-03-05 16:11:36 -08001827 " WARNING: status received unknown response" )
Jon Hall0468b042015-02-19 19:08:21 -08001828 main.log.warn( response )
1829 return 'ERROR', "Unknown response: %s" % response
1830 except pexpect.TIMEOUT:
1831 main.log.exception( self.name + ": Timeout exception in "
1832 "setIpTables function" )
1833 return 'ERROR', "Pexpect Timeout"
1834 except pexpect.EOF:
1835 main.log.error( self.name + ": EOF exception found" )
1836 main.log.error( self.name + ": " + self.handle.before )
1837 main.cleanup()
1838 main.exit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001839 except Exception:
1840 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall0468b042015-02-19 19:08:21 -08001841 main.cleanup()
1842 main.exit()
1843
andrew@onlab.us3b087132015-03-11 15:00:08 -07001844 def createLinkGraphFile( self, benchIp, ONOSIpList, deviceCount):
1845 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07001846 Create/formats the LinkGraph.cfg file based on arguments
1847 -only creates a linear topology and connects islands
1848 -evenly distributes devices
andrew@onlab.us3b087132015-03-11 15:00:08 -07001849 -must be called by ONOSbench
1850
Jon Hall4ba53f02015-07-29 13:07:41 -07001851 ONOSIpList - list of all of the node IPs to be used
1852
1853 deviceCount - number of switches to be assigned
andrew@onlab.us3b087132015-03-11 15:00:08 -07001854 '''
Jon Hall6509dbf2016-06-21 17:01:17 -07001855 main.log.info("Creating link graph configuration file." )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001856 linkGraphPath = self.home + "/tools/package/etc/linkGraph.cfg"
Jon Hall4ba53f02015-07-29 13:07:41 -07001857 tempFile = "/tmp/linkGraph.cfg"
andrew@onlab.us3b087132015-03-11 15:00:08 -07001858
1859 linkGraph = open(tempFile, 'w+')
1860 linkGraph.write("# NullLinkProvider topology description (config file).\n")
1861 linkGraph.write("# The NodeId is only added if the destination is another node's device.\n")
1862 linkGraph.write("# Bugs: Comments cannot be appended to a line to be read.\n")
Jon Hall4ba53f02015-07-29 13:07:41 -07001863
andrew@onlab.us3b087132015-03-11 15:00:08 -07001864 clusterCount = len(ONOSIpList)
Jon Hall4ba53f02015-07-29 13:07:41 -07001865
1866 if type(deviceCount) is int or type(deviceCount) is str:
andrew@onlab.us3b087132015-03-11 15:00:08 -07001867 deviceCount = int(deviceCount)
1868 switchList = [0]*(clusterCount+1)
1869 baselineSwitchCount = deviceCount/clusterCount
Jon Hall4ba53f02015-07-29 13:07:41 -07001870
andrew@onlab.us3b087132015-03-11 15:00:08 -07001871 for node in range(1, clusterCount + 1):
1872 switchList[node] = baselineSwitchCount
1873
1874 for node in range(1, (deviceCount%clusterCount)+1):
1875 switchList[node] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001876
andrew@onlab.us3b087132015-03-11 15:00:08 -07001877 if type(deviceCount) is list:
1878 main.log.info("Using provided device distribution")
1879 switchList = [0]
1880 for i in deviceCount:
1881 switchList.append(int(i))
1882
1883 tempList = ['0']
1884 tempList.extend(ONOSIpList)
1885 ONOSIpList = tempList
1886
1887 myPort = 6
1888 lastSwitch = 0
1889 for node in range(1, clusterCount+1):
1890 if switchList[node] == 0:
1891 continue
1892
1893 linkGraph.write("graph " + ONOSIpList[node] + " {\n")
Jon Hall4ba53f02015-07-29 13:07:41 -07001894
andrew@onlab.us3b087132015-03-11 15:00:08 -07001895 if node > 1:
1896 #connect to last device on previous node
Jon Hall4ba53f02015-07-29 13:07:41 -07001897 line = ("\t0:5 -> " + str(lastSwitch) + ":6:" + lastIp + "\n") #ONOSIpList[node-1]
1898 linkGraph.write(line)
1899
1900 lastSwitch = 0
1901 for switch in range (0, switchList[node]-1):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001902 line = ""
1903 line = ("\t" + str(switch) + ":" + str(myPort))
1904 line += " -- "
1905 line += (str(switch+1) + ":" + str(myPort-1) + "\n")
1906 linkGraph.write(line)
Jon Hall4ba53f02015-07-29 13:07:41 -07001907 lastSwitch = switch+1
andrew@onlab.us3b087132015-03-11 15:00:08 -07001908 lastIp = ONOSIpList[node]
Jon Hall4ba53f02015-07-29 13:07:41 -07001909
andrew@onlab.us3b087132015-03-11 15:00:08 -07001910 #lastSwitch += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001911 if node < (clusterCount):
andrew@onlab.us3b087132015-03-11 15:00:08 -07001912 #connect to first device on the next node
Jon Hall4ba53f02015-07-29 13:07:41 -07001913 line = ("\t" + str(lastSwitch) + ":6 -> 0:5:" + ONOSIpList[node+1] + "\n")
andrew@onlab.us3b087132015-03-11 15:00:08 -07001914 linkGraph.write(line)
Jon Hall4ba53f02015-07-29 13:07:41 -07001915
andrew@onlab.us3b087132015-03-11 15:00:08 -07001916 linkGraph.write("}\n")
1917 linkGraph.close()
1918
1919 #SCP
Jon Hall4ba53f02015-07-29 13:07:41 -07001920 os.system( "scp " + tempFile + " " + self.user_name + "@" + benchIp + ":" + linkGraphPath)
andrew@onlab.us3b087132015-03-11 15:00:08 -07001921 main.log.info("linkGraph.cfg creation complete")
1922
cameron@onlab.us75900962015-03-30 13:22:49 -07001923 def configNullDev( self, ONOSIpList, deviceCount, numPorts=10):
Jon Hall4ba53f02015-07-29 13:07:41 -07001924
andrew@onlab.us3b087132015-03-11 15:00:08 -07001925 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07001926 ONOSIpList = list of Ip addresses of nodes switches will be devided amongst
1927 deviceCount = number of switches to distribute, or list of values to use as custom distribution
cameron@onlab.us75900962015-03-30 13:22:49 -07001928 numPorts = number of ports per device. Defaults to 10 both in this function and in ONOS. Optional arg
andrew@onlab.us3b087132015-03-11 15:00:08 -07001929 '''
1930
Jon Hall6509dbf2016-06-21 17:01:17 -07001931 main.log.info("Configuring Null Device Provider" )
andrew@onlab.us3b087132015-03-11 15:00:08 -07001932 clusterCount = len(ONOSIpList)
1933
Jon Hall4ba53f02015-07-29 13:07:41 -07001934 try:
1935
cameron@onlab.us75900962015-03-30 13:22:49 -07001936 if type(deviceCount) is int or type(deviceCount) is str:
Jon Hall6509dbf2016-06-21 17:01:17 -07001937 main.log.info("Creating device distribution")
cameron@onlab.us75900962015-03-30 13:22:49 -07001938 deviceCount = int(deviceCount)
1939 switchList = [0]*(clusterCount+1)
1940 baselineSwitchCount = deviceCount/clusterCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001941
cameron@onlab.us75900962015-03-30 13:22:49 -07001942 for node in range(1, clusterCount + 1):
1943 switchList[node] = baselineSwitchCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001944
cameron@onlab.us75900962015-03-30 13:22:49 -07001945 for node in range(1, (deviceCount%clusterCount)+1):
1946 switchList[node] += 1
Jon Hall4ba53f02015-07-29 13:07:41 -07001947
1948 if type(deviceCount) is list:
1949 main.log.info("Using provided device distribution")
1950
1951 if len(deviceCount) == clusterCount:
cameron@onlab.us75900962015-03-30 13:22:49 -07001952 switchList = ['0']
1953 switchList.extend(deviceCount)
Jon Hall4ba53f02015-07-29 13:07:41 -07001954
1955 if len(deviceCount) == (clusterCount + 1):
1956 if deviceCount[0] == '0' or deviceCount[0] == 0:
cameron@onlab.us75900962015-03-30 13:22:49 -07001957 switchList = deviceCount
andrew@onlab.us3b087132015-03-11 15:00:08 -07001958
cameron@onlab.us75900962015-03-30 13:22:49 -07001959 assert len(switchList) == (clusterCount + 1)
Jon Hall4ba53f02015-07-29 13:07:41 -07001960
cameron@onlab.us75900962015-03-30 13:22:49 -07001961 except AssertionError:
Jon Hall4ba53f02015-07-29 13:07:41 -07001962 main.log.error( "Bad device/Ip list match")
cameron@onlab.us75900962015-03-30 13:22:49 -07001963 except TypeError:
1964 main.log.exception( self.name + ": Object not as expected" )
1965 return None
Jon Hall77ba41c2015-04-06 10:25:40 -07001966 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07001967 main.log.exception( self.name + ": Uncaught exception!" )
1968 main.cleanup()
1969 main.exit()
1970
andrew@onlab.us3b087132015-03-11 15:00:08 -07001971
1972 ONOSIp = [0]
1973 ONOSIp.extend(ONOSIpList)
Jon Hall4ba53f02015-07-29 13:07:41 -07001974
andrew@onlab.us3b087132015-03-11 15:00:08 -07001975 devicesString = "devConfigs = "
1976 for node in range(1, len(ONOSIp)):
1977 devicesString += (ONOSIp[node] + ":" + str(switchList[node] ))
1978 if node < clusterCount:
1979 devicesString += (",")
Jon Hall4ba53f02015-07-29 13:07:41 -07001980
1981 try:
cameron@onlab.us75900962015-03-30 13:22:49 -07001982 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider devConfigs " + devicesString )
1983 self.handle.expect(":~")
1984 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.device.impl.NullDeviceProvider numPorts " + str(numPorts) )
1985 self.handle.expect(":~")
andrew@onlab.us3b087132015-03-11 15:00:08 -07001986
cameron@onlab.us75900962015-03-30 13:22:49 -07001987 for i in range(10):
1988 self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.device.impl.NullDeviceProvider")
1989 self.handle.expect(":~")
1990 verification = self.handle.before
1991 if (" value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification:
1992 break
1993 else:
1994 time.sleep(1)
andrew@onlab.us3b087132015-03-11 15:00:08 -07001995
cameron@onlab.us2cc8bf12015-04-02 14:12:30 -07001996 assert ("value=" + str(numPorts)) in verification and (" value=" + devicesString) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07001997
cameron@onlab.us75900962015-03-30 13:22:49 -07001998 except AssertionError:
1999 main.log.error("Incorrect Config settings: " + verification)
Jon Hall77ba41c2015-04-06 10:25:40 -07002000 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002001 main.log.exception( self.name + ": Uncaught exception!" )
2002 main.cleanup()
2003 main.exit()
2004
Jon Hall4ba53f02015-07-29 13:07:41 -07002005 def configNullLink( self,fileName="/opt/onos/apache-karaf-3.0.3/etc/linkGraph.cfg", eventRate=0):
andrew@onlab.us3b087132015-03-11 15:00:08 -07002006 '''
Jon Hall4ba53f02015-07-29 13:07:41 -07002007 fileName default is currently the same as the default on ONOS, specify alternate file if
cameron@onlab.us75900962015-03-30 13:22:49 -07002008 you want to use a different topology file than linkGraph.cfg
andrew@onlab.us3b087132015-03-11 15:00:08 -07002009 '''
2010
Jon Hall4ba53f02015-07-29 13:07:41 -07002011
2012 try:
2013 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider eventRate " + str(eventRate))
2014 self.handle.expect(":~")
cameron@onlab.us75900962015-03-30 13:22:49 -07002015 self.handle.sendline("onos $OC1 cfg set org.onosproject.provider.nil.link.impl.NullLinkProvider cfgFile " + fileName )
2016 self.handle.expect(":~")
Jon Hall4ba53f02015-07-29 13:07:41 -07002017
2018 for i in range(10):
2019 self.handle.sendline("onos $OC1 cfg get org.onosproject.provider.nil.link.impl.NullLinkProvider")
cameron@onlab.us75900962015-03-30 13:22:49 -07002020 self.handle.expect(":~")
2021 verification = self.handle.before
Jon Hall4ba53f02015-07-29 13:07:41 -07002022 if (" value=" + str(eventRate)) in verification and (" value=" + fileName) in verification:
cameron@onlab.us75900962015-03-30 13:22:49 -07002023 break
Jon Hall4ba53f02015-07-29 13:07:41 -07002024 else:
cameron@onlab.us75900962015-03-30 13:22:49 -07002025 time.sleep(1)
Jon Hall4ba53f02015-07-29 13:07:41 -07002026
cameron@onlab.us75900962015-03-30 13:22:49 -07002027 assert ("value=" + str(eventRate)) in verification and (" value=" + fileName) in verification
Jon Hall4ba53f02015-07-29 13:07:41 -07002028
cameron@onlab.us75900962015-03-30 13:22:49 -07002029 except pexpect.EOF:
2030 main.log.error( self.name + ": EOF exception found" )
2031 main.log.error( self.name + ": " + self.handle.before )
2032 main.cleanup()
2033 main.exit()
cameron@onlab.us75900962015-03-30 13:22:49 -07002034 except AssertionError:
2035 main.log.info("Settings did not post to ONOS")
Jon Hall4ba53f02015-07-29 13:07:41 -07002036 main.log.error(varification)
Jon Hall77ba41c2015-04-06 10:25:40 -07002037 except Exception:
cameron@onlab.us75900962015-03-30 13:22:49 -07002038 main.log.exception( self.name + ": Uncaught exception!" )
2039 main.log.error(varification)
2040 main.cleanup()
2041 main.exit()
andrew@onlab.us3b087132015-03-11 15:00:08 -07002042
kelvin-onlaba4074292015-07-09 15:19:49 -07002043 def getOnosIps( self ):
2044 """
2045 Get all onos IPs stored in
2046 """
cameron@onlab.us59d29d92015-05-11 14:31:54 -07002047
kelvin-onlaba4074292015-07-09 15:19:49 -07002048 return sorted( self.onosIps.values() )
cameron@onlab.us59d29d92015-05-11 14:31:54 -07002049
kelvin-onlaba4074292015-07-09 15:19:49 -07002050 def logReport( self, nodeIp, searchTerms, outputMode="s" ):
Jon Hallb4242222016-01-25 17:07:04 -08002051 """
2052 Searches the latest ONOS log file for the given search terms and
2053 prints the total occurances of each term. Returns to combined total of
2054 all occurances.
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002055
Jon Hallb4242222016-01-25 17:07:04 -08002056 Arguments:
2057 * nodeIp - The ip of the ONOS node where the log is located
2058 * searchTerms - A string to grep for or a list of strings to grep
2059 for in the ONOS log. Will print out the number of
2060 occurances for each term.
2061 Optional Arguments:
2062 * outputMode - 's' or 'd'. If 'd' will print the last 5 lines
2063 containing each search term as well as the total
2064 number of occurances of each term. Defaults to 's',
2065 which prints the simple output of just the number
2066 of occurances for each term.
2067 """
2068 try:
2069 main.log.info( " Log Report for {} ".format( nodeIp ).center( 70, '=' ) )
2070 if type( searchTerms ) is str:
2071 searchTerms = [searchTerms]
2072 numTerms = len( searchTerms )
2073 outputMode = outputMode.lower()
cameron@onlab.us70dd8c62015-05-14 11:19:39 -07002074
Jon Hallb4242222016-01-25 17:07:04 -08002075 totalHits = 0
2076 logLines = []
2077 for termIndex in range( numTerms ):
2078 term = searchTerms[termIndex]
2079 logLines.append( [term] )
2080 cmd = "onos-ssh " + nodeIp + " cat /opt/onos/log/karaf.log | grep " + term
2081 self.handle.sendline( cmd )
2082 self.handle.expect( ":~" )
2083 before = self.handle.before.splitlines()
2084 count = 0
2085 for line in before:
2086 if term in line and "grep" not in line:
2087 count += 1
2088 if before.index( line ) > ( len( before ) - 7 ):
2089 logLines[termIndex].append( line )
2090 main.log.info( "{}: {}".format( term, count ) )
2091 totalHits += count
2092 if termIndex == numTerms - 1:
2093 print "\n"
2094 if outputMode != "s":
2095 outputString = ""
2096 for term in logLines:
2097 outputString = term[0] + ": \n"
2098 for line in range( 1, len( term ) ):
2099 outputString += ( "\t" + term[line] + "\n" )
2100 if outputString != ( term[0] + ": \n" ):
2101 main.log.info( outputString )
2102 main.log.info( "=" * 70 )
2103 return totalHits
2104 except pexpect.EOF:
2105 main.log.error( self.name + ": EOF exception found" )
2106 main.log.error( self.name + ": " + self.handle.before )
2107 main.cleanup()
2108 main.exit()
2109 except pexpect.TIMEOUT:
2110 main.log.error( self.name + ": TIMEOUT exception found" )
2111 main.log.error( self.name + ": " + self.handle.before )
2112 main.cleanup()
2113 main.exit()
2114 except Exception:
2115 main.log.exception( self.name + ": Uncaught exception!" )
2116 main.cleanup()
2117 main.exit()
kelvin-onlab7a719bb2015-07-08 11:09:51 -07002118
2119 def copyMininetFile( self, fileName, localPath, userName, ip,
2120 mnPath='~/mininet/custom/', timeout = 60 ):
2121 """
2122 Description:
2123 Copy mininet topology file from dependency folder in the test folder
2124 and paste it to the mininet machine's mininet/custom folder
2125 Required:
2126 fileName - Name of the topology file to copy
2127 localPath - File path of the mininet topology file
2128 userName - User name of the mininet machine to send the file to
2129 ip - Ip address of the mininet machine
2130 Optional:
2131 mnPath - of the mininet directory to send the file to
2132 Return:
2133 Return main.TRUE if successfully copied the file otherwise
2134 return main.FALSE
2135 """
2136
2137 try:
2138 cmd = "scp " + localPath + fileName + " " + userName + "@" + \
2139 str( ip ) + ":" + mnPath + fileName
2140
2141 self.handle.sendline( "" )
2142 self.handle.expect( "\$" )
2143
2144 main.log.info( self.name + ": Execute: " + cmd )
2145
2146 self.handle.sendline( cmd )
2147
2148 i = self.handle.expect( [ 'No such file',
2149 "100%",
2150 pexpect.TIMEOUT ] )
2151
2152 if i == 0:
2153 main.log.error( self.name + ": File " + fileName +
2154 " does not exist!" )
2155 return main.FALSE
2156
2157 if i == 1:
2158 main.log.info( self.name + ": File " + fileName +
2159 " has been copied!" )
2160 self.handle.sendline( "" )
2161 self.handle.expect( "\$" )
2162 return main.TRUE
2163
2164 except pexpect.EOF:
2165 main.log.error( self.name + ": EOF exception found" )
2166 main.log.error( self.name + ": " + self.handle.before )
2167 main.cleanup()
2168 main.exit()
2169 except pexpect.TIMEOUT:
2170 main.log.error( self.name + ": TIMEOUT exception found" )
2171 main.log.error( self.name + ": " + self.handle.before )
2172 main.cleanup()
2173 main.exit()
cameron@onlab.us78b89652015-07-08 15:21:03 -07002174
2175 def jvmSet(self, memory=8):
Jon Hall4ba53f02015-07-29 13:07:41 -07002176
cameron@onlab.us78b89652015-07-08 15:21:03 -07002177 import os
2178
2179 homeDir = os.path.expanduser('~')
2180 filename = "/onos/tools/package/bin/onos-service"
2181
2182 serviceConfig = open(homeDir + filename, 'w+')
2183 serviceConfig.write("#!/bin/bash\n ")
2184 serviceConfig.write("#------------------------------------- \n ")
2185 serviceConfig.write("# Starts ONOS Apache Karaf container\n ")
2186 serviceConfig.write("#------------------------------------- \n ")
2187 serviceConfig.write("#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/}\n ")
2188 serviceConfig.write("""export JAVA_OPTS="${JAVA_OPTS:--Xms""" + str(memory) + "G -Xmx" + str(memory) + """G}" \n """)
2189 serviceConfig.write("[ -d $ONOS_HOME ] && cd $ONOS_HOME || ONOS_HOME=$(dirname $0)/..\n")
2190 serviceConfig.write("""${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf "$@" \n """)
2191 serviceConfig.close()
2192
Jon Hall6c44c0b2016-04-20 15:21:00 -07002193 def createDBFile( self, testData ):
Jon Hall4ba53f02015-07-29 13:07:41 -07002194
cameron@onlab.us78b89652015-07-08 15:21:03 -07002195 filename = main.TEST + "DB"
2196 DBString = ""
Jon Hall4ba53f02015-07-29 13:07:41 -07002197
cameron@onlab.us78b89652015-07-08 15:21:03 -07002198 for item in testData:
Jon Hall6c44c0b2016-04-20 15:21:00 -07002199 if type( item ) is string:
cameron@onlab.us78b89652015-07-08 15:21:03 -07002200 item = "'" + item + "'"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002201 if testData.index( item ) < len( testData - 1 ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002202 item += ","
Jon Hall6c44c0b2016-04-20 15:21:00 -07002203 DBString += str( item )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002204
Jon Hall6c44c0b2016-04-20 15:21:00 -07002205 DBFile = open( filename, "a" )
2206 DBFile.write( DBString )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002207 DBFile.close()
2208
Jon Hall6c44c0b2016-04-20 15:21:00 -07002209 def verifySummary( self, ONOSIp, *deviceCount ):
cameron@onlab.us78b89652015-07-08 15:21:03 -07002210
Jon Hall6c44c0b2016-04-20 15:21:00 -07002211 self.handle.sendline( "onos " + ONOSIp + " summary" )
2212 self.handle.expect( ":~" )
cameron@onlab.us78b89652015-07-08 15:21:03 -07002213
2214 summaryStr = self.handle.before
2215 print "\nSummary\n==============\n" + summaryStr + "\n\n"
2216
2217 #passed = "SCC(s)=1" in summaryStr
2218 #if deviceCount:
2219 # passed = "devices=" + str(deviceCount) + "," not in summaryStr
2220
GlennRC772363b2015-08-25 13:05:57 -07002221 passed = False
cameron@onlab.us78b89652015-07-08 15:21:03 -07002222 if "SCC(s)=1," in summaryStr:
2223 passed = True
Jon Hall6c44c0b2016-04-20 15:21:00 -07002224 print "Summary is verifed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002225 else:
Jon Hall6c44c0b2016-04-20 15:21:00 -07002226 print "Summary failed"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002227
2228 if deviceCount:
2229 print" ============================="
Jon Hall6c44c0b2016-04-20 15:21:00 -07002230 checkStr = "devices=" + str( deviceCount[0] ) + ","
cameron@onlab.us78b89652015-07-08 15:21:03 -07002231 print "Checkstr: " + checkStr
2232 if checkStr not in summaryStr:
2233 passed = False
Jon Hall6c44c0b2016-04-20 15:21:00 -07002234 print "Device count failed"
Jon Hall4ba53f02015-07-29 13:07:41 -07002235 else:
2236 print "device count verified"
cameron@onlab.us78b89652015-07-08 15:21:03 -07002237
2238 return passed
Jon Hall6c44c0b2016-04-20 15:21:00 -07002239
Jon Hall8f6d4622016-05-23 15:27:18 -07002240 def getIpAddr( self, iface=None ):
Jon Hall6c44c0b2016-04-20 15:21:00 -07002241 """
2242 Update self.ip_address with numerical ip address. If multiple IP's are
2243 located on the device, will attempt to use self.nicAddr to choose the
2244 right one. Defaults to 127.0.0.1 if no other address is found or cannot
2245 determine the correct address.
2246
2247 ONLY WORKS WITH IPV4 ADDRESSES
2248 """
2249 try:
Jon Hall8f6d4622016-05-23 15:27:18 -07002250 LOCALHOST = "127.0.0.1"
Jon Hall6c44c0b2016-04-20 15:21:00 -07002251 ipPat = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
2252 pattern = re.compile( ipPat )
2253 match = re.search( pattern, self.ip_address )
2254 if self.nicAddr:
2255 nicPat = self.nicAddr.replace( ".", "\." ).replace( "\*", r"\d{1,3}" )
2256 nicPat = re.compile( nicPat )
2257 else:
2258 nicPat = None
2259 # IF self.ip_address is an ip address and matches
2260 # self.nicAddr: return self.ip_address
2261 if match:
2262 curIp = match.group(0)
2263 if nicPat:
2264 nicMatch = re.search( nicPat, curIp )
2265 if nicMatch:
2266 return self.ip_address
Jon Hall8f6d4622016-05-23 15:27:18 -07002267 # ELSE: IF iface, return ip of interface
2268 cmd = "ifconfig"
2269 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2270 if iface:
2271 cmd += " " + str( iface )
2272 raw = subprocess.check_output( cmd.split() )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002273 ifPat = re.compile( "inet addr:({})".format( ipPat ) )
2274 ips = re.findall( ifPat, raw )
Jon Hall8f6d4622016-05-23 15:27:18 -07002275 if iface:
2276 if ips:
2277 ip = ips[0]
2278 self.ip_address = ip
2279 return ip
2280 else:
2281 main.log.error( "Error finding ip, ifconfig output:".format( raw ) )
2282 # ELSE: attempt to get address matching nicPat.
Jon Hall6c44c0b2016-04-20 15:21:00 -07002283 if nicPat:
2284 for ip in ips:
2285 curMatch = re.search( nicPat, ip )
2286 if curMatch:
2287 self.ip_address = ip
2288 return ip
Jon Hall8f6d4622016-05-23 15:27:18 -07002289 else: # If only one non-localhost ip, return that
2290 tmpList = [ ip for ip in ips if ip is not LOCALHOST ]
Jon Hall6c44c0b2016-04-20 15:21:00 -07002291 if len(tmpList) == 1:
2292 curIp = tmpList[0]
2293 self.ip_address = curIp
2294 return curIp
Jon Hall8f6d4622016-05-23 15:27:18 -07002295 # Either no non-localhost IPs, or more than 1
Jon Hallebccd352016-05-20 15:17:17 -07002296 main.log.warn( "getIpAddr failed to find a public IP address" )
Jon Hall8f6d4622016-05-23 15:27:18 -07002297 return LOCALHOST
Jon Halle1790952016-05-23 15:51:46 -07002298 except subprocess.CalledProcessError:
Jon Hall8f6d4622016-05-23 15:27:18 -07002299 main.log.exception( "Error executing ifconfig" )
2300 except IndexError:
2301 main.log.exception( "Error getting IP Address" )
Jon Hall6c44c0b2016-04-20 15:21:00 -07002302 except Exception:
2303 main.log.exception( "Uncaught exception" )
suibin zhang116647a2016-05-06 16:30:09 -07002304
2305 def startBasicONOS(self, nodeList, opSleep = 60, onosStartupSleep = 60):
2306
2307 '''
2308 Start onos cluster with defined nodes, but only with drivers app
2309
2310 '''
2311 import time
2312
2313 self.createCellFile( self.ip_address,
2314 "temp",
2315 self.ip_address,
2316 "drivers",
2317 nodeList )
2318
2319 main.log.info( self.name + ": Apply cell to environment" )
2320 cellResult = self.setCell( "temp" )
2321 verifyResult = self.verifyCell()
2322
2323 main.log.info( self.name + ": Creating ONOS package" )
2324 packageResult = self.onosPackage( opTimeout=opSleep )
2325
2326 main.log.info( self.name + ": Installing ONOS package" )
2327 for nd in nodeList:
2328 self.onosInstall( node=nd )
2329
2330 main.log.info( self.name + ": Starting ONOS service" )
2331 time.sleep( onosStartupSleep )
2332
2333 onosStatus = True
2334 for nd in nodeList:
2335 onosStatus = onosStatus & self.isup( node = nd )
2336 #print "onosStatus is: " + str( onosStatus )
2337
2338 return main.TRUE if onosStatus else main.FALSE
2339
Jeremy Songster5665f1b2016-06-20 14:38:22 -07002340 def onosNetCfg( self, controllerIps, path, fileName ):
2341 """
2342 Push a specified json file to ONOS through the onos-netcfg service
2343
2344 Required:
2345 controllerIps - the Ips of the ONOS nodes in the cluster
2346 path - the location of the file to be sent
2347 fileName - name of the json file to be sent
2348
2349 Returns main.TRUE on successfully sending json file, and main.FALSE if
2350 there is an error.
2351 """
2352 try:
2353 cmd = "onos-netcfg {0} {1}{2}.json".format( controllerIps, path, fileName )
2354 main.log.info( "Sending: " + cmd )
2355 main.ONOSbench.handle.sendline( cmd )
2356 handle = self.handle.before
2357 print handle
2358 if "Error" in handle:
2359 main.log.error( self.name + ": " + self.handle.before )
2360 return main.FALSE
2361 else:
2362 self.handle.expect( "\$" )
2363 return main.TRUE
2364 except pexpect.EOF:
2365 main.log.error( self.name + ": EOF exception found" )
2366 main.log.error( self.name + ": " + self.handle.before )
2367 main.cleanup()
2368 main.exit()
2369 except Exception:
2370 main.log.exception( self.name + ": Uncaught exception!" )
2371 main.cleanup()
Jeremy Songsterae01bba2016-07-11 15:39:17 -07002372 main.exit()