blob: cb8a9a748115e45dea3e6ea2793de5128d4de4c0 [file] [log] [blame]
andrewonlab95ce8322014-10-13 14:12:04 -04001#!/usr/bin/env python
2
kelvin8ec71442015-01-15 16:57:00 -08003"""
andrewonlab95ce8322014-10-13 14:12:04 -04004This driver enters the onos> prompt to issue commands.
5
kelvin8ec71442015-01-15 16:57:00 -08006Please follow the coding style demonstrated by existing
andrewonlab95ce8322014-10-13 14:12:04 -04007functions and document properly.
8
9If you are a contributor to the driver, please
10list your email here for future contact:
11
12jhall@onlab.us
13andrew@onlab.us
Jon Halle8217482014-10-17 13:49:14 -040014shreya@onlab.us
andrewonlab95ce8322014-10-13 14:12:04 -040015
16OCT 13 2014
17
kelvin8ec71442015-01-15 16:57:00 -080018"""
andrewonlab95ce8322014-10-13 14:12:04 -040019import sys
andrewonlab95ce8322014-10-13 14:12:04 -040020import pexpect
21import re
Jon Hall30b82fa2015-03-04 17:15:43 -080022import json
23import types
kelvin8ec71442015-01-15 16:57:00 -080024sys.path.append( "../" )
andrewonlab95ce8322014-10-13 14:12:04 -040025from drivers.common.clidriver import CLI
26
andrewonlab95ce8322014-10-13 14:12:04 -040027
kelvin8ec71442015-01-15 16:57:00 -080028class OnosCliDriver( CLI ):
andrewonlab95ce8322014-10-13 14:12:04 -040029
kelvin8ec71442015-01-15 16:57:00 -080030 def __init__( self ):
31 """
32 Initialize client
33 """
34 super( CLI, self ).__init__()
35
36 def connect( self, **connectargs ):
37 """
andrewonlab95ce8322014-10-13 14:12:04 -040038 Creates ssh handle for ONOS cli.
kelvin8ec71442015-01-15 16:57:00 -080039 """
andrewonlab95ce8322014-10-13 14:12:04 -040040 try:
41 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080042 vars( self )[ key ] = connectargs[ key ]
andrewonlab95ce8322014-10-13 14:12:04 -040043 self.home = "~/ONOS"
44 for key in self.options:
45 if key == "home":
kelvin8ec71442015-01-15 16:57:00 -080046 self.home = self.options[ 'home' ]
andrewonlab95ce8322014-10-13 14:12:04 -040047 break
kelvin-onlabfb521662015-02-27 09:52:40 -080048 if self.home is None or self.home == "":
kelvin-onlabd6634ac2015-01-29 14:23:10 -080049 self.home = "~/ONOS"
kelvin-onlabfb521662015-02-27 09:52:40 -080050
kelvin8ec71442015-01-15 16:57:00 -080051 self.name = self.options[ 'name' ]
52 self.handle = super( OnosCliDriver, self ).connect(
kelvin-onlab08679eb2015-01-21 16:11:48 -080053 user_name=self.user_name,
54 ip_address=self.ip_address,
kelvin-onlab898a6c62015-01-16 14:13:53 -080055 port=self.port,
56 pwd=self.pwd,
57 home=self.home )
andrewonlab95ce8322014-10-13 14:12:04 -040058
kelvin8ec71442015-01-15 16:57:00 -080059 self.handle.sendline( "cd " + self.home )
60 self.handle.expect( "\$" )
andrewonlab95ce8322014-10-13 14:12:04 -040061 if self.handle:
62 return self.handle
kelvin8ec71442015-01-15 16:57:00 -080063 else:
64 main.log.info( "NO ONOS HANDLE" )
andrewonlab95ce8322014-10-13 14:12:04 -040065 return main.FALSE
Jon Halld4d4b372015-01-28 16:02:41 -080066 except TypeError:
67 main.log.exception( self.name + ": Object not as expected" )
68 return None
andrewonlab95ce8322014-10-13 14:12:04 -040069 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080070 main.log.error( self.name + ": EOF exception found" )
71 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040072 main.cleanup()
73 main.exit()
74 except:
Jon Halld4d4b372015-01-28 16:02:41 -080075 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab95ce8322014-10-13 14:12:04 -040076 main.cleanup()
77 main.exit()
78
kelvin8ec71442015-01-15 16:57:00 -080079 def disconnect( self ):
80 """
andrewonlab95ce8322014-10-13 14:12:04 -040081 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -080082 """
Jon Halld61331b2015-02-17 16:35:47 -080083 response = main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -040084 try:
Jon Hallb7fce3e2015-03-04 10:18:32 -080085 self.logout()
kelvin8ec71442015-01-15 16:57:00 -080086 self.handle.sendline( "" )
87 self.handle.expect( "\$" )
88 self.handle.sendline( "exit" )
89 self.handle.expect( "closed" )
Jon Halld4d4b372015-01-28 16:02:41 -080090 except TypeError:
91 main.log.exception( self.name + ": Object not as expected" )
Jon Halld61331b2015-02-17 16:35:47 -080092 response = main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -040093 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -080094 main.log.error( self.name + ": EOF exception found" )
95 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -040096 except:
Jon Halld4d4b372015-01-28 16:02:41 -080097 main.log.exception( self.name + ": Connection failed to the host" )
andrewonlab95ce8322014-10-13 14:12:04 -040098 response = main.FALSE
99 return response
100
kelvin8ec71442015-01-15 16:57:00 -0800101 def logout( self ):
102 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500103 Sends 'logout' command to ONOS cli
kelvin8ec71442015-01-15 16:57:00 -0800104 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500105 try:
kelvin8ec71442015-01-15 16:57:00 -0800106 self.handle.sendline( "" )
Jon Hallb7fce3e2015-03-04 10:18:32 -0800107 i = self.handle.expect( [ "onos>", "\$", pexpect.TIMEOUT ],
108 timeout=10 )
109 if i == 0: # In ONOS CLI
kelvin8ec71442015-01-15 16:57:00 -0800110 self.handle.sendline( "logout" )
111 self.handle.expect( "\$" )
Jon Hallb7fce3e2015-03-04 10:18:32 -0800112 elif i == 1: # not in CLI
andrewonlab9627f432014-11-14 12:45:10 -0500113 return main.TRUE
Jon Hallb7fce3e2015-03-04 10:18:32 -0800114 elif i == 3: # Timeout
115 return main.FALSE
Jon Halld4d4b372015-01-28 16:02:41 -0800116 except TypeError:
117 main.log.exception( self.name + ": Object not as expected" )
118 return None
andrewonlab38d2b4a2014-11-13 16:28:47 -0500119 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800120 main.log.error( self.name + ": eof exception found" )
121 main.log.error( self.name + ": " +
122 self.handle.before )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500123 main.cleanup()
124 main.exit()
125 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800126 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab38d2b4a2014-11-13 16:28:47 -0500127 main.cleanup()
128 main.exit()
129
kelvin-onlabd3b64892015-01-20 13:26:24 -0800130 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800131 """
andrewonlab95ce8322014-10-13 14:12:04 -0400132 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800133
andrewonlab95ce8322014-10-13 14:12:04 -0400134 Before issuing any cli commands, set the environment variable first.
kelvin8ec71442015-01-15 16:57:00 -0800135 """
andrewonlab95ce8322014-10-13 14:12:04 -0400136 try:
137 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800138 main.log.error( "Must define cellname" )
andrewonlab95ce8322014-10-13 14:12:04 -0400139 main.cleanup()
140 main.exit()
141 else:
kelvin8ec71442015-01-15 16:57:00 -0800142 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800143 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800144 # Note that this variable name is subject to change
andrewonlab95ce8322014-10-13 14:12:04 -0400145 # and that this driver will have to change accordingly
Jon Hall1e03cb62015-02-19 12:07:12 -0800146 self.handle.expect( "ONOS_CELL" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800147 handleBefore = self.handle.before
148 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800149 # Get the rest of the handle
150 self.handle.sendline( "" )
151 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800152 handleMore = self.handle.before
andrewonlab95ce8322014-10-13 14:12:04 -0400153
kelvin-onlabd3b64892015-01-20 13:26:24 -0800154 main.log.info( "Cell call returned: " + handleBefore +
155 handleAfter + handleMore )
andrewonlab95ce8322014-10-13 14:12:04 -0400156
157 return main.TRUE
158
Jon Halld4d4b372015-01-28 16:02:41 -0800159 except TypeError:
160 main.log.exception( self.name + ": Object not as expected" )
161 return None
andrewonlab95ce8322014-10-13 14:12:04 -0400162 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800163 main.log.error( self.name + ": eof exception found" )
164 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400165 main.cleanup()
166 main.exit()
167 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800168 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab95ce8322014-10-13 14:12:04 -0400169 main.cleanup()
170 main.exit()
kelvin8ec71442015-01-15 16:57:00 -0800171
kelvin-onlabd3b64892015-01-20 13:26:24 -0800172 def startOnosCli( self, ONOSIp, karafTimeout="" ):
kelvin8ec71442015-01-15 16:57:00 -0800173 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800174 karafTimeout is an optional arugument. karafTimeout value passed
175 by user would be used to set the current karaf shell idle timeout.
176 Note that when ever this property is modified the shell will exit and
Hari Krishnad7b9c202015-01-05 10:38:14 -0800177 the subsequent login would reflect new idle timeout.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800178 Below is an example to start a session with 60 seconds idle timeout
179 ( input value is in milliseconds ):
kelvin8ec71442015-01-15 16:57:00 -0800180
Hari Krishna25d42f72015-01-05 15:08:28 -0800181 tValue = "60000"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800182 main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue )
kelvin8ec71442015-01-15 16:57:00 -0800183
kelvin-onlabd3b64892015-01-20 13:26:24 -0800184 Note: karafTimeout is left as str so that this could be read
185 and passed to startOnosCli from PARAMS file as str.
kelvin8ec71442015-01-15 16:57:00 -0800186 """
andrewonlab95ce8322014-10-13 14:12:04 -0400187 try:
kelvin8ec71442015-01-15 16:57:00 -0800188 self.handle.sendline( "" )
189 x = self.handle.expect( [
190 "\$", "onos>" ], timeout=10 )
andrewonlab48829f62014-11-17 13:49:01 -0500191
192 if x == 1:
kelvin8ec71442015-01-15 16:57:00 -0800193 main.log.info( "ONOS cli is already running" )
andrewonlab48829f62014-11-17 13:49:01 -0500194 return main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -0400195
kelvin8ec71442015-01-15 16:57:00 -0800196 # Wait for onos start ( -w ) and enter onos cli
kelvin-onlabd3b64892015-01-20 13:26:24 -0800197 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800198 i = self.handle.expect( [
199 "onos>",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800200 pexpect.TIMEOUT ], timeout=60 )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400201
202 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800203 main.log.info( str( ONOSIp ) + " CLI Started successfully" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800204 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800205 self.handle.sendline(
Hari Krishnaac4e1782015-01-26 12:09:12 -0800206 "config:property-set -p org.apache.karaf.shell\
207 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800208 karafTimeout )
209 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800210 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800211 self.handle.expect( "onos>" )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400212 return main.TRUE
213 else:
kelvin8ec71442015-01-15 16:57:00 -0800214 # If failed, send ctrl+c to process and try again
215 main.log.info( "Starting CLI failed. Retrying..." )
216 self.handle.send( "\x03" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800217 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800218 i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ],
219 timeout=30 )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400220 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800221 main.log.info( str( ONOSIp ) + " CLI Started " +
kelvin8ec71442015-01-15 16:57:00 -0800222 "successfully after retry attempt" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800223 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800224 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800225 "config:property-set -p org.apache.karaf.shell\
226 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800227 karafTimeout )
228 self.handle.expect( "\$" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800229 self.handle.sendline( "onos -w " + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800230 self.handle.expect( "onos>" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400231 return main.TRUE
232 else:
kelvin8ec71442015-01-15 16:57:00 -0800233 main.log.error( "Connection to CLI " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800234 str( ONOSIp ) + " timeout" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400235 return main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -0400236
Jon Halld4d4b372015-01-28 16:02:41 -0800237 except TypeError:
238 main.log.exception( self.name + ": Object not as expected" )
239 return None
andrewonlab95ce8322014-10-13 14:12:04 -0400240 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800241 main.log.error( self.name + ": EOF exception found" )
242 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400243 main.cleanup()
244 main.exit()
245 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800246 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab95ce8322014-10-13 14:12:04 -0400247 main.cleanup()
248 main.exit()
249
kelvin-onlab338f5512015-02-06 10:53:16 -0800250 def log( self, cmdStr , level = "" ):
kelvin-onlab9f541032015-02-04 16:19:53 -0800251 """
252 log the commands in the onos CLI.
kelvin-onlab338f5512015-02-06 10:53:16 -0800253 returns main.TRUE on success
254 returns main.FALSE if Error occured
255 Available level: DEBUG, TRACE, INFO, WARN, ERROR
256 Level defaults to INFO
kelvin-onlab9f541032015-02-04 16:19:53 -0800257 """
258 try:
kelvin-onlab338f5512015-02-06 10:53:16 -0800259 lvlStr = ""
260 if level:
261 lvlStr = "--level=" + level
262
kelvin-onlab9f541032015-02-04 16:19:53 -0800263 self.handle.sendline( "" )
264 self.handle.expect( "onos>" )
kelvin-onlab338f5512015-02-06 10:53:16 -0800265 self.handle.sendline( "log:log " + lvlStr + " " + cmdStr )
kelvin-onlab9f541032015-02-04 16:19:53 -0800266 self.handle.expect( "onos>" )
kelvin-onlabfb521662015-02-27 09:52:40 -0800267
kelvin-onlab9f541032015-02-04 16:19:53 -0800268 response = self.handle.before
269 if re.search( "Error", response ):
270 return main.FALSE
271 return main.TRUE
272
273 except pexpect.EOF:
274 main.log.error( self.name + ": EOF exception found" )
275 main.log.error( self.name + ": " + self.handle.before )
276 main.cleanup()
277 main.exit()
278 except:
kelvin-onlabfb521662015-02-27 09:52:40 -0800279 main.log.exception( self.name + ": Uncaught exception!" )
kelvin-onlab9f541032015-02-04 16:19:53 -0800280 main.cleanup()
281 main.exit()
282
kelvin-onlabd3b64892015-01-20 13:26:24 -0800283 def sendline( self, cmdStr ):
kelvin8ec71442015-01-15 16:57:00 -0800284 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800285 Send a completely user specified string to
286 the onos> prompt. Use this function if you have
andrewonlaba18f6bf2014-10-13 19:31:54 -0400287 a very specific command to send.
Jon Halle3f39ff2015-01-13 11:50:53 -0800288
andrewonlaba18f6bf2014-10-13 19:31:54 -0400289 Warning: There are no sanity checking to commands
290 sent using this method.
kelvin8ec71442015-01-15 16:57:00 -0800291 """
andrewonlaba18f6bf2014-10-13 19:31:54 -0400292 try:
kelvin-onlab338f5512015-02-06 10:53:16 -0800293 logStr = "\"Sending CLI command: '" + cmdStr + "'\""
294 self.log( logStr )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800295 self.handle.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -0800296 self.handle.expect( "onos>" )
Jon Hallaea67aa2015-01-23 13:30:57 -0800297 main.log.info( "Command '" + str( cmdStr ) + "' sent to "
298 + self.name + "." )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400299 handle = self.handle.before
Jon Hall7bdfc122015-01-23 11:45:32 -0800300 # Remove control strings from output
301 ansiEscape = re.compile( r'\x1b[^m]*m' )
302 handle = ansiEscape.sub( '', handle )
kelvin-onlabfb521662015-02-27 09:52:40 -0800303 # Remove extra return chars that get added
Jon Hallaea67aa2015-01-23 13:30:57 -0800304 handle = re.sub( r"\s\r", "", handle )
305 handle = handle.strip()
Jon Hall7bdfc122015-01-23 11:45:32 -0800306 # parse for just the output, remove the cmd from handle
307 output = handle.split( cmdStr, 1 )[1]
Jon Hall7bdfc122015-01-23 11:45:32 -0800308 return output
Jon Halld4d4b372015-01-28 16:02:41 -0800309 except TypeError:
310 main.log.exception( self.name + ": Object not as expected" )
311 return None
andrewonlaba18f6bf2014-10-13 19:31:54 -0400312 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800313 main.log.error( self.name + ": EOF exception found" )
314 main.log.error( self.name + ": " + self.handle.before )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400315 main.cleanup()
316 main.exit()
317 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800318 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlaba18f6bf2014-10-13 19:31:54 -0400319 main.cleanup()
320 main.exit()
321
kelvin8ec71442015-01-15 16:57:00 -0800322 # IMPORTANT NOTE:
323 # For all cli commands, naming convention should match
kelvin-onlabd3b64892015-01-20 13:26:24 -0800324 # the cli command changing 'a:b' with 'aB'.
325 # Ex ) onos:topology > onosTopology
326 # onos:links > onosLinks
327 # feature:list > featureList
Jon Halle3f39ff2015-01-13 11:50:53 -0800328
kelvin-onlabd3b64892015-01-20 13:26:24 -0800329 def addNode( self, nodeId, ONOSIp, tcpPort="" ):
kelvin8ec71442015-01-15 16:57:00 -0800330 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400331 Adds a new cluster node by ID and address information.
332 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800333 * nodeId
334 * ONOSIp
andrewonlabc2d05aa2014-10-13 16:51:10 -0400335 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800336 * tcpPort
kelvin8ec71442015-01-15 16:57:00 -0800337 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400338 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800339 cmdStr = "add-node " + str( nodeId ) + " " +\
340 str( ONOSIp ) + " " + str( tcpPort )
341 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800342 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800343 main.log.error( "Error in adding node" )
344 main.log.error( handle )
Jon Halle3f39ff2015-01-13 11:50:53 -0800345 return main.FALSE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400346 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800347 main.log.info( "Node " + str( ONOSIp ) + " added" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400348 return main.TRUE
Jon Halld4d4b372015-01-28 16:02:41 -0800349 except TypeError:
350 main.log.exception( self.name + ": Object not as expected" )
351 return None
andrewonlabc2d05aa2014-10-13 16:51:10 -0400352 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800353 main.log.error( self.name + ": EOF exception found" )
354 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400355 main.cleanup()
356 main.exit()
357 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800358 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400359 main.cleanup()
360 main.exit()
361
kelvin-onlabd3b64892015-01-20 13:26:24 -0800362 def removeNode( self, nodeId ):
kelvin8ec71442015-01-15 16:57:00 -0800363 """
andrewonlab86dc3082014-10-13 18:18:38 -0400364 Removes a cluster by ID
365 Issues command: 'remove-node [<node-id>]'
366 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800367 * nodeId
kelvin8ec71442015-01-15 16:57:00 -0800368 """
andrewonlab86dc3082014-10-13 18:18:38 -0400369 try:
andrewonlab86dc3082014-10-13 18:18:38 -0400370
kelvin-onlabd3b64892015-01-20 13:26:24 -0800371 cmdStr = "remove-node " + str( nodeId )
372 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800373 # TODO: add error checking. Does ONOS give any errors?
andrewonlab86dc3082014-10-13 18:18:38 -0400374
375 return main.TRUE
Jon Halle3f39ff2015-01-13 11:50:53 -0800376
Jon Halld4d4b372015-01-28 16:02:41 -0800377 except TypeError:
378 main.log.exception( self.name + ": Object not as expected" )
379 return None
andrewonlab86dc3082014-10-13 18:18:38 -0400380 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800381 main.log.error( self.name + ": EOF exception found" )
382 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400383 main.cleanup()
384 main.exit()
385 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800386 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab86dc3082014-10-13 18:18:38 -0400387 main.cleanup()
388 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400389
kelvin8ec71442015-01-15 16:57:00 -0800390 def nodes( self ):
391 """
andrewonlab7c211572014-10-15 16:45:20 -0400392 List the nodes currently visible
393 Issues command: 'nodes'
394 Returns: entire handle of list of nodes
kelvin8ec71442015-01-15 16:57:00 -0800395 """
andrewonlab7c211572014-10-15 16:45:20 -0400396 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800397 cmdStr = "nodes"
398 handle = self.sendline( cmdStr )
andrewonlab7c211572014-10-15 16:45:20 -0400399 return handle
Jon Halld4d4b372015-01-28 16:02:41 -0800400 except TypeError:
401 main.log.exception( self.name + ": Object not as expected" )
402 return None
andrewonlab7c211572014-10-15 16:45:20 -0400403 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800404 main.log.error( self.name + ": EOF exception found" )
405 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400406 main.cleanup()
407 main.exit()
408 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800409 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab7c211572014-10-15 16:45:20 -0400410 main.cleanup()
411 main.exit()
412
kelvin8ec71442015-01-15 16:57:00 -0800413 def topology( self ):
414 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400415 Shows the current state of the topology
416 by issusing command: 'onos> onos:topology'
kelvin8ec71442015-01-15 16:57:00 -0800417 """
andrewonlab95ce8322014-10-13 14:12:04 -0400418 try:
Jon Halle3f39ff2015-01-13 11:50:53 -0800419 # either onos:topology or 'topology' will work in CLI
kelvin-onlabd3b64892015-01-20 13:26:24 -0800420 cmdStr = "onos:topology"
421 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800422 main.log.info( "onos:topology returned: " + str( handle ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400423 return handle
Jon Halld4d4b372015-01-28 16:02:41 -0800424 except TypeError:
425 main.log.exception( self.name + ": Object not as expected" )
426 return None
andrewonlab95ce8322014-10-13 14:12:04 -0400427 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800428 main.log.error( self.name + ": EOF exception found" )
429 main.log.error( self.name + ": " + self.handle.before )
andrewonlab95ce8322014-10-13 14:12:04 -0400430 main.cleanup()
431 main.exit()
432 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800433 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab95ce8322014-10-13 14:12:04 -0400434 main.cleanup()
435 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800436
kelvin-onlabd3b64892015-01-20 13:26:24 -0800437 def featureInstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800438 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800439 Installs a specified feature
andrewonlabc2d05aa2014-10-13 16:51:10 -0400440 by issuing command: 'onos> feature:install <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800441 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400442 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800443 cmdStr = "feature:install " + str( featureStr )
444 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800445 # TODO: Check for possible error responses from karaf
andrewonlabc2d05aa2014-10-13 16:51:10 -0400446 return main.TRUE
Jon Halld4d4b372015-01-28 16:02:41 -0800447 except TypeError:
448 main.log.exception( self.name + ": Object not as expected" )
449 return None
andrewonlabc2d05aa2014-10-13 16:51:10 -0400450 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800451 main.log.error( self.name + ": EOF exception found" )
452 main.log.error( self.name + ": " + self.handle.before )
453 main.log.report( "Failed to install feature" )
454 main.log.report( "Exiting test" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400455 main.cleanup()
456 main.exit()
457 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800458 main.log.exception( self.name + ": Uncaught exception!" )
kelvin8ec71442015-01-15 16:57:00 -0800459 main.log.report( "Failed to install feature" )
460 main.log.report( "Exiting test" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400461 main.cleanup()
462 main.exit()
Jon Halle3f39ff2015-01-13 11:50:53 -0800463
kelvin-onlabd3b64892015-01-20 13:26:24 -0800464 def featureUninstall( self, featureStr ):
kelvin8ec71442015-01-15 16:57:00 -0800465 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400466 Uninstalls a specified feature
467 by issuing command: 'onos> feature:uninstall <feature_str>'
kelvin8ec71442015-01-15 16:57:00 -0800468 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400469 try:
Jon Hall30b82fa2015-03-04 17:15:43 -0800470 cmdStr = 'feature:list -i | grep "' + featureStr + '"'
471 handle = self.sendline( cmdStr )
472 if handle != '':
473 cmdStr = "feature:uninstall " + str( featureStr )
474 self.sendline( cmdStr )
475 # TODO: Check for possible error responses from karaf
476 else:
477 main.log.info( "Feature needs to be installed before uninstalling it" )
shahshreya280223a2015-02-26 12:25:25 -0800478 return main.TRUE
Jon Halld4d4b372015-01-28 16:02:41 -0800479 except TypeError:
480 main.log.exception( self.name + ": Object not as expected" )
481 return None
andrewonlabc2d05aa2014-10-13 16:51:10 -0400482 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800483 main.log.error( self.name + ": EOF exception found" )
484 main.log.error( self.name + ": " + self.handle.before )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400485 main.cleanup()
486 main.exit()
487 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800488 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400489 main.cleanup()
490 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800491
kelvin-onlabd3b64892015-01-20 13:26:24 -0800492 def devices( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800493 """
Jon Hall7b02d952014-10-17 20:14:54 -0400494 Lists all infrastructure devices or switches
andrewonlab86dc3082014-10-13 18:18:38 -0400495 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800496 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800497 """
andrewonlab86dc3082014-10-13 18:18:38 -0400498 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800499 if jsonFormat:
500 cmdStr = "devices -j"
501 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800502 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800503 handle variable here contains some ANSI escape color code
504 sequences at the end which are invisible in the print command
505 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800506 function. The repr( handle ) output when printed shows the
507 ANSI escape sequences. In json.loads( somestring ), this
508 somestring variable is actually repr( somestring ) and
Jon Halle3f39ff2015-01-13 11:50:53 -0800509 json.loads would fail with the escape sequence. So we take off
510 that escape sequence using:
511
kelvin-onlabd3b64892015-01-20 13:26:24 -0800512 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
513 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800514 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800515 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
516 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400517 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400518 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800519 cmdStr = "devices"
520 handle = self.sendline( cmdStr )
Jon Hallcd707292014-10-17 19:06:17 -0400521 return handle
Jon Halld4d4b372015-01-28 16:02:41 -0800522 except TypeError:
523 main.log.exception( self.name + ": Object not as expected" )
524 return None
andrewonlab7c211572014-10-15 16:45:20 -0400525 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800526 main.log.error( self.name + ": EOF exception found" )
527 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -0400528 main.cleanup()
529 main.exit()
530 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800531 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab7c211572014-10-15 16:45:20 -0400532 main.cleanup()
533 main.exit()
534
kelvin-onlabd3b64892015-01-20 13:26:24 -0800535 def balanceMasters( self ):
kelvin8ec71442015-01-15 16:57:00 -0800536 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800537 This balances the devices across all controllers
538 by issuing command: 'onos> onos:balance-masters'
539 If required this could be extended to return devices balanced output.
kelvin8ec71442015-01-15 16:57:00 -0800540 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800541 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800542 cmdStr = "onos:balance-masters"
543 self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800544 # TODO: Check for error responses from ONOS
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800545 return main.TRUE
Jon Halld4d4b372015-01-28 16:02:41 -0800546 except TypeError:
547 main.log.exception( self.name + ": Object not as expected" )
548 return None
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800549 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800550 main.log.error( self.name + ": EOF exception found" )
551 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800552 main.cleanup()
553 main.exit()
554 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800555 main.log.exception( self.name + ": Uncaught exception!" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800556 main.cleanup()
557 main.exit()
558
kelvin-onlabd3b64892015-01-20 13:26:24 -0800559 def links( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800560 """
Jon Halle8217482014-10-17 13:49:14 -0400561 Lists all core links
562 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800563 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800564 """
Jon Halle8217482014-10-17 13:49:14 -0400565 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800566 if jsonFormat:
567 cmdStr = "links -j"
568 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800569 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800570 handle variable here contains some ANSI escape color code
571 sequences at the end which are invisible in the print command
572 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800573 function. The repr( handle ) output when printed shows the ANSI
574 escape sequences. In json.loads( somestring ), this somestring
575 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800576 fail with the escape sequence. So we take off that escape
577 sequence using:
578
kelvin-onlabd3b64892015-01-20 13:26:24 -0800579 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
580 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800581 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800582 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
583 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400584 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400585 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800586 cmdStr = "links"
587 handle = self.sendline( cmdStr )
Jon Halla001c392014-10-17 18:50:59 -0400588 return handle
Jon Halld4d4b372015-01-28 16:02:41 -0800589 except TypeError:
590 main.log.exception( self.name + ": Object not as expected" )
591 return None
Jon Halle8217482014-10-17 13:49:14 -0400592 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800593 main.log.error( self.name + ": EOF exception found" )
594 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400595 main.cleanup()
596 main.exit()
597 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800598 main.log.exception( self.name + ": Uncaught exception!" )
Jon Halle8217482014-10-17 13:49:14 -0400599 main.cleanup()
600 main.exit()
601
kelvin-onlabd3b64892015-01-20 13:26:24 -0800602 def ports( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800603 """
Jon Halle8217482014-10-17 13:49:14 -0400604 Lists all ports
605 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800606 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800607 """
Jon Halle8217482014-10-17 13:49:14 -0400608 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800609 if jsonFormat:
610 cmdStr = "ports -j"
611 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800612 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800613 handle variable here contains some ANSI escape color code
614 sequences at the end which are invisible in the print command
615 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800616 function. The repr( handle ) output when printed shows the ANSI
617 escape sequences. In json.loads( somestring ), this somestring
618 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800619 fail with the escape sequence. So we take off that escape
620 sequence using the following commads:
621
kelvin-onlabd3b64892015-01-20 13:26:24 -0800622 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
623 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800624 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800625 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
626 handle1 = ansiEscape.sub( '', handle )
Jon Halla001c392014-10-17 18:50:59 -0400627 return handle1
628
Jon Halle8217482014-10-17 13:49:14 -0400629 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800630 cmdStr = "ports"
631 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800632 return handle
Jon Halld4d4b372015-01-28 16:02:41 -0800633 except TypeError:
634 main.log.exception( self.name + ": Object not as expected" )
635 return None
Jon Halle8217482014-10-17 13:49:14 -0400636 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800637 main.log.error( self.name + ": EOF exception found" )
638 main.log.error( self.name + ": " + self.handle.before )
Jon Halle8217482014-10-17 13:49:14 -0400639 main.cleanup()
640 main.exit()
641 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800642 main.log.exception( self.name + ": Uncaught exception!" )
Jon Halle8217482014-10-17 13:49:14 -0400643 main.cleanup()
644 main.exit()
645
kelvin-onlabd3b64892015-01-20 13:26:24 -0800646 def roles( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800647 """
Jon Hall983a1702014-10-28 18:44:22 -0400648 Lists all devices and the controllers with roles assigned to them
649 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800650 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800651 """
andrewonlab7c211572014-10-15 16:45:20 -0400652 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800653 if jsonFormat:
654 cmdStr = "roles -j"
655 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800656 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800657 handle variable here contains some ANSI escape color code
658 sequences at the end which are invisible in the print command
659 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800660 function. The repr( handle ) output when printed shows the ANSI
661 escape sequences. In json.loads( somestring ), this somestring
662 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800663 fail with the escape sequence.
Jon Hallb1290e82014-11-18 16:17:48 -0500664
Jon Halle3f39ff2015-01-13 11:50:53 -0800665 So we take off that escape sequence using the following
666 commads:
667
kelvin-onlabd3b64892015-01-20 13:26:24 -0800668 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
669 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800670 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800671 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
672 handle1 = ansiEscape.sub( '', handle )
Jon Hall983a1702014-10-28 18:44:22 -0400673 return handle1
andrewonlab7c211572014-10-15 16:45:20 -0400674
andrewonlab7c211572014-10-15 16:45:20 -0400675 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800676 cmdStr = "roles"
677 handle = self.sendline( cmdStr )
Jon Hallffb386d2014-11-21 13:43:38 -0800678 return handle
Jon Halld4d4b372015-01-28 16:02:41 -0800679 except TypeError:
680 main.log.exception( self.name + ": Object not as expected" )
681 return None
Jon Hall983a1702014-10-28 18:44:22 -0400682 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800683 main.log.error( self.name + ": EOF exception found" )
684 main.log.error( self.name + ": " + self.handle.before )
Jon Hall983a1702014-10-28 18:44:22 -0400685 main.cleanup()
686 main.exit()
687 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800688 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall983a1702014-10-28 18:44:22 -0400689 main.cleanup()
690 main.exit()
691
kelvin-onlabd3b64892015-01-20 13:26:24 -0800692 def getRole( self, deviceId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -0800693 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800694 Given the a string containing the json representation of the "roles"
695 cli command and a partial or whole device id, returns a json object
696 containing the roles output for the first device whose id contains
697 "device_id"
Jon Hall983a1702014-10-28 18:44:22 -0400698
699 Returns:
Jon Halle3f39ff2015-01-13 11:50:53 -0800700 A dict of the role assignments for the given device or
701 None if no match
kelvin8ec71442015-01-15 16:57:00 -0800702 """
Jon Hall983a1702014-10-28 18:44:22 -0400703 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800704 if deviceId is None:
Jon Hall983a1702014-10-28 18:44:22 -0400705 return None
706 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800707 rawRoles = self.roles()
708 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800709 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800710 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800711 # print device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800712 if str( deviceId ) in device[ 'id' ]:
Jon Hall983a1702014-10-28 18:44:22 -0400713 return device
714 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800715 except TypeError:
716 main.log.exception( self.name + ": Object not as expected" )
717 return None
andrewonlab86dc3082014-10-13 18:18:38 -0400718 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800719 main.log.error( self.name + ": EOF exception found" )
720 main.log.error( self.name + ": " + self.handle.before )
andrewonlab86dc3082014-10-13 18:18:38 -0400721 main.cleanup()
722 main.exit()
723 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800724 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab86dc3082014-10-13 18:18:38 -0400725 main.cleanup()
726 main.exit()
Jon Hall94fd0472014-12-08 11:52:42 -0800727
kelvin-onlabd3b64892015-01-20 13:26:24 -0800728 def rolesNotNull( self ):
kelvin8ec71442015-01-15 16:57:00 -0800729 """
Jon Hall94fd0472014-12-08 11:52:42 -0800730 Iterates through each device and checks if there is a master assigned
731 Returns: main.TRUE if each device has a master
732 main.FALSE any device has no master
kelvin8ec71442015-01-15 16:57:00 -0800733 """
Jon Hall94fd0472014-12-08 11:52:42 -0800734 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800735 rawRoles = self.roles()
736 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800737 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800738 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800739 # print device
740 if device[ 'master' ] == "none":
741 main.log.warn( "Device has no master: " + str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800742 return main.FALSE
743 return main.TRUE
744
Jon Halld4d4b372015-01-28 16:02:41 -0800745 except TypeError:
746 main.log.exception( self.name + ": Object not as expected" )
747 return None
Jon Hall94fd0472014-12-08 11:52:42 -0800748 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800749 main.log.error( self.name + ": EOF exception found" )
750 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -0800751 main.cleanup()
752 main.exit()
753 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800754 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall94fd0472014-12-08 11:52:42 -0800755 main.cleanup()
756 main.exit()
757
kelvin-onlabd3b64892015-01-20 13:26:24 -0800758 def paths( self, srcId, dstId ):
kelvin8ec71442015-01-15 16:57:00 -0800759 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400760 Returns string of paths, and the cost.
761 Issues command: onos:paths <src> <dst>
kelvin8ec71442015-01-15 16:57:00 -0800762 """
andrewonlab3e15ead2014-10-15 14:21:34 -0400763 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800764 cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId )
765 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -0800766 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800767 main.log.error( "Error in getting paths" )
768 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400769 else:
kelvin8ec71442015-01-15 16:57:00 -0800770 path = handle.split( ";" )[ 0 ]
771 cost = handle.split( ";" )[ 1 ]
772 return ( path, cost )
Jon Halld4d4b372015-01-28 16:02:41 -0800773 except TypeError:
774 main.log.exception( self.name + ": Object not as expected" )
775 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400776 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800777 main.log.error( self.name + ": EOF exception found" )
778 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3e15ead2014-10-15 14:21:34 -0400779 main.cleanup()
780 main.exit()
781 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800782 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab3e15ead2014-10-15 14:21:34 -0400783 main.cleanup()
784 main.exit()
Jon Hallffb386d2014-11-21 13:43:38 -0800785
kelvin-onlabd3b64892015-01-20 13:26:24 -0800786 def hosts( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800787 """
Jon Hallffb386d2014-11-21 13:43:38 -0800788 Lists all discovered hosts
Jon Hall42db6dc2014-10-24 19:03:48 -0400789 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800790 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800791 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400792 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800793 if jsonFormat:
794 cmdStr = "hosts -j"
795 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800796 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800797 handle variable here contains some ANSI escape color code
798 sequences at the end which are invisible in the print command
799 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -0800800 function. The repr( handle ) output when printed shows the ANSI
801 escape sequences. In json.loads( somestring ), this somestring
802 variable is actually repr( somestring ) and json.loads would
Jon Halle3f39ff2015-01-13 11:50:53 -0800803 fail with the escape sequence. So we take off that escape
804 sequence using:
805
kelvin-onlabd3b64892015-01-20 13:26:24 -0800806 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
807 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800808 """
kelvin-onlabd3b64892015-01-20 13:26:24 -0800809 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
810 handle1 = ansiEscape.sub( '', handle )
Jon Hall42db6dc2014-10-24 19:03:48 -0400811 return handle1
812 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800813 cmdStr = "hosts"
814 handle = self.sendline( cmdStr )
Jon Hall42db6dc2014-10-24 19:03:48 -0400815 return handle
Jon Halld4d4b372015-01-28 16:02:41 -0800816 except TypeError:
817 main.log.exception( self.name + ": Object not as expected" )
818 return None
Jon Hall42db6dc2014-10-24 19:03:48 -0400819 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800820 main.log.error( self.name + ": EOF exception found" )
821 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400822 main.cleanup()
823 main.exit()
824 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800825 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400826 main.cleanup()
827 main.exit()
828
kelvin-onlabd3b64892015-01-20 13:26:24 -0800829 def getHost( self, mac ):
kelvin8ec71442015-01-15 16:57:00 -0800830 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400831 Return the first host from the hosts api whose 'id' contains 'mac'
Jon Halle3f39ff2015-01-13 11:50:53 -0800832
833 Note: mac must be a colon seperated mac address, but could be a
834 partial mac address
835
Jon Hall42db6dc2014-10-24 19:03:48 -0400836 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -0800837 """
Jon Hall42db6dc2014-10-24 19:03:48 -0400838 try:
kelvin8ec71442015-01-15 16:57:00 -0800839 if mac is None:
Jon Hall42db6dc2014-10-24 19:03:48 -0400840 return None
841 else:
842 mac = mac
kelvin-onlabd3b64892015-01-20 13:26:24 -0800843 rawHosts = self.hosts()
844 hostsJson = json.loads( rawHosts )
kelvin8ec71442015-01-15 16:57:00 -0800845 # search json for the host with mac then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800846 for host in hostsJson:
kelvin8ec71442015-01-15 16:57:00 -0800847 # print "%s in %s?" % ( mac, host[ 'id' ] )
Jon Halld4d4b372015-01-28 16:02:41 -0800848 if not host:
849 pass
850 elif mac in host[ 'id' ]:
Jon Hall42db6dc2014-10-24 19:03:48 -0400851 return host
852 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800853 except TypeError:
854 main.log.exception( self.name + ": Object not as expected" )
855 return None
Jon Hall42db6dc2014-10-24 19:03:48 -0400856 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800857 main.log.error( self.name + ": EOF exception found" )
858 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -0400859 main.cleanup()
860 main.exit()
861 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800862 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall42db6dc2014-10-24 19:03:48 -0400863 main.cleanup()
864 main.exit()
865
kelvin-onlabd3b64892015-01-20 13:26:24 -0800866 def getHostsId( self, hostList ):
kelvin8ec71442015-01-15 16:57:00 -0800867 """
868 Obtain list of hosts
andrewonlab3f0a4af2014-10-17 12:25:14 -0400869 Issues command: 'onos> hosts'
kelvin8ec71442015-01-15 16:57:00 -0800870
andrewonlab3f0a4af2014-10-17 12:25:14 -0400871 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800872 * hostList: List of hosts obtained by Mininet
andrewonlab3f0a4af2014-10-17 12:25:14 -0400873 IMPORTANT:
874 This function assumes that you started your
kelvin8ec71442015-01-15 16:57:00 -0800875 topology with the option '--mac'.
andrewonlab3f0a4af2014-10-17 12:25:14 -0400876 Furthermore, it assumes that value of VLAN is '-1'
877 Description:
kelvin8ec71442015-01-15 16:57:00 -0800878 Converts mininet hosts ( h1, h2, h3... ) into
879 ONOS format ( 00:00:00:00:00:01/-1 , ... )
880 """
andrewonlab3f0a4af2014-10-17 12:25:14 -0400881 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800882 onosHostList = []
andrewonlab3f0a4af2014-10-17 12:25:14 -0400883
kelvin-onlabd3b64892015-01-20 13:26:24 -0800884 for host in hostList:
kelvin8ec71442015-01-15 16:57:00 -0800885 host = host.replace( "h", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800886 hostHex = hex( int( host ) ).zfill( 12 )
887 hostHex = str( hostHex ).replace( 'x', '0' )
888 i = iter( str( hostHex ) )
889 hostHex = ":".join( a + b for a, b in zip( i, i ) )
890 hostHex = hostHex + "/-1"
891 onosHostList.append( hostHex )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400892
kelvin-onlabd3b64892015-01-20 13:26:24 -0800893 return onosHostList
andrewonlab3f0a4af2014-10-17 12:25:14 -0400894
Jon Halld4d4b372015-01-28 16:02:41 -0800895 except TypeError:
896 main.log.exception( self.name + ": Object not as expected" )
897 return None
andrewonlab3f0a4af2014-10-17 12:25:14 -0400898 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800899 main.log.error( self.name + ": EOF exception found" )
900 main.log.error( self.name + ": " + self.handle.before )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400901 main.cleanup()
902 main.exit()
903 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800904 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab3f0a4af2014-10-17 12:25:14 -0400905 main.cleanup()
906 main.exit()
andrewonlab3e15ead2014-10-15 14:21:34 -0400907
kelvin-onlabd3b64892015-01-20 13:26:24 -0800908 def addHostIntent( self, hostIdOne, hostIdTwo ):
kelvin8ec71442015-01-15 16:57:00 -0800909 """
andrewonlabe6745342014-10-17 14:29:13 -0400910 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800911 * hostIdOne: ONOS host id for host1
912 * hostIdTwo: ONOS host id for host2
andrewonlabe6745342014-10-17 14:29:13 -0400913 Description:
kelvin8ec71442015-01-15 16:57:00 -0800914 Adds a host-to-host intent ( bidrectional ) by
Jon Hallb1290e82014-11-18 16:17:48 -0500915 specifying the two hosts.
kelvin-onlabfb521662015-02-27 09:52:40 -0800916 Returns:
917 A string of the intent id or None on Error
kelvin8ec71442015-01-15 16:57:00 -0800918 """
andrewonlabe6745342014-10-17 14:29:13 -0400919 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800920 cmdStr = "add-host-intent " + str( hostIdOne ) +\
921 " " + str( hostIdTwo )
922 handle = self.sendline( cmdStr )
Hari Krishnaac4e1782015-01-26 12:09:12 -0800923 if re.search( "Error", handle ):
924 main.log.error( "Error in adding Host intent" )
kelvin-onlabfb521662015-02-27 09:52:40 -0800925 return None
Hari Krishnaac4e1782015-01-26 12:09:12 -0800926 else:
927 main.log.info( "Host intent installed between " +
kelvin-onlabfb521662015-02-27 09:52:40 -0800928 str( hostIdOne ) + " and " + str( hostIdTwo ) )
929 match = re.search('id=0x([\da-f]+),', handle)
930 if match:
931 return match.group()[3:-1]
932 else:
933 main.log.error( "Error, intent ID not found" )
934 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800935 except TypeError:
936 main.log.exception( self.name + ": Object not as expected" )
937 return None
andrewonlabe6745342014-10-17 14:29:13 -0400938 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800939 main.log.error( self.name + ": EOF exception found" )
940 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -0400941 main.cleanup()
942 main.exit()
943 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800944 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabe6745342014-10-17 14:29:13 -0400945 main.cleanup()
946 main.exit()
947
kelvin-onlabd3b64892015-01-20 13:26:24 -0800948 def addOpticalIntent( self, ingressDevice, egressDevice ):
kelvin8ec71442015-01-15 16:57:00 -0800949 """
andrewonlab7b31d232014-10-24 13:31:47 -0400950 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800951 * ingressDevice: device id of ingress device
952 * egressDevice: device id of egress device
andrewonlab7b31d232014-10-24 13:31:47 -0400953 Optional:
954 TODO: Still needs to be implemented via dev side
kelvin-onlabfb521662015-02-27 09:52:40 -0800955 Description:
956 Adds an optical intent by specifying an ingress and egress device
957 Returns:
958 A string of the intent id or None on error
kelvin-onlab898a6c62015-01-16 14:13:53 -0800959 """
andrewonlab7b31d232014-10-24 13:31:47 -0400960 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800961 cmdStr = "add-optical-intent " + str( ingressDevice ) +\
962 " " + str( egressDevice )
963 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -0800964 # If error, return error message
Jon Halle3f39ff2015-01-13 11:50:53 -0800965 if re.search( "Error", handle ):
kelvin-onlabfb521662015-02-27 09:52:40 -0800966 main.log.error( "Error in adding Optical intent" )
967 return None
andrewonlab7b31d232014-10-24 13:31:47 -0400968 else:
kelvin-onlabfb521662015-02-27 09:52:40 -0800969 main.log.info( "Optical intent installed between " +
970 str( ingressDevice ) + " and " +
971 str( egressDevice ) )
972 match = re.search('id=0x([\da-f]+),', handle)
973 if match:
974 return match.group()[3:-1]
975 else:
976 main.log.error( "Error, intent ID not found" )
977 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800978 except TypeError:
979 main.log.exception( self.name + ": Object not as expected" )
980 return None
andrewonlab7b31d232014-10-24 13:31:47 -0400981 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800982 main.log.error( self.name + ": EOF exception found" )
983 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7b31d232014-10-24 13:31:47 -0400984 main.cleanup()
985 main.exit()
986 except:
Jon Halld4d4b372015-01-28 16:02:41 -0800987 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab7b31d232014-10-24 13:31:47 -0400988 main.cleanup()
989 main.exit()
990
kelvin-onlabd3b64892015-01-20 13:26:24 -0800991 def addPointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -0800992 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -0800993 ingressDevice,
994 egressDevice,
995 portIngress="",
996 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -0800997 ethType="",
998 ethSrc="",
999 ethDst="",
1000 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001001 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -08001002 ipProto="",
1003 ipSrc="",
1004 ipDst="",
1005 tcpSrc="",
1006 tcpDst="" ):
kelvin8ec71442015-01-15 16:57:00 -08001007 """
andrewonlab4dbb4d82014-10-17 18:22:31 -04001008 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001009 * ingressDevice: device id of ingress device
1010 * egressDevice: device id of egress device
andrewonlab289e4b72014-10-21 21:24:18 -04001011 Optional:
1012 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001013 * ethSrc: specify ethSrc ( i.e. src mac addr )
1014 * ethDst: specify ethDst ( i.e. dst mac addr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001015 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -08001016 * lambdaAlloc: if True, intent will allocate lambda
andrewonlab40ccd8b2014-11-06 16:23:34 -05001017 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001018 * ipProto: specify ip protocol
andrewonlabf77e0cb2014-11-11 17:17:59 -05001019 * ipSrc: specify ip source address
1020 * ipDst: specify ip destination address
1021 * tcpSrc: specify tcp source port
1022 * tcpDst: specify tcp destination port
andrewonlab4dbb4d82014-10-17 18:22:31 -04001023 Description:
kelvin8ec71442015-01-15 16:57:00 -08001024 Adds a point-to-point intent ( uni-directional ) by
andrewonlab289e4b72014-10-21 21:24:18 -04001025 specifying device id's and optional fields
kelvin-onlabfb521662015-02-27 09:52:40 -08001026 Returns:
1027 A string of the intent id or None on error
andrewonlab289e4b72014-10-21 21:24:18 -04001028
Jon Halle3f39ff2015-01-13 11:50:53 -08001029 NOTE: This function may change depending on the
andrewonlab4dbb4d82014-10-17 18:22:31 -04001030 options developers provide for point-to-point
1031 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001032 """
andrewonlab4dbb4d82014-10-17 18:22:31 -04001033 try:
andrewonlab289e4b72014-10-21 21:24:18 -04001034 cmd = ""
1035
kelvin8ec71442015-01-15 16:57:00 -08001036 # If there are no optional arguments
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001037 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001038 and not bandwidth and not lambdaAlloc \
andrewonlabfa4ff502014-11-11 16:41:30 -05001039 and not ipProto and not ipSrc and not ipDst \
1040 and not tcpSrc and not tcpDst:
andrewonlab36af3822014-11-18 17:48:18 -05001041 cmd = "add-point-intent"
andrewonlab36af3822014-11-18 17:48:18 -05001042
andrewonlab289e4b72014-10-21 21:24:18 -04001043 else:
andrewonlab36af3822014-11-18 17:48:18 -05001044 cmd = "add-point-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001045
andrewonlab0c0a6772014-10-22 12:31:18 -04001046 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001047 cmd += " --ethType " + str( ethType )
andrewonlab289e4b72014-10-21 21:24:18 -04001048 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -08001049 cmd += " --ethSrc " + str( ethSrc )
1050 if ethDst:
1051 cmd += " --ethDst " + str( ethDst )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001052 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001053 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001054 if lambdaAlloc:
andrewonlabfa4ff502014-11-11 16:41:30 -05001055 cmd += " --lambda "
1056 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001057 cmd += " --ipProto " + str( ipProto )
andrewonlabfa4ff502014-11-11 16:41:30 -05001058 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001059 cmd += " --ipSrc " + str( ipSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -05001060 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001061 cmd += " --ipDst " + str( ipDst )
andrewonlabfa4ff502014-11-11 16:41:30 -05001062 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001063 cmd += " --tcpSrc " + str( tcpSrc )
andrewonlabfa4ff502014-11-11 16:41:30 -05001064 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001065 cmd += " --tcpDst " + str( tcpDst )
andrewonlab289e4b72014-10-21 21:24:18 -04001066
kelvin8ec71442015-01-15 16:57:00 -08001067 # Check whether the user appended the port
1068 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -08001069 if "/" in ingressDevice:
1070 cmd += " " + str( ingressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001071 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001072 if not portIngress:
kelvin-onlabfb521662015-02-27 09:52:40 -08001073 main.log.error( "You must specify the ingress port" )
kelvin8ec71442015-01-15 16:57:00 -08001074 # TODO: perhaps more meaningful return
kelvin-onlabfb521662015-02-27 09:52:40 -08001075 # Would it make sense to throw an exception and exit
1076 # the test?
1077 return None
andrewonlab36af3822014-11-18 17:48:18 -05001078
kelvin8ec71442015-01-15 16:57:00 -08001079 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001080 str( ingressDevice ) + "/" +\
1081 str( portIngress ) + " "
andrewonlab36af3822014-11-18 17:48:18 -05001082
kelvin-onlabd3b64892015-01-20 13:26:24 -08001083 if "/" in egressDevice:
1084 cmd += " " + str( egressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001085 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001086 if not portEgress:
kelvin-onlabfb521662015-02-27 09:52:40 -08001087 main.log.error( "You must specify the egress port" )
1088 return None
Jon Halle3f39ff2015-01-13 11:50:53 -08001089
kelvin8ec71442015-01-15 16:57:00 -08001090 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001091 str( egressDevice ) + "/" +\
1092 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001093
kelvin-onlab898a6c62015-01-16 14:13:53 -08001094 handle = self.sendline( cmd )
kelvin-onlabfb521662015-02-27 09:52:40 -08001095 # If error, return error message
kelvin-onlab898a6c62015-01-16 14:13:53 -08001096 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001097 main.log.error( "Error in adding point-to-point intent" )
kelvin-onlabfb521662015-02-27 09:52:40 -08001098 return None
andrewonlab4dbb4d82014-10-17 18:22:31 -04001099 else:
kelvin-onlabfb521662015-02-27 09:52:40 -08001100 # TODO: print out all the options in this message?
1101 main.log.info( "Point-to-point intent installed between " +
1102 str( ingressDevice ) + " and " +
1103 str( egressDevice ) )
1104 match = re.search('id=0x([\da-f]+),', handle)
1105 if match:
1106 return match.group()[3:-1]
1107 else:
1108 main.log.error( "Error, intent ID not found" )
1109 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001110 except TypeError:
1111 main.log.exception( self.name + ": Object not as expected" )
1112 return None
andrewonlab4dbb4d82014-10-17 18:22:31 -04001113 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001114 main.log.error( self.name + ": EOF exception found" )
1115 main.log.error( self.name + ": " + self.handle.before )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001116 main.cleanup()
1117 main.exit()
1118 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001119 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab4dbb4d82014-10-17 18:22:31 -04001120 main.cleanup()
1121 main.exit()
1122
kelvin-onlabd3b64892015-01-20 13:26:24 -08001123 def addMultipointToSinglepointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -08001124 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -08001125 ingressDevice1,
1126 ingressDevice2,
1127 egressDevice,
kelvin-onlabfb521662015-02-27 09:52:40 -08001128 portIngress1="",
1129 portIngress2="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001130 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -08001131 ethType="",
1132 ethSrc="",
1133 ethDst="",
1134 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001135 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -08001136 ipProto="",
1137 ipSrc="",
1138 ipDst="",
1139 tcpSrc="",
1140 tcpDst="",
1141 setEthSrc="",
1142 setEthDst="" ):
kelvin8ec71442015-01-15 16:57:00 -08001143 """
shahshreyad0c80432014-12-04 16:56:05 -08001144 Note:
Jon Halle3f39ff2015-01-13 11:50:53 -08001145 This function assumes that there would be 2 ingress devices and
1146 one egress device. For more number of ingress devices, this
1147 function needs to be modified
shahshreyad0c80432014-12-04 16:56:05 -08001148 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001149 * ingressDevice1: device id of ingress device1
1150 * ingressDevice2: device id of ingress device2
1151 * egressDevice: device id of egress device
shahshreyad0c80432014-12-04 16:56:05 -08001152 Optional:
1153 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001154 * ethSrc: specify ethSrc ( i.e. src mac addr )
1155 * ethDst: specify ethDst ( i.e. dst mac addr )
shahshreyad0c80432014-12-04 16:56:05 -08001156 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -08001157 * lambdaAlloc: if True, intent will allocate lambda
shahshreyad0c80432014-12-04 16:56:05 -08001158 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001159 * ipProto: specify ip protocol
shahshreyad0c80432014-12-04 16:56:05 -08001160 * ipSrc: specify ip source address
1161 * ipDst: specify ip destination address
1162 * tcpSrc: specify tcp source port
1163 * tcpDst: specify tcp destination port
1164 * setEthSrc: action to Rewrite Source MAC Address
1165 * setEthDst: action to Rewrite Destination MAC Address
1166 Description:
kelvin8ec71442015-01-15 16:57:00 -08001167 Adds a multipoint-to-singlepoint intent ( uni-directional ) by
shahshreyad0c80432014-12-04 16:56:05 -08001168 specifying device id's and optional fields
kelvin-onlabfb521662015-02-27 09:52:40 -08001169 Returns:
1170 A string of the intent id or None on error
shahshreyad0c80432014-12-04 16:56:05 -08001171
Jon Halle3f39ff2015-01-13 11:50:53 -08001172 NOTE: This function may change depending on the
shahshreyad0c80432014-12-04 16:56:05 -08001173 options developers provide for multipointpoint-to-singlepoint
1174 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001175 """
shahshreyad0c80432014-12-04 16:56:05 -08001176 try:
1177 cmd = ""
1178
kelvin8ec71442015-01-15 16:57:00 -08001179 # If there are no optional arguments
shahshreyad0c80432014-12-04 16:56:05 -08001180 if not ethType and not ethSrc and not ethDst\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001181 and not bandwidth and not lambdaAlloc\
Jon Halle3f39ff2015-01-13 11:50:53 -08001182 and not ipProto and not ipSrc and not ipDst\
1183 and not tcpSrc and not tcpDst and not setEthSrc\
1184 and not setEthDst:
shahshreyad0c80432014-12-04 16:56:05 -08001185 cmd = "add-multi-to-single-intent"
shahshreyad0c80432014-12-04 16:56:05 -08001186
1187 else:
1188 cmd = "add-multi-to-single-intent"
Jon Halle3f39ff2015-01-13 11:50:53 -08001189
shahshreyad0c80432014-12-04 16:56:05 -08001190 if ethType:
kelvin8ec71442015-01-15 16:57:00 -08001191 cmd += " --ethType " + str( ethType )
shahshreyad0c80432014-12-04 16:56:05 -08001192 if ethSrc:
kelvin8ec71442015-01-15 16:57:00 -08001193 cmd += " --ethSrc " + str( ethSrc )
1194 if ethDst:
1195 cmd += " --ethDst " + str( ethDst )
shahshreyad0c80432014-12-04 16:56:05 -08001196 if bandwidth:
kelvin8ec71442015-01-15 16:57:00 -08001197 cmd += " --bandwidth " + str( bandwidth )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001198 if lambdaAlloc:
shahshreyad0c80432014-12-04 16:56:05 -08001199 cmd += " --lambda "
1200 if ipProto:
kelvin8ec71442015-01-15 16:57:00 -08001201 cmd += " --ipProto " + str( ipProto )
shahshreyad0c80432014-12-04 16:56:05 -08001202 if ipSrc:
kelvin8ec71442015-01-15 16:57:00 -08001203 cmd += " --ipSrc " + str( ipSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001204 if ipDst:
kelvin8ec71442015-01-15 16:57:00 -08001205 cmd += " --ipDst " + str( ipDst )
shahshreyad0c80432014-12-04 16:56:05 -08001206 if tcpSrc:
kelvin8ec71442015-01-15 16:57:00 -08001207 cmd += " --tcpSrc " + str( tcpSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001208 if tcpDst:
kelvin8ec71442015-01-15 16:57:00 -08001209 cmd += " --tcpDst " + str( tcpDst )
shahshreyad0c80432014-12-04 16:56:05 -08001210 if setEthSrc:
kelvin8ec71442015-01-15 16:57:00 -08001211 cmd += " --setEthSrc " + str( setEthSrc )
shahshreyad0c80432014-12-04 16:56:05 -08001212 if setEthDst:
kelvin8ec71442015-01-15 16:57:00 -08001213 cmd += " --setEthDst " + str( setEthDst )
shahshreyad0c80432014-12-04 16:56:05 -08001214
kelvin8ec71442015-01-15 16:57:00 -08001215 # Check whether the user appended the port
1216 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -08001217 if "/" in ingressDevice1:
1218 cmd += " " + str( ingressDevice1 )
shahshreyad0c80432014-12-04 16:56:05 -08001219 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001220 if not portIngress1:
kelvin8ec71442015-01-15 16:57:00 -08001221 main.log.error( "You must specify " +
1222 "the ingress port1" )
1223 # TODO: perhaps more meaningful return
kelvin-onlabfb521662015-02-27 09:52:40 -08001224 return None
shahshreyad0c80432014-12-04 16:56:05 -08001225
kelvin8ec71442015-01-15 16:57:00 -08001226 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001227 str( ingressDevice1 ) + "/" +\
1228 str( portIngress1 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001229
kelvin-onlabd3b64892015-01-20 13:26:24 -08001230 if "/" in ingressDevice2:
1231 cmd += " " + str( ingressDevice2 )
shahshreyad0c80432014-12-04 16:56:05 -08001232 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001233 if not portIngress2:
kelvin8ec71442015-01-15 16:57:00 -08001234 main.log.error( "You must specify " +
1235 "the ingress port2" )
1236 # TODO: perhaps more meaningful return
kelvin-onlabfb521662015-02-27 09:52:40 -08001237 return None
shahshreyad0c80432014-12-04 16:56:05 -08001238
kelvin8ec71442015-01-15 16:57:00 -08001239 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001240 str( ingressDevice2 ) + "/" +\
1241 str( portIngress2 ) + " "
shahshreyad0c80432014-12-04 16:56:05 -08001242
kelvin-onlabd3b64892015-01-20 13:26:24 -08001243 if "/" in egressDevice:
1244 cmd += " " + str( egressDevice )
shahshreyad0c80432014-12-04 16:56:05 -08001245 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001246 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001247 main.log.error( "You must specify " +
1248 "the egress port" )
shahshreyad0c80432014-12-04 16:56:05 -08001249 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001250
kelvin8ec71442015-01-15 16:57:00 -08001251 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001252 str( egressDevice ) + "/" +\
1253 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001254 print "cmd= ", cmd
kelvin-onlab898a6c62015-01-16 14:13:53 -08001255 handle = self.sendline( cmd )
kelvin-onlabfb521662015-02-27 09:52:40 -08001256 # If error, return error message
kelvin-onlab898a6c62015-01-16 14:13:53 -08001257 if re.search( "Error", handle ):
kelvin-onlabfb521662015-02-27 09:52:40 -08001258 main.log.error( "Error in adding multipoint-to-singlepoint " +
1259 "intent" )
1260 return None
shahshreyad0c80432014-12-04 16:56:05 -08001261 else:
kelvin-onlabfb521662015-02-27 09:52:40 -08001262 # TODO: print out all the options in this message?
1263 main.log.info( "Multipoint-to-singlepoint intent installed" +
1264 " between " + str( ingressDevice1 ) + ", " +
1265 str( ingressDevice2 ) + " and " +
1266 str( egressDevice ) )
1267 match = re.search('id=0x([\da-f]+),', handle)
1268 if match:
1269 return match.group()[3:-1]
1270 else:
1271 main.log.error( "Error, intent ID not found" )
1272 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001273 except TypeError:
1274 main.log.exception( self.name + ": Object not as expected" )
1275 return None
shahshreyad0c80432014-12-04 16:56:05 -08001276 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001277 main.log.error( self.name + ": EOF exception found" )
1278 main.log.error( self.name + ": " + self.handle.before )
shahshreyad0c80432014-12-04 16:56:05 -08001279 main.cleanup()
1280 main.exit()
1281 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001282 main.log.exception( self.name + ": Uncaught exception!" )
shahshreyad0c80432014-12-04 16:56:05 -08001283 main.cleanup()
1284 main.exit()
1285
shahshreya1c818fc2015-02-26 13:44:08 -08001286 def removeIntent( self, intentId, app = 'org.onosproject.cli',
1287 purge = False, sync = False ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001288 """
shahshreya1c818fc2015-02-26 13:44:08 -08001289 Remove intent for specified application id and intent id
1290 Optional args:-
1291 -s or --sync: Waits for the removal before returning
1292 -p or --purge: Purge the intent from the store after removal
1293
Jon Halle3f39ff2015-01-13 11:50:53 -08001294 Returns:
1295 main.False on error and
1296 cli output otherwise
kelvin-onlab898a6c62015-01-16 14:13:53 -08001297 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001298 try:
shahshreya1c818fc2015-02-26 13:44:08 -08001299 cmdStr = "remove-intent "
1300 if purge:
1301 cmdStr += " -p"
1302 if sync:
1303 cmdStr += " -s"
1304
1305 cmdStr += " " + app + " " + str( intentId )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001306 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001307 if re.search( "Error", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001308 main.log.error( "Error in removing intent" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001309 return main.FALSE
andrewonlab9a50dfe2014-10-17 17:22:31 -04001310 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001311 # TODO: Should this be main.TRUE
1312 return handle
Jon Halld4d4b372015-01-28 16:02:41 -08001313 except TypeError:
1314 main.log.exception( self.name + ": Object not as expected" )
1315 return None
andrewonlab9a50dfe2014-10-17 17:22:31 -04001316 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001317 main.log.error( self.name + ": EOF exception found" )
1318 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001319 main.cleanup()
1320 main.exit()
1321 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001322 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001323 main.cleanup()
1324 main.exit()
1325
kelvin-onlabd3b64892015-01-20 13:26:24 -08001326 def routes( self, jsonFormat=False ):
kelvin8ec71442015-01-15 16:57:00 -08001327 """
kelvin-onlab898a6c62015-01-16 14:13:53 -08001328 NOTE: This method should be used after installing application:
1329 onos-app-sdnip
pingping-lin8b306ac2014-11-17 18:13:51 -08001330 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001331 * jsonFormat: enable output formatting in json
pingping-lin8b306ac2014-11-17 18:13:51 -08001332 Description:
1333 Obtain all routes in the system
kelvin8ec71442015-01-15 16:57:00 -08001334 """
pingping-lin8b306ac2014-11-17 18:13:51 -08001335 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001336 if jsonFormat:
1337 cmdStr = "routes -j"
1338 handleTmp = self.sendline( cmdStr )
1339 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1340 handle = ansiEscape.sub( '', handleTmp )
pingping-lin8b306ac2014-11-17 18:13:51 -08001341 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001342 cmdStr = "routes"
1343 handle = self.sendline( cmdStr )
pingping-lin8b306ac2014-11-17 18:13:51 -08001344 return handle
Jon Halld4d4b372015-01-28 16:02:41 -08001345 except TypeError:
1346 main.log.exception( self.name + ": Object not as expected" )
1347 return None
pingping-lin8b306ac2014-11-17 18:13:51 -08001348 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001349 main.log.error( self.name + ": EOF exception found" )
1350 main.log.error( self.name + ": " + self.handle.before )
pingping-lin8b306ac2014-11-17 18:13:51 -08001351 main.cleanup()
1352 main.exit()
1353 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001354 main.log.exception( self.name + ": Uncaught exception!" )
pingping-lin8b306ac2014-11-17 18:13:51 -08001355 main.cleanup()
1356 main.exit()
1357
kelvin-onlabd3b64892015-01-20 13:26:24 -08001358 def intents( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001359 """
andrewonlab377693f2014-10-21 16:00:30 -04001360 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001361 * jsonFormat: enable output formatting in json
andrewonlabe6745342014-10-17 14:29:13 -04001362 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001363 Obtain intents currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001364 """
andrewonlabe6745342014-10-17 14:29:13 -04001365 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001366 if jsonFormat:
1367 cmdStr = "intents -j"
1368 handle = self.sendline( cmdStr )
1369 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1370 handle = ansiEscape.sub( '', handle )
kelvin8ec71442015-01-15 16:57:00 -08001371 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001372 cmdStr = "intents"
1373 handle = self.sendline( cmdStr )
andrewonlabe6745342014-10-17 14:29:13 -04001374 return handle
Jon Halld4d4b372015-01-28 16:02:41 -08001375 except TypeError:
1376 main.log.exception( self.name + ": Object not as expected" )
1377 return None
andrewonlabe6745342014-10-17 14:29:13 -04001378 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001379 main.log.error( self.name + ": EOF exception found" )
1380 main.log.error( self.name + ": " + self.handle.before )
andrewonlabe6745342014-10-17 14:29:13 -04001381 main.cleanup()
1382 main.exit()
1383 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001384 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlabe6745342014-10-17 14:29:13 -04001385 main.cleanup()
1386 main.exit()
1387
kelvin-onlab54400a92015-02-26 18:05:51 -08001388 def getIntentState(self, intentsId, intentsJson=None):
1389 """
kelvin-onlab54400a92015-02-26 18:05:51 -08001390 Check intent state.
1391 Accepts a single intent ID (string type) or a list of intent IDs.
1392 Returns the state(string type) of the id if a single intent ID is
1393 accepted.
1394 Returns a dictionary with intent IDs as the key and its corresponding
1395 states as the values
kelvin-onlabfb521662015-02-27 09:52:40 -08001396 Parameters:
kelvin-onlab54400a92015-02-26 18:05:51 -08001397 intentId: intent ID (string type)
1398 intentsJson: parsed json object from the onos:intents api
1399 Returns:
1400 state = An intent's state- INSTALL,WITHDRAWN etc.
1401 stateDict = Dictionary of intent's state. intent ID as the keys and
1402 state as the values.
1403 """
kelvin-onlab54400a92015-02-26 18:05:51 -08001404 try:
1405 state = "State is Undefined"
1406 if not intentsJson:
1407 intentsJsonTemp = json.loads(self.intents())
1408 else:
1409 intentsJsonTemp = json.loads(intentsJson)
1410 if isinstance(intentsId,types.StringType):
1411 for intent in intentsJsonTemp:
1412 if intentsId == intent['id']:
1413 state = intent['state']
1414 return state
1415 main.log.info("Cannot find intent ID" + str(intentsId) +" on the list")
1416 return state
1417 elif isinstance(intentsId,types.ListType):
kelvin-onlab07dbd012015-03-04 16:29:39 -08001418 dictList = []
kelvin-onlab54400a92015-02-26 18:05:51 -08001419 for ID in intentsId:
kelvin-onlab07dbd012015-03-04 16:29:39 -08001420 stateDict = {}
kelvin-onlab54400a92015-02-26 18:05:51 -08001421 for intents in intentsJsonTemp:
1422 if ID == intents['id']:
kelvin-onlab07dbd012015-03-04 16:29:39 -08001423 stateDict['state'] = intents['state']
1424 stateDict['id'] = ID
1425 dictList.append(stateDict)
kelvin-onlab54400a92015-02-26 18:05:51 -08001426 break
kelvin-onlab07dbd012015-03-04 16:29:39 -08001427 if len(intentsId) != len(dictList):
kelvin-onlab54400a92015-02-26 18:05:51 -08001428 main.log.info("Cannot find some of the intent ID state")
kelvin-onlab07dbd012015-03-04 16:29:39 -08001429 return dictList
kelvin-onlab54400a92015-02-26 18:05:51 -08001430 else:
1431 main.log.info("Invalid intents ID entry")
1432 return None
1433 main.log.info("Something went wrong getting intent ID state")
1434 return None
1435 except TypeError:
1436 main.log.exception( self.name + ": Object not as expected" )
1437 return None
1438 except pexpect.EOF:
1439 main.log.error( self.name + ": EOF exception found" )
1440 main.log.error( self.name + ": " + self.handle.before )
1441 main.cleanup()
1442 main.exit()
1443 except:
1444 main.log.exception( self.name + ": Uncaught exception!" )
1445 main.cleanup()
1446 main.exit()
Jon Hall30b82fa2015-03-04 17:15:43 -08001447
kelvin-onlabd3b64892015-01-20 13:26:24 -08001448 def flows( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001449 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001450 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001451 * jsonFormat: enable output formatting in json
Shreya Shah0f01c812014-10-26 20:15:28 -04001452 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001453 Obtain flows currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08001454 """
Shreya Shah0f01c812014-10-26 20:15:28 -04001455 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001456 if jsonFormat:
1457 cmdStr = "flows -j"
1458 handle = self.sendline( cmdStr )
1459 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1460 handle = ansiEscape.sub( '', handle )
Shreya Shah0f01c812014-10-26 20:15:28 -04001461 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001462 cmdStr = "flows"
1463 handle = self.sendline( cmdStr )
kelvin8ec71442015-01-15 16:57:00 -08001464 if re.search( "Error\sexecuting\scommand:", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001465 main.log.error( self.name + ".flows() response: " +
1466 str( handle ) )
Shreya Shah0f01c812014-10-26 20:15:28 -04001467 return handle
Jon Halld4d4b372015-01-28 16:02:41 -08001468 except TypeError:
1469 main.log.exception( self.name + ": Object not as expected" )
1470 return None
Shreya Shah0f01c812014-10-26 20:15:28 -04001471 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001472 main.log.error( self.name + ": EOF exception found" )
1473 main.log.error( self.name + ": " + self.handle.before )
Shreya Shah0f01c812014-10-26 20:15:28 -04001474 main.cleanup()
1475 main.exit()
1476 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001477 main.log.exception( self.name + ": Uncaught exception!" )
Shreya Shah0f01c812014-10-26 20:15:28 -04001478 main.cleanup()
1479 main.exit()
1480
kelvin-onlabd3b64892015-01-20 13:26:24 -08001481 def pushTestIntents( self, dpidSrc, dpidDst, numIntents,
1482 numMult="", appId="", report=True ):
kelvin8ec71442015-01-15 16:57:00 -08001483 """
andrewonlab87852b02014-11-19 18:44:19 -05001484 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08001485 Push a number of intents in a batch format to
andrewonlab87852b02014-11-19 18:44:19 -05001486 a specific point-to-point intent definition
1487 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001488 * dpidSrc: specify source dpid
1489 * dpidDst: specify destination dpid
1490 * numIntents: specify number of intents to push
andrewonlab87852b02014-11-19 18:44:19 -05001491 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001492 * numMult: number multiplier for multiplying
andrewonlabb66dfa12014-12-02 15:51:10 -05001493 the number of intents specified
kelvin-onlabd3b64892015-01-20 13:26:24 -08001494 * appId: specify the application id init to further
andrewonlabb66dfa12014-12-02 15:51:10 -05001495 modularize the intents
andrewonlab87852b02014-11-19 18:44:19 -05001496 * report: default True, returns latency information
kelvin8ec71442015-01-15 16:57:00 -08001497 """
andrewonlab87852b02014-11-19 18:44:19 -05001498 try:
kelvin8ec71442015-01-15 16:57:00 -08001499 cmd = "push-test-intents " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001500 str( dpidSrc ) + " " + str( dpidDst ) + " " +\
1501 str( numIntents )
1502 if numMult:
1503 cmd += " " + str( numMult )
1504 # If app id is specified, then numMult
kelvin8ec71442015-01-15 16:57:00 -08001505 # must exist because of the way this command
kelvin-onlabd3b64892015-01-20 13:26:24 -08001506 if appId:
1507 cmd += " " + str( appId )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001508 handle = self.sendline( cmd )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001509 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1510 handle = ansiEscape.sub( '', handle )
andrewonlab87852b02014-11-19 18:44:19 -05001511 if report:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001512 latResult = []
kelvin8ec71442015-01-15 16:57:00 -08001513 main.log.info( handle )
1514 # Split result by newline
1515 newline = handle.split( "\r\r\n" )
1516 # Ignore the first object of list, which is empty
1517 newline = newline[ 1: ]
1518 # Some sloppy parsing method to get the latency
andrewonlabb66dfa12014-12-02 15:51:10 -05001519 for result in newline:
kelvin8ec71442015-01-15 16:57:00 -08001520 result = result.split( ": " )
1521 # Append the first result of second parse
kelvin-onlabd3b64892015-01-20 13:26:24 -08001522 latResult.append( result[ 1 ].split( " " )[ 0 ] )
1523 main.log.info( latResult )
1524 return latResult
andrewonlab87852b02014-11-19 18:44:19 -05001525 else:
1526 return main.TRUE
Jon Halld4d4b372015-01-28 16:02:41 -08001527 except TypeError:
1528 main.log.exception( self.name + ": Object not as expected" )
1529 return None
andrewonlab87852b02014-11-19 18:44:19 -05001530 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001531 main.log.error( self.name + ": EOF exception found" )
1532 main.log.error( self.name + ": " + self.handle.before )
andrewonlab87852b02014-11-19 18:44:19 -05001533 main.cleanup()
1534 main.exit()
1535 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001536 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab87852b02014-11-19 18:44:19 -05001537 main.cleanup()
1538 main.exit()
1539
kelvin-onlabd3b64892015-01-20 13:26:24 -08001540 def intentsEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001541 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001542 Description:Returns topology metrics
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001543 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001544 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001545 """
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001546 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001547 if jsonFormat:
1548 cmdStr = "intents-events-metrics -j"
1549 handle = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001550 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001551 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1552 handle = ansiEscape.sub( '', handle )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001553 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001554 cmdStr = "intents-events-metrics"
1555 handle = self.sendline( cmdStr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001556 return handle
Jon Halld4d4b372015-01-28 16:02:41 -08001557 except TypeError:
1558 main.log.exception( self.name + ": Object not as expected" )
1559 return None
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001560 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001561 main.log.error( self.name + ": EOF exception found" )
1562 main.log.error( self.name + ": " + self.handle.before )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001563 main.cleanup()
1564 main.exit()
1565 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001566 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001567 main.cleanup()
1568 main.exit()
Shreya Shah0f01c812014-10-26 20:15:28 -04001569
kelvin-onlabd3b64892015-01-20 13:26:24 -08001570 def topologyEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001571 """
1572 Description:Returns topology metrics
andrewonlab867212a2014-10-22 20:13:38 -04001573 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001574 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08001575 """
andrewonlab867212a2014-10-22 20:13:38 -04001576 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001577 if jsonFormat:
1578 cmdStr = "topology-events-metrics -j"
1579 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001580 # Some color thing that we want to escape
kelvin-onlabd3b64892015-01-20 13:26:24 -08001581 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1582 handle = ansiEscape.sub( '', handle )
andrewonlab867212a2014-10-22 20:13:38 -04001583 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001584 cmdStr = "topology-events-metrics"
1585 handle = self.sendline( cmdStr )
andrewonlab867212a2014-10-22 20:13:38 -04001586 return handle
Jon Halld4d4b372015-01-28 16:02:41 -08001587 except TypeError:
1588 main.log.exception( self.name + ": Object not as expected" )
1589 return None
andrewonlab867212a2014-10-22 20:13:38 -04001590 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001591 main.log.error( self.name + ": EOF exception found" )
1592 main.log.error( self.name + ": " + self.handle.before )
andrewonlab867212a2014-10-22 20:13:38 -04001593 main.cleanup()
1594 main.exit()
1595 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001596 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab867212a2014-10-22 20:13:38 -04001597 main.cleanup()
1598 main.exit()
1599
kelvin8ec71442015-01-15 16:57:00 -08001600 # Wrapper functions ****************
1601 # Wrapper functions use existing driver
1602 # functions and extends their use case.
1603 # For example, we may use the output of
1604 # a normal driver function, and parse it
1605 # using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -04001606
kelvin-onlabd3b64892015-01-20 13:26:24 -08001607 def getAllIntentsId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001608 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001609 Description:
1610 Obtain all intent id's in a list
kelvin8ec71442015-01-15 16:57:00 -08001611 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001612 try:
kelvin8ec71442015-01-15 16:57:00 -08001613 # Obtain output of intents function
kelvin-onlabfb521662015-02-27 09:52:40 -08001614 intentsStr = self.intents(jsonFormat=False)
kelvin-onlabd3b64892015-01-20 13:26:24 -08001615 intentIdList = []
andrewonlab9a50dfe2014-10-17 17:22:31 -04001616
kelvin8ec71442015-01-15 16:57:00 -08001617 # Parse the intents output for ID's
kelvin-onlabd3b64892015-01-20 13:26:24 -08001618 intentsList = [ s.strip() for s in intentsStr.splitlines() ]
1619 for intents in intentsList:
kelvin-onlabfb521662015-02-27 09:52:40 -08001620 match = re.search('id=0x([\da-f]+),', intents)
1621 if match:
1622 tmpId = match.group()[3:-1]
1623 intentIdList.append( tmpId )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001624 return intentIdList
andrewonlab9a50dfe2014-10-17 17:22:31 -04001625
Jon Halld4d4b372015-01-28 16:02:41 -08001626 except TypeError:
1627 main.log.exception( self.name + ": Object not as expected" )
1628 return None
andrewonlab9a50dfe2014-10-17 17:22:31 -04001629 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001630 main.log.error( self.name + ": EOF exception found" )
1631 main.log.error( self.name + ": " + self.handle.before )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001632 main.cleanup()
1633 main.exit()
1634 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001635 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab9a50dfe2014-10-17 17:22:31 -04001636 main.cleanup()
1637 main.exit()
1638
Jon Hall30b82fa2015-03-04 17:15:43 -08001639 def FlowAddedCount( self, deviceId ):
1640 """
1641 Determine the number of flow rules for the given device id that are
1642 in the added state
1643 """
1644 try:
1645 cmdStr = "flows any " + str( deviceId ) + " | " +\
1646 "grep 'state=ADDED' | wc -l"
1647 handle = self.sendline( cmdStr )
1648 return handle
1649 except pexpect.EOF:
1650 main.log.error( self.name + ": EOF exception found" )
1651 main.log.error( self.name + ": " + self.handle.before )
1652 main.cleanup()
1653 main.exit()
1654 except:
1655 main.log.exception( self.name + ": Uncaught exception!" )
1656 main.cleanup()
1657 main.exit()
1658
kelvin-onlabd3b64892015-01-20 13:26:24 -08001659 def getAllDevicesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001660 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001661 Use 'devices' function to obtain list of all devices
1662 and parse the result to obtain a list of all device
1663 id's. Returns this list. Returns empty list if no
1664 devices exist
kelvin8ec71442015-01-15 16:57:00 -08001665 List is ordered sequentially
1666
andrewonlab3e15ead2014-10-15 14:21:34 -04001667 This function may be useful if you are not sure of the
kelvin8ec71442015-01-15 16:57:00 -08001668 device id, and wish to execute other commands using
andrewonlab3e15ead2014-10-15 14:21:34 -04001669 the ids. By obtaining the list of device ids on the fly,
1670 you can iterate through the list to get mastership, etc.
kelvin8ec71442015-01-15 16:57:00 -08001671 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04001672 try:
kelvin8ec71442015-01-15 16:57:00 -08001673 # Call devices and store result string
kelvin-onlabd3b64892015-01-20 13:26:24 -08001674 devicesStr = self.devices( jsonFormat=False )
1675 idList = []
kelvin8ec71442015-01-15 16:57:00 -08001676
kelvin-onlabd3b64892015-01-20 13:26:24 -08001677 if not devicesStr:
kelvin8ec71442015-01-15 16:57:00 -08001678 main.log.info( "There are no devices to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001679 return idList
kelvin8ec71442015-01-15 16:57:00 -08001680
1681 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001682 deviceList = devicesStr.split( "," )
kelvin8ec71442015-01-15 16:57:00 -08001683 # Get temporary list of all arguments with string 'id='
kelvin-onlabd3b64892015-01-20 13:26:24 -08001684 tempList = [ dev for dev in deviceList if "id=" in dev ]
kelvin8ec71442015-01-15 16:57:00 -08001685 # Split list further into arguments before and after string
1686 # 'id='. Get the latter portion ( the actual device id ) and
kelvin-onlabd3b64892015-01-20 13:26:24 -08001687 # append to idList
1688 for arg in tempList:
1689 idList.append( arg.split( "id=" )[ 1 ] )
1690 return idList
andrewonlab7e4d2d32014-10-15 13:23:21 -04001691
Jon Halld4d4b372015-01-28 16:02:41 -08001692 except TypeError:
1693 main.log.exception( self.name + ": Object not as expected" )
1694 return None
andrewonlab7e4d2d32014-10-15 13:23:21 -04001695 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001696 main.log.error( self.name + ": EOF exception found" )
1697 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001698 main.cleanup()
1699 main.exit()
1700 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001701 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab7e4d2d32014-10-15 13:23:21 -04001702 main.cleanup()
1703 main.exit()
1704
kelvin-onlabd3b64892015-01-20 13:26:24 -08001705 def getAllNodesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08001706 """
andrewonlab7c211572014-10-15 16:45:20 -04001707 Uses 'nodes' function to obtain list of all nodes
1708 and parse the result of nodes to obtain just the
kelvin8ec71442015-01-15 16:57:00 -08001709 node id's.
andrewonlab7c211572014-10-15 16:45:20 -04001710 Returns:
1711 list of node id's
kelvin8ec71442015-01-15 16:57:00 -08001712 """
andrewonlab7c211572014-10-15 16:45:20 -04001713 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001714 nodesStr = self.nodes()
1715 idList = []
andrewonlab7c211572014-10-15 16:45:20 -04001716
kelvin-onlabd3b64892015-01-20 13:26:24 -08001717 if not nodesStr:
kelvin8ec71442015-01-15 16:57:00 -08001718 main.log.info( "There are no nodes to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001719 return idList
andrewonlab7c211572014-10-15 16:45:20 -04001720
kelvin-onlabd3b64892015-01-20 13:26:24 -08001721 # Sample nodesStr output
kelvin8ec71442015-01-15 16:57:00 -08001722 # id=local, address=127.0.0.1:9876, state=ACTIVE *
andrewonlab7c211572014-10-15 16:45:20 -04001723
kelvin8ec71442015-01-15 16:57:00 -08001724 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08001725 nodesList = nodesStr.split( "," )
1726 tempList = [ node for node in nodesList if "id=" in node ]
1727 for arg in tempList:
1728 idList.append( arg.split( "id=" )[ 1 ] )
andrewonlab7c211572014-10-15 16:45:20 -04001729
kelvin-onlabd3b64892015-01-20 13:26:24 -08001730 return idList
kelvin8ec71442015-01-15 16:57:00 -08001731
Jon Halld4d4b372015-01-28 16:02:41 -08001732 except TypeError:
1733 main.log.exception( self.name + ": Object not as expected" )
1734 return None
andrewonlab7c211572014-10-15 16:45:20 -04001735 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001736 main.log.error( self.name + ": EOF exception found" )
1737 main.log.error( self.name + ": " + self.handle.before )
andrewonlab7c211572014-10-15 16:45:20 -04001738 main.cleanup()
1739 main.exit()
1740 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001741 main.log.exception( self.name + ": Uncaught exception!" )
andrewonlab7c211572014-10-15 16:45:20 -04001742 main.cleanup()
1743 main.exit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04001744
kelvin-onlabd3b64892015-01-20 13:26:24 -08001745 def getDevice( self, dpid=None ):
kelvin8ec71442015-01-15 16:57:00 -08001746 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001747 Return the first device from the devices api whose 'id' contains 'dpid'
1748 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08001749 """
Jon Halla91c4dc2014-10-22 12:57:04 -04001750 try:
kelvin8ec71442015-01-15 16:57:00 -08001751 if dpid is None:
Jon Halla91c4dc2014-10-22 12:57:04 -04001752 return None
1753 else:
kelvin8ec71442015-01-15 16:57:00 -08001754 dpid = dpid.replace( ':', '' )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001755 rawDevices = self.devices()
1756 devicesJson = json.loads( rawDevices )
kelvin8ec71442015-01-15 16:57:00 -08001757 # search json for the device with dpid then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -08001758 for device in devicesJson:
kelvin8ec71442015-01-15 16:57:00 -08001759 # print "%s in %s?" % ( dpid, device[ 'id' ] )
1760 if dpid in device[ 'id' ]:
Jon Halla91c4dc2014-10-22 12:57:04 -04001761 return device
1762 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001763 except TypeError:
1764 main.log.exception( self.name + ": Object not as expected" )
1765 return None
Jon Halla91c4dc2014-10-22 12:57:04 -04001766 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001767 main.log.error( self.name + ": EOF exception found" )
1768 main.log.error( self.name + ": " + self.handle.before )
Jon Halla91c4dc2014-10-22 12:57:04 -04001769 main.cleanup()
1770 main.exit()
1771 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001772 main.log.exception( self.name + ": Uncaught exception!" )
Jon Halla91c4dc2014-10-22 12:57:04 -04001773 main.cleanup()
1774 main.exit()
1775
kelvin-onlabd3b64892015-01-20 13:26:24 -08001776 def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08001777 """
1778 Checks the number of swithes & links that ONOS sees against the
1779 supplied values. By default this will report to main.log, but the
Jon Hall42db6dc2014-10-24 19:03:48 -04001780 log level can be specifid.
kelvin8ec71442015-01-15 16:57:00 -08001781
Jon Hall42db6dc2014-10-24 19:03:48 -04001782 Params: ip = ip used for the onos cli
1783 numoswitch = expected number of switches
1784 numlink = expected number of links
kelvin-onlabd3b64892015-01-20 13:26:24 -08001785 logLevel = level to log to. Currently accepts
1786 'info', 'warn' and 'report'
Jon Hall42db6dc2014-10-24 19:03:48 -04001787
1788
kelvin-onlabd3b64892015-01-20 13:26:24 -08001789 logLevel can
Jon Hall42db6dc2014-10-24 19:03:48 -04001790
kelvin8ec71442015-01-15 16:57:00 -08001791 Returns: main.TRUE if the number of switchs and links are correct,
Jon Hall42db6dc2014-10-24 19:03:48 -04001792 main.FALSE if the numer of switches and links is incorrect,
1793 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08001794 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001795 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001796 topology = self.getTopology( ip )
Jon Hall42db6dc2014-10-24 19:03:48 -04001797 if topology == {}:
1798 return main.ERROR
1799 output = ""
kelvin8ec71442015-01-15 16:57:00 -08001800 # Is the number of switches is what we expected
1801 devices = topology.get( 'devices', False )
1802 links = topology.get( 'links', False )
kelvin-onlabfb521662015-02-27 09:52:40 -08001803 if devices is False or links is False:
Jon Hall42db6dc2014-10-24 19:03:48 -04001804 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08001805 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08001806 # Is the number of links is what we expected
kelvin-onlabd3b64892015-01-20 13:26:24 -08001807 linkCheck = ( int( links ) == int( numolink ) )
1808 if ( switchCheck and linkCheck ):
kelvin8ec71442015-01-15 16:57:00 -08001809 # We expected the correct numbers
Jon Hall42db6dc2014-10-24 19:03:48 -04001810 output = output + "The number of links and switches match "\
kelvin8ec71442015-01-15 16:57:00 -08001811 + "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001812 result = main.TRUE
1813 else:
1814 output = output + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001815 "The number of links and switches does not matc\
1816 h what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04001817 result = main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001818 output = output + "\n ONOS sees %i devices (%i expected) \
1819 and %i links (%i expected)" % (
1820 int( devices ), int( numoswitch ), int( links ),
1821 int( numolink ) )
1822 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08001823 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001824 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08001825 main.log.warn( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04001826 else:
kelvin8ec71442015-01-15 16:57:00 -08001827 main.log.info( output )
1828 return result
Jon Halld4d4b372015-01-28 16:02:41 -08001829 except TypeError:
1830 main.log.exception( self.name + ": Object not as expected" )
1831 return None
Jon Hall42db6dc2014-10-24 19:03:48 -04001832 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001833 main.log.error( self.name + ": EOF exception found" )
1834 main.log.error( self.name + ": " + self.handle.before )
Jon Hall42db6dc2014-10-24 19:03:48 -04001835 main.cleanup()
1836 main.exit()
1837 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001838 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall42db6dc2014-10-24 19:03:48 -04001839 main.cleanup()
1840 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04001841
kelvin-onlabd3b64892015-01-20 13:26:24 -08001842 def deviceRole( self, deviceId, onosNode, role="master" ):
kelvin8ec71442015-01-15 16:57:00 -08001843 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001844 Calls the device-role cli command.
kelvin-onlabd3b64892015-01-20 13:26:24 -08001845 deviceId must be the id of a device as seen in the onos devices command
1846 onosNode is the ip of one of the onos nodes in the cluster
Jon Hall1c9e8732014-10-27 19:29:27 -04001847 role must be either master, standby, or none
1848
Jon Halle3f39ff2015-01-13 11:50:53 -08001849 Returns:
1850 main.TRUE or main.FALSE based on argument verification and
1851 main.ERROR if command returns and error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001852 """
Jon Hall1c9e8732014-10-27 19:29:27 -04001853 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08001854 if role.lower() == "master" or role.lower() == "standby" or\
Jon Hall1c9e8732014-10-27 19:29:27 -04001855 role.lower() == "none":
kelvin-onlabd3b64892015-01-20 13:26:24 -08001856 cmdStr = "device-role " +\
1857 str( deviceId ) + " " +\
1858 str( onosNode ) + " " +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001859 str( role )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001860 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001861 if re.search( "Error", handle ):
1862 # end color output to escape any colours
1863 # from the cli
kelvin8ec71442015-01-15 16:57:00 -08001864 main.log.error( self.name + ": " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001865 handle + '\033[0m' )
kelvin8ec71442015-01-15 16:57:00 -08001866 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08001867 return main.TRUE
Jon Hall1c9e8732014-10-27 19:29:27 -04001868 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001869 main.log.error( "Invalid 'role' given to device_role(). " +
1870 "Value was '" + str(role) + "'." )
Jon Hall1c9e8732014-10-27 19:29:27 -04001871 return main.FALSE
Jon Halld4d4b372015-01-28 16:02:41 -08001872 except TypeError:
1873 main.log.exception( self.name + ": Object not as expected" )
1874 return None
Jon Hall1c9e8732014-10-27 19:29:27 -04001875 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001876 main.log.error( self.name + ": EOF exception found" )
1877 main.log.error( self.name + ": " + self.handle.before )
Jon Hall1c9e8732014-10-27 19:29:27 -04001878 main.cleanup()
1879 main.exit()
1880 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001881 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall1c9e8732014-10-27 19:29:27 -04001882 main.cleanup()
1883 main.exit()
1884
kelvin-onlabd3b64892015-01-20 13:26:24 -08001885 def clusters( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001886 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001887 Lists all clusters
Jon Hallffb386d2014-11-21 13:43:38 -08001888 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001889 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08001890 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001891 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001892 if jsonFormat:
1893 cmdStr = "clusters -j"
1894 handle = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001895 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001896 handle variable here contains some ANSI escape color code
1897 sequences at the end which are invisible in the print command
Jon Halle3f39ff2015-01-13 11:50:53 -08001898 output. To make that escape sequence visible, use repr()
kelvin-onlab898a6c62015-01-16 14:13:53 -08001899 function. The repr( handle ) output when printed shows the ANSI
1900 escape sequences. In json.loads( somestring ), this somestring
kelvin-onlabd3b64892015-01-20 13:26:24 -08001901 variable is actually repr( somestring ) and json.loads would
1902 fail with the escape sequence. So we take off that escape
1903 sequence using:
Jon Halle3f39ff2015-01-13 11:50:53 -08001904
kelvin-onlabd3b64892015-01-20 13:26:24 -08001905 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1906 handle1 = ansiEscape.sub( '', handle )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001907 """
kelvin-onlabd3b64892015-01-20 13:26:24 -08001908 ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' )
1909 handle1 = ansiEscape.sub( '', handle )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001910 return handle1
1911 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001912 cmdStr = "clusters"
1913 handle = self.sendline( cmdStr )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001914 return handle
Jon Halld4d4b372015-01-28 16:02:41 -08001915 except TypeError:
1916 main.log.exception( self.name + ": Object not as expected" )
1917 return None
Jon Hall73cf9cc2014-11-20 22:28:38 -08001918 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001919 main.log.error( self.name + ": EOF exception found" )
1920 main.log.error( self.name + ": " + self.handle.before )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001921 main.cleanup()
1922 main.exit()
1923 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001924 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001925 main.cleanup()
1926 main.exit()
1927
kelvin-onlabd3b64892015-01-20 13:26:24 -08001928 def electionTestLeader( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001929 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001930 CLI command to get the current leader for the Election test application
1931 NOTE: Requires installation of the onos-app-election feature
1932 Returns: Node IP of the leader if one exists
1933 None if none exists
1934 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001935 """
Jon Hall94fd0472014-12-08 11:52:42 -08001936 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001937 cmdStr = "election-test-leader"
1938 response = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08001939 # Leader
1940 leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001941 "app\sis\s(?P<node>.+)\."
kelvin-onlabd3b64892015-01-20 13:26:24 -08001942 nodeSearch = re.search( leaderPattern, response )
1943 if nodeSearch:
1944 node = nodeSearch.group( 'node' )
Jon Halle3f39ff2015-01-13 11:50:53 -08001945 main.log.info( "Election-test-leader on " + str( self.name ) +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001946 " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08001947 return node
Jon Halle3f39ff2015-01-13 11:50:53 -08001948 # no leader
1949 nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001950 "the\sElection\sapp"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001951 nullSearch = re.search( nullPattern, response )
1952 if nullSearch:
Jon Halle3f39ff2015-01-13 11:50:53 -08001953 main.log.info( "Election-test-leader found no leader on " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001954 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08001955 return None
kelvin-onlab898a6c62015-01-16 14:13:53 -08001956 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001957 errorPattern = "Command\snot\sfound"
kelvin-onlab898a6c62015-01-16 14:13:53 -08001958 if re.search( errorPattern, response ):
1959 main.log.error( "Election app is not loaded on " + self.name )
Jon Halle3f39ff2015-01-13 11:50:53 -08001960 # TODO: Should this be main.ERROR?
Jon Hall669173b2014-12-17 11:36:30 -08001961 return main.FALSE
1962 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08001963 main.log.error( "Error in election_test_leader: " +
1964 "unexpected response" )
kelvin8ec71442015-01-15 16:57:00 -08001965 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08001966 return main.FALSE
Jon Halld4d4b372015-01-28 16:02:41 -08001967 except TypeError:
1968 main.log.exception( self.name + ": Object not as expected" )
1969 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001970 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001971 main.log.error( self.name + ": EOF exception found" )
1972 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08001973 main.cleanup()
1974 main.exit()
1975 except:
Jon Halld4d4b372015-01-28 16:02:41 -08001976 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall94fd0472014-12-08 11:52:42 -08001977 main.cleanup()
1978 main.exit()
1979
kelvin-onlabd3b64892015-01-20 13:26:24 -08001980 def electionTestRun( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001981 """
Jon Halle3f39ff2015-01-13 11:50:53 -08001982 CLI command to run for leadership of the Election test application.
1983 NOTE: Requires installation of the onos-app-election feature
1984 Returns: Main.TRUE on success
1985 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001986 """
Jon Hall94fd0472014-12-08 11:52:42 -08001987 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001988 cmdStr = "election-test-run"
1989 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001990 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08001991 successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08001992 "Election\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08001993 search = re.search( successPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08001994 if search:
Jon Halle3f39ff2015-01-13 11:50:53 -08001995 main.log.info( self.name + " entering leadership elections " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08001996 "for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08001997 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08001998 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08001999 errorPattern = "Command\snot\sfound"
2000 if re.search( errorPattern, response ):
2001 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08002002 return main.FALSE
2003 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002004 main.log.error( "Error in election_test_run: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08002005 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08002006 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08002007 return main.FALSE
Jon Halld4d4b372015-01-28 16:02:41 -08002008 except TypeError:
2009 main.log.exception( self.name + ": Object not as expected" )
2010 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08002011 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002012 main.log.error( self.name + ": EOF exception found" )
2013 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08002014 main.cleanup()
2015 main.exit()
2016 except:
Jon Halld4d4b372015-01-28 16:02:41 -08002017 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall94fd0472014-12-08 11:52:42 -08002018 main.cleanup()
2019 main.exit()
2020
kelvin-onlabd3b64892015-01-20 13:26:24 -08002021 def electionTestWithdraw( self ):
kelvin8ec71442015-01-15 16:57:00 -08002022 """
Jon Hall94fd0472014-12-08 11:52:42 -08002023 * CLI command to withdraw the local node from leadership election for
2024 * the Election test application.
2025 #NOTE: Requires installation of the onos-app-election feature
2026 Returns: Main.TRUE on success
2027 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08002028 """
Jon Hall94fd0472014-12-08 11:52:42 -08002029 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08002030 cmdStr = "election-test-withdraw"
2031 response = self.sendline( cmdStr )
kelvin-onlab898a6c62015-01-16 14:13:53 -08002032 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08002033 successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08002034 "\sthe\sElection\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08002035 if re.search( successPattern, response ):
2036 main.log.info( self.name + " withdrawing from leadership " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08002037 "elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08002038 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08002039 # error
Jon Halle3f39ff2015-01-13 11:50:53 -08002040 errorPattern = "Command\snot\sfound"
2041 if re.search( errorPattern, response ):
2042 main.log.error( "Election app is not loaded on " + self.name )
Jon Hall669173b2014-12-17 11:36:30 -08002043 return main.FALSE
2044 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002045 main.log.error( "Error in election_test_withdraw: " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08002046 "unexpected response" )
Jon Halle3f39ff2015-01-13 11:50:53 -08002047 main.log.error( repr( response ) )
Jon Hall669173b2014-12-17 11:36:30 -08002048 return main.FALSE
Jon Halld4d4b372015-01-28 16:02:41 -08002049 except TypeError:
2050 main.log.exception( self.name + ": Object not as expected" )
2051 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08002052 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002053 main.log.error( self.name + ": EOF exception found" )
2054 main.log.error( self.name + ": " + self.handle.before )
Jon Hall94fd0472014-12-08 11:52:42 -08002055 main.cleanup()
2056 main.exit()
2057 except:
Jon Halld4d4b372015-01-28 16:02:41 -08002058 main.log.exception( self.name + ": Uncaught exception!" )
Jon Hall94fd0472014-12-08 11:52:42 -08002059 main.cleanup()
2060 main.exit()
Jon Hall1c9e8732014-10-27 19:29:27 -04002061
kelvin8ec71442015-01-15 16:57:00 -08002062 def getDevicePortsEnabledCount( self, dpid ):
2063 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002064 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08002065 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002066 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08002067 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08002068 cmdStr = "onos:ports -e " + dpid + " | wc -l"
2069 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08002070 if re.search( "No such device", output ):
2071 main.log.error( "Error in getting ports" )
2072 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002073 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002074 return output
Jon Halld4d4b372015-01-28 16:02:41 -08002075 except TypeError:
2076 main.log.exception( self.name + ": Object not as expected" )
2077 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002078 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002079 main.log.error( self.name + ": EOF exception found" )
2080 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002081 main.cleanup()
2082 main.exit()
2083 except:
Jon Halld4d4b372015-01-28 16:02:41 -08002084 main.log.exception( self.name + ": Uncaught exception!" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002085 main.cleanup()
2086 main.exit()
2087
kelvin8ec71442015-01-15 16:57:00 -08002088 def getDeviceLinksActiveCount( self, dpid ):
2089 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002090 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08002091 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002092 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -08002093 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08002094 cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l"
2095 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08002096 if re.search( "No such device", output ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08002097 main.log.error( "Error in getting ports " )
2098 return ( output, "Error " )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002099 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002100 return output
Jon Halld4d4b372015-01-28 16:02:41 -08002101 except TypeError:
2102 main.log.exception( self.name + ": Object not as expected" )
2103 return ( output, "Error " )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002104 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002105 main.log.error( self.name + ": EOF exception found" )
2106 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002107 main.cleanup()
2108 main.exit()
2109 except:
Jon Halld4d4b372015-01-28 16:02:41 -08002110 main.log.exception( self.name + ": Uncaught exception!" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002111 main.cleanup()
2112 main.exit()
2113
kelvin8ec71442015-01-15 16:57:00 -08002114 def getAllIntentIds( self ):
2115 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002116 Return a list of all Intent IDs
kelvin8ec71442015-01-15 16:57:00 -08002117 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002118 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08002119 cmdStr = "onos:intents | grep id="
2120 output = self.sendline( cmdStr )
Jon Halle3f39ff2015-01-13 11:50:53 -08002121 if re.search( "Error", output ):
2122 main.log.error( "Error in getting ports" )
2123 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002124 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08002125 return output
Jon Halld4d4b372015-01-28 16:02:41 -08002126 except TypeError:
2127 main.log.exception( self.name + ": Object not as expected" )
2128 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002129 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002130 main.log.error( self.name + ": EOF exception found" )
2131 main.log.error( self.name + ": " + self.handle.before )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08002132 main.cleanup()
2133 main.exit()
2134 except:
Jon Halld4d4b372015-01-28 16:02:41 -08002135 main.log.exception( self.name + ": Uncaught exception!" )
2136 main.cleanup()
2137 main.exit()
2138
Jon Hall73509952015-02-24 16:42:56 -08002139 def intentSummary( self ):
2140 """
2141 Returns a dictonary containing the current intent states and the count
2142 """
2143 try:
2144 intents = self.intents( )
2145 intentStates = []
2146 out = []
2147 for intent in json.loads( intents ):
2148 intentStates.append( intent.get( 'state', None ) )
2149 for i in set( intentStates ):
2150 out.append( (i, intentStates.count( i ) ) )
2151 return dict( out )
2152 except TypeError:
2153 main.log.exception( self.name + ": Object not as expected" )
2154 return None
2155 except pexpect.EOF:
2156 main.log.error( self.name + ": EOF exception found" )
2157 main.log.error( self.name + ": " + self.handle.before )
2158 main.cleanup()
2159 main.exit()
2160 except:
2161 main.log.exception( self.name + ": Uncaught exception!" )
2162 main.cleanup()
2163 main.exit()