blob: 3b57cb2394da9f94bc5b9ceebad75bf94fffc0dc [file] [log] [blame]
andrewonlab95ce8322014-10-13 14:12:04 -04001#!/usr/bin/env python
2
kelvin8ec71442015-01-15 16:57:00 -08003"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07004OCT 13 2014
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005Copyright 2014 Open Networking Foundation (ONF)
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07006
7Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
8the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
9or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
10
11 TestON is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000014 (at your option) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070015
16 TestON is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with TestON. If not, see <http://www.gnu.org/licenses/>.
23"""
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +000024
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070025"""
andrewonlab95ce8322014-10-13 14:12:04 -040026This driver enters the onos> prompt to issue commands.
27
kelvin8ec71442015-01-15 16:57:00 -080028Please follow the coding style demonstrated by existing
andrewonlab95ce8322014-10-13 14:12:04 -040029functions and document properly.
30
31If you are a contributor to the driver, please
32list your email here for future contact:
33
34jhall@onlab.us
35andrew@onlab.us
Jon Halle8217482014-10-17 13:49:14 -040036shreya@onlab.us
Jeremy Ronquillo818bc7c2017-08-09 17:14:53 +000037jeremyr@opennetworking.org
kelvin8ec71442015-01-15 16:57:00 -080038"""
andrewonlab95ce8322014-10-13 14:12:04 -040039import pexpect
40import re
Jon Hall30b82fa2015-03-04 17:15:43 -080041import json
42import types
Jon Hallbd16b922015-03-26 17:53:15 -070043import time
kelvin-onlaba4074292015-07-09 15:19:49 -070044import os
andrewonlab95ce8322014-10-13 14:12:04 -040045from drivers.common.clidriver import CLI
You Wangdb8cd0a2016-05-26 15:19:45 -070046from core.graph import Graph
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -070047from cStringIO import StringIO
48from itertools import izip
andrewonlab95ce8322014-10-13 14:12:04 -040049
kelvin8ec71442015-01-15 16:57:00 -080050class OnosCliDriver( CLI ):
andrewonlab95ce8322014-10-13 14:12:04 -040051
kelvin8ec71442015-01-15 16:57:00 -080052 def __init__( self ):
53 """
54 Initialize client
55 """
Jon Hallefbd9792015-03-05 16:11:36 -080056 self.name = None
57 self.home = None
58 self.handle = None
Devin Limdc78e202017-06-09 18:30:07 -070059 self.karafUser = None
60 self.karafPass = None
You Wangdb8cd0a2016-05-26 15:19:45 -070061 self.graph = Graph()
Devin Limdc78e202017-06-09 18:30:07 -070062 super( OnosCliDriver, self ).__init__()
kelvin8ec71442015-01-15 16:57:00 -080063
Jeremy Ronquillo82705492017-10-18 14:19:55 -070064 def checkOptions( self, var, defaultVar ):
Devin Limdc78e202017-06-09 18:30:07 -070065 if var is None or var == "":
66 return defaultVar
67 return var
Jeremy Ronquillo82705492017-10-18 14:19:55 -070068
kelvin8ec71442015-01-15 16:57:00 -080069 def connect( self, **connectargs ):
70 """
andrewonlab95ce8322014-10-13 14:12:04 -040071 Creates ssh handle for ONOS cli.
kelvin8ec71442015-01-15 16:57:00 -080072 """
andrewonlab95ce8322014-10-13 14:12:04 -040073 try:
74 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -080075 vars( self )[ key ] = connectargs[ key ]
andrew@onlab.us658ec012015-03-11 15:13:09 -070076 self.home = "~/onos"
andrewonlab95ce8322014-10-13 14:12:04 -040077 for key in self.options:
78 if key == "home":
Devin Limdc78e202017-06-09 18:30:07 -070079 self.home = self.options[ key ]
80 elif key == "karaf_username":
81 self.karafUser = self.options[ key ]
82 elif key == "karaf_password":
83 self.karafPass = self.options[ key ]
84
Jeremy Ronquillo82705492017-10-18 14:19:55 -070085 self.home = self.checkOptions( self.home, "~/onos" )
86 self.karafUser = self.checkOptions( self.karafUser, self.user_name )
87 self.karafPass = self.checkOptions( self.karafPass, self.pwd )
andrewonlab95ce8322014-10-13 14:12:04 -040088
kelvin-onlaba4074292015-07-09 15:19:49 -070089 for key in self.options:
90 if key == 'onosIp':
91 self.onosIp = self.options[ 'onosIp' ]
92 break
93
kelvin8ec71442015-01-15 16:57:00 -080094 self.name = self.options[ 'name' ]
kelvin-onlaba4074292015-07-09 15:19:49 -070095
96 try:
Jon Hallc6793552016-01-19 14:18:37 -080097 if os.getenv( str( self.ip_address ) ) is not None:
kelvin-onlaba4074292015-07-09 15:19:49 -070098 self.ip_address = os.getenv( str( self.ip_address ) )
99 else:
100 main.log.info( self.name +
101 ": Trying to connect to " +
102 self.ip_address )
103
104 except KeyError:
105 main.log.info( "Invalid host name," +
106 " connecting to local host instead" )
107 self.ip_address = 'localhost'
108 except Exception as inst:
109 main.log.error( "Uncaught exception: " + str( inst ) )
110
kelvin8ec71442015-01-15 16:57:00 -0800111 self.handle = super( OnosCliDriver, self ).connect(
kelvin-onlab08679eb2015-01-21 16:11:48 -0800112 user_name=self.user_name,
113 ip_address=self.ip_address,
kelvin-onlab898a6c62015-01-16 14:13:53 -0800114 port=self.port,
115 pwd=self.pwd,
116 home=self.home )
andrewonlab95ce8322014-10-13 14:12:04 -0400117
kelvin8ec71442015-01-15 16:57:00 -0800118 self.handle.sendline( "cd " + self.home )
Devin Limdc78e202017-06-09 18:30:07 -0700119 self.handle.expect( self.prompt )
andrewonlab95ce8322014-10-13 14:12:04 -0400120 if self.handle:
121 return self.handle
kelvin8ec71442015-01-15 16:57:00 -0800122 else:
123 main.log.info( "NO ONOS HANDLE" )
andrewonlab95ce8322014-10-13 14:12:04 -0400124 return main.FALSE
Jon Halld4d4b372015-01-28 16:02:41 -0800125 except TypeError:
126 main.log.exception( self.name + ": Object not as expected" )
127 return None
andrewonlab95ce8322014-10-13 14:12:04 -0400128 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800129 main.log.error( self.name + ": EOF exception found" )
130 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700131 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800132 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800133 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700134 main.cleanAndExit()
andrewonlab95ce8322014-10-13 14:12:04 -0400135
kelvin8ec71442015-01-15 16:57:00 -0800136 def disconnect( self ):
137 """
andrewonlab95ce8322014-10-13 14:12:04 -0400138 Called when Test is complete to disconnect the ONOS handle.
kelvin8ec71442015-01-15 16:57:00 -0800139 """
Jon Halld61331b2015-02-17 16:35:47 -0800140 response = main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -0400141 try:
Jon Hall61282e32015-03-19 11:34:11 -0700142 if self.handle:
143 i = self.logout()
144 if i == main.TRUE:
145 self.handle.sendline( "" )
Devin Limdc78e202017-06-09 18:30:07 -0700146 self.handle.expect( self.prompt )
Jon Hall61282e32015-03-19 11:34:11 -0700147 self.handle.sendline( "exit" )
148 self.handle.expect( "closed" )
Jon Halld4d4b372015-01-28 16:02:41 -0800149 except TypeError:
150 main.log.exception( self.name + ": Object not as expected" )
Jon Halld61331b2015-02-17 16:35:47 -0800151 response = main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -0400152 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800153 main.log.error( self.name + ": EOF exception found" )
154 main.log.error( self.name + ": " + self.handle.before )
Jon Hall61282e32015-03-19 11:34:11 -0700155 except ValueError:
Jon Hall1a77a1e2015-04-06 10:41:13 -0700156 main.log.exception( "Exception in disconnect of " + self.name )
Jon Hall61282e32015-03-19 11:34:11 -0700157 response = main.TRUE
Jon Hallfebb1c72015-03-05 13:30:09 -0800158 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800159 main.log.exception( self.name + ": Connection failed to the host" )
andrewonlab95ce8322014-10-13 14:12:04 -0400160 response = main.FALSE
161 return response
162
kelvin8ec71442015-01-15 16:57:00 -0800163 def logout( self ):
164 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500165 Sends 'logout' command to ONOS cli
Jon Hall61282e32015-03-19 11:34:11 -0700166 Returns main.TRUE if exited CLI and
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000167 main.FALSE on timeout (not guranteed you are disconnected)
Jon Hall61282e32015-03-19 11:34:11 -0700168 None on TypeError
169 Exits test on unknown error or pexpect exits unexpectedly
kelvin8ec71442015-01-15 16:57:00 -0800170 """
andrewonlab38d2b4a2014-11-13 16:28:47 -0500171 try:
Jon Hall61282e32015-03-19 11:34:11 -0700172 if self.handle:
173 self.handle.sendline( "" )
Devin Limdc78e202017-06-09 18:30:07 -0700174 i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ],
Jon Hall61282e32015-03-19 11:34:11 -0700175 timeout=10 )
176 if i == 0: # In ONOS CLI
177 self.handle.sendline( "logout" )
Devin Limdc78e202017-06-09 18:30:07 -0700178 j = self.handle.expect( [ self.prompt,
Jon Hallbfe00002016-04-05 10:23:54 -0700179 "Command not found:",
180 pexpect.TIMEOUT ] )
181 if j == 0: # Successfully logged out
182 return main.TRUE
183 elif j == 1 or j == 2:
184 # ONOS didn't fully load, and logout command isn't working
185 # or the command timed out
186 self.handle.send( "\x04" ) # send ctrl-d
Jon Hall64ab3bd2016-05-13 11:29:44 -0700187 try:
Devin Limdc78e202017-06-09 18:30:07 -0700188 self.handle.expect( self.prompt )
Jon Hall64ab3bd2016-05-13 11:29:44 -0700189 except pexpect.TIMEOUT:
190 main.log.error( "ONOS did not respond to 'logout' or CTRL-d" )
Jon Hallbfe00002016-04-05 10:23:54 -0700191 return main.TRUE
Jon Halle0f0b342017-04-18 11:43:47 -0700192 else: # some other output
Jon Hallbfe00002016-04-05 10:23:54 -0700193 main.log.warn( "Unknown repsonse to logout command: '{}'",
194 repr( self.handle.before ) )
195 return main.FALSE
Jon Hall61282e32015-03-19 11:34:11 -0700196 elif i == 1: # not in CLI
197 return main.TRUE
198 elif i == 3: # Timeout
199 return main.FALSE
200 else:
andrewonlab9627f432014-11-14 12:45:10 -0500201 return main.TRUE
Jon Halld4d4b372015-01-28 16:02:41 -0800202 except TypeError:
203 main.log.exception( self.name + ": Object not as expected" )
204 return None
andrewonlab38d2b4a2014-11-13 16:28:47 -0500205 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800206 main.log.error( self.name + ": eof exception found" )
Jon Hall61282e32015-03-19 11:34:11 -0700207 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700208 main.cleanAndExit()
Jon Hall61282e32015-03-19 11:34:11 -0700209 except ValueError:
Jon Hall5aa168b2015-03-23 14:23:09 -0700210 main.log.error( self.name +
211 "ValueError exception in logout method" )
Jon Hallfebb1c72015-03-05 13:30:09 -0800212 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800213 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700214 main.cleanAndExit()
andrewonlab38d2b4a2014-11-13 16:28:47 -0500215
kelvin-onlabd3b64892015-01-20 13:26:24 -0800216 def setCell( self, cellname ):
kelvin8ec71442015-01-15 16:57:00 -0800217 """
andrewonlab95ce8322014-10-13 14:12:04 -0400218 Calls 'cell <name>' to set the environment variables on ONOSbench
kelvin8ec71442015-01-15 16:57:00 -0800219
andrewonlab95ce8322014-10-13 14:12:04 -0400220 Before issuing any cli commands, set the environment variable first.
kelvin8ec71442015-01-15 16:57:00 -0800221 """
andrewonlab95ce8322014-10-13 14:12:04 -0400222 try:
223 if not cellname:
kelvin8ec71442015-01-15 16:57:00 -0800224 main.log.error( "Must define cellname" )
Devin Lim44075962017-08-11 10:56:37 -0700225 main.cleanAndExit()
andrewonlab95ce8322014-10-13 14:12:04 -0400226 else:
kelvin8ec71442015-01-15 16:57:00 -0800227 self.handle.sendline( "cell " + str( cellname ) )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800228 # Expect the cellname in the ONOSCELL variable.
kelvin8ec71442015-01-15 16:57:00 -0800229 # Note that this variable name is subject to change
andrewonlab95ce8322014-10-13 14:12:04 -0400230 # and that this driver will have to change accordingly
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700231 self.handle.expect( str( cellname ) )
andrew@onlab.usc400b112015-01-21 15:33:19 -0800232 handleBefore = self.handle.before
233 handleAfter = self.handle.after
kelvin8ec71442015-01-15 16:57:00 -0800234 # Get the rest of the handle
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700235 self.handle.sendline( "" )
236 self.handle.expect( self.prompt )
andrew@onlab.usc400b112015-01-21 15:33:19 -0800237 handleMore = self.handle.before
andrewonlab95ce8322014-10-13 14:12:04 -0400238
kelvin-onlabd3b64892015-01-20 13:26:24 -0800239 main.log.info( "Cell call returned: " + handleBefore +
240 handleAfter + handleMore )
andrewonlab95ce8322014-10-13 14:12:04 -0400241
242 return main.TRUE
243
Jon Halld4d4b372015-01-28 16:02:41 -0800244 except TypeError:
245 main.log.exception( self.name + ": Object not as expected" )
246 return None
andrewonlab95ce8322014-10-13 14:12:04 -0400247 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800248 main.log.error( self.name + ": eof exception found" )
249 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700250 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800251 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800252 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700253 main.cleanAndExit()
kelvin8ec71442015-01-15 16:57:00 -0800254
pingping-lin57a56ce2015-05-20 16:43:48 -0700255 def startOnosCli( self, ONOSIp, karafTimeout="",
Chiyu Chengef109502016-11-21 15:51:38 -0800256 commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ):
kelvin8ec71442015-01-15 16:57:00 -0800257 """
Jon Hallefbd9792015-03-05 16:11:36 -0800258 karafTimeout is an optional argument. karafTimeout value passed
kelvin-onlabd3b64892015-01-20 13:26:24 -0800259 by user would be used to set the current karaf shell idle timeout.
260 Note that when ever this property is modified the shell will exit and
Hari Krishnad7b9c202015-01-05 10:38:14 -0800261 the subsequent login would reflect new idle timeout.
kelvin-onlabd3b64892015-01-20 13:26:24 -0800262 Below is an example to start a session with 60 seconds idle timeout
263 ( input value is in milliseconds ):
kelvin8ec71442015-01-15 16:57:00 -0800264
Hari Krishna25d42f72015-01-05 15:08:28 -0800265 tValue = "60000"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800266 main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue )
kelvin8ec71442015-01-15 16:57:00 -0800267
kelvin-onlabd3b64892015-01-20 13:26:24 -0800268 Note: karafTimeout is left as str so that this could be read
269 and passed to startOnosCli from PARAMS file as str.
kelvin8ec71442015-01-15 16:57:00 -0800270 """
You Wangf69ab392016-01-26 16:34:38 -0800271 self.onosIp = ONOSIp
andrewonlab95ce8322014-10-13 14:12:04 -0400272 try:
Jon Hall67253832016-12-05 09:47:13 -0800273 # Check if we are already in the cli
kelvin8ec71442015-01-15 16:57:00 -0800274 self.handle.sendline( "" )
275 x = self.handle.expect( [
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700276 self.prompt, "onos>" ], commandlineTimeout )
andrewonlab48829f62014-11-17 13:49:01 -0500277 if x == 1:
kelvin8ec71442015-01-15 16:57:00 -0800278 main.log.info( "ONOS cli is already running" )
andrewonlab48829f62014-11-17 13:49:01 -0500279 return main.TRUE
andrewonlab95ce8322014-10-13 14:12:04 -0400280
Jon Hall67253832016-12-05 09:47:13 -0800281 # Not in CLI so login
Chiyu Chengef109502016-11-21 15:51:38 -0800282 if waitForStart:
Jeremy Ronquilloec916a42018-02-02 13:05:57 -0800283 # Wait for onos start ( onos-wait-for-start ) and enter onos cli
284 startCliCommand = "onos-wait-for-start "
Chiyu Chengef109502016-11-21 15:51:38 -0800285 else:
286 startCliCommand = "onos "
287 self.handle.sendline( startCliCommand + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800288 i = self.handle.expect( [
289 "onos>",
pingping-lin57a56ce2015-05-20 16:43:48 -0700290 pexpect.TIMEOUT ], onosStartTimeout )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400291
292 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800293 main.log.info( str( ONOSIp ) + " CLI Started successfully" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800294 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800295 self.handle.sendline(
Hari Krishnaac4e1782015-01-26 12:09:12 -0800296 "config:property-set -p org.apache.karaf.shell\
297 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800298 karafTimeout )
Devin Limdc78e202017-06-09 18:30:07 -0700299 self.handle.expect( self.prompt )
Chiyu Chengef109502016-11-21 15:51:38 -0800300 self.handle.sendline( startCliCommand + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800301 self.handle.expect( "onos>" )
andrewonlab2a7ea9b2014-10-24 12:21:05 -0400302 return main.TRUE
303 else:
kelvin8ec71442015-01-15 16:57:00 -0800304 # If failed, send ctrl+c to process and try again
305 main.log.info( "Starting CLI failed. Retrying..." )
306 self.handle.send( "\x03" )
Chiyu Chengef109502016-11-21 15:51:38 -0800307 self.handle.sendline( startCliCommand + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800308 i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ],
309 timeout=30 )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400310 if i == 0:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800311 main.log.info( str( ONOSIp ) + " CLI Started " +
kelvin8ec71442015-01-15 16:57:00 -0800312 "successfully after retry attempt" )
Hari Krishnae36ef212015-01-04 14:09:13 -0800313 if karafTimeout:
kelvin8ec71442015-01-15 16:57:00 -0800314 self.handle.sendline(
kelvin-onlabd3b64892015-01-20 13:26:24 -0800315 "config:property-set -p org.apache.karaf.shell\
316 sshIdleTimeout " +
kelvin8ec71442015-01-15 16:57:00 -0800317 karafTimeout )
Devin Limdc78e202017-06-09 18:30:07 -0700318 self.handle.expect( self.prompt )
Chiyu Chengef109502016-11-21 15:51:38 -0800319 self.handle.sendline( startCliCommand + str( ONOSIp ) )
kelvin8ec71442015-01-15 16:57:00 -0800320 self.handle.expect( "onos>" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400321 return main.TRUE
322 else:
kelvin8ec71442015-01-15 16:57:00 -0800323 main.log.error( "Connection to CLI " +
kelvin-onlabd3b64892015-01-20 13:26:24 -0800324 str( ONOSIp ) + " timeout" )
andrewonlab3a7c3c72014-10-24 17:21:03 -0400325 return main.FALSE
andrewonlab95ce8322014-10-13 14:12:04 -0400326
Jon Halld4d4b372015-01-28 16:02:41 -0800327 except TypeError:
328 main.log.exception( self.name + ": Object not as expected" )
329 return None
andrewonlab95ce8322014-10-13 14:12:04 -0400330 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800331 main.log.error( self.name + ": EOF exception found" )
332 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700333 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800334 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800335 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700336 main.cleanAndExit()
andrewonlab95ce8322014-10-13 14:12:04 -0400337
suibin zhang116647a2016-05-06 16:30:09 -0700338 def startCellCli( self, karafTimeout="",
339 commandlineTimeout=10, onosStartTimeout=60 ):
340 """
341 Start CLI on onos ecll handle.
342
343 karafTimeout is an optional argument. karafTimeout value passed
344 by user would be used to set the current karaf shell idle timeout.
345 Note that when ever this property is modified the shell will exit and
346 the subsequent login would reflect new idle timeout.
347 Below is an example to start a session with 60 seconds idle timeout
348 ( input value is in milliseconds ):
349
350 tValue = "60000"
351
352 Note: karafTimeout is left as str so that this could be read
353 and passed to startOnosCli from PARAMS file as str.
354 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000355
suibin zhang116647a2016-05-06 16:30:09 -0700356 try:
357 self.handle.sendline( "" )
358 x = self.handle.expect( [
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700359 self.prompt, "onos>" ], commandlineTimeout )
suibin zhang116647a2016-05-06 16:30:09 -0700360
361 if x == 1:
362 main.log.info( "ONOS cli is already running" )
363 return main.TRUE
364
Jeremy Ronquilloec916a42018-02-02 13:05:57 -0800365 # Wait for onos start ( onos-wait-for-start ) and enter onos cli
suibin zhang116647a2016-05-06 16:30:09 -0700366 self.handle.sendline( "/opt/onos/bin/onos" )
367 i = self.handle.expect( [
368 "onos>",
369 pexpect.TIMEOUT ], onosStartTimeout )
370
371 if i == 0:
372 main.log.info( self.name + " CLI Started successfully" )
373 if karafTimeout:
374 self.handle.sendline(
375 "config:property-set -p org.apache.karaf.shell\
376 sshIdleTimeout " +
377 karafTimeout )
Devin Limdc78e202017-06-09 18:30:07 -0700378 self.handle.expect( self.prompt )
suibin zhang116647a2016-05-06 16:30:09 -0700379 self.handle.sendline( "/opt/onos/bin/onos" )
380 self.handle.expect( "onos>" )
381 return main.TRUE
382 else:
383 # If failed, send ctrl+c to process and try again
384 main.log.info( "Starting CLI failed. Retrying..." )
385 self.handle.send( "\x03" )
386 self.handle.sendline( "/opt/onos/bin/onos" )
387 i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ],
388 timeout=30 )
389 if i == 0:
390 main.log.info( self.name + " CLI Started " +
391 "successfully after retry attempt" )
392 if karafTimeout:
393 self.handle.sendline(
394 "config:property-set -p org.apache.karaf.shell\
395 sshIdleTimeout " +
396 karafTimeout )
Devin Limdc78e202017-06-09 18:30:07 -0700397 self.handle.expect( self.prompt )
suibin zhang116647a2016-05-06 16:30:09 -0700398 self.handle.sendline( "/opt/onos/bin/onos" )
399 self.handle.expect( "onos>" )
400 return main.TRUE
401 else:
402 main.log.error( "Connection to CLI " +
403 self.name + " timeout" )
404 return main.FALSE
405
406 except TypeError:
407 main.log.exception( self.name + ": Object not as expected" )
408 return None
409 except pexpect.EOF:
410 main.log.error( self.name + ": EOF exception found" )
411 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700412 main.cleanAndExit()
suibin zhang116647a2016-05-06 16:30:09 -0700413 except Exception:
414 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700415 main.cleanAndExit()
suibin zhang116647a2016-05-06 16:30:09 -0700416
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800417 def log( self, cmdStr, level="", noExit=False ):
kelvin-onlab9f541032015-02-04 16:19:53 -0800418 """
419 log the commands in the onos CLI.
kelvin-onlab338f5512015-02-06 10:53:16 -0800420 returns main.TRUE on success
Jon Hallefbd9792015-03-05 16:11:36 -0800421 returns main.FALSE if Error occurred
YPZhangebf9eb52016-05-12 15:20:24 -0700422 if noExit is True, TestON will not exit, but clean up
kelvin-onlab338f5512015-02-06 10:53:16 -0800423 Available level: DEBUG, TRACE, INFO, WARN, ERROR
424 Level defaults to INFO
Pratik Parab3b2ab5a2017-02-14 13:15:14 -0800425 if cmdStr has spaces then put quotes in the passed string
kelvin-onlab9f541032015-02-04 16:19:53 -0800426 """
427 try:
kelvin-onlab338f5512015-02-06 10:53:16 -0800428 lvlStr = ""
429 if level:
430 lvlStr = "--level=" + level
431
kelvin-onlab338f5512015-02-06 10:53:16 -0800432 self.handle.sendline( "log:log " + lvlStr + " " + cmdStr )
Jon Hall390696c2015-05-05 17:13:41 -0700433 self.handle.expect( "log:log" )
kelvin-onlab9f541032015-02-04 16:19:53 -0800434 self.handle.expect( "onos>" )
kelvin-onlabfb521662015-02-27 09:52:40 -0800435
kelvin-onlab9f541032015-02-04 16:19:53 -0800436 response = self.handle.before
437 if re.search( "Error", response ):
438 return main.FALSE
439 return main.TRUE
Jon Hall80daded2015-05-27 16:07:00 -0700440 except pexpect.TIMEOUT:
441 main.log.exception( self.name + ": TIMEOUT exception found" )
YPZhangebf9eb52016-05-12 15:20:24 -0700442 if noExit:
443 main.cleanup()
444 return None
445 else:
Devin Lim44075962017-08-11 10:56:37 -0700446 main.cleanAndExit()
kelvin-onlab9f541032015-02-04 16:19:53 -0800447 except pexpect.EOF:
448 main.log.error( self.name + ": EOF exception found" )
449 main.log.error( self.name + ": " + self.handle.before )
YPZhangebf9eb52016-05-12 15:20:24 -0700450 if noExit:
451 main.cleanup()
452 return None
453 else:
Devin Lim44075962017-08-11 10:56:37 -0700454 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800455 except Exception:
kelvin-onlabfb521662015-02-27 09:52:40 -0800456 main.log.exception( self.name + ": Uncaught exception!" )
YPZhangebf9eb52016-05-12 15:20:24 -0700457 if noExit:
458 main.cleanup()
459 return None
460 else:
Devin Lim44075962017-08-11 10:56:37 -0700461 main.cleanAndExit()
andrewonlab95ce8322014-10-13 14:12:04 -0400462
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700463 def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, dollarSign=False ):
kelvin8ec71442015-01-15 16:57:00 -0800464 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800465 Send a completely user specified string to
466 the onos> prompt. Use this function if you have
andrewonlaba18f6bf2014-10-13 19:31:54 -0400467 a very specific command to send.
Jon Halle3f39ff2015-01-13 11:50:53 -0800468
YPZhang14a4aa92016-07-15 13:37:15 -0700469 if noExit is True, TestON will not exit, and return None
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700470 if dollarSign is True, TestON will not expect for '$' as a new CLI or onos> prompt
471 since '$' can be in the output.
YPZhangebf9eb52016-05-12 15:20:24 -0700472
andrewonlaba18f6bf2014-10-13 19:31:54 -0400473 Warning: There are no sanity checking to commands
474 sent using this method.
GlennRCed771242016-01-13 17:02:47 -0800475
kelvin8ec71442015-01-15 16:57:00 -0800476 """
andrewonlaba18f6bf2014-10-13 19:31:54 -0400477 try:
Jon Halla495f562016-05-16 18:03:26 -0700478 # Try to reconnect if disconnected from cli
479 self.handle.sendline( "" )
Devin Limdc78e202017-06-09 18:30:07 -0700480 i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ] )
Jon Halla495f562016-05-16 18:03:26 -0700481 if i == 1:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700482 main.log.error( self.name + ": onos cli session closed. " )
Jon Halla495f562016-05-16 18:03:26 -0700483 if self.onosIp:
484 main.log.warn( "Trying to reconnect " + self.onosIp )
485 reconnectResult = self.startOnosCli( self.onosIp )
486 if reconnectResult:
487 main.log.info( self.name + ": onos cli session reconnected." )
488 else:
489 main.log.error( self.name + ": reconnection failed." )
YPZhang14a4aa92016-07-15 13:37:15 -0700490 if noExit:
491 return None
492 else:
Devin Lim44075962017-08-11 10:56:37 -0700493 main.cleanAndExit()
Jon Halla495f562016-05-16 18:03:26 -0700494 else:
Devin Lim44075962017-08-11 10:56:37 -0700495 main.cleanAndExit()
Jon Halla495f562016-05-16 18:03:26 -0700496 if i == 2:
Jon Hall7a6ebfd2017-03-13 10:58:58 -0700497 main.log.warn( "Timeout when testing cli responsiveness" )
498 main.log.debug( self.handle.before )
499 self.handle.send( "\x03" ) # Send ctrl-c to clear previous output
Jon Halla495f562016-05-16 18:03:26 -0700500 self.handle.expect( "onos>" )
501
Jon Hall14a03b52016-05-11 12:07:30 -0700502 if debug:
503 # NOTE: This adds and average of .4 seconds per call
504 logStr = "\"Sending CLI command: '" + cmdStr + "'\""
Jon Halle0f0b342017-04-18 11:43:47 -0700505 self.log( logStr, noExit=noExit )
kelvin-onlabd3b64892015-01-20 13:26:24 -0800506 self.handle.sendline( cmdStr )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700507 if dollarSign:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700508 i = self.handle.expect( [ "onos>" ], timeout )
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -0700509 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700510 i = self.handle.expect( [ "onos>", self.prompt ], timeout )
Jon Hall63604932015-02-26 17:09:50 -0800511 response = self.handle.before
Jon Hall63604932015-02-26 17:09:50 -0800512 # TODO: do something with i
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000513 main.log.info( "Command '" + str( cmdStr ) + "' sent to "
Jon Hallc6793552016-01-19 14:18:37 -0800514 + self.name + "." )
Jon Hallc6358dd2015-04-10 12:44:28 -0700515 if debug:
Jon Hall390696c2015-05-05 17:13:41 -0700516 main.log.debug( self.name + ": Raw output" )
517 main.log.debug( self.name + ": " + repr( response ) )
Jon Hallc6358dd2015-04-10 12:44:28 -0700518
519 # Remove ANSI color control strings from output
kelvin-onlabd3b64892015-01-20 13:26:24 -0800520 ansiEscape = re.compile( r'\x1b[^m]*m' )
Jon Hall63604932015-02-26 17:09:50 -0800521 response = ansiEscape.sub( '', response )
Jon Hallc6358dd2015-04-10 12:44:28 -0700522 if debug:
Jon Hall390696c2015-05-05 17:13:41 -0700523 main.log.debug( self.name + ": ansiEscape output" )
524 main.log.debug( self.name + ": " + repr( response ) )
Jon Hallc6358dd2015-04-10 12:44:28 -0700525
kelvin-onlabfb521662015-02-27 09:52:40 -0800526 # Remove extra return chars that get added
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000527 response = re.sub( r"\s\r", "", response )
Jon Hallc6358dd2015-04-10 12:44:28 -0700528 if debug:
Jon Hall390696c2015-05-05 17:13:41 -0700529 main.log.debug( self.name + ": Removed extra returns " +
530 "from output" )
531 main.log.debug( self.name + ": " + repr( response ) )
Jon Hallc6358dd2015-04-10 12:44:28 -0700532
533 # Strip excess whitespace
Jon Hall63604932015-02-26 17:09:50 -0800534 response = response.strip()
Jon Hallc6358dd2015-04-10 12:44:28 -0700535 if debug:
Jon Hall390696c2015-05-05 17:13:41 -0700536 main.log.debug( self.name + ": parsed and stripped output" )
537 main.log.debug( self.name + ": " + repr( response ) )
Jon Hallc6358dd2015-04-10 12:44:28 -0700538
Jon Hall63604932015-02-26 17:09:50 -0800539 # parse for just the output, remove the cmd from response
Jon Hallc6358dd2015-04-10 12:44:28 -0700540 output = response.split( cmdStr.strip(), 1 )
541 if debug:
Jon Hall390696c2015-05-05 17:13:41 -0700542 main.log.debug( self.name + ": split output" )
Jon Hallc6358dd2015-04-10 12:44:28 -0700543 for r in output:
Jon Hall390696c2015-05-05 17:13:41 -0700544 main.log.debug( self.name + ": " + repr( r ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700545 output = output[ 1 ].strip()
GlennRC85870432015-11-23 11:45:51 -0800546 if showResponse:
GlennRCed771242016-01-13 17:02:47 -0800547 main.log.info( "Response from ONOS: {}".format( output ) )
GlennRC85870432015-11-23 11:45:51 -0800548 return output
GlennRCed771242016-01-13 17:02:47 -0800549 except pexpect.TIMEOUT:
550 main.log.error( self.name + ":ONOS timeout" )
551 if debug:
552 main.log.debug( self.handle.before )
553 return None
Jon Hallc6358dd2015-04-10 12:44:28 -0700554 except IndexError:
555 main.log.exception( self.name + ": Object not as expected" )
Jon Halla495f562016-05-16 18:03:26 -0700556 main.log.debug( "response: {}".format( repr( response ) ) )
Jon Hallc6358dd2015-04-10 12:44:28 -0700557 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800558 except TypeError:
559 main.log.exception( self.name + ": Object not as expected" )
560 return None
andrewonlaba18f6bf2014-10-13 19:31:54 -0400561 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800562 main.log.error( self.name + ": EOF exception found" )
563 main.log.error( self.name + ": " + self.handle.before )
YPZhangebf9eb52016-05-12 15:20:24 -0700564 if noExit:
YPZhangebf9eb52016-05-12 15:20:24 -0700565 return None
566 else:
Devin Lim44075962017-08-11 10:56:37 -0700567 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800568 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800569 main.log.exception( self.name + ": Uncaught exception!" )
YPZhangebf9eb52016-05-12 15:20:24 -0700570 if noExit:
YPZhangebf9eb52016-05-12 15:20:24 -0700571 return None
572 else:
Devin Lim44075962017-08-11 10:56:37 -0700573 main.cleanAndExit()
andrewonlaba18f6bf2014-10-13 19:31:54 -0400574
kelvin8ec71442015-01-15 16:57:00 -0800575 # IMPORTANT NOTE:
576 # For all cli commands, naming convention should match
kelvin-onlabd3b64892015-01-20 13:26:24 -0800577 # the cli command changing 'a:b' with 'aB'.
578 # Ex ) onos:topology > onosTopology
579 # onos:links > onosLinks
580 # feature:list > featureList
Jon Halle3f39ff2015-01-13 11:50:53 -0800581
kelvin-onlabd3b64892015-01-20 13:26:24 -0800582 def addNode( self, nodeId, ONOSIp, tcpPort="" ):
kelvin8ec71442015-01-15 16:57:00 -0800583 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400584 Adds a new cluster node by ID and address information.
585 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800586 * nodeId
587 * ONOSIp
andrewonlabc2d05aa2014-10-13 16:51:10 -0400588 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800589 * tcpPort
kelvin8ec71442015-01-15 16:57:00 -0800590 """
andrewonlabc2d05aa2014-10-13 16:51:10 -0400591 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800592 cmdStr = "add-node " + str( nodeId ) + " " +\
593 str( ONOSIp ) + " " + str( tcpPort )
594 handle = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -0700595 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800596 assert "Command not found:" not in handle, handle
kelvin-onlab898a6c62015-01-16 14:13:53 -0800597 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -0800598 main.log.error( "Error in adding node" )
599 main.log.error( handle )
Jon Halle3f39ff2015-01-13 11:50:53 -0800600 return main.FALSE
andrewonlabc2d05aa2014-10-13 16:51:10 -0400601 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800602 main.log.info( "Node " + str( ONOSIp ) + " added" )
andrewonlabc2d05aa2014-10-13 16:51:10 -0400603 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -0800604 except AssertionError:
605 main.log.exception( "" )
606 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800607 except TypeError:
608 main.log.exception( self.name + ": Object not as expected" )
609 return None
andrewonlabc2d05aa2014-10-13 16:51:10 -0400610 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800611 main.log.error( self.name + ": EOF exception found" )
612 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700613 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800614 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800615 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700616 main.cleanAndExit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400617
kelvin-onlabd3b64892015-01-20 13:26:24 -0800618 def removeNode( self, nodeId ):
kelvin8ec71442015-01-15 16:57:00 -0800619 """
andrewonlab86dc3082014-10-13 18:18:38 -0400620 Removes a cluster by ID
621 Issues command: 'remove-node [<node-id>]'
622 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800623 * nodeId
kelvin8ec71442015-01-15 16:57:00 -0800624 """
andrewonlab86dc3082014-10-13 18:18:38 -0400625 try:
andrewonlab86dc3082014-10-13 18:18:38 -0400626
kelvin-onlabd3b64892015-01-20 13:26:24 -0800627 cmdStr = "remove-node " + str( nodeId )
Jon Hall08f61bc2015-04-13 16:00:30 -0700628 handle = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -0700629 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800630 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700631 if re.search( "Error", handle ):
632 main.log.error( "Error in removing node" )
633 main.log.error( handle )
634 return main.FALSE
635 else:
636 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -0800637 except AssertionError:
638 main.log.exception( "" )
639 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800640 except TypeError:
641 main.log.exception( self.name + ": Object not as expected" )
642 return None
andrewonlab86dc3082014-10-13 18:18:38 -0400643 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800644 main.log.error( self.name + ": EOF exception found" )
645 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700646 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800647 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800648 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700649 main.cleanAndExit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400650
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700651 def nodes( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800652 """
andrewonlab7c211572014-10-15 16:45:20 -0400653 List the nodes currently visible
654 Issues command: 'nodes'
Jon Hall61282e32015-03-19 11:34:11 -0700655 Optional argument:
656 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800657 """
andrewonlab7c211572014-10-15 16:45:20 -0400658 try:
Jon Hallc6358dd2015-04-10 12:44:28 -0700659 cmdStr = "nodes"
Jon Hall61282e32015-03-19 11:34:11 -0700660 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -0700661 cmdStr += " -j"
662 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -0700663 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800664 assert "Command not found:" not in output, output
Jon Hallc6358dd2015-04-10 12:44:28 -0700665 return output
Jon Hallc6793552016-01-19 14:18:37 -0800666 except AssertionError:
667 main.log.exception( "" )
668 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800669 except TypeError:
670 main.log.exception( self.name + ": Object not as expected" )
671 return None
andrewonlab7c211572014-10-15 16:45:20 -0400672 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800673 main.log.error( self.name + ": EOF exception found" )
674 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700675 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800676 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800677 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700678 main.cleanAndExit()
andrewonlab7c211572014-10-15 16:45:20 -0400679
kelvin8ec71442015-01-15 16:57:00 -0800680 def topology( self ):
681 """
Hari Krishnaef1bd4e2015-03-12 16:55:30 -0700682 Definition:
Jon Hall390696c2015-05-05 17:13:41 -0700683 Returns the output of topology command.
Hari Krishnaef1bd4e2015-03-12 16:55:30 -0700684 Return:
685 topology = current ONOS topology
kelvin8ec71442015-01-15 16:57:00 -0800686 """
andrewonlab95ce8322014-10-13 14:12:04 -0400687 try:
Hari Krishnaef1bd4e2015-03-12 16:55:30 -0700688 cmdStr = "topology -j"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800689 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -0800690 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800691 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700692 main.log.info( cmdStr + " returned: " + str( handle ) )
andrewonlab95ce8322014-10-13 14:12:04 -0400693 return handle
Jon Hallc6793552016-01-19 14:18:37 -0800694 except AssertionError:
695 main.log.exception( "" )
Jon Halld4d4b372015-01-28 16:02:41 -0800696 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800697 except TypeError:
698 main.log.exception( self.name + ": Object not as expected" )
699 return None
andrewonlabc2d05aa2014-10-13 16:51:10 -0400700 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800701 main.log.error( self.name + ": EOF exception found" )
702 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700703 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800704 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800705 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700706 main.cleanAndExit()
Jon Hallffb386d2014-11-21 13:43:38 -0800707
jenkins7ead5a82015-03-13 10:28:21 -0700708 def deviceRemove( self, deviceId ):
709 """
710 Removes particular device from storage
711
712 TODO: refactor this function
713 """
714 try:
Jon Hallc6358dd2015-04-10 12:44:28 -0700715 cmdStr = "device-remove " + str( deviceId )
716 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -0800717 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800718 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700719 if re.search( "Error", handle ):
720 main.log.error( "Error in removing device" )
721 main.log.error( handle )
722 return main.FALSE
723 else:
724 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -0800725 except AssertionError:
726 main.log.exception( "" )
727 return None
jenkins7ead5a82015-03-13 10:28:21 -0700728 except TypeError:
729 main.log.exception( self.name + ": Object not as expected" )
730 return None
731 except pexpect.EOF:
732 main.log.error( self.name + ": EOF exception found" )
733 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700734 main.cleanAndExit()
jenkins7ead5a82015-03-13 10:28:21 -0700735 except Exception:
736 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700737 main.cleanAndExit()
jenkins7ead5a82015-03-13 10:28:21 -0700738
kelvin-onlabd3b64892015-01-20 13:26:24 -0800739 def devices( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800740 """
Jon Hall7b02d952014-10-17 20:14:54 -0400741 Lists all infrastructure devices or switches
andrewonlab86dc3082014-10-13 18:18:38 -0400742 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800743 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800744 """
andrewonlab86dc3082014-10-13 18:18:38 -0400745 try:
Jon Hallc6358dd2015-04-10 12:44:28 -0700746 cmdStr = "devices"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800747 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -0700748 cmdStr += " -j"
749 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -0800750 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800751 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700752 return handle
Jon Hallc6793552016-01-19 14:18:37 -0800753 except AssertionError:
754 main.log.exception( "" )
755 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800756 except TypeError:
757 main.log.exception( self.name + ": Object not as expected" )
758 return None
andrewonlab7c211572014-10-15 16:45:20 -0400759 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800760 main.log.error( self.name + ": EOF exception found" )
761 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700762 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800763 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800764 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700765 main.cleanAndExit()
andrewonlab7c211572014-10-15 16:45:20 -0400766
kelvin-onlabd3b64892015-01-20 13:26:24 -0800767 def balanceMasters( self ):
kelvin8ec71442015-01-15 16:57:00 -0800768 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800769 This balances the devices across all controllers
770 by issuing command: 'onos> onos:balance-masters'
771 If required this could be extended to return devices balanced output.
kelvin8ec71442015-01-15 16:57:00 -0800772 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800773 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800774 cmdStr = "onos:balance-masters"
Jon Hallc6358dd2015-04-10 12:44:28 -0700775 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -0800776 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800777 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700778 if re.search( "Error", handle ):
779 main.log.error( "Error in balancing masters" )
780 main.log.error( handle )
781 return main.FALSE
782 else:
783 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -0800784 except AssertionError:
785 main.log.exception( "" )
786 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800787 except TypeError:
788 main.log.exception( self.name + ": Object not as expected" )
789 return None
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800790 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800791 main.log.error( self.name + ": EOF exception found" )
792 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700793 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800794 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800795 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700796 main.cleanAndExit()
Hari Krishnaa43d4e92014-12-19 13:22:40 -0800797
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +0000798 def checkMasters( self, jsonFormat=True ):
acsmars24950022015-07-30 18:00:43 -0700799 """
800 Returns the output of the masters command.
801 Optional argument:
802 * jsonFormat - boolean indicating if you want output in json
803 """
804 try:
805 cmdStr = "onos:masters"
806 if jsonFormat:
807 cmdStr += " -j"
808 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -0700809 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800810 assert "Command not found:" not in output, output
acsmars24950022015-07-30 18:00:43 -0700811 return output
Jon Hallc6793552016-01-19 14:18:37 -0800812 except AssertionError:
813 main.log.exception( "" )
814 return None
acsmars24950022015-07-30 18:00:43 -0700815 except TypeError:
816 main.log.exception( self.name + ": Object not as expected" )
817 return None
818 except pexpect.EOF:
819 main.log.error( self.name + ": EOF exception found" )
820 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700821 main.cleanAndExit()
acsmars24950022015-07-30 18:00:43 -0700822 except Exception:
823 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700824 main.cleanAndExit()
acsmars24950022015-07-30 18:00:43 -0700825
Jon Hallc6793552016-01-19 14:18:37 -0800826 def checkBalanceMasters( self, jsonFormat=True ):
acsmars24950022015-07-30 18:00:43 -0700827 """
828 Uses the master command to check that the devices' leadership
829 is evenly divided
830
831 Dependencies: checkMasters() and summary()
832
Jon Hall6509dbf2016-06-21 17:01:17 -0700833 Returns main.TRUE if the devices are balanced
834 Returns main.FALSE if the devices are unbalanced
acsmars24950022015-07-30 18:00:43 -0700835 Exits on Exception
836 Returns None on TypeError
837 """
838 try:
Jon Hallc6793552016-01-19 14:18:37 -0800839 summaryOutput = self.summary()
840 totalDevices = json.loads( summaryOutput )[ "devices" ]
841 except ( TypeError, ValueError ):
842 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) )
843 return None
844 try:
acsmars24950022015-07-30 18:00:43 -0700845 totalOwnedDevices = 0
Jon Hallc6793552016-01-19 14:18:37 -0800846 mastersOutput = self.checkMasters()
847 masters = json.loads( mastersOutput )
acsmars24950022015-07-30 18:00:43 -0700848 first = masters[ 0 ][ "size" ]
849 for master in masters:
850 totalOwnedDevices += master[ "size" ]
851 if master[ "size" ] > first + 1 or master[ "size" ] < first - 1:
852 main.log.error( "Mastership not balanced" )
853 main.log.info( "\n" + self.checkMasters( False ) )
854 return main.FALSE
Jon Halle0f0b342017-04-18 11:43:47 -0700855 main.log.info( "Mastership balanced between " +
Jeremy Ronquillo82705492017-10-18 14:19:55 -0700856 str( len( masters ) ) + " masters" )
acsmars24950022015-07-30 18:00:43 -0700857 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -0800858 except ( TypeError, ValueError ):
859 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) )
acsmars24950022015-07-30 18:00:43 -0700860 return None
861 except pexpect.EOF:
862 main.log.error( self.name + ": EOF exception found" )
863 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700864 main.cleanAndExit()
acsmars24950022015-07-30 18:00:43 -0700865 except Exception:
866 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700867 main.cleanAndExit()
acsmars24950022015-07-30 18:00:43 -0700868
YPZhangfebf7302016-05-24 16:45:56 -0700869 def links( self, jsonFormat=True, timeout=30 ):
kelvin8ec71442015-01-15 16:57:00 -0800870 """
Jon Halle8217482014-10-17 13:49:14 -0400871 Lists all core links
872 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800873 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800874 """
Jon Halle8217482014-10-17 13:49:14 -0400875 try:
Jon Hallc6358dd2015-04-10 12:44:28 -0700876 cmdStr = "links"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800877 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -0700878 cmdStr += " -j"
YPZhangfebf7302016-05-24 16:45:56 -0700879 handle = self.sendline( cmdStr, timeout=timeout )
You Wangb5a55f72017-03-03 12:51:05 -0800880 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800881 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700882 return handle
Jon Hallc6793552016-01-19 14:18:37 -0800883 except AssertionError:
884 main.log.exception( "" )
885 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800886 except TypeError:
887 main.log.exception( self.name + ": Object not as expected" )
888 return None
Jon Halle8217482014-10-17 13:49:14 -0400889 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800890 main.log.error( self.name + ": EOF exception found" )
891 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700892 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800893 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800894 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700895 main.cleanAndExit()
Jon Halle8217482014-10-17 13:49:14 -0400896
kelvin-onlabd3b64892015-01-20 13:26:24 -0800897 def ports( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800898 """
Jon Halle8217482014-10-17 13:49:14 -0400899 Lists all ports
900 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800901 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800902 """
Jon Halle8217482014-10-17 13:49:14 -0400903 try:
Jon Hallc6358dd2015-04-10 12:44:28 -0700904 cmdStr = "ports"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800905 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -0700906 cmdStr += " -j"
907 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -0800908 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800909 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700910 return handle
Jon Hallc6793552016-01-19 14:18:37 -0800911 except AssertionError:
912 main.log.exception( "" )
913 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800914 except TypeError:
915 main.log.exception( self.name + ": Object not as expected" )
916 return None
Jon Halle8217482014-10-17 13:49:14 -0400917 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800918 main.log.error( self.name + ": EOF exception found" )
919 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700920 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800921 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800922 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700923 main.cleanAndExit()
Jon Halle8217482014-10-17 13:49:14 -0400924
kelvin-onlabd3b64892015-01-20 13:26:24 -0800925 def roles( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -0800926 """
Jon Hall983a1702014-10-28 18:44:22 -0400927 Lists all devices and the controllers with roles assigned to them
928 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800929 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -0800930 """
andrewonlab7c211572014-10-15 16:45:20 -0400931 try:
Jon Hallc6358dd2015-04-10 12:44:28 -0700932 cmdStr = "roles"
kelvin-onlabd3b64892015-01-20 13:26:24 -0800933 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -0700934 cmdStr += " -j"
935 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -0800936 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -0800937 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -0700938 return handle
Jon Hallc6793552016-01-19 14:18:37 -0800939 except AssertionError:
940 main.log.exception( "" )
941 return None
Jon Halld4d4b372015-01-28 16:02:41 -0800942 except TypeError:
943 main.log.exception( self.name + ": Object not as expected" )
944 return None
Jon Hall983a1702014-10-28 18:44:22 -0400945 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800946 main.log.error( self.name + ": EOF exception found" )
947 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700948 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800949 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800950 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700951 main.cleanAndExit()
Jon Hall983a1702014-10-28 18:44:22 -0400952
kelvin-onlabd3b64892015-01-20 13:26:24 -0800953 def getRole( self, deviceId ):
kelvin-onlab898a6c62015-01-16 14:13:53 -0800954 """
Jon Halle3f39ff2015-01-13 11:50:53 -0800955 Given the a string containing the json representation of the "roles"
956 cli command and a partial or whole device id, returns a json object
957 containing the roles output for the first device whose id contains
958 "device_id"
Jon Hall983a1702014-10-28 18:44:22 -0400959
960 Returns:
Jon Halle3f39ff2015-01-13 11:50:53 -0800961 A dict of the role assignments for the given device or
962 None if no match
kelvin8ec71442015-01-15 16:57:00 -0800963 """
Jon Hall983a1702014-10-28 18:44:22 -0400964 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800965 if deviceId is None:
Jon Hall983a1702014-10-28 18:44:22 -0400966 return None
967 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800968 rawRoles = self.roles()
969 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800970 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800971 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800972 # print device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800973 if str( deviceId ) in device[ 'id' ]:
Jon Hall983a1702014-10-28 18:44:22 -0400974 return device
975 return None
Jon Hallc6793552016-01-19 14:18:37 -0800976 except ( TypeError, ValueError ):
977 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) )
Jon Halld4d4b372015-01-28 16:02:41 -0800978 return None
andrewonlab86dc3082014-10-13 18:18:38 -0400979 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -0800980 main.log.error( self.name + ": EOF exception found" )
981 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -0700982 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -0800983 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -0800984 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -0700985 main.cleanAndExit()
Jon Hall94fd0472014-12-08 11:52:42 -0800986
kelvin-onlabd3b64892015-01-20 13:26:24 -0800987 def rolesNotNull( self ):
kelvin8ec71442015-01-15 16:57:00 -0800988 """
Jon Hall94fd0472014-12-08 11:52:42 -0800989 Iterates through each device and checks if there is a master assigned
990 Returns: main.TRUE if each device has a master
991 main.FALSE any device has no master
kelvin8ec71442015-01-15 16:57:00 -0800992 """
Jon Hall94fd0472014-12-08 11:52:42 -0800993 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -0800994 rawRoles = self.roles()
995 rolesJson = json.loads( rawRoles )
kelvin8ec71442015-01-15 16:57:00 -0800996 # search json for the device with id then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -0800997 for device in rolesJson:
kelvin8ec71442015-01-15 16:57:00 -0800998 # print device
999 if device[ 'master' ] == "none":
1000 main.log.warn( "Device has no master: " + str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001001 return main.FALSE
1002 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -08001003 except ( TypeError, ValueError ):
1004 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) )
Jon Halld4d4b372015-01-28 16:02:41 -08001005 return None
Jon Hall94fd0472014-12-08 11:52:42 -08001006 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001007 main.log.error( self.name + ": EOF exception found" )
1008 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001009 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001010 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001011 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001012 main.cleanAndExit()
Jon Hall94fd0472014-12-08 11:52:42 -08001013
kelvin-onlabd3b64892015-01-20 13:26:24 -08001014 def paths( self, srcId, dstId ):
kelvin8ec71442015-01-15 16:57:00 -08001015 """
andrewonlab3e15ead2014-10-15 14:21:34 -04001016 Returns string of paths, and the cost.
1017 Issues command: onos:paths <src> <dst>
kelvin8ec71442015-01-15 16:57:00 -08001018 """
andrewonlab3e15ead2014-10-15 14:21:34 -04001019 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001020 cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId )
1021 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08001022 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001023 assert "Command not found:" not in handle, handle
Jon Halle3f39ff2015-01-13 11:50:53 -08001024 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001025 main.log.error( "Error in getting paths" )
1026 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -04001027 else:
kelvin8ec71442015-01-15 16:57:00 -08001028 path = handle.split( ";" )[ 0 ]
1029 cost = handle.split( ";" )[ 1 ]
1030 return ( path, cost )
Jon Hallc6793552016-01-19 14:18:37 -08001031 except AssertionError:
1032 main.log.exception( "" )
1033 return ( handle, "Error" )
Jon Halld4d4b372015-01-28 16:02:41 -08001034 except TypeError:
1035 main.log.exception( self.name + ": Object not as expected" )
1036 return ( handle, "Error" )
andrewonlab3e15ead2014-10-15 14:21:34 -04001037 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001038 main.log.error( self.name + ": EOF exception found" )
1039 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001040 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001041 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001042 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001043 main.cleanAndExit()
Jon Hallffb386d2014-11-21 13:43:38 -08001044
kelvin-onlabd3b64892015-01-20 13:26:24 -08001045 def hosts( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08001046 """
Jon Hallffb386d2014-11-21 13:43:38 -08001047 Lists all discovered hosts
Jon Hall42db6dc2014-10-24 19:03:48 -04001048 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001049 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08001050 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001051 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07001052 cmdStr = "hosts"
kelvin-onlabd3b64892015-01-20 13:26:24 -08001053 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07001054 cmdStr += " -j"
1055 handle = self.sendline( cmdStr )
Jeremyd9e4eb12016-04-13 12:09:06 -07001056 if handle:
1057 assert "Command not found:" not in handle, handle
Jon Hallbaf53162015-12-17 17:04:34 -08001058 # TODO: Maybe make this less hardcoded
1059 # ConsistentMap Exceptions
1060 assert "org.onosproject.store.service" not in handle
1061 # Node not leader
1062 assert "java.lang.IllegalStateException" not in handle
Jon Hallc6358dd2015-04-10 12:44:28 -07001063 return handle
Jon Hallc6793552016-01-19 14:18:37 -08001064 except AssertionError:
Jeremyd9e4eb12016-04-13 12:09:06 -07001065 main.log.exception( "Error in processing '" + cmdStr + "' " +
Jeremy Songster6949cea2016-04-19 18:13:18 -07001066 "command: " + str( handle ) )
Jon Hallc6793552016-01-19 14:18:37 -08001067 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001068 except TypeError:
1069 main.log.exception( self.name + ": Object not as expected" )
1070 return None
Jon Hall42db6dc2014-10-24 19:03:48 -04001071 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001072 main.log.error( self.name + ": EOF exception found" )
1073 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001074 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001075 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001076 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001077 main.cleanAndExit()
Jon Hall42db6dc2014-10-24 19:03:48 -04001078
kelvin-onlabd3b64892015-01-20 13:26:24 -08001079 def getHost( self, mac ):
kelvin8ec71442015-01-15 16:57:00 -08001080 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001081 Return the first host from the hosts api whose 'id' contains 'mac'
Jon Halle3f39ff2015-01-13 11:50:53 -08001082
Jon Hallefbd9792015-03-05 16:11:36 -08001083 Note: mac must be a colon separated mac address, but could be a
Jon Halle3f39ff2015-01-13 11:50:53 -08001084 partial mac address
1085
Jon Hall42db6dc2014-10-24 19:03:48 -04001086 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08001087 """
Jon Hall42db6dc2014-10-24 19:03:48 -04001088 try:
kelvin8ec71442015-01-15 16:57:00 -08001089 if mac is None:
Jon Hall42db6dc2014-10-24 19:03:48 -04001090 return None
1091 else:
1092 mac = mac
kelvin-onlabd3b64892015-01-20 13:26:24 -08001093 rawHosts = self.hosts()
1094 hostsJson = json.loads( rawHosts )
kelvin8ec71442015-01-15 16:57:00 -08001095 # search json for the host with mac then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -08001096 for host in hostsJson:
kelvin8ec71442015-01-15 16:57:00 -08001097 # print "%s in %s?" % ( mac, host[ 'id' ] )
Jon Halld4d4b372015-01-28 16:02:41 -08001098 if not host:
1099 pass
1100 elif mac in host[ 'id' ]:
Jon Hall42db6dc2014-10-24 19:03:48 -04001101 return host
1102 return None
Jon Hallc6793552016-01-19 14:18:37 -08001103 except ( TypeError, ValueError ):
1104 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) )
Jon Halld4d4b372015-01-28 16:02:41 -08001105 return None
Jon Hall42db6dc2014-10-24 19:03:48 -04001106 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001107 main.log.error( self.name + ": EOF exception found" )
1108 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001109 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001110 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001111 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001112 main.cleanAndExit()
Jon Hall42db6dc2014-10-24 19:03:48 -04001113
kelvin-onlabd3b64892015-01-20 13:26:24 -08001114 def getHostsId( self, hostList ):
kelvin8ec71442015-01-15 16:57:00 -08001115 """
1116 Obtain list of hosts
andrewonlab3f0a4af2014-10-17 12:25:14 -04001117 Issues command: 'onos> hosts'
kelvin8ec71442015-01-15 16:57:00 -08001118
andrewonlab3f0a4af2014-10-17 12:25:14 -04001119 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001120 * hostList: List of hosts obtained by Mininet
andrewonlab3f0a4af2014-10-17 12:25:14 -04001121 IMPORTANT:
1122 This function assumes that you started your
kelvin8ec71442015-01-15 16:57:00 -08001123 topology with the option '--mac'.
andrewonlab3f0a4af2014-10-17 12:25:14 -04001124 Furthermore, it assumes that value of VLAN is '-1'
1125 Description:
kelvin8ec71442015-01-15 16:57:00 -08001126 Converts mininet hosts ( h1, h2, h3... ) into
1127 ONOS format ( 00:00:00:00:00:01/-1 , ... )
1128 """
andrewonlab3f0a4af2014-10-17 12:25:14 -04001129 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001130 onosHostList = []
andrewonlab3f0a4af2014-10-17 12:25:14 -04001131
kelvin-onlabd3b64892015-01-20 13:26:24 -08001132 for host in hostList:
kelvin8ec71442015-01-15 16:57:00 -08001133 host = host.replace( "h", "" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001134 hostHex = hex( int( host ) ).zfill( 12 )
1135 hostHex = str( hostHex ).replace( 'x', '0' )
1136 i = iter( str( hostHex ) )
1137 hostHex = ":".join( a + b for a, b in zip( i, i ) )
1138 hostHex = hostHex + "/-1"
1139 onosHostList.append( hostHex )
andrewonlab3f0a4af2014-10-17 12:25:14 -04001140
kelvin-onlabd3b64892015-01-20 13:26:24 -08001141 return onosHostList
andrewonlab3f0a4af2014-10-17 12:25:14 -04001142
Jon Halld4d4b372015-01-28 16:02:41 -08001143 except TypeError:
1144 main.log.exception( self.name + ": Object not as expected" )
1145 return None
andrewonlab3f0a4af2014-10-17 12:25:14 -04001146 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001147 main.log.error( self.name + ": EOF exception found" )
1148 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001149 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001150 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001151 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001152 main.cleanAndExit()
andrewonlab3e15ead2014-10-15 14:21:34 -04001153
You Wangbc898b82018-05-03 16:22:34 -07001154 def verifyHostLocation( self, hostIp, location ):
1155 """
1156 Description:
1157 Verify the host given is discovered in all locations expected
1158 Required:
1159 hostIp: IP address of the host
1160 location: expected location(s) of the given host. ex. "of:0000000000000005/8"
1161 Could be a string or list
1162 Returns:
1163 main.TRUE if host is discovered on all locations provided
1164 main.FALSE otherwise
1165 """
1166 import json
1167 locations = [ location ] if isinstance( location, str ) else location
1168 assert isinstance( locations, list ), "Wrong type of location: {}".format( type( location ) )
1169 try:
1170 hosts = self.hosts()
1171 hosts = json.loads( hosts )
1172 targetHost = None
1173 for host in hosts:
1174 if hostIp in host[ "ipAddresses" ]:
1175 targetHost = host
You Wangfd80ab42018-05-10 17:21:53 -07001176 assert targetHost, "Not able to find host with IP {}".format( hostIp )
You Wangbc898b82018-05-03 16:22:34 -07001177 result = main.TRUE
1178 locationsDiscovered = [ loc[ "elementId" ] + "/" + loc[ "port" ] for loc in targetHost[ "locations" ] ]
1179 for loc in locations:
1180 discovered = False
1181 for locDiscovered in locationsDiscovered:
You Wang547893e2018-05-08 13:34:59 -07001182 locToMatch = locDiscovered if "/" in loc else locDiscovered.split( "/" )[0]
1183 if loc == locToMatch:
You Wangbc898b82018-05-03 16:22:34 -07001184 main.log.debug( "Host {} discovered with location {}".format( hostIp, loc ) )
You Wang547893e2018-05-08 13:34:59 -07001185 discovered = True
You Wangbc898b82018-05-03 16:22:34 -07001186 break
1187 if discovered:
1188 locationsDiscovered.remove( locDiscovered )
1189 else:
1190 main.log.warn( "Host {} not discovered with location {}".format( hostIp, loc ) )
1191 result = main.FALSE
1192 if locationsDiscovered:
1193 main.log.warn( "Host {} is also discovered with location {}".format( hostIp, locationsDiscovered ) )
1194 result = main.FALSE
1195 return result
1196 except KeyError:
1197 main.log.exception( self.name + ": host data not as expected: " + hosts )
1198 return None
1199 except pexpect.EOF:
1200 main.log.error( self.name + ": EOF exception found" )
1201 main.log.error( self.name + ": " + self.handle.before )
1202 main.cleanAndExit()
1203 except Exception:
1204 main.log.exception( self.name + ": Uncaught exception" )
1205 return None
1206
You Wang53dba1e2018-02-02 17:45:44 -08001207 def verifyHostIp( self, hostList=[], prefix="" ):
1208 """
1209 Description:
1210 Verify that all hosts have IP address assigned to them
1211 Optional:
1212 hostList: If specified, verifications only happen to the hosts
1213 in hostList
1214 prefix: at least one of the ip address assigned to the host
1215 needs to have the specified prefix
1216 Returns:
1217 main.TRUE if all hosts have specific IP address assigned;
1218 main.FALSE otherwise
1219 """
1220 import json
1221 try:
1222 hosts = self.hosts()
1223 hosts = json.loads( hosts )
1224 if not hostList:
1225 hostList = [ host[ "id" ] for host in hosts ]
1226 for host in hosts:
1227 hostId = host[ "id" ]
1228 if hostId not in hostList:
1229 continue
1230 ipList = host[ "ipAddresses" ]
1231 main.log.debug( self.name + ": IP list on host " + str( hostId ) + ": " + str( ipList ) )
1232 if not ipList:
1233 main.log.warn( self.name + ": Failed to discover any IP addresses on host " + str( hostId ) )
1234 else:
1235 if not any( ip.startswith( str( prefix ) ) for ip in ipList ):
1236 main.log.warn( self.name + ": None of the IPs on host " + str( hostId ) + " has prefix " + str( prefix ) )
1237 else:
1238 main.log.debug( self.name + ": Found matching IP on host " + str( hostId ) )
1239 hostList.remove( hostId )
1240 if hostList:
1241 main.log.warn( self.name + ": failed to verify IP on following hosts: " + str( hostList) )
1242 return main.FALSE
1243 else:
1244 return main.TRUE
1245 except KeyError:
1246 main.log.exception( self.name + ": host data not as expected: " + hosts )
1247 return None
1248 except pexpect.EOF:
1249 main.log.error( self.name + ": EOF exception found" )
1250 main.log.error( self.name + ": " + self.handle.before )
1251 main.cleanAndExit()
1252 except Exception:
1253 main.log.exception( self.name + ": Uncaught exception" )
1254 return None
1255
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001256 def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ):
kelvin8ec71442015-01-15 16:57:00 -08001257 """
andrewonlabe6745342014-10-17 14:29:13 -04001258 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001259 * hostIdOne: ONOS host id for host1
1260 * hostIdTwo: ONOS host id for host2
Jeremy Songster832f9e92016-05-05 14:30:49 -07001261 Optional:
1262 * vlanId: specify a VLAN id for the intent
Jeremy Songsterff553672016-05-12 17:06:23 -07001263 * setVlan: specify a VLAN id treatment
Jeremy Songsterc032f162016-08-04 17:14:49 -07001264 * encap: specify an encapsulation type
andrewonlabe6745342014-10-17 14:29:13 -04001265 Description:
Jon Hallefbd9792015-03-05 16:11:36 -08001266 Adds a host-to-host intent ( bidirectional ) by
Jon Hallb1290e82014-11-18 16:17:48 -05001267 specifying the two hosts.
kelvin-onlabfb521662015-02-27 09:52:40 -08001268 Returns:
1269 A string of the intent id or None on Error
kelvin8ec71442015-01-15 16:57:00 -08001270 """
andrewonlabe6745342014-10-17 14:29:13 -04001271 try:
Jeremy Songster832f9e92016-05-05 14:30:49 -07001272 cmdStr = "add-host-intent "
1273 if vlanId:
1274 cmdStr += "-v " + str( vlanId ) + " "
Jeremy Songsterff553672016-05-12 17:06:23 -07001275 if setVlan:
1276 cmdStr += "--setVlan " + str( vlanId ) + " "
Jeremy Songsterc032f162016-08-04 17:14:49 -07001277 if encap:
1278 cmdStr += "--encapsulation " + str( encap ) + " "
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07001279 if bandwidth:
1280 cmdStr += "-b " + str( bandwidth ) + " "
Jeremy Songster832f9e92016-05-05 14:30:49 -07001281 cmdStr += str( hostIdOne ) + " " + str( hostIdTwo )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001282 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08001283 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001284 assert "Command not found:" not in handle, handle
Hari Krishnaac4e1782015-01-26 12:09:12 -08001285 if re.search( "Error", handle ):
1286 main.log.error( "Error in adding Host intent" )
Jon Hall61282e32015-03-19 11:34:11 -07001287 main.log.debug( "Response from ONOS was: " + repr( handle ) )
kelvin-onlabfb521662015-02-27 09:52:40 -08001288 return None
Hari Krishnaac4e1782015-01-26 12:09:12 -08001289 else:
1290 main.log.info( "Host intent installed between " +
kelvin-onlabfb521662015-02-27 09:52:40 -08001291 str( hostIdOne ) + " and " + str( hostIdTwo ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001292 match = re.search( 'id=0x([\da-f]+),', handle )
kelvin-onlabfb521662015-02-27 09:52:40 -08001293 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001294 return match.group()[ 3:-1 ]
kelvin-onlabfb521662015-02-27 09:52:40 -08001295 else:
1296 main.log.error( "Error, intent ID not found" )
Jon Hall61282e32015-03-19 11:34:11 -07001297 main.log.debug( "Response from ONOS was: " +
1298 repr( handle ) )
kelvin-onlabfb521662015-02-27 09:52:40 -08001299 return None
Jon Hallc6793552016-01-19 14:18:37 -08001300 except AssertionError:
1301 main.log.exception( "" )
1302 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001303 except TypeError:
1304 main.log.exception( self.name + ": Object not as expected" )
1305 return None
andrewonlabe6745342014-10-17 14:29:13 -04001306 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001307 main.log.error( self.name + ": EOF exception found" )
1308 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001309 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001310 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001311 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001312 main.cleanAndExit()
andrewonlabe6745342014-10-17 14:29:13 -04001313
kelvin-onlabd3b64892015-01-20 13:26:24 -08001314 def addOpticalIntent( self, ingressDevice, egressDevice ):
kelvin8ec71442015-01-15 16:57:00 -08001315 """
andrewonlab7b31d232014-10-24 13:31:47 -04001316 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001317 * ingressDevice: device id of ingress device
1318 * egressDevice: device id of egress device
andrewonlab7b31d232014-10-24 13:31:47 -04001319 Optional:
1320 TODO: Still needs to be implemented via dev side
kelvin-onlabfb521662015-02-27 09:52:40 -08001321 Description:
1322 Adds an optical intent by specifying an ingress and egress device
1323 Returns:
1324 A string of the intent id or None on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08001325 """
andrewonlab7b31d232014-10-24 13:31:47 -04001326 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001327 cmdStr = "add-optical-intent " + str( ingressDevice ) +\
1328 " " + str( egressDevice )
1329 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08001330 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001331 assert "Command not found:" not in handle, handle
kelvin-onlab898a6c62015-01-16 14:13:53 -08001332 # If error, return error message
Jon Halle3f39ff2015-01-13 11:50:53 -08001333 if re.search( "Error", handle ):
kelvin-onlabfb521662015-02-27 09:52:40 -08001334 main.log.error( "Error in adding Optical intent" )
1335 return None
andrewonlab7b31d232014-10-24 13:31:47 -04001336 else:
kelvin-onlabfb521662015-02-27 09:52:40 -08001337 main.log.info( "Optical intent installed between " +
1338 str( ingressDevice ) + " and " +
1339 str( egressDevice ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001340 match = re.search( 'id=0x([\da-f]+),', handle )
kelvin-onlabfb521662015-02-27 09:52:40 -08001341 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001342 return match.group()[ 3:-1 ]
kelvin-onlabfb521662015-02-27 09:52:40 -08001343 else:
1344 main.log.error( "Error, intent ID not found" )
1345 return None
Jon Hallc6793552016-01-19 14:18:37 -08001346 except AssertionError:
1347 main.log.exception( "" )
1348 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001349 except TypeError:
1350 main.log.exception( self.name + ": Object not as expected" )
1351 return None
andrewonlab7b31d232014-10-24 13:31:47 -04001352 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001353 main.log.error( self.name + ": EOF exception found" )
1354 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001355 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001356 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001357 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001358 main.cleanAndExit()
andrewonlab7b31d232014-10-24 13:31:47 -04001359
kelvin-onlabd3b64892015-01-20 13:26:24 -08001360 def addPointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -08001361 self,
kelvin-onlabd3b64892015-01-20 13:26:24 -08001362 ingressDevice,
1363 egressDevice,
1364 portIngress="",
1365 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -08001366 ethType="",
1367 ethSrc="",
1368 ethDst="",
1369 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001370 lambdaAlloc=False,
alisonda157272016-12-22 01:13:21 -08001371 protected=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -08001372 ipProto="",
1373 ipSrc="",
1374 ipDst="",
1375 tcpSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001376 tcpDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001377 vlanId="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001378 setVlan="",
1379 encap="" ):
kelvin8ec71442015-01-15 16:57:00 -08001380 """
andrewonlab4dbb4d82014-10-17 18:22:31 -04001381 Required:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001382 * ingressDevice: device id of ingress device
1383 * egressDevice: device id of egress device
andrewonlab289e4b72014-10-21 21:24:18 -04001384 Optional:
1385 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001386 * ethSrc: specify ethSrc ( i.e. src mac addr )
1387 * ethDst: specify ethDst ( i.e. dst mac addr )
andrewonlab0dbb6ec2014-11-06 13:46:55 -05001388 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -08001389 * lambdaAlloc: if True, intent will allocate lambda
andrewonlab40ccd8b2014-11-06 16:23:34 -05001390 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001391 * ipProto: specify ip protocol
andrewonlabf77e0cb2014-11-11 17:17:59 -05001392 * ipSrc: specify ip source address
1393 * ipDst: specify ip destination address
1394 * tcpSrc: specify tcp source port
1395 * tcpDst: specify tcp destination port
Jeremy Songster832f9e92016-05-05 14:30:49 -07001396 * vlanId: specify vlan ID
Jeremy Songsterff553672016-05-12 17:06:23 -07001397 * setVlan: specify a VLAN id treatment
Jeremy Songsterc032f162016-08-04 17:14:49 -07001398 * encap: specify an Encapsulation type to use
andrewonlab4dbb4d82014-10-17 18:22:31 -04001399 Description:
kelvin8ec71442015-01-15 16:57:00 -08001400 Adds a point-to-point intent ( uni-directional ) by
andrewonlab289e4b72014-10-21 21:24:18 -04001401 specifying device id's and optional fields
kelvin-onlabfb521662015-02-27 09:52:40 -08001402 Returns:
1403 A string of the intent id or None on error
andrewonlab289e4b72014-10-21 21:24:18 -04001404
Jon Halle3f39ff2015-01-13 11:50:53 -08001405 NOTE: This function may change depending on the
andrewonlab4dbb4d82014-10-17 18:22:31 -04001406 options developers provide for point-to-point
1407 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001408 """
andrewonlab4dbb4d82014-10-17 18:22:31 -04001409 try:
Jeremy Songsterff553672016-05-12 17:06:23 -07001410 cmd = "add-point-intent"
andrewonlab36af3822014-11-18 17:48:18 -05001411
Jeremy Songsterff553672016-05-12 17:06:23 -07001412 if ethType:
1413 cmd += " --ethType " + str( ethType )
1414 if ethSrc:
1415 cmd += " --ethSrc " + str( ethSrc )
1416 if ethDst:
1417 cmd += " --ethDst " + str( ethDst )
1418 if bandwidth:
1419 cmd += " --bandwidth " + str( bandwidth )
1420 if lambdaAlloc:
1421 cmd += " --lambda "
1422 if ipProto:
1423 cmd += " --ipProto " + str( ipProto )
1424 if ipSrc:
1425 cmd += " --ipSrc " + str( ipSrc )
1426 if ipDst:
1427 cmd += " --ipDst " + str( ipDst )
1428 if tcpSrc:
1429 cmd += " --tcpSrc " + str( tcpSrc )
1430 if tcpDst:
1431 cmd += " --tcpDst " + str( tcpDst )
1432 if vlanId:
1433 cmd += " -v " + str( vlanId )
1434 if setVlan:
1435 cmd += " --setVlan " + str( setVlan )
Jeremy Songsterc032f162016-08-04 17:14:49 -07001436 if encap:
1437 cmd += " --encapsulation " + str( encap )
alisonda157272016-12-22 01:13:21 -08001438 if protected:
1439 cmd += " --protect "
andrewonlab289e4b72014-10-21 21:24:18 -04001440
kelvin8ec71442015-01-15 16:57:00 -08001441 # Check whether the user appended the port
1442 # or provided it as an input
kelvin-onlabd3b64892015-01-20 13:26:24 -08001443 if "/" in ingressDevice:
1444 cmd += " " + str( ingressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001445 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001446 if not portIngress:
kelvin-onlabfb521662015-02-27 09:52:40 -08001447 main.log.error( "You must specify the ingress port" )
kelvin8ec71442015-01-15 16:57:00 -08001448 # TODO: perhaps more meaningful return
kelvin-onlabfb521662015-02-27 09:52:40 -08001449 # Would it make sense to throw an exception and exit
1450 # the test?
1451 return None
andrewonlab36af3822014-11-18 17:48:18 -05001452
kelvin8ec71442015-01-15 16:57:00 -08001453 cmd += " " + \
kelvin-onlabd3b64892015-01-20 13:26:24 -08001454 str( ingressDevice ) + "/" +\
1455 str( portIngress ) + " "
andrewonlab36af3822014-11-18 17:48:18 -05001456
kelvin-onlabd3b64892015-01-20 13:26:24 -08001457 if "/" in egressDevice:
1458 cmd += " " + str( egressDevice )
andrewonlab36af3822014-11-18 17:48:18 -05001459 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001460 if not portEgress:
kelvin-onlabfb521662015-02-27 09:52:40 -08001461 main.log.error( "You must specify the egress port" )
1462 return None
Jon Halle3f39ff2015-01-13 11:50:53 -08001463
kelvin8ec71442015-01-15 16:57:00 -08001464 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001465 str( egressDevice ) + "/" +\
1466 str( portEgress )
kelvin8ec71442015-01-15 16:57:00 -08001467
kelvin-onlab898a6c62015-01-16 14:13:53 -08001468 handle = self.sendline( cmd )
You Wangb5a55f72017-03-03 12:51:05 -08001469 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001470 assert "Command not found:" not in handle, handle
kelvin-onlabfb521662015-02-27 09:52:40 -08001471 # If error, return error message
kelvin-onlab898a6c62015-01-16 14:13:53 -08001472 if re.search( "Error", handle ):
kelvin8ec71442015-01-15 16:57:00 -08001473 main.log.error( "Error in adding point-to-point intent" )
kelvin-onlabfb521662015-02-27 09:52:40 -08001474 return None
andrewonlab4dbb4d82014-10-17 18:22:31 -04001475 else:
kelvin-onlabfb521662015-02-27 09:52:40 -08001476 # TODO: print out all the options in this message?
1477 main.log.info( "Point-to-point intent installed between " +
1478 str( ingressDevice ) + " and " +
1479 str( egressDevice ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001480 match = re.search( 'id=0x([\da-f]+),', handle )
kelvin-onlabfb521662015-02-27 09:52:40 -08001481 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001482 return match.group()[ 3:-1 ]
kelvin-onlabfb521662015-02-27 09:52:40 -08001483 else:
1484 main.log.error( "Error, intent ID not found" )
1485 return None
Jon Hallc6793552016-01-19 14:18:37 -08001486 except AssertionError:
1487 main.log.exception( "" )
1488 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001489 except TypeError:
1490 main.log.exception( self.name + ": Object not as expected" )
1491 return None
andrewonlab4dbb4d82014-10-17 18:22:31 -04001492 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001493 main.log.error( self.name + ": EOF exception found" )
1494 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001495 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001496 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001497 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001498 main.cleanAndExit()
andrewonlab4dbb4d82014-10-17 18:22:31 -04001499
kelvin-onlabd3b64892015-01-20 13:26:24 -08001500 def addMultipointToSinglepointIntent(
kelvin-onlab898a6c62015-01-16 14:13:53 -08001501 self,
shahshreyac2f97072015-03-19 17:04:29 -07001502 ingressDeviceList,
kelvin-onlabd3b64892015-01-20 13:26:24 -08001503 egressDevice,
shahshreyac2f97072015-03-19 17:04:29 -07001504 portIngressList=None,
kelvin-onlabd3b64892015-01-20 13:26:24 -08001505 portEgress="",
kelvin-onlab898a6c62015-01-16 14:13:53 -08001506 ethType="",
1507 ethSrc="",
1508 ethDst="",
1509 bandwidth="",
kelvin-onlabd3b64892015-01-20 13:26:24 -08001510 lambdaAlloc=False,
kelvin-onlab898a6c62015-01-16 14:13:53 -08001511 ipProto="",
1512 ipSrc="",
1513 ipDst="",
1514 tcpSrc="",
1515 tcpDst="",
1516 setEthSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001517 setEthDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001518 vlanId="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001519 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001520 partial=False,
1521 encap="" ):
kelvin8ec71442015-01-15 16:57:00 -08001522 """
shahshreyad0c80432014-12-04 16:56:05 -08001523 Note:
shahshreya70622b12015-03-19 17:19:00 -07001524 This function assumes the format of all ingress devices
Jon Hallbe379602015-03-24 13:39:32 -07001525 is same. That is, all ingress devices include port numbers
1526 with a "/" or all ingress devices could specify device
1527 ids and port numbers seperately.
shahshreyad0c80432014-12-04 16:56:05 -08001528 Required:
Jon Hallbe379602015-03-24 13:39:32 -07001529 * ingressDeviceList: List of device ids of ingress device
shahshreyac2f97072015-03-19 17:04:29 -07001530 ( Atleast 2 ingress devices required in the list )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001531 * egressDevice: device id of egress device
shahshreyad0c80432014-12-04 16:56:05 -08001532 Optional:
1533 * ethType: specify ethType
kelvin8ec71442015-01-15 16:57:00 -08001534 * ethSrc: specify ethSrc ( i.e. src mac addr )
1535 * ethDst: specify ethDst ( i.e. dst mac addr )
shahshreyad0c80432014-12-04 16:56:05 -08001536 * bandwidth: specify bandwidth capacity of link
kelvin-onlabd3b64892015-01-20 13:26:24 -08001537 * lambdaAlloc: if True, intent will allocate lambda
shahshreyad0c80432014-12-04 16:56:05 -08001538 for the specified intent
Jon Halle3f39ff2015-01-13 11:50:53 -08001539 * ipProto: specify ip protocol
shahshreyad0c80432014-12-04 16:56:05 -08001540 * ipSrc: specify ip source address
1541 * ipDst: specify ip destination address
1542 * tcpSrc: specify tcp source port
1543 * tcpDst: specify tcp destination port
1544 * setEthSrc: action to Rewrite Source MAC Address
1545 * setEthDst: action to Rewrite Destination MAC Address
Jeremy Songster832f9e92016-05-05 14:30:49 -07001546 * vlanId: specify vlan Id
Jeremy Songsterff553672016-05-12 17:06:23 -07001547 * setVlan: specify VLAN Id treatment
Jeremy Songsterc032f162016-08-04 17:14:49 -07001548 * encap: specify a type of encapsulation
shahshreyad0c80432014-12-04 16:56:05 -08001549 Description:
kelvin8ec71442015-01-15 16:57:00 -08001550 Adds a multipoint-to-singlepoint intent ( uni-directional ) by
shahshreyad0c80432014-12-04 16:56:05 -08001551 specifying device id's and optional fields
kelvin-onlabfb521662015-02-27 09:52:40 -08001552 Returns:
1553 A string of the intent id or None on error
shahshreyad0c80432014-12-04 16:56:05 -08001554
Jon Halle3f39ff2015-01-13 11:50:53 -08001555 NOTE: This function may change depending on the
Jon Hallefbd9792015-03-05 16:11:36 -08001556 options developers provide for multipoint-to-singlepoint
shahshreyad0c80432014-12-04 16:56:05 -08001557 intent via cli
kelvin8ec71442015-01-15 16:57:00 -08001558 """
shahshreyad0c80432014-12-04 16:56:05 -08001559 try:
Jeremy Songsterff553672016-05-12 17:06:23 -07001560 cmd = "add-multi-to-single-intent"
shahshreyad0c80432014-12-04 16:56:05 -08001561
Jeremy Songsterff553672016-05-12 17:06:23 -07001562 if ethType:
1563 cmd += " --ethType " + str( ethType )
1564 if ethSrc:
1565 cmd += " --ethSrc " + str( ethSrc )
1566 if ethDst:
1567 cmd += " --ethDst " + str( ethDst )
1568 if bandwidth:
1569 cmd += " --bandwidth " + str( bandwidth )
1570 if lambdaAlloc:
1571 cmd += " --lambda "
1572 if ipProto:
1573 cmd += " --ipProto " + str( ipProto )
1574 if ipSrc:
1575 cmd += " --ipSrc " + str( ipSrc )
1576 if ipDst:
1577 cmd += " --ipDst " + str( ipDst )
1578 if tcpSrc:
1579 cmd += " --tcpSrc " + str( tcpSrc )
1580 if tcpDst:
1581 cmd += " --tcpDst " + str( tcpDst )
1582 if setEthSrc:
1583 cmd += " --setEthSrc " + str( setEthSrc )
1584 if setEthDst:
1585 cmd += " --setEthDst " + str( setEthDst )
1586 if vlanId:
1587 cmd += " -v " + str( vlanId )
1588 if setVlan:
1589 cmd += " --setVlan " + str( setVlan )
Jeremy Songster9385d412016-06-02 17:57:36 -07001590 if partial:
1591 cmd += " --partial"
Jeremy Songsterc032f162016-08-04 17:14:49 -07001592 if encap:
1593 cmd += " --encapsulation " + str( encap )
shahshreyad0c80432014-12-04 16:56:05 -08001594
kelvin8ec71442015-01-15 16:57:00 -08001595 # Check whether the user appended the port
1596 # or provided it as an input
shahshreyac2f97072015-03-19 17:04:29 -07001597
1598 if portIngressList is None:
1599 for ingressDevice in ingressDeviceList:
1600 if "/" in ingressDevice:
1601 cmd += " " + str( ingressDevice )
1602 else:
1603 main.log.error( "You must specify " +
Jon Hallbe379602015-03-24 13:39:32 -07001604 "the ingress port" )
shahshreyac2f97072015-03-19 17:04:29 -07001605 # TODO: perhaps more meaningful return
1606 return main.FALSE
shahshreyad0c80432014-12-04 16:56:05 -08001607 else:
Jon Hall71ce4e72015-03-23 14:05:58 -07001608 if len( ingressDeviceList ) == len( portIngressList ):
Jon Hall08f61bc2015-04-13 16:00:30 -07001609 for ingressDevice, portIngress in zip( ingressDeviceList,
1610 portIngressList ):
shahshreya70622b12015-03-19 17:19:00 -07001611 cmd += " " + \
1612 str( ingressDevice ) + "/" +\
1613 str( portIngress ) + " "
kelvin-onlab38143812015-04-01 15:03:01 -07001614 else:
Jon Hall08f61bc2015-04-13 16:00:30 -07001615 main.log.error( "Device list and port list does not " +
1616 "have the same length" )
kelvin-onlab38143812015-04-01 15:03:01 -07001617 return main.FALSE
kelvin-onlabd3b64892015-01-20 13:26:24 -08001618 if "/" in egressDevice:
1619 cmd += " " + str( egressDevice )
shahshreyad0c80432014-12-04 16:56:05 -08001620 else:
kelvin-onlabd3b64892015-01-20 13:26:24 -08001621 if not portEgress:
kelvin8ec71442015-01-15 16:57:00 -08001622 main.log.error( "You must specify " +
1623 "the egress port" )
shahshreyad0c80432014-12-04 16:56:05 -08001624 return main.FALSE
Jon Halle3f39ff2015-01-13 11:50:53 -08001625
kelvin8ec71442015-01-15 16:57:00 -08001626 cmd += " " +\
kelvin-onlabd3b64892015-01-20 13:26:24 -08001627 str( egressDevice ) + "/" +\
1628 str( portEgress )
kelvin-onlab898a6c62015-01-16 14:13:53 -08001629 handle = self.sendline( cmd )
You Wangb5a55f72017-03-03 12:51:05 -08001630 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001631 assert "Command not found:" not in handle, handle
kelvin-onlabfb521662015-02-27 09:52:40 -08001632 # If error, return error message
kelvin-onlab898a6c62015-01-16 14:13:53 -08001633 if re.search( "Error", handle ):
kelvin-onlabfb521662015-02-27 09:52:40 -08001634 main.log.error( "Error in adding multipoint-to-singlepoint " +
1635 "intent" )
1636 return None
shahshreyad0c80432014-12-04 16:56:05 -08001637 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001638 match = re.search( 'id=0x([\da-f]+),', handle )
kelvin-onlabb9408212015-04-01 13:34:04 -07001639 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001640 return match.group()[ 3:-1 ]
kelvin-onlabb9408212015-04-01 13:34:04 -07001641 else:
1642 main.log.error( "Error, intent ID not found" )
1643 return None
Jon Hallc6793552016-01-19 14:18:37 -08001644 except AssertionError:
1645 main.log.exception( "" )
1646 return None
kelvin-onlabb9408212015-04-01 13:34:04 -07001647 except TypeError:
1648 main.log.exception( self.name + ": Object not as expected" )
1649 return None
1650 except pexpect.EOF:
1651 main.log.error( self.name + ": EOF exception found" )
1652 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001653 main.cleanAndExit()
kelvin-onlabb9408212015-04-01 13:34:04 -07001654 except Exception:
1655 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001656 main.cleanAndExit()
kelvin-onlabb9408212015-04-01 13:34:04 -07001657
1658 def addSinglepointToMultipointIntent(
1659 self,
1660 ingressDevice,
1661 egressDeviceList,
1662 portIngress="",
1663 portEgressList=None,
1664 ethType="",
1665 ethSrc="",
1666 ethDst="",
1667 bandwidth="",
1668 lambdaAlloc=False,
1669 ipProto="",
1670 ipSrc="",
1671 ipDst="",
1672 tcpSrc="",
1673 tcpDst="",
1674 setEthSrc="",
Jeremy Songster832f9e92016-05-05 14:30:49 -07001675 setEthDst="",
Jeremy Songsterff553672016-05-12 17:06:23 -07001676 vlanId="",
Jeremy Songster9385d412016-06-02 17:57:36 -07001677 setVlan="",
Jeremy Songsterc032f162016-08-04 17:14:49 -07001678 partial=False,
1679 encap="" ):
kelvin-onlabb9408212015-04-01 13:34:04 -07001680 """
1681 Note:
1682 This function assumes the format of all egress devices
1683 is same. That is, all egress devices include port numbers
1684 with a "/" or all egress devices could specify device
1685 ids and port numbers seperately.
1686 Required:
1687 * EgressDeviceList: List of device ids of egress device
1688 ( Atleast 2 eress devices required in the list )
1689 * ingressDevice: device id of ingress device
1690 Optional:
1691 * ethType: specify ethType
1692 * ethSrc: specify ethSrc ( i.e. src mac addr )
1693 * ethDst: specify ethDst ( i.e. dst mac addr )
1694 * bandwidth: specify bandwidth capacity of link
1695 * lambdaAlloc: if True, intent will allocate lambda
1696 for the specified intent
1697 * ipProto: specify ip protocol
1698 * ipSrc: specify ip source address
1699 * ipDst: specify ip destination address
1700 * tcpSrc: specify tcp source port
1701 * tcpDst: specify tcp destination port
1702 * setEthSrc: action to Rewrite Source MAC Address
1703 * setEthDst: action to Rewrite Destination MAC Address
Jeremy Songster832f9e92016-05-05 14:30:49 -07001704 * vlanId: specify vlan Id
Jeremy Songsterff553672016-05-12 17:06:23 -07001705 * setVlan: specify VLAN ID treatment
Jeremy Songsterc032f162016-08-04 17:14:49 -07001706 * encap: specify an encapsulation type
kelvin-onlabb9408212015-04-01 13:34:04 -07001707 Description:
1708 Adds a singlepoint-to-multipoint intent ( uni-directional ) by
1709 specifying device id's and optional fields
1710 Returns:
1711 A string of the intent id or None on error
1712
1713 NOTE: This function may change depending on the
1714 options developers provide for singlepoint-to-multipoint
1715 intent via cli
1716 """
1717 try:
Jeremy Songsterff553672016-05-12 17:06:23 -07001718 cmd = "add-single-to-multi-intent"
kelvin-onlabb9408212015-04-01 13:34:04 -07001719
Jeremy Songsterff553672016-05-12 17:06:23 -07001720 if ethType:
1721 cmd += " --ethType " + str( ethType )
1722 if ethSrc:
1723 cmd += " --ethSrc " + str( ethSrc )
1724 if ethDst:
1725 cmd += " --ethDst " + str( ethDst )
1726 if bandwidth:
1727 cmd += " --bandwidth " + str( bandwidth )
1728 if lambdaAlloc:
1729 cmd += " --lambda "
1730 if ipProto:
1731 cmd += " --ipProto " + str( ipProto )
1732 if ipSrc:
1733 cmd += " --ipSrc " + str( ipSrc )
1734 if ipDst:
1735 cmd += " --ipDst " + str( ipDst )
1736 if tcpSrc:
1737 cmd += " --tcpSrc " + str( tcpSrc )
1738 if tcpDst:
1739 cmd += " --tcpDst " + str( tcpDst )
1740 if setEthSrc:
1741 cmd += " --setEthSrc " + str( setEthSrc )
1742 if setEthDst:
1743 cmd += " --setEthDst " + str( setEthDst )
1744 if vlanId:
1745 cmd += " -v " + str( vlanId )
1746 if setVlan:
1747 cmd += " --setVlan " + str( setVlan )
Jeremy Songster9385d412016-06-02 17:57:36 -07001748 if partial:
1749 cmd += " --partial"
Jeremy Songsterc032f162016-08-04 17:14:49 -07001750 if encap:
1751 cmd += " --encapsulation " + str( encap )
kelvin-onlabb9408212015-04-01 13:34:04 -07001752
1753 # Check whether the user appended the port
1754 # or provided it as an input
Jon Hall08f61bc2015-04-13 16:00:30 -07001755
kelvin-onlabb9408212015-04-01 13:34:04 -07001756 if "/" in ingressDevice:
1757 cmd += " " + str( ingressDevice )
1758 else:
1759 if not portIngress:
1760 main.log.error( "You must specify " +
1761 "the Ingress port" )
1762 return main.FALSE
1763
1764 cmd += " " +\
1765 str( ingressDevice ) + "/" +\
1766 str( portIngress )
1767
1768 if portEgressList is None:
1769 for egressDevice in egressDeviceList:
1770 if "/" in egressDevice:
1771 cmd += " " + str( egressDevice )
1772 else:
1773 main.log.error( "You must specify " +
1774 "the egress port" )
1775 # TODO: perhaps more meaningful return
1776 return main.FALSE
1777 else:
1778 if len( egressDeviceList ) == len( portEgressList ):
Jon Hall08f61bc2015-04-13 16:00:30 -07001779 for egressDevice, portEgress in zip( egressDeviceList,
1780 portEgressList ):
kelvin-onlabb9408212015-04-01 13:34:04 -07001781 cmd += " " + \
1782 str( egressDevice ) + "/" +\
1783 str( portEgress )
kelvin-onlab38143812015-04-01 15:03:01 -07001784 else:
Jon Hall08f61bc2015-04-13 16:00:30 -07001785 main.log.error( "Device list and port list does not " +
1786 "have the same length" )
kelvin-onlab38143812015-04-01 15:03:01 -07001787 return main.FALSE
kelvin-onlabb9408212015-04-01 13:34:04 -07001788 handle = self.sendline( cmd )
You Wangb5a55f72017-03-03 12:51:05 -08001789 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001790 assert "Command not found:" not in handle, handle
kelvin-onlabb9408212015-04-01 13:34:04 -07001791 # If error, return error message
1792 if re.search( "Error", handle ):
1793 main.log.error( "Error in adding singlepoint-to-multipoint " +
1794 "intent" )
shahshreyac2f97072015-03-19 17:04:29 -07001795 return None
kelvin-onlabb9408212015-04-01 13:34:04 -07001796 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001797 match = re.search( 'id=0x([\da-f]+),', handle )
kelvin-onlabb9408212015-04-01 13:34:04 -07001798 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001799 return match.group()[ 3:-1 ]
kelvin-onlabb9408212015-04-01 13:34:04 -07001800 else:
1801 main.log.error( "Error, intent ID not found" )
1802 return None
Jon Hallc6793552016-01-19 14:18:37 -08001803 except AssertionError:
1804 main.log.exception( "" )
1805 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001806 except TypeError:
1807 main.log.exception( self.name + ": Object not as expected" )
1808 return None
shahshreyad0c80432014-12-04 16:56:05 -08001809 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001810 main.log.error( self.name + ": EOF exception found" )
1811 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001812 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001813 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001814 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001815 main.cleanAndExit()
shahshreyad0c80432014-12-04 16:56:05 -08001816
Hari Krishna9e232602015-04-13 17:29:08 -07001817 def addMplsIntent(
1818 self,
1819 ingressDevice,
1820 egressDevice,
Hari Krishna87a17f12015-04-13 17:42:23 -07001821 ingressPort="",
1822 egressPort="",
Hari Krishna9e232602015-04-13 17:29:08 -07001823 ethType="",
1824 ethSrc="",
1825 ethDst="",
1826 bandwidth="",
1827 lambdaAlloc=False,
1828 ipProto="",
1829 ipSrc="",
1830 ipDst="",
1831 tcpSrc="",
1832 tcpDst="",
Hari Krishna87a17f12015-04-13 17:42:23 -07001833 ingressLabel="",
Hari Krishnadfff6672015-04-13 17:53:27 -07001834 egressLabel="",
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001835 priority="" ):
Hari Krishna9e232602015-04-13 17:29:08 -07001836 """
1837 Required:
1838 * ingressDevice: device id of ingress device
1839 * egressDevice: device id of egress device
1840 Optional:
1841 * ethType: specify ethType
1842 * ethSrc: specify ethSrc ( i.e. src mac addr )
1843 * ethDst: specify ethDst ( i.e. dst mac addr )
1844 * bandwidth: specify bandwidth capacity of link
1845 * lambdaAlloc: if True, intent will allocate lambda
1846 for the specified intent
1847 * ipProto: specify ip protocol
1848 * ipSrc: specify ip source address
1849 * ipDst: specify ip destination address
1850 * tcpSrc: specify tcp source port
1851 * tcpDst: specify tcp destination port
1852 * ingressLabel: Ingress MPLS label
1853 * egressLabel: Egress MPLS label
1854 Description:
1855 Adds MPLS intent by
1856 specifying device id's and optional fields
1857 Returns:
1858 A string of the intent id or None on error
1859
1860 NOTE: This function may change depending on the
1861 options developers provide for MPLS
1862 intent via cli
1863 """
1864 try:
Jeremy Songsterff553672016-05-12 17:06:23 -07001865 cmd = "add-mpls-intent"
Hari Krishna9e232602015-04-13 17:29:08 -07001866
Jeremy Songsterff553672016-05-12 17:06:23 -07001867 if ethType:
1868 cmd += " --ethType " + str( ethType )
1869 if ethSrc:
1870 cmd += " --ethSrc " + str( ethSrc )
1871 if ethDst:
1872 cmd += " --ethDst " + str( ethDst )
1873 if bandwidth:
1874 cmd += " --bandwidth " + str( bandwidth )
1875 if lambdaAlloc:
1876 cmd += " --lambda "
1877 if ipProto:
1878 cmd += " --ipProto " + str( ipProto )
1879 if ipSrc:
1880 cmd += " --ipSrc " + str( ipSrc )
1881 if ipDst:
1882 cmd += " --ipDst " + str( ipDst )
1883 if tcpSrc:
1884 cmd += " --tcpSrc " + str( tcpSrc )
1885 if tcpDst:
1886 cmd += " --tcpDst " + str( tcpDst )
1887 if ingressLabel:
1888 cmd += " --ingressLabel " + str( ingressLabel )
1889 if egressLabel:
1890 cmd += " --egressLabel " + str( egressLabel )
1891 if priority:
1892 cmd += " --priority " + str( priority )
Hari Krishna9e232602015-04-13 17:29:08 -07001893
1894 # Check whether the user appended the port
1895 # or provided it as an input
1896 if "/" in ingressDevice:
1897 cmd += " " + str( ingressDevice )
1898 else:
Hari Krishna87a17f12015-04-13 17:42:23 -07001899 if not ingressPort:
Hari Krishna9e232602015-04-13 17:29:08 -07001900 main.log.error( "You must specify the ingress port" )
1901 return None
1902
1903 cmd += " " + \
1904 str( ingressDevice ) + "/" +\
Hari Krishna87a17f12015-04-13 17:42:23 -07001905 str( ingressPort ) + " "
Hari Krishna9e232602015-04-13 17:29:08 -07001906
1907 if "/" in egressDevice:
1908 cmd += " " + str( egressDevice )
1909 else:
Hari Krishna87a17f12015-04-13 17:42:23 -07001910 if not egressPort:
Hari Krishna9e232602015-04-13 17:29:08 -07001911 main.log.error( "You must specify the egress port" )
1912 return None
1913
1914 cmd += " " +\
1915 str( egressDevice ) + "/" +\
Hari Krishna87a17f12015-04-13 17:42:23 -07001916 str( egressPort )
Hari Krishna9e232602015-04-13 17:29:08 -07001917
1918 handle = self.sendline( cmd )
You Wangb5a55f72017-03-03 12:51:05 -08001919 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001920 assert "Command not found:" not in handle, handle
Hari Krishna9e232602015-04-13 17:29:08 -07001921 # If error, return error message
1922 if re.search( "Error", handle ):
1923 main.log.error( "Error in adding mpls intent" )
1924 return None
1925 else:
1926 # TODO: print out all the options in this message?
1927 main.log.info( "MPLS intent installed between " +
1928 str( ingressDevice ) + " and " +
1929 str( egressDevice ) )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001930 match = re.search( 'id=0x([\da-f]+),', handle )
Hari Krishna9e232602015-04-13 17:29:08 -07001931 if match:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07001932 return match.group()[ 3:-1 ]
Hari Krishna9e232602015-04-13 17:29:08 -07001933 else:
1934 main.log.error( "Error, intent ID not found" )
1935 return None
Jon Hallc6793552016-01-19 14:18:37 -08001936 except AssertionError:
1937 main.log.exception( "" )
1938 return None
Hari Krishna9e232602015-04-13 17:29:08 -07001939 except TypeError:
1940 main.log.exception( self.name + ": Object not as expected" )
1941 return None
1942 except pexpect.EOF:
1943 main.log.error( self.name + ": EOF exception found" )
1944 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001945 main.cleanAndExit()
Hari Krishna9e232602015-04-13 17:29:08 -07001946 except Exception:
1947 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001948 main.cleanAndExit()
Hari Krishna9e232602015-04-13 17:29:08 -07001949
Jon Hallefbd9792015-03-05 16:11:36 -08001950 def removeIntent( self, intentId, app='org.onosproject.cli',
1951 purge=False, sync=False ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001952 """
shahshreya1c818fc2015-02-26 13:44:08 -08001953 Remove intent for specified application id and intent id
Jon Hall61282e32015-03-19 11:34:11 -07001954 Optional args:-
shahshreya1c818fc2015-02-26 13:44:08 -08001955 -s or --sync: Waits for the removal before returning
Jon Hall61282e32015-03-19 11:34:11 -07001956 -p or --purge: Purge the intent from the store after removal
1957
Jon Halle3f39ff2015-01-13 11:50:53 -08001958 Returns:
Jon Hall6509dbf2016-06-21 17:01:17 -07001959 main.FALSE on error and
Jon Halle3f39ff2015-01-13 11:50:53 -08001960 cli output otherwise
kelvin-onlab898a6c62015-01-16 14:13:53 -08001961 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04001962 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07001963 cmdStr = "remove-intent"
shahshreya1c818fc2015-02-26 13:44:08 -08001964 if purge:
1965 cmdStr += " -p"
1966 if sync:
1967 cmdStr += " -s"
1968
1969 cmdStr += " " + app + " " + str( intentId )
kelvin-onlabd3b64892015-01-20 13:26:24 -08001970 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08001971 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08001972 assert "Command not found:" not in handle, handle
Jon Halle3f39ff2015-01-13 11:50:53 -08001973 if re.search( "Error", handle ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08001974 main.log.error( "Error in removing intent" )
Jon Halle3f39ff2015-01-13 11:50:53 -08001975 return main.FALSE
andrewonlab9a50dfe2014-10-17 17:22:31 -04001976 else:
Jon Halle3f39ff2015-01-13 11:50:53 -08001977 # TODO: Should this be main.TRUE
1978 return handle
Jon Hallc6793552016-01-19 14:18:37 -08001979 except AssertionError:
1980 main.log.exception( "" )
1981 return None
Jon Halld4d4b372015-01-28 16:02:41 -08001982 except TypeError:
1983 main.log.exception( self.name + ": Object not as expected" )
1984 return None
andrewonlab9a50dfe2014-10-17 17:22:31 -04001985 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08001986 main.log.error( self.name + ": EOF exception found" )
1987 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07001988 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08001989 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08001990 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07001991 main.cleanAndExit()
andrewonlab9a50dfe2014-10-17 17:22:31 -04001992
YPZhangfebf7302016-05-24 16:45:56 -07001993 def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ):
Jeremy42df2e72016-02-23 16:37:46 -08001994 """
1995 Description:
1996 Remove all the intents
1997 Optional args:-
1998 -s or --sync: Waits for the removal before returning
1999 -p or --purge: Purge the intent from the store after removal
2000 Returns:
2001 Returns main.TRUE if all intents are removed, otherwise returns
2002 main.FALSE; Returns None for exception
2003 """
2004 try:
2005 cmdStr = "remove-intent"
2006 if purge:
2007 cmdStr += " -p"
2008 if sync:
2009 cmdStr += " -s"
2010
2011 cmdStr += " " + app
YPZhangfebf7302016-05-24 16:45:56 -07002012 handle = self.sendline( cmdStr, timeout=timeout )
You Wangb5a55f72017-03-03 12:51:05 -08002013 assert handle is not None, "Error in sendline"
Jeremy42df2e72016-02-23 16:37:46 -08002014 assert "Command not found:" not in handle, handle
2015 if re.search( "Error", handle ):
2016 main.log.error( "Error in removing intent" )
2017 return main.FALSE
2018 else:
2019 return main.TRUE
2020 except AssertionError:
2021 main.log.exception( "" )
2022 return None
2023 except TypeError:
2024 main.log.exception( self.name + ": Object not as expected" )
2025 return None
2026 except pexpect.EOF:
2027 main.log.error( self.name + ": EOF exception found" )
2028 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002029 main.cleanAndExit()
Jeremy42df2e72016-02-23 16:37:46 -08002030 except Exception:
2031 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002032 main.cleanAndExit()
Jeremy42df2e72016-02-23 16:37:46 -08002033
Hari Krishnaacabd5a2015-07-01 17:10:19 -07002034 def purgeWithdrawnIntents( self ):
Hari Krishna0ce0e152015-06-23 09:55:29 -07002035 """
2036 Purges all WITHDRAWN Intents
2037 """
2038 try:
2039 cmdStr = "purge-intents"
2040 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08002041 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002042 assert "Command not found:" not in handle, handle
Hari Krishna0ce0e152015-06-23 09:55:29 -07002043 if re.search( "Error", handle ):
2044 main.log.error( "Error in purging intents" )
2045 return main.FALSE
2046 else:
2047 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -08002048 except AssertionError:
2049 main.log.exception( "" )
2050 return None
Hari Krishna0ce0e152015-06-23 09:55:29 -07002051 except TypeError:
2052 main.log.exception( self.name + ": Object not as expected" )
2053 return None
2054 except pexpect.EOF:
2055 main.log.error( self.name + ": EOF exception found" )
2056 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002057 main.cleanAndExit()
Hari Krishna0ce0e152015-06-23 09:55:29 -07002058 except Exception:
2059 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002060 main.cleanAndExit()
Hari Krishna0ce0e152015-06-23 09:55:29 -07002061
Devin Lime6fe3c42017-10-18 16:28:40 -07002062 def wipeout( self ):
2063 """
2064 Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS.
2065 """
2066 try:
2067 cmdStr = "wipe-out please"
2068 handle = self.sendline( cmdStr, timeout=60 )
2069 assert handle is not None, "Error in sendline"
2070 assert "Command not found:" not in handle, handle
2071 return main.TRUE
2072 except AssertionError:
2073 main.log.exception( "" )
2074 return None
2075 except TypeError:
2076 main.log.exception( self.name + ": Object not as expected" )
2077 return None
2078 except pexpect.EOF:
2079 main.log.error( self.name + ": EOF exception found" )
2080 main.log.error( self.name + ": " + self.handle.before )
2081 main.cleanAndExit()
2082 except Exception:
2083 main.log.exception( self.name + ": Uncaught exception!" )
2084 main.cleanAndExit()
2085
kelvin-onlabd3b64892015-01-20 13:26:24 -08002086 def routes( self, jsonFormat=False ):
kelvin8ec71442015-01-15 16:57:00 -08002087 """
kelvin-onlab898a6c62015-01-16 14:13:53 -08002088 NOTE: This method should be used after installing application:
2089 onos-app-sdnip
pingping-lin8b306ac2014-11-17 18:13:51 -08002090 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08002091 * jsonFormat: enable output formatting in json
pingping-lin8b306ac2014-11-17 18:13:51 -08002092 Description:
2093 Obtain all routes in the system
kelvin8ec71442015-01-15 16:57:00 -08002094 """
pingping-lin8b306ac2014-11-17 18:13:51 -08002095 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07002096 cmdStr = "routes"
kelvin-onlabd3b64892015-01-20 13:26:24 -08002097 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07002098 cmdStr += " -j"
2099 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08002100 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002101 assert "Command not found:" not in handle, handle
pingping-lin8b306ac2014-11-17 18:13:51 -08002102 return handle
Jon Hallc6793552016-01-19 14:18:37 -08002103 except AssertionError:
2104 main.log.exception( "" )
2105 return None
Jon Halld4d4b372015-01-28 16:02:41 -08002106 except TypeError:
2107 main.log.exception( self.name + ": Object not as expected" )
2108 return None
pingping-lin8b306ac2014-11-17 18:13:51 -08002109 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002110 main.log.error( self.name + ": EOF exception found" )
2111 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002112 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08002113 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08002114 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002115 main.cleanAndExit()
pingping-lin8b306ac2014-11-17 18:13:51 -08002116
pingping-lin54b03372015-08-13 14:43:10 -07002117 def ipv4RouteNumber( self ):
2118 """
2119 NOTE: This method should be used after installing application:
2120 onos-app-sdnip
2121 Description:
2122 Obtain the total IPv4 routes number in the system
2123 """
2124 try:
Pratik Parab57963572017-05-09 11:37:54 -07002125 cmdStr = "routes -j"
pingping-lin54b03372015-08-13 14:43:10 -07002126 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08002127 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002128 assert "Command not found:" not in handle, handle
pingping-lin54b03372015-08-13 14:43:10 -07002129 jsonResult = json.loads( handle )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002130 return len( jsonResult[ 'routes4' ] )
Jon Hallc6793552016-01-19 14:18:37 -08002131 except AssertionError:
2132 main.log.exception( "" )
2133 return None
2134 except ( TypeError, ValueError ):
2135 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) )
pingping-lin54b03372015-08-13 14:43:10 -07002136 return None
2137 except pexpect.EOF:
2138 main.log.error( self.name + ": EOF exception found" )
2139 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002140 main.cleanAndExit()
pingping-lin54b03372015-08-13 14:43:10 -07002141 except Exception:
2142 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002143 main.cleanAndExit()
pingping-lin54b03372015-08-13 14:43:10 -07002144
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002145 # =============Function to check Bandwidth allocation========
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002146 def allocations( self, jsonFormat = True, dollarSign = True ):
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07002147 """
2148 Description:
2149 Obtain Bandwidth Allocation Information from ONOS cli.
2150 """
2151 try:
2152 cmdStr = "allocations"
2153 if jsonFormat:
2154 cmdStr += " -j"
2155 handle = self.sendline( cmdStr, timeout=300, dollarSign=True )
2156 assert handle is not None, "Error in sendline"
2157 assert "Command not found:" not in handle, handle
2158 return handle
2159 except AssertionError:
2160 main.log.exception( "" )
2161 return None
2162 except ( TypeError, ValueError ):
2163 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) )
2164 return None
2165 except pexpect.EOF:
2166 main.log.error( self.name + ": EOF exception found" )
2167 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002168 main.cleanAndExit()
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07002169 except Exception:
2170 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002171 main.cleanAndExit()
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07002172
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002173 def intents( self, jsonFormat = True, summary = False, **intentargs ):
kelvin8ec71442015-01-15 16:57:00 -08002174 """
andrewonlabe6745342014-10-17 14:29:13 -04002175 Description:
Jon Hallff566d52016-01-15 14:45:36 -08002176 Obtain intents from the ONOS cli.
2177 Optional:
2178 * jsonFormat: Enable output formatting in json, default to True
2179 * summary: Whether only output the intent summary, defaults to False
2180 * type: Only output a certain type of intent. This options is valid
2181 only when jsonFormat is True and summary is True.
kelvin-onlab898a6c62015-01-16 14:13:53 -08002182 """
andrewonlabe6745342014-10-17 14:29:13 -04002183 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07002184 cmdStr = "intents"
pingping-lin8244a3b2015-09-16 13:36:56 -07002185 if summary:
2186 cmdStr += " -s"
kelvin-onlabd3b64892015-01-20 13:26:24 -08002187 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07002188 cmdStr += " -j"
Shreya Chowdhary6fbb96c2017-05-02 16:20:19 -07002189 handle = self.sendline( cmdStr, timeout=300 )
You Wangb5a55f72017-03-03 12:51:05 -08002190 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002191 assert "Command not found:" not in handle, handle
pingping-lin8244a3b2015-09-16 13:36:56 -07002192 args = utilities.parse_args( [ "TYPE" ], **intentargs )
acsmars5b5fbaf2015-09-18 10:38:20 -07002193 if "TYPE" in args.keys():
Jon Hallff566d52016-01-15 14:45:36 -08002194 intentType = args[ "TYPE" ]
acsmars5b5fbaf2015-09-18 10:38:20 -07002195 else:
Jon Hallff566d52016-01-15 14:45:36 -08002196 intentType = ""
2197 # IF we want the summary of a specific intent type
2198 if jsonFormat and summary and ( intentType != "" ):
pingping-lin8244a3b2015-09-16 13:36:56 -07002199 jsonResult = json.loads( handle )
Jon Hallff566d52016-01-15 14:45:36 -08002200 if intentType in jsonResult.keys():
2201 return jsonResult[ intentType ]
pingping-lin8244a3b2015-09-16 13:36:56 -07002202 else:
Jon Hallff566d52016-01-15 14:45:36 -08002203 main.log.error( "unknown TYPE, returning all types of intents" )
pingping-lin8244a3b2015-09-16 13:36:56 -07002204 return handle
2205 else:
2206 return handle
Jon Hallc6793552016-01-19 14:18:37 -08002207 except AssertionError:
2208 main.log.exception( "" )
2209 return None
2210 except ( TypeError, ValueError ):
2211 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) )
pingping-lin54b03372015-08-13 14:43:10 -07002212 return None
2213 except pexpect.EOF:
2214 main.log.error( self.name + ": EOF exception found" )
2215 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002216 main.cleanAndExit()
pingping-lin54b03372015-08-13 14:43:10 -07002217 except Exception:
2218 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002219 main.cleanAndExit()
pingping-lin54b03372015-08-13 14:43:10 -07002220
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002221 def getIntentState( self, intentsId, intentsJson=None ):
kelvin-onlab54400a92015-02-26 18:05:51 -08002222 """
You Wangfdcbfc42016-05-16 12:16:53 -07002223 Description:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002224 Gets intent state. Accepts a single intent ID (string type) or a
You Wangfdcbfc42016-05-16 12:16:53 -07002225 list of intent IDs.
2226 Parameters:
2227 intentsId: intent ID, both string type and list type are acceptable
kelvin-onlab54400a92015-02-26 18:05:51 -08002228 intentsJson: parsed json object from the onos:intents api
You Wangfdcbfc42016-05-16 12:16:53 -07002229 Returns:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002230 Returns the state (string type) of the ID if a single intent ID is
You Wangfdcbfc42016-05-16 12:16:53 -07002231 accepted.
2232 Returns a list of dictionaries if a list of intent IDs is accepted,
2233 and each dictionary maps 'id' to the Intent ID and 'state' to
2234 corresponding intent state.
kelvin-onlab54400a92015-02-26 18:05:51 -08002235 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002236
kelvin-onlab54400a92015-02-26 18:05:51 -08002237 try:
2238 state = "State is Undefined"
2239 if not intentsJson:
Jon Hallc6793552016-01-19 14:18:37 -08002240 rawJson = self.intents()
kelvin-onlab54400a92015-02-26 18:05:51 -08002241 else:
Jon Hallc6793552016-01-19 14:18:37 -08002242 rawJson = intentsJson
2243 parsedIntentsJson = json.loads( rawJson )
Jon Hallefbd9792015-03-05 16:11:36 -08002244 if isinstance( intentsId, types.StringType ):
Jon Hallc6793552016-01-19 14:18:37 -08002245 for intent in parsedIntentsJson:
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002246 if intentsId == intent[ 'id' ]:
2247 state = intent[ 'state' ]
kelvin-onlab54400a92015-02-26 18:05:51 -08002248 return state
Jon Hallefbd9792015-03-05 16:11:36 -08002249 main.log.info( "Cannot find intent ID" + str( intentsId ) +
Jon Hall53158082017-05-18 11:17:00 -07002250 " in the list" )
kelvin-onlab54400a92015-02-26 18:05:51 -08002251 return state
Jon Hallefbd9792015-03-05 16:11:36 -08002252 elif isinstance( intentsId, types.ListType ):
kelvin-onlab07dbd012015-03-04 16:29:39 -08002253 dictList = []
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002254 for i in xrange( len( intentsId ) ):
kelvin-onlab07dbd012015-03-04 16:29:39 -08002255 stateDict = {}
Jon Hall53158082017-05-18 11:17:00 -07002256 for intent in parsedIntentsJson:
2257 if intentsId[ i ] == intent[ 'id' ]:
2258 stateDict[ 'state' ] = intent[ 'state' ]
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002259 stateDict[ 'id' ] = intentsId[ i ]
Jon Hallefbd9792015-03-05 16:11:36 -08002260 dictList.append( stateDict )
kelvin-onlab54400a92015-02-26 18:05:51 -08002261 break
Jon Hallefbd9792015-03-05 16:11:36 -08002262 if len( intentsId ) != len( dictList ):
Jon Hall53158082017-05-18 11:17:00 -07002263 main.log.warn( "Could not find all intents in ONOS output" )
2264 main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) )
kelvin-onlab07dbd012015-03-04 16:29:39 -08002265 return dictList
kelvin-onlab54400a92015-02-26 18:05:51 -08002266 else:
Jon Hall53158082017-05-18 11:17:00 -07002267 main.log.info( "Invalid type for intentsId argument" )
kelvin-onlab54400a92015-02-26 18:05:51 -08002268 return None
Jon Hallc6793552016-01-19 14:18:37 -08002269 except ( TypeError, ValueError ):
2270 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) )
kelvin-onlab54400a92015-02-26 18:05:51 -08002271 return None
2272 except pexpect.EOF:
2273 main.log.error( self.name + ": EOF exception found" )
2274 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002275 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08002276 except Exception:
kelvin-onlab54400a92015-02-26 18:05:51 -08002277 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002278 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07002279
Jon Hallf539eb92017-05-22 17:18:42 -07002280 def checkIntentState( self, intentsId, expectedState='INSTALLED' ):
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002281 """
2282 Description:
2283 Check intents state
2284 Required:
2285 intentsId - List of intents ID to be checked
2286 Optional:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002287 expectedState - Check the expected state(s) of each intents
kelvin-onlabf512e942015-06-08 19:42:59 -07002288 state in the list.
2289 *NOTE: You can pass in a list of expected state,
2290 Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ]
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002291 Return:
Jon Hall53158082017-05-18 11:17:00 -07002292 Returns main.TRUE only if all intent are the same as expected states,
2293 otherwise returns main.FALSE.
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002294 """
2295 try:
kelvin-onlabf512e942015-06-08 19:42:59 -07002296 returnValue = main.TRUE
Jon Hallf539eb92017-05-22 17:18:42 -07002297 # Generating a dictionary: intent id as a key and state as value
Devin Lim752dd7b2017-06-27 14:40:03 -07002298
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002299 # intentsDict = self.getIntentState( intentsId )
Devin Lim752dd7b2017-06-27 14:40:03 -07002300 intentsDict = []
2301 for intent in json.loads( self.intents() ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002302 if isinstance( intentsId, types.StringType ) \
2303 and intent.get( 'id' ) == intentsId:
2304 intentsDict.append( intent )
2305 elif isinstance( intentsId, types.ListType ) \
Devin Lim752dd7b2017-06-27 14:40:03 -07002306 and any( intent.get( 'id' ) == ids for ids in intentsId ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002307 intentsDict.append( intent )
Devin Lim752dd7b2017-06-27 14:40:03 -07002308
2309 if not intentsDict:
Jon Hallae04e622016-01-27 10:38:05 -08002310 main.log.info( self.name + ": There is something wrong " +
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002311 "getting intents state" )
2312 return main.FALSE
kelvin-onlabf512e942015-06-08 19:42:59 -07002313
2314 if isinstance( expectedState, types.StringType ):
2315 for intents in intentsDict:
2316 if intents.get( 'state' ) != expectedState:
kelvin-onlaba297c4d2015-06-01 13:53:55 -07002317 main.log.debug( self.name + " : Intent ID - " +
2318 intents.get( 'id' ) +
kelvin-onlabf512e942015-06-08 19:42:59 -07002319 " actual state = " +
2320 intents.get( 'state' )
2321 + " does not equal expected state = "
2322 + expectedState )
kelvin-onlaba297c4d2015-06-01 13:53:55 -07002323 returnValue = main.FALSE
kelvin-onlabf512e942015-06-08 19:42:59 -07002324 elif isinstance( expectedState, types.ListType ):
2325 for intents in intentsDict:
2326 if not any( state == intents.get( 'state' ) for state in
2327 expectedState ):
2328 main.log.debug( self.name + " : Intent ID - " +
2329 intents.get( 'id' ) +
2330 " actual state = " +
2331 intents.get( 'state' ) +
2332 " does not equal expected states = "
2333 + str( expectedState ) )
2334 returnValue = main.FALSE
2335
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002336 if returnValue == main.TRUE:
2337 main.log.info( self.name + ": All " +
2338 str( len( intentsDict ) ) +
kelvin-onlabf512e942015-06-08 19:42:59 -07002339 " intents are in " + str( expectedState ) +
2340 " state" )
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002341 return returnValue
2342 except TypeError:
2343 main.log.exception( self.name + ": Object not as expected" )
2344 return None
2345 except pexpect.EOF:
2346 main.log.error( self.name + ": EOF exception found" )
2347 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002348 main.cleanAndExit()
kelvin-onlabc2dcd3f2015-04-09 16:40:02 -07002349 except Exception:
2350 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002351 main.cleanAndExit()
andrewonlabe6745342014-10-17 14:29:13 -04002352
Jon Hallf539eb92017-05-22 17:18:42 -07002353 def compareBandwidthAllocations( self, expectedAllocations ):
2354 """
2355 Description:
2356 Compare the allocated bandwidth with the given allocations
2357 Required:
2358 expectedAllocations - The expected ONOS output of the allocations command
2359 Return:
2360 Returns main.TRUE only if all intent are the same as expected states,
2361 otherwise returns main.FALSE.
2362 """
2363 # FIXME: Convert these string comparisons to object comparisons
2364 try:
2365 returnValue = main.TRUE
2366 bandwidthFailed = False
2367 rawAlloc = self.allocations()
2368 expectedFormat = StringIO( expectedAllocations )
2369 ONOSOutput = StringIO( rawAlloc )
2370 main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ),
2371 str( expectedFormat ) ) )
2372
2373 for actual, expected in izip( ONOSOutput, expectedFormat ):
2374 actual = actual.rstrip()
2375 expected = expected.rstrip()
2376 main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) )
2377 if actual != expected and 'allocated' in actual and 'allocated' in expected:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002378 marker1 = actual.find( 'allocated' )
2379 m1 = actual[ :marker1 ]
2380 marker2 = expected.find( 'allocated' )
2381 m2 = expected[ :marker2 ]
Jon Hallf539eb92017-05-22 17:18:42 -07002382 if m1 != m2:
2383 bandwidthFailed = True
2384 elif actual != expected and 'allocated' not in actual and 'allocated' not in expected:
2385 bandwidthFailed = True
2386 expectedFormat.close()
2387 ONOSOutput.close()
2388
2389 if bandwidthFailed:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002390 main.log.error( "Bandwidth not allocated correctly using Intents!!" )
Jon Hallf539eb92017-05-22 17:18:42 -07002391 returnValue = main.FALSE
2392 return returnValue
2393 except TypeError:
2394 main.log.exception( self.name + ": Object not as expected" )
2395 return None
2396 except pexpect.EOF:
2397 main.log.error( self.name + ": EOF exception found" )
2398 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002399 main.cleanAndExit()
Jon Hallf539eb92017-05-22 17:18:42 -07002400 except Exception:
2401 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002402 main.cleanAndExit()
Jon Hallf539eb92017-05-22 17:18:42 -07002403
You Wang66518af2016-05-16 15:32:59 -07002404 def compareIntent( self, intentDict ):
2405 """
2406 Description:
2407 Compare the intent ids and states provided in the argument with all intents in ONOS
2408 Return:
2409 Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE
2410 Arguments:
2411 intentDict: a dictionary which maps intent ids to intent states
2412 """
2413 try:
2414 intentsRaw = self.intents()
2415 intentsJson = json.loads( intentsRaw )
2416 intentDictONOS = {}
2417 for intent in intentsJson:
2418 intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ]
You Wang58d04452016-09-21 15:13:05 -07002419 returnValue = main.TRUE
You Wang66518af2016-05-16 15:32:59 -07002420 if len( intentDict ) != len( intentDictONOS ):
You Wang58d04452016-09-21 15:13:05 -07002421 main.log.warn( self.name + ": expected intent count does not match that in ONOS, " +
You Wang66518af2016-05-16 15:32:59 -07002422 str( len( intentDict ) ) + " expected and " +
2423 str( len( intentDictONOS ) ) + " actual" )
You Wang58d04452016-09-21 15:13:05 -07002424 returnValue = main.FALSE
You Wang66518af2016-05-16 15:32:59 -07002425 for intentID in intentDict.keys():
Jon Halle0f0b342017-04-18 11:43:47 -07002426 if intentID not in intentDictONOS.keys():
You Wang66518af2016-05-16 15:32:59 -07002427 main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" )
2428 returnValue = main.FALSE
You Wang58d04452016-09-21 15:13:05 -07002429 else:
2430 if intentDict[ intentID ] != intentDictONOS[ intentID ]:
2431 main.log.debug( self.name + ": intent ID - " + intentID +
2432 " expected state is " + intentDict[ intentID ] +
2433 " but actual state is " + intentDictONOS[ intentID ] )
2434 returnValue = main.FALSE
2435 intentDictONOS.pop( intentID )
2436 if len( intentDictONOS ) > 0:
2437 returnValue = main.FALSE
2438 for intentID in intentDictONOS.keys():
2439 main.log.debug( self.name + ": find extra intent in ONOS: intent ID " + intentID )
You Wang66518af2016-05-16 15:32:59 -07002440 if returnValue == main.TRUE:
2441 main.log.info( self.name + ": all intent IDs and states match that in ONOS" )
2442 return returnValue
You Wang1be9a512016-05-26 16:54:17 -07002443 except KeyError:
2444 main.log.exception( self.name + ": KeyError exception found" )
2445 return main.ERROR
You Wang66518af2016-05-16 15:32:59 -07002446 except ( TypeError, ValueError ):
2447 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) )
You Wang85560372016-05-18 10:44:33 -07002448 return main.ERROR
You Wang66518af2016-05-16 15:32:59 -07002449 except pexpect.EOF:
2450 main.log.error( self.name + ": EOF exception found" )
2451 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002452 main.cleanAndExit()
You Wang66518af2016-05-16 15:32:59 -07002453 except Exception:
2454 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002455 main.cleanAndExit()
You Wang66518af2016-05-16 15:32:59 -07002456
YPZhang14a4aa92016-07-15 13:37:15 -07002457 def checkIntentSummary( self, timeout=60, noExit=True ):
GlennRCed771242016-01-13 17:02:47 -08002458 """
2459 Description:
2460 Check the number of installed intents.
2461 Optional:
2462 timeout - the timeout for pexcept
YPZhang14a4aa92016-07-15 13:37:15 -07002463 noExit - If noExit, TestON will not exit if any except.
GlennRCed771242016-01-13 17:02:47 -08002464 Return:
2465 Returns main.TRUE only if the number of all installed intents are the same as total intents number
2466 , otherwise, returns main.FALSE.
2467 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002468
GlennRCed771242016-01-13 17:02:47 -08002469 try:
2470 cmd = "intents -s -j"
2471
2472 # Check response if something wrong
YPZhang14a4aa92016-07-15 13:37:15 -07002473 response = self.sendline( cmd, timeout=timeout, noExit=noExit )
Jon Halle0f0b342017-04-18 11:43:47 -07002474 if response is None:
YPZhang0584d432016-06-21 15:20:13 -07002475 return main.FALSE
GlennRCed771242016-01-13 17:02:47 -08002476 response = json.loads( response )
2477
2478 # get total and installed number, see if they are match
2479 allState = response.get( 'all' )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002480 if allState.get( 'total' ) == allState.get( 'installed' ):
Jon Halla478b852017-12-04 15:00:15 -08002481 main.log.info( 'Total Intents: {} Installed Intents: {}'.format(
2482 allState.get( 'total' ), allState.get( 'installed' ) ) )
GlennRCed771242016-01-13 17:02:47 -08002483 return main.TRUE
Jon Halla478b852017-12-04 15:00:15 -08002484 main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format(
2485 allState.get( 'total' ), allState.get( 'installed' ) ) )
GlennRCed771242016-01-13 17:02:47 -08002486 return main.FALSE
2487
Jon Hallc6793552016-01-19 14:18:37 -08002488 except ( TypeError, ValueError ):
2489 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) )
GlennRCed771242016-01-13 17:02:47 -08002490 return None
2491 except pexpect.EOF:
2492 main.log.error( self.name + ": EOF exception found" )
2493 main.log.error( self.name + ": " + self.handle.before )
YPZhang14a4aa92016-07-15 13:37:15 -07002494 if noExit:
2495 return main.FALSE
2496 else:
Devin Lim44075962017-08-11 10:56:37 -07002497 main.cleanAndExit()
Jon Halle0f0b342017-04-18 11:43:47 -07002498 except pexpect.TIMEOUT:
2499 main.log.error( self.name + ": ONOS timeout" )
2500 return None
GlennRCed771242016-01-13 17:02:47 -08002501 except Exception:
2502 main.log.exception( self.name + ": Uncaught exception!" )
YPZhang14a4aa92016-07-15 13:37:15 -07002503 if noExit:
2504 return main.FALSE
2505 else:
Devin Lim44075962017-08-11 10:56:37 -07002506 main.cleanAndExit()
GlennRCed771242016-01-13 17:02:47 -08002507
Andreas Pantelopoulosdf5061f2018-05-15 11:46:59 -07002508 def flows( self, state="any", jsonFormat=True, timeout=60, noExit=False, noCore=False, device=""):
kelvin8ec71442015-01-15 16:57:00 -08002509 """
Shreya Shah0f01c812014-10-26 20:15:28 -04002510 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08002511 * jsonFormat: enable output formatting in json
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002512 * noCore: suppress core flows
Shreya Shah0f01c812014-10-26 20:15:28 -04002513 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08002514 Obtain flows currently installed
kelvin-onlab898a6c62015-01-16 14:13:53 -08002515 """
Shreya Shah0f01c812014-10-26 20:15:28 -04002516 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07002517 cmdStr = "flows"
kelvin-onlabd3b64892015-01-20 13:26:24 -08002518 if jsonFormat:
Andreas Pantelopoulosdf5061f2018-05-15 11:46:59 -07002519 cmdStr += " -j"
Jeremy Songster306ed7a2016-07-19 10:59:07 -07002520 if noCore:
Andreas Pantelopoulosdf5061f2018-05-15 11:46:59 -07002521 cmdStr += " -n"
2522 cmdStr += " " + state
2523 cmdStr += " " + device
YPZhangebf9eb52016-05-12 15:20:24 -07002524 handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit )
You Wangb5a55f72017-03-03 12:51:05 -08002525 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002526 assert "Command not found:" not in handle, handle
2527 if re.search( "Error:", handle ):
2528 main.log.error( self.name + ": flows() response: " +
2529 str( handle ) )
2530 return handle
2531 except AssertionError:
2532 main.log.exception( "" )
GlennRCed771242016-01-13 17:02:47 -08002533 return None
Jon Halld4d4b372015-01-28 16:02:41 -08002534 except TypeError:
2535 main.log.exception( self.name + ": Object not as expected" )
2536 return None
Jon Hallc6793552016-01-19 14:18:37 -08002537 except pexpect.TIMEOUT:
2538 main.log.error( self.name + ": ONOS timeout" )
2539 return None
Shreya Shah0f01c812014-10-26 20:15:28 -04002540 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002541 main.log.error( self.name + ": EOF exception found" )
2542 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002543 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08002544 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08002545 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002546 main.cleanAndExit()
Shreya Shah0f01c812014-10-26 20:15:28 -04002547
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002548 def checkFlowCount( self, min=0, timeout=60 ):
Flavio Castroa1286fe2016-07-25 14:48:51 -07002549 count = self.getTotalFlowsNum( timeout=timeout )
Jon Halle0f0b342017-04-18 11:43:47 -07002550 count = int( count ) if count else 0
2551 return count if ( count > min ) else False
GlennRCed771242016-01-13 17:02:47 -08002552
Jon Halle0f0b342017-04-18 11:43:47 -07002553 def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ):
kelvin-onlab4df89f22015-04-13 18:10:23 -07002554 """
2555 Description:
GlennRCed771242016-01-13 17:02:47 -08002556 Check the if all the current flows are in ADDED state
Jon Hallc6793552016-01-19 14:18:37 -08002557 We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows,
2558 if the count of those states is 0, which means all current flows
2559 are in ADDED state, and return main.TRUE otherwise return main.FALSE
pingping-linbab7f8a2015-09-21 17:33:36 -07002560 Optional:
GlennRCed771242016-01-13 17:02:47 -08002561 * isPENDING: whether the PENDING_ADD is also a correct status
kelvin-onlab4df89f22015-04-13 18:10:23 -07002562 Return:
2563 returnValue - Returns main.TRUE only if all flows are in
Jon Hallc6793552016-01-19 14:18:37 -08002564 ADDED state or PENDING_ADD if the isPENDING
pingping-linbab7f8a2015-09-21 17:33:36 -07002565 parameter is set true, return main.FALSE otherwise.
kelvin-onlab4df89f22015-04-13 18:10:23 -07002566 """
2567 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002568 states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ]
GlennRCed771242016-01-13 17:02:47 -08002569 checkedStates = []
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002570 statesCount = [ 0, 0, 0, 0 ]
GlennRCed771242016-01-13 17:02:47 -08002571 for s in states:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002572 rawFlows = self.flows( state=s, timeout = timeout )
YPZhang240842b2016-05-17 12:00:50 -07002573 if rawFlows:
2574 # if we didn't get flows or flows function return None, we should return
2575 # main.Flase
2576 checkedStates.append( json.loads( rawFlows ) )
2577 else:
2578 return main.FALSE
Jon Hallc6793552016-01-19 14:18:37 -08002579 for i in range( len( states ) ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002580 for c in checkedStates[ i ]:
Jon Hallc6793552016-01-19 14:18:37 -08002581 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002582 statesCount[ i ] += int( c.get( "flowCount" ) )
Jon Hallc6793552016-01-19 14:18:37 -08002583 except TypeError:
2584 main.log.exception( "Json object not as expected" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002585 main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) )
kelvin-onlabf2ec6e02015-05-27 14:15:28 -07002586
GlennRCed771242016-01-13 17:02:47 -08002587 # We want to count PENDING_ADD if isPENDING is true
2588 if isPENDING:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002589 if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0:
GlennRCed771242016-01-13 17:02:47 -08002590 return main.FALSE
pingping-linbab7f8a2015-09-21 17:33:36 -07002591 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002592 if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0:
GlennRCed771242016-01-13 17:02:47 -08002593 return main.FALSE
GlennRCed771242016-01-13 17:02:47 -08002594 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -08002595 except ( TypeError, ValueError ):
2596 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) )
kelvin-onlab4df89f22015-04-13 18:10:23 -07002597 return None
Jeremy Songster9385d412016-06-02 17:57:36 -07002598
YPZhang240842b2016-05-17 12:00:50 -07002599 except AssertionError:
2600 main.log.exception( "" )
2601 return None
Jon Halle0f0b342017-04-18 11:43:47 -07002602 except pexpect.TIMEOUT:
2603 main.log.error( self.name + ": ONOS timeout" )
2604 return None
kelvin-onlab4df89f22015-04-13 18:10:23 -07002605 except pexpect.EOF:
2606 main.log.error( self.name + ": EOF exception found" )
2607 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002608 main.cleanAndExit()
kelvin-onlab4df89f22015-04-13 18:10:23 -07002609 except Exception:
2610 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002611 main.cleanAndExit()
kelvin-onlab4df89f22015-04-13 18:10:23 -07002612
GlennRCed771242016-01-13 17:02:47 -08002613 def pushTestIntents( self, ingress, egress, batchSize, offset="",
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002614 options="", timeout=10, background = False, noExit=False, getResponse=False ):
kelvin8ec71442015-01-15 16:57:00 -08002615 """
andrewonlab87852b02014-11-19 18:44:19 -05002616 Description:
Jon Halle3f39ff2015-01-13 11:50:53 -08002617 Push a number of intents in a batch format to
andrewonlab87852b02014-11-19 18:44:19 -05002618 a specific point-to-point intent definition
2619 Required:
GlennRCed771242016-01-13 17:02:47 -08002620 * ingress: specify source dpid
2621 * egress: specify destination dpid
2622 * batchSize: specify number of intents to push
andrewonlab87852b02014-11-19 18:44:19 -05002623 Optional:
GlennRCed771242016-01-13 17:02:47 -08002624 * offset: the keyOffset is where the next batch of intents
2625 will be installed
YPZhangb34b7e12016-06-14 14:28:19 -07002626 * noExit: If set to True, TestON will not exit if any error when issus command
2627 * getResponse: If set to True, function will return ONOS response.
2628
GlennRCed771242016-01-13 17:02:47 -08002629 Returns: If failed to push test intents, it will returen None,
2630 if successful, return true.
2631 Timeout expection will return None,
2632 TypeError will return false
2633 other expections will exit()
kelvin8ec71442015-01-15 16:57:00 -08002634 """
andrewonlab87852b02014-11-19 18:44:19 -05002635 try:
GlennRCed771242016-01-13 17:02:47 -08002636 if background:
2637 back = "&"
andrewonlab87852b02014-11-19 18:44:19 -05002638 else:
GlennRCed771242016-01-13 17:02:47 -08002639 back = ""
2640 cmd = "push-test-intents {} {} {} {} {} {}".format( options,
Jon Hallc6793552016-01-19 14:18:37 -08002641 ingress,
2642 egress,
2643 batchSize,
2644 offset,
2645 back )
YPZhangebf9eb52016-05-12 15:20:24 -07002646 response = self.sendline( cmd, timeout=timeout, noExit=noExit )
You Wangb5a55f72017-03-03 12:51:05 -08002647 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002648 assert "Command not found:" not in response, response
GlennRCed771242016-01-13 17:02:47 -08002649 main.log.info( response )
YPZhangb34b7e12016-06-14 14:28:19 -07002650 if getResponse:
2651 return response
2652
GlennRCed771242016-01-13 17:02:47 -08002653 # TODO: We should handle if there is failure in installation
2654 return main.TRUE
2655
Jon Hallc6793552016-01-19 14:18:37 -08002656 except AssertionError:
2657 main.log.exception( "" )
2658 return None
GlennRCed771242016-01-13 17:02:47 -08002659 except pexpect.TIMEOUT:
2660 main.log.error( self.name + ": ONOS timeout" )
Jon Halld4d4b372015-01-28 16:02:41 -08002661 return None
andrewonlab87852b02014-11-19 18:44:19 -05002662 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002663 main.log.error( self.name + ": EOF exception found" )
2664 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002665 main.cleanAndExit()
GlennRCed771242016-01-13 17:02:47 -08002666 except TypeError:
2667 main.log.exception( self.name + ": Object not as expected" )
Jon Hallc6793552016-01-19 14:18:37 -08002668 return None
Jon Hallfebb1c72015-03-05 13:30:09 -08002669 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08002670 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002671 main.cleanAndExit()
andrewonlab87852b02014-11-19 18:44:19 -05002672
YPZhangebf9eb52016-05-12 15:20:24 -07002673 def getTotalFlowsNum( self, timeout=60, noExit=False ):
YPZhangb5d3f832016-01-23 22:54:26 -08002674 """
2675 Description:
YPZhangf6f14a02016-01-28 15:17:31 -08002676 Get the number of ADDED flows.
YPZhangb5d3f832016-01-23 22:54:26 -08002677 Return:
YPZhangf6f14a02016-01-28 15:17:31 -08002678 The number of ADDED flows
YPZhang14a4aa92016-07-15 13:37:15 -07002679 Or return None if any exceptions
YPZhangb5d3f832016-01-23 22:54:26 -08002680 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002681
YPZhangb5d3f832016-01-23 22:54:26 -08002682 try:
YPZhange3109a72016-02-02 11:25:37 -08002683 # get total added flows number
YPZhang14a4aa92016-07-15 13:37:15 -07002684 cmd = "flows -c added"
2685 rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit )
2686 if rawFlows:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002687 rawFlows = rawFlows.split( "\n" )
YPZhange3109a72016-02-02 11:25:37 -08002688 totalFlows = 0
YPZhang14a4aa92016-07-15 13:37:15 -07002689 for l in rawFlows:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002690 totalFlows += int( l.split( "Count=" )[ 1 ] )
YPZhang14a4aa92016-07-15 13:37:15 -07002691 else:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002692 main.log.error( "Response not as expected!" )
YPZhang14a4aa92016-07-15 13:37:15 -07002693 return None
2694 return totalFlows
YPZhange3109a72016-02-02 11:25:37 -08002695
You Wangd3cb2ce2016-05-16 14:01:24 -07002696 except ( TypeError, ValueError ):
YPZhang14a4aa92016-07-15 13:37:15 -07002697 main.log.exception( "{}: Object not as expected!".format( self.name ) )
YPZhangb5d3f832016-01-23 22:54:26 -08002698 return None
2699 except pexpect.EOF:
2700 main.log.error( self.name + ": EOF exception found" )
2701 main.log.error( self.name + ": " + self.handle.before )
YPZhang14a4aa92016-07-15 13:37:15 -07002702 if not noExit:
Devin Lim44075962017-08-11 10:56:37 -07002703 main.cleanAndExit()
YPZhang14a4aa92016-07-15 13:37:15 -07002704 return None
Jon Halle0f0b342017-04-18 11:43:47 -07002705 except pexpect.TIMEOUT:
2706 main.log.error( self.name + ": ONOS timeout" )
2707 return None
YPZhangb5d3f832016-01-23 22:54:26 -08002708 except Exception:
2709 main.log.exception( self.name + ": Uncaught exception!" )
YPZhang14a4aa92016-07-15 13:37:15 -07002710 if not noExit:
Devin Lim44075962017-08-11 10:56:37 -07002711 main.cleanAndExit()
YPZhang14a4aa92016-07-15 13:37:15 -07002712 return None
YPZhangb5d3f832016-01-23 22:54:26 -08002713
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00002714 def getTotalIntentsNum( self, timeout=60, noExit = False ):
YPZhangb5d3f832016-01-23 22:54:26 -08002715 """
2716 Description:
2717 Get the total number of intents, include every states.
YPZhang14a4aa92016-07-15 13:37:15 -07002718 Optional:
2719 noExit - If noExit, TestON will not exit if any except.
YPZhangb5d3f832016-01-23 22:54:26 -08002720 Return:
2721 The number of intents
2722 """
2723 try:
2724 cmd = "summary -j"
YPZhang14a4aa92016-07-15 13:37:15 -07002725 response = self.sendline( cmd, timeout=timeout, noExit=noExit )
Jon Halle0f0b342017-04-18 11:43:47 -07002726 if response is None:
2727 return -1
YPZhangb5d3f832016-01-23 22:54:26 -08002728 response = json.loads( response )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002729 return int( response.get( "intents" ) )
You Wangd3cb2ce2016-05-16 14:01:24 -07002730 except ( TypeError, ValueError ):
2731 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) )
YPZhangb5d3f832016-01-23 22:54:26 -08002732 return None
2733 except pexpect.EOF:
2734 main.log.error( self.name + ": EOF exception found" )
2735 main.log.error( self.name + ": " + self.handle.before )
YPZhang14a4aa92016-07-15 13:37:15 -07002736 if noExit:
2737 return -1
2738 else:
Devin Lim44075962017-08-11 10:56:37 -07002739 main.cleanAndExit()
YPZhangb5d3f832016-01-23 22:54:26 -08002740 except Exception:
2741 main.log.exception( self.name + ": Uncaught exception!" )
YPZhang14a4aa92016-07-15 13:37:15 -07002742 if noExit:
2743 return -1
2744 else:
Devin Lim44075962017-08-11 10:56:37 -07002745 main.cleanAndExit()
YPZhangb5d3f832016-01-23 22:54:26 -08002746
kelvin-onlabd3b64892015-01-20 13:26:24 -08002747 def intentsEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08002748 """
Jon Halle3f39ff2015-01-13 11:50:53 -08002749 Description:Returns topology metrics
andrewonlab0dbb6ec2014-11-06 13:46:55 -05002750 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08002751 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08002752 """
andrewonlab0dbb6ec2014-11-06 13:46:55 -05002753 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07002754 cmdStr = "intents-events-metrics"
kelvin-onlabd3b64892015-01-20 13:26:24 -08002755 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07002756 cmdStr += " -j"
2757 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08002758 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002759 assert "Command not found:" not in handle, handle
andrewonlab0dbb6ec2014-11-06 13:46:55 -05002760 return handle
Jon Hallc6793552016-01-19 14:18:37 -08002761 except AssertionError:
2762 main.log.exception( "" )
2763 return None
Jon Halld4d4b372015-01-28 16:02:41 -08002764 except TypeError:
2765 main.log.exception( self.name + ": Object not as expected" )
2766 return None
andrewonlab0dbb6ec2014-11-06 13:46:55 -05002767 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002768 main.log.error( self.name + ": EOF exception found" )
2769 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002770 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08002771 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08002772 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002773 main.cleanAndExit()
Shreya Shah0f01c812014-10-26 20:15:28 -04002774
kelvin-onlabd3b64892015-01-20 13:26:24 -08002775 def topologyEventsMetrics( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08002776 """
2777 Description:Returns topology metrics
andrewonlab867212a2014-10-22 20:13:38 -04002778 Optional:
kelvin-onlabd3b64892015-01-20 13:26:24 -08002779 * jsonFormat: enable json formatting of output
kelvin8ec71442015-01-15 16:57:00 -08002780 """
andrewonlab867212a2014-10-22 20:13:38 -04002781 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07002782 cmdStr = "topology-events-metrics"
kelvin-onlabd3b64892015-01-20 13:26:24 -08002783 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07002784 cmdStr += " -j"
2785 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08002786 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002787 assert "Command not found:" not in handle, handle
jenkins7ead5a82015-03-13 10:28:21 -07002788 if handle:
2789 return handle
Jon Hallc6358dd2015-04-10 12:44:28 -07002790 elif jsonFormat:
Jon Hallbe379602015-03-24 13:39:32 -07002791 # Return empty json
jenkins7ead5a82015-03-13 10:28:21 -07002792 return '{}'
Jon Hallc6358dd2015-04-10 12:44:28 -07002793 else:
2794 return handle
Jon Hallc6793552016-01-19 14:18:37 -08002795 except AssertionError:
2796 main.log.exception( "" )
2797 return None
Jon Halld4d4b372015-01-28 16:02:41 -08002798 except TypeError:
2799 main.log.exception( self.name + ": Object not as expected" )
2800 return None
andrewonlab867212a2014-10-22 20:13:38 -04002801 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002802 main.log.error( self.name + ": EOF exception found" )
2803 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002804 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08002805 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08002806 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002807 main.cleanAndExit()
andrewonlab867212a2014-10-22 20:13:38 -04002808
kelvin8ec71442015-01-15 16:57:00 -08002809 # Wrapper functions ****************
2810 # Wrapper functions use existing driver
2811 # functions and extends their use case.
2812 # For example, we may use the output of
2813 # a normal driver function, and parse it
2814 # using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -04002815
kelvin-onlabd3b64892015-01-20 13:26:24 -08002816 def getAllIntentsId( self ):
kelvin8ec71442015-01-15 16:57:00 -08002817 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04002818 Description:
2819 Obtain all intent id's in a list
kelvin8ec71442015-01-15 16:57:00 -08002820 """
andrewonlab9a50dfe2014-10-17 17:22:31 -04002821 try:
kelvin8ec71442015-01-15 16:57:00 -08002822 # Obtain output of intents function
Jeremy Ronquillo82705492017-10-18 14:19:55 -07002823 intentsStr = self.intents( jsonFormat=True )
Jon Hall7a6ebfd2017-03-13 10:58:58 -07002824 if intentsStr is None:
2825 raise TypeError
Jon Hall6021e062017-01-30 11:10:06 -08002826 # Convert to a dictionary
2827 intents = json.loads( intentsStr )
kelvin-onlabd3b64892015-01-20 13:26:24 -08002828 intentIdList = []
Jon Hall6021e062017-01-30 11:10:06 -08002829 for intent in intents:
2830 intentIdList.append( intent[ 'id' ] )
kelvin-onlabd3b64892015-01-20 13:26:24 -08002831 return intentIdList
Jon Halld4d4b372015-01-28 16:02:41 -08002832 except TypeError:
2833 main.log.exception( self.name + ": Object not as expected" )
2834 return None
andrewonlab9a50dfe2014-10-17 17:22:31 -04002835 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08002836 main.log.error( self.name + ": EOF exception found" )
2837 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002838 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08002839 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08002840 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002841 main.cleanAndExit()
andrewonlab9a50dfe2014-10-17 17:22:31 -04002842
You Wang3c276252016-09-21 15:21:36 -07002843 def flowAddedCount( self, deviceId, core=False ):
Jon Hall30b82fa2015-03-04 17:15:43 -08002844 """
2845 Determine the number of flow rules for the given device id that are
2846 in the added state
You Wang3c276252016-09-21 15:21:36 -07002847 Params:
2848 core: if True, only return the number of core flows added
Jon Hall30b82fa2015-03-04 17:15:43 -08002849 """
2850 try:
You Wang3c276252016-09-21 15:21:36 -07002851 if core:
2852 cmdStr = "flows any " + str( deviceId ) + " | " +\
2853 "grep 'state=ADDED' | grep org.onosproject.core | wc -l"
2854 else:
2855 cmdStr = "flows any " + str( deviceId ) + " | " +\
2856 "grep 'state=ADDED' | wc -l"
Jon Hall30b82fa2015-03-04 17:15:43 -08002857 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08002858 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08002859 assert "Command not found:" not in handle, handle
Jon Hall30b82fa2015-03-04 17:15:43 -08002860 return handle
Jon Hallc6793552016-01-19 14:18:37 -08002861 except AssertionError:
2862 main.log.exception( "" )
2863 return None
Jon Hall30b82fa2015-03-04 17:15:43 -08002864 except pexpect.EOF:
2865 main.log.error( self.name + ": EOF exception found" )
2866 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07002867 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08002868 except Exception:
Jon Hall30b82fa2015-03-04 17:15:43 -08002869 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07002870 main.cleanAndExit()
andrewonlab95ce8322014-10-13 14:12:04 -04002871
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -08002872 def groupAddedCount( self, deviceId, core=False ):
2873 """
2874 Determine the number of group rules for the given device id that are
2875 in the added state
2876 Params:
2877 core: if True, only return the number of core groups added
2878 """
2879 try:
2880 if core:
2881 cmdStr = "groups any " + str( deviceId ) + " | " +\
2882 "grep 'state=ADDED' | grep org.onosproject.core | wc -l"
2883 else:
2884 cmdStr = "groups any " + str( deviceId ) + " | " +\
2885 "grep 'state=ADDED' | wc -l"
2886 handle = self.sendline( cmdStr )
2887 assert handle is not None, "Error in sendline"
2888 assert "Command not found:" not in handle, handle
2889 return handle
2890 except AssertionError:
2891 main.log.exception( "" )
2892 return None
2893 except pexpect.EOF:
2894 main.log.error( self.name + ": EOF exception found" )
2895 main.log.error( self.name + ": " + self.handle.before )
2896 main.cleanAndExit()
2897 except Exception:
2898 main.log.exception( self.name + ": Uncaught exception!" )
2899 main.cleanAndExit()
2900
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -08002901 def addStaticRoute( self, subnet, intf):
2902 """
2903 Adds a static route to onos.
2904 Params:
2905 subnet: The subnet reaching through this route
2906 intf: The interface this route is reachable through
2907 """
2908 try:
2909 cmdStr = "route-add " + subnet + " " + intf
2910 handle = self.sendline( cmdStr )
2911 assert handle is not None, "Error in sendline"
2912 assert "Command not found:" not in handle, handle
2913 return handle
2914 except AssertionError:
2915 main.log.exception( "" )
2916 return None
2917 except pexpect.EOF:
2918 main.log.error( self.name + ": EOF exception found" )
2919 main.log.error( self.name + ": " + self.handle.before )
2920 main.cleanAndExit()
2921 except Exception:
2922 main.log.exception( self.name + ": Uncaught exception!" )
2923 main.cleanAndExit()
2924
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -08002925 def checkGroupAddedCount( self, deviceId, expectedGroupCount=0, core=False, comparison=0):
2926 """
2927 Description:
2928 Check whether the number of groups for the given device id that
2929 are in ADDED state is bigger than minGroupCount.
2930 Required:
2931 * deviceId: device id to check the number of added group rules
2932 Optional:
2933 * minGroupCount: the number of groups to compare
2934 * core: if True, only check the number of core groups added
2935 * comparison: if 0, compare with greater than minFlowCount
2936 * if 1, compare with equal to minFlowCount
2937 Return:
2938 Returns the number of groups if it is bigger than minGroupCount,
2939 returns main.FALSE otherwise.
2940 """
2941 count = self.groupAddedCount( deviceId, core )
2942 count = int( count ) if count else 0
Jon Hall9677ed32018-04-24 11:16:23 -07002943 main.log.debug( "found {} groups".format( count ) )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -08002944 return count if ((count > expectedGroupCount) if (comparison == 0) else (count == expectedGroupCount)) else main.FALSE
2945
Andreas Pantelopoulosdf5061f2018-05-15 11:46:59 -07002946 def getGroups( self, deviceId, group_type="any"):
2947 """
2948 Retrieve groups from a specific device.
2949 group_type = Type of group
2950 """
2951
2952 try:
2953 group_cmd = "groups -t {0} any {1}".format(group_type, deviceId)
2954 self.sendline(group_cmd, showResponse=False)
2955 handle = self.sendline( group_cmd )
2956 assert handle is not None, "Error in sendline"
2957 assert "Command not found:" not in handle, handle
2958 return handle
2959 except AssertionError:
2960 main.log.exception( "" )
2961 return None
2962 except TypeError:
2963 main.log.exception( self.name + ": Object not as expected" )
2964 return None
2965 except pexpect.EOF:
2966 main.log.error( self.name + ": EOF exception found" )
2967 main.log.error( self.name + ": " + self.handle.before )
2968 main.cleanAndExit()
2969 except Exception:
2970 main.log.exception( self.name + ": Uncaught exception!" )
2971 main.cleanAndExit()
2972
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -08002973 def checkFlowAddedCount( self, deviceId, expectedFlowCount=0, core=False, comparison=0):
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -08002974 """
2975 Description:
2976 Check whether the number of flow rules for the given device id that
2977 are in ADDED state is bigger than minFlowCount.
2978 Required:
2979 * deviceId: device id to check the number of added flow rules
2980 Optional:
2981 * minFlowCount: the number of flow rules to compare
2982 * core: if True, only check the number of core flows added
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -08002983 * comparison: if 0, compare with greater than minFlowCount
2984 * if 1, compare with equal to minFlowCount
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -08002985 Return:
2986 Returns the number of flow rules if it is bigger than minFlowCount,
2987 returns main.FALSE otherwise.
2988 """
2989 count = self.flowAddedCount( deviceId, core )
2990 count = int( count ) if count else 0
Jon Hall9677ed32018-04-24 11:16:23 -07002991 main.log.debug( "found {} flows".format( count ) )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -08002992 return count if ((count > expectedFlowCount) if (comparison == 0) else (count == expectedFlowCount)) else main.FALSE
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -08002993
kelvin-onlabd3b64892015-01-20 13:26:24 -08002994 def getAllDevicesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08002995 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04002996 Use 'devices' function to obtain list of all devices
2997 and parse the result to obtain a list of all device
2998 id's. Returns this list. Returns empty list if no
2999 devices exist
kelvin8ec71442015-01-15 16:57:00 -08003000 List is ordered sequentially
3001
andrewonlab3e15ead2014-10-15 14:21:34 -04003002 This function may be useful if you are not sure of the
kelvin8ec71442015-01-15 16:57:00 -08003003 device id, and wish to execute other commands using
andrewonlab3e15ead2014-10-15 14:21:34 -04003004 the ids. By obtaining the list of device ids on the fly,
3005 you can iterate through the list to get mastership, etc.
kelvin8ec71442015-01-15 16:57:00 -08003006 """
andrewonlab7e4d2d32014-10-15 13:23:21 -04003007 try:
kelvin8ec71442015-01-15 16:57:00 -08003008 # Call devices and store result string
kelvin-onlabd3b64892015-01-20 13:26:24 -08003009 devicesStr = self.devices( jsonFormat=False )
3010 idList = []
kelvin8ec71442015-01-15 16:57:00 -08003011
kelvin-onlabd3b64892015-01-20 13:26:24 -08003012 if not devicesStr:
kelvin8ec71442015-01-15 16:57:00 -08003013 main.log.info( "There are no devices to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003014 return idList
kelvin8ec71442015-01-15 16:57:00 -08003015
3016 # Split the string into list by comma
kelvin-onlabd3b64892015-01-20 13:26:24 -08003017 deviceList = devicesStr.split( "," )
kelvin8ec71442015-01-15 16:57:00 -08003018 # Get temporary list of all arguments with string 'id='
kelvin-onlabd3b64892015-01-20 13:26:24 -08003019 tempList = [ dev for dev in deviceList if "id=" in dev ]
kelvin8ec71442015-01-15 16:57:00 -08003020 # Split list further into arguments before and after string
3021 # 'id='. Get the latter portion ( the actual device id ) and
kelvin-onlabd3b64892015-01-20 13:26:24 -08003022 # append to idList
3023 for arg in tempList:
3024 idList.append( arg.split( "id=" )[ 1 ] )
3025 return idList
andrewonlab7e4d2d32014-10-15 13:23:21 -04003026
Jon Halld4d4b372015-01-28 16:02:41 -08003027 except TypeError:
3028 main.log.exception( self.name + ": Object not as expected" )
3029 return None
andrewonlab7e4d2d32014-10-15 13:23:21 -04003030 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003031 main.log.error( self.name + ": EOF exception found" )
3032 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003033 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003034 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003035 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003036 main.cleanAndExit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04003037
kelvin-onlabd3b64892015-01-20 13:26:24 -08003038 def getAllNodesId( self ):
kelvin8ec71442015-01-15 16:57:00 -08003039 """
andrewonlab7c211572014-10-15 16:45:20 -04003040 Uses 'nodes' function to obtain list of all nodes
3041 and parse the result of nodes to obtain just the
kelvin8ec71442015-01-15 16:57:00 -08003042 node id's.
andrewonlab7c211572014-10-15 16:45:20 -04003043 Returns:
3044 list of node id's
kelvin8ec71442015-01-15 16:57:00 -08003045 """
andrewonlab7c211572014-10-15 16:45:20 -04003046 try:
Jon Hall5aa168b2015-03-23 14:23:09 -07003047 nodesStr = self.nodes( jsonFormat=True )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003048 idList = []
Jon Hall5aa168b2015-03-23 14:23:09 -07003049 # Sample nodesStr output
Jon Hallbd182782016-03-28 16:42:22 -07003050 # id=local, address=127.0.0.1:9876, state=READY *
kelvin-onlabd3b64892015-01-20 13:26:24 -08003051 if not nodesStr:
kelvin8ec71442015-01-15 16:57:00 -08003052 main.log.info( "There are no nodes to get id from" )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003053 return idList
Jon Hall5aa168b2015-03-23 14:23:09 -07003054 nodesJson = json.loads( nodesStr )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003055 idList = [ node.get( 'id' ) for node in nodesJson ]
kelvin-onlabd3b64892015-01-20 13:26:24 -08003056 return idList
Jon Hallc6793552016-01-19 14:18:37 -08003057 except ( TypeError, ValueError ):
3058 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) )
Jon Halld4d4b372015-01-28 16:02:41 -08003059 return None
andrewonlab7c211572014-10-15 16:45:20 -04003060 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003061 main.log.error( self.name + ": EOF exception found" )
3062 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003063 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003064 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003065 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003066 main.cleanAndExit()
andrewonlab7e4d2d32014-10-15 13:23:21 -04003067
kelvin-onlabd3b64892015-01-20 13:26:24 -08003068 def getDevice( self, dpid=None ):
kelvin8ec71442015-01-15 16:57:00 -08003069 """
Jon Halla91c4dc2014-10-22 12:57:04 -04003070 Return the first device from the devices api whose 'id' contains 'dpid'
3071 Return None if there is no match
kelvin8ec71442015-01-15 16:57:00 -08003072 """
Jon Halla91c4dc2014-10-22 12:57:04 -04003073 try:
kelvin8ec71442015-01-15 16:57:00 -08003074 if dpid is None:
Jon Halla91c4dc2014-10-22 12:57:04 -04003075 return None
3076 else:
kelvin8ec71442015-01-15 16:57:00 -08003077 dpid = dpid.replace( ':', '' )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003078 rawDevices = self.devices()
3079 devicesJson = json.loads( rawDevices )
kelvin8ec71442015-01-15 16:57:00 -08003080 # search json for the device with dpid then return the device
kelvin-onlabd3b64892015-01-20 13:26:24 -08003081 for device in devicesJson:
kelvin8ec71442015-01-15 16:57:00 -08003082 # print "%s in %s?" % ( dpid, device[ 'id' ] )
3083 if dpid in device[ 'id' ]:
Jon Halla91c4dc2014-10-22 12:57:04 -04003084 return device
3085 return None
Jon Hallc6793552016-01-19 14:18:37 -08003086 except ( TypeError, ValueError ):
3087 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) )
Jon Halld4d4b372015-01-28 16:02:41 -08003088 return None
Jon Halla91c4dc2014-10-22 12:57:04 -04003089 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003090 main.log.error( self.name + ": EOF exception found" )
3091 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003092 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003093 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003094 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003095 main.cleanAndExit()
Jon Halla91c4dc2014-10-22 12:57:04 -04003096
You Wang24139872016-05-03 11:48:47 -07003097 def getTopology( self, topologyOutput ):
3098 """
3099 Definition:
3100 Loads a json topology output
3101 Return:
3102 topology = current ONOS topology
3103 """
3104 import json
3105 try:
3106 # either onos:topology or 'topology' will work in CLI
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003107 topology = json.loads( topologyOutput )
Jeremy Songsterbc2d8ac2016-05-04 11:25:42 -07003108 main.log.debug( topology )
You Wang24139872016-05-03 11:48:47 -07003109 return topology
You Wangd3cb2ce2016-05-16 14:01:24 -07003110 except ( TypeError, ValueError ):
3111 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) )
3112 return None
You Wang24139872016-05-03 11:48:47 -07003113 except pexpect.EOF:
3114 main.log.error( self.name + ": EOF exception found" )
3115 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003116 main.cleanAndExit()
You Wang24139872016-05-03 11:48:47 -07003117 except Exception:
3118 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003119 main.cleanAndExit()
You Wang24139872016-05-03 11:48:47 -07003120
Pier6a0c4de2018-03-18 16:01:30 -07003121 def checkStatus( self, numoswitch, numolink = -1, numoctrl = -1, logLevel="info" ):
kelvin8ec71442015-01-15 16:57:00 -08003122 """
Jon Hallefbd9792015-03-05 16:11:36 -08003123 Checks the number of switches & links that ONOS sees against the
kelvin8ec71442015-01-15 16:57:00 -08003124 supplied values. By default this will report to main.log, but the
You Wang24139872016-05-03 11:48:47 -07003125 log level can be specific.
kelvin8ec71442015-01-15 16:57:00 -08003126
Flavio Castro82ee2f62016-06-07 15:04:12 -07003127 Params: numoswitch = expected number of switches
Jon Hallefbd9792015-03-05 16:11:36 -08003128 numolink = expected number of links
Flavio Castro82ee2f62016-06-07 15:04:12 -07003129 numoctrl = expected number of controllers
You Wang24139872016-05-03 11:48:47 -07003130 logLevel = level to log to.
3131 Currently accepts 'info', 'warn' and 'report'
Jon Hall42db6dc2014-10-24 19:03:48 -04003132
Jon Hallefbd9792015-03-05 16:11:36 -08003133 Returns: main.TRUE if the number of switches and links are correct,
3134 main.FALSE if the number of switches and links is incorrect,
Jon Hall42db6dc2014-10-24 19:03:48 -04003135 and main.ERROR otherwise
kelvin8ec71442015-01-15 16:57:00 -08003136 """
Flavio Castro82ee2f62016-06-07 15:04:12 -07003137 import json
Jon Hall42db6dc2014-10-24 19:03:48 -04003138 try:
You Wang13310252016-07-31 10:56:14 -07003139 summary = self.summary()
3140 summary = json.loads( summary )
Flavio Castrof5b3f872016-06-23 17:52:31 -07003141 except ( TypeError, ValueError ):
3142 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) )
3143 return main.ERROR
3144 try:
3145 topology = self.getTopology( self.topology() )
Jon Halle0f0b342017-04-18 11:43:47 -07003146 if topology == {} or topology is None or summary == {} or summary is None:
Jon Hall42db6dc2014-10-24 19:03:48 -04003147 return main.ERROR
3148 output = ""
kelvin8ec71442015-01-15 16:57:00 -08003149 # Is the number of switches is what we expected
3150 devices = topology.get( 'devices', False )
3151 links = topology.get( 'links', False )
Flavio Castro82ee2f62016-06-07 15:04:12 -07003152 nodes = summary.get( 'nodes', False )
3153 if devices is False or links is False or nodes is False:
Jon Hall42db6dc2014-10-24 19:03:48 -04003154 return main.ERROR
kelvin-onlabd3b64892015-01-20 13:26:24 -08003155 switchCheck = ( int( devices ) == int( numoswitch ) )
kelvin8ec71442015-01-15 16:57:00 -08003156 # Is the number of links is what we expected
Pier6a0c4de2018-03-18 16:01:30 -07003157 linkCheck = ( int( links ) == int( numolink ) ) or int( numolink ) == -1
Flavio Castro82ee2f62016-06-07 15:04:12 -07003158 nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1
3159 if switchCheck and linkCheck and nodeCheck:
kelvin8ec71442015-01-15 16:57:00 -08003160 # We expected the correct numbers
You Wang24139872016-05-03 11:48:47 -07003161 output = output + "The number of links and switches match "\
3162 + "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04003163 result = main.TRUE
3164 else:
You Wang24139872016-05-03 11:48:47 -07003165 output = output + \
3166 "The number of links and switches does not match " + \
3167 "what was expected"
Jon Hall42db6dc2014-10-24 19:03:48 -04003168 result = main.FALSE
You Wang24139872016-05-03 11:48:47 -07003169 output = output + "\n ONOS sees %i devices" % int( devices )
3170 output = output + " (%i expected) " % int( numoswitch )
Pier6a0c4de2018-03-18 16:01:30 -07003171 if int( numolink ) > 0:
3172 output = output + "and %i links " % int( links )
3173 output = output + "(%i expected)" % int( numolink )
YPZhangd7e4b6e2016-06-17 16:07:55 -07003174 if int( numoctrl ) > 0:
Flavio Castro82ee2f62016-06-07 15:04:12 -07003175 output = output + "and %i controllers " % int( nodes )
3176 output = output + "(%i expected)" % int( numoctrl )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003177 if logLevel == "report":
kelvin8ec71442015-01-15 16:57:00 -08003178 main.log.report( output )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003179 elif logLevel == "warn":
kelvin8ec71442015-01-15 16:57:00 -08003180 main.log.warn( output )
Jon Hall42db6dc2014-10-24 19:03:48 -04003181 else:
You Wang24139872016-05-03 11:48:47 -07003182 main.log.info( output )
kelvin8ec71442015-01-15 16:57:00 -08003183 return result
Jon Hall42db6dc2014-10-24 19:03:48 -04003184 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003185 main.log.error( self.name + ": EOF exception found" )
3186 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003187 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003188 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003189 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003190 main.cleanAndExit()
Jon Hall1c9e8732014-10-27 19:29:27 -04003191
kelvin-onlabd3b64892015-01-20 13:26:24 -08003192 def deviceRole( self, deviceId, onosNode, role="master" ):
kelvin8ec71442015-01-15 16:57:00 -08003193 """
Jon Hall1c9e8732014-10-27 19:29:27 -04003194 Calls the device-role cli command.
kelvin-onlabd3b64892015-01-20 13:26:24 -08003195 deviceId must be the id of a device as seen in the onos devices command
3196 onosNode is the ip of one of the onos nodes in the cluster
Jon Hall1c9e8732014-10-27 19:29:27 -04003197 role must be either master, standby, or none
3198
Jon Halle3f39ff2015-01-13 11:50:53 -08003199 Returns:
3200 main.TRUE or main.FALSE based on argument verification and
3201 main.ERROR if command returns and error
kelvin-onlab898a6c62015-01-16 14:13:53 -08003202 """
Jon Hall1c9e8732014-10-27 19:29:27 -04003203 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08003204 if role.lower() == "master" or role.lower() == "standby" or\
Jon Hall1c9e8732014-10-27 19:29:27 -04003205 role.lower() == "none":
kelvin-onlabd3b64892015-01-20 13:26:24 -08003206 cmdStr = "device-role " +\
3207 str( deviceId ) + " " +\
3208 str( onosNode ) + " " +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08003209 str( role )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003210 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08003211 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003212 assert "Command not found:" not in handle, handle
kelvin-onlab898a6c62015-01-16 14:13:53 -08003213 if re.search( "Error", handle ):
3214 # end color output to escape any colours
3215 # from the cli
kelvin8ec71442015-01-15 16:57:00 -08003216 main.log.error( self.name + ": " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08003217 handle + '\033[0m' )
kelvin8ec71442015-01-15 16:57:00 -08003218 return main.ERROR
kelvin8ec71442015-01-15 16:57:00 -08003219 return main.TRUE
Jon Hall1c9e8732014-10-27 19:29:27 -04003220 else:
kelvin-onlab898a6c62015-01-16 14:13:53 -08003221 main.log.error( "Invalid 'role' given to device_role(). " +
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003222 "Value was '" + str( role ) + "'." )
Jon Hall1c9e8732014-10-27 19:29:27 -04003223 return main.FALSE
Jon Hallc6793552016-01-19 14:18:37 -08003224 except AssertionError:
3225 main.log.exception( "" )
3226 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003227 except TypeError:
3228 main.log.exception( self.name + ": Object not as expected" )
3229 return None
Jon Hall1c9e8732014-10-27 19:29:27 -04003230 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003231 main.log.error( self.name + ": EOF exception found" )
3232 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003233 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003234 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003235 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003236 main.cleanAndExit()
Jon Hall1c9e8732014-10-27 19:29:27 -04003237
kelvin-onlabd3b64892015-01-20 13:26:24 -08003238 def clusters( self, jsonFormat=True ):
kelvin8ec71442015-01-15 16:57:00 -08003239 """
Jon Hall0dd09952018-04-19 09:59:11 -07003240 Lists all topology clusters
Jon Hallffb386d2014-11-21 13:43:38 -08003241 Optional argument:
kelvin-onlabd3b64892015-01-20 13:26:24 -08003242 * jsonFormat - boolean indicating if you want output in json
kelvin8ec71442015-01-15 16:57:00 -08003243 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08003244 try:
Jon Hall0dd09952018-04-19 09:59:11 -07003245 cmdStr = "topo-clusters"
kelvin-onlabd3b64892015-01-20 13:26:24 -08003246 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07003247 cmdStr += " -j"
3248 handle = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08003249 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003250 assert "Command not found:" not in handle, handle
Jon Hallc6358dd2015-04-10 12:44:28 -07003251 return handle
Jon Hallc6793552016-01-19 14:18:37 -08003252 except AssertionError:
3253 main.log.exception( "" )
3254 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003255 except TypeError:
3256 main.log.exception( self.name + ": Object not as expected" )
3257 return None
Jon Hall73cf9cc2014-11-20 22:28:38 -08003258 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003259 main.log.error( self.name + ": EOF exception found" )
3260 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003261 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003262 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003263 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003264 main.cleanAndExit()
Jon Hall73cf9cc2014-11-20 22:28:38 -08003265
kelvin-onlabd3b64892015-01-20 13:26:24 -08003266 def electionTestLeader( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08003267 """
Jon Halle3f39ff2015-01-13 11:50:53 -08003268 CLI command to get the current leader for the Election test application
3269 NOTE: Requires installation of the onos-app-election feature
3270 Returns: Node IP of the leader if one exists
3271 None if none exists
3272 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08003273 """
Jon Hall94fd0472014-12-08 11:52:42 -08003274 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08003275 cmdStr = "election-test-leader"
3276 response = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08003277 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003278 assert "Command not found:" not in response, response
Jon Halle3f39ff2015-01-13 11:50:53 -08003279 # Leader
3280 leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08003281 "app\sis\s(?P<node>.+)\."
kelvin-onlabd3b64892015-01-20 13:26:24 -08003282 nodeSearch = re.search( leaderPattern, response )
3283 if nodeSearch:
3284 node = nodeSearch.group( 'node' )
Jon Halle3f39ff2015-01-13 11:50:53 -08003285 main.log.info( "Election-test-leader on " + str( self.name ) +
kelvin-onlab898a6c62015-01-16 14:13:53 -08003286 " found " + node + " as the leader" )
Jon Hall94fd0472014-12-08 11:52:42 -08003287 return node
Jon Halle3f39ff2015-01-13 11:50:53 -08003288 # no leader
3289 nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08003290 "the\sElection\sapp"
kelvin-onlabd3b64892015-01-20 13:26:24 -08003291 nullSearch = re.search( nullPattern, response )
3292 if nullSearch:
Jon Halle3f39ff2015-01-13 11:50:53 -08003293 main.log.info( "Election-test-leader found no leader on " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08003294 self.name )
Jon Hall94fd0472014-12-08 11:52:42 -08003295 return None
kelvin-onlab898a6c62015-01-16 14:13:53 -08003296 # error
Jon Hall97cf84a2016-06-20 13:35:58 -07003297 main.log.error( "Error in electionTestLeader on " + self.name +
3298 ": " + "unexpected response" )
3299 main.log.error( repr( response ) )
3300 return main.FALSE
Jon Hallc6793552016-01-19 14:18:37 -08003301 except AssertionError:
3302 main.log.exception( "" )
3303 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003304 except TypeError:
3305 main.log.exception( self.name + ": Object not as expected" )
3306 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08003307 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003308 main.log.error( self.name + ": EOF exception found" )
3309 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003310 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003311 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003312 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003313 main.cleanAndExit()
Jon Hall94fd0472014-12-08 11:52:42 -08003314
kelvin-onlabd3b64892015-01-20 13:26:24 -08003315 def electionTestRun( self ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08003316 """
Jon Halle3f39ff2015-01-13 11:50:53 -08003317 CLI command to run for leadership of the Election test application.
3318 NOTE: Requires installation of the onos-app-election feature
3319 Returns: Main.TRUE on success
3320 Main.FALSE on error
kelvin-onlab898a6c62015-01-16 14:13:53 -08003321 """
Jon Hall94fd0472014-12-08 11:52:42 -08003322 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08003323 cmdStr = "election-test-run"
3324 response = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08003325 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003326 assert "Command not found:" not in response, response
kelvin-onlab898a6c62015-01-16 14:13:53 -08003327 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08003328 successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08003329 "Election\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08003330 search = re.search( successPattern, response )
Jon Hall94fd0472014-12-08 11:52:42 -08003331 if search:
Jon Halle3f39ff2015-01-13 11:50:53 -08003332 main.log.info( self.name + " entering leadership elections " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08003333 "for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08003334 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08003335 # error
Jon Hall97cf84a2016-06-20 13:35:58 -07003336 main.log.error( "Error in electionTestRun on " + self.name +
3337 ": " + "unexpected response" )
3338 main.log.error( repr( response ) )
3339 return main.FALSE
Jon Hallc6793552016-01-19 14:18:37 -08003340 except AssertionError:
3341 main.log.exception( "" )
3342 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003343 except TypeError:
3344 main.log.exception( self.name + ": Object not as expected" )
3345 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08003346 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003347 main.log.error( self.name + ": EOF exception found" )
3348 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003349 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003350 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003351 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003352 main.cleanAndExit()
Jon Hall94fd0472014-12-08 11:52:42 -08003353
kelvin-onlabd3b64892015-01-20 13:26:24 -08003354 def electionTestWithdraw( self ):
kelvin8ec71442015-01-15 16:57:00 -08003355 """
Jon Hall94fd0472014-12-08 11:52:42 -08003356 * CLI command to withdraw the local node from leadership election for
3357 * the Election test application.
3358 #NOTE: Requires installation of the onos-app-election feature
3359 Returns: Main.TRUE on success
3360 Main.FALSE on error
kelvin8ec71442015-01-15 16:57:00 -08003361 """
Jon Hall94fd0472014-12-08 11:52:42 -08003362 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08003363 cmdStr = "election-test-withdraw"
3364 response = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08003365 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003366 assert "Command not found:" not in response, response
kelvin-onlab898a6c62015-01-16 14:13:53 -08003367 # success
Jon Halle3f39ff2015-01-13 11:50:53 -08003368 successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\
kelvin-onlab898a6c62015-01-16 14:13:53 -08003369 "\sthe\sElection\sapp."
Jon Halle3f39ff2015-01-13 11:50:53 -08003370 if re.search( successPattern, response ):
3371 main.log.info( self.name + " withdrawing from leadership " +
kelvin-onlab898a6c62015-01-16 14:13:53 -08003372 "elections for the Election app." )
Jon Hall94fd0472014-12-08 11:52:42 -08003373 return main.TRUE
kelvin-onlab898a6c62015-01-16 14:13:53 -08003374 # error
Jon Hall97cf84a2016-06-20 13:35:58 -07003375 main.log.error( "Error in electionTestWithdraw on " +
3376 self.name + ": " + "unexpected response" )
3377 main.log.error( repr( response ) )
3378 return main.FALSE
Jon Hallc6793552016-01-19 14:18:37 -08003379 except AssertionError:
3380 main.log.exception( "" )
3381 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003382 except TypeError:
3383 main.log.exception( self.name + ": Object not as expected" )
3384 return main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08003385 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003386 main.log.error( self.name + ": EOF exception found" )
3387 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003388 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003389 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003390 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003391 main.cleanAndExit()
Jon Hall1c9e8732014-10-27 19:29:27 -04003392
kelvin8ec71442015-01-15 16:57:00 -08003393 def getDevicePortsEnabledCount( self, dpid ):
3394 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003395 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08003396 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003397 try:
Jon Halle3f39ff2015-01-13 11:50:53 -08003398 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003399 cmdStr = "onos:ports -e " + dpid + " | wc -l"
3400 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003401 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003402 assert "Command not found:" not in output, output
Jon Halle3f39ff2015-01-13 11:50:53 -08003403 if re.search( "No such device", output ):
3404 main.log.error( "Error in getting ports" )
3405 return ( output, "Error" )
Jon Halla495f562016-05-16 18:03:26 -07003406 return output
Jon Hallc6793552016-01-19 14:18:37 -08003407 except AssertionError:
3408 main.log.exception( "" )
3409 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003410 except TypeError:
3411 main.log.exception( self.name + ": Object not as expected" )
3412 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003413 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003414 main.log.error( self.name + ": EOF exception found" )
3415 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003416 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003417 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003418 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003419 main.cleanAndExit()
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003420
kelvin8ec71442015-01-15 16:57:00 -08003421 def getDeviceLinksActiveCount( self, dpid ):
3422 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003423 Get the count of all enabled ports on a particular device/switch
kelvin8ec71442015-01-15 16:57:00 -08003424 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003425 try:
kelvin-onlab898a6c62015-01-16 14:13:53 -08003426 dpid = str( dpid )
kelvin-onlabd3b64892015-01-20 13:26:24 -08003427 cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l"
3428 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003429 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003430 assert "Command not found:" not in output, output
Jon Halle3f39ff2015-01-13 11:50:53 -08003431 if re.search( "No such device", output ):
kelvin-onlab898a6c62015-01-16 14:13:53 -08003432 main.log.error( "Error in getting ports " )
3433 return ( output, "Error " )
Jon Halla495f562016-05-16 18:03:26 -07003434 return output
Jon Hallc6793552016-01-19 14:18:37 -08003435 except AssertionError:
3436 main.log.exception( "" )
3437 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003438 except TypeError:
3439 main.log.exception( self.name + ": Object not as expected" )
3440 return ( output, "Error " )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003441 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003442 main.log.error( self.name + ": EOF exception found" )
3443 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003444 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003445 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003446 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003447 main.cleanAndExit()
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003448
kelvin8ec71442015-01-15 16:57:00 -08003449 def getAllIntentIds( self ):
3450 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003451 Return a list of all Intent IDs
kelvin8ec71442015-01-15 16:57:00 -08003452 """
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003453 try:
kelvin-onlabd3b64892015-01-20 13:26:24 -08003454 cmdStr = "onos:intents | grep id="
3455 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003456 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003457 assert "Command not found:" not in output, output
Jon Halle3f39ff2015-01-13 11:50:53 -08003458 if re.search( "Error", output ):
3459 main.log.error( "Error in getting ports" )
3460 return ( output, "Error" )
Jon Halla495f562016-05-16 18:03:26 -07003461 return output
Jon Hallc6793552016-01-19 14:18:37 -08003462 except AssertionError:
3463 main.log.exception( "" )
3464 return None
Jon Halld4d4b372015-01-28 16:02:41 -08003465 except TypeError:
3466 main.log.exception( self.name + ": Object not as expected" )
3467 return ( output, "Error" )
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003468 except pexpect.EOF:
kelvin8ec71442015-01-15 16:57:00 -08003469 main.log.error( self.name + ": EOF exception found" )
3470 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003471 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003472 except Exception:
Jon Halld4d4b372015-01-28 16:02:41 -08003473 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003474 main.cleanAndExit()
Jon Halld4d4b372015-01-28 16:02:41 -08003475
Jon Hall73509952015-02-24 16:42:56 -08003476 def intentSummary( self ):
3477 """
Jon Hallefbd9792015-03-05 16:11:36 -08003478 Returns a dictionary containing the current intent states and the count
Jon Hall73509952015-02-24 16:42:56 -08003479 """
3480 try:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00003481 intents = self.intents( )
Jon Hall08f61bc2015-04-13 16:00:30 -07003482 states = []
Jon Hall5aa168b2015-03-23 14:23:09 -07003483 for intent in json.loads( intents ):
Jon Hall08f61bc2015-04-13 16:00:30 -07003484 states.append( intent.get( 'state', None ) )
3485 out = [ ( i, states.count( i ) ) for i in set( states ) ]
Jon Hall63604932015-02-26 17:09:50 -08003486 main.log.info( dict( out ) )
Jon Hall73509952015-02-24 16:42:56 -08003487 return dict( out )
Jon Hallc6793552016-01-19 14:18:37 -08003488 except ( TypeError, ValueError ):
3489 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) )
Jon Hall73509952015-02-24 16:42:56 -08003490 return None
3491 except pexpect.EOF:
3492 main.log.error( self.name + ": EOF exception found" )
3493 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003494 main.cleanAndExit()
Jon Hallfebb1c72015-03-05 13:30:09 -08003495 except Exception:
Jon Hall73509952015-02-24 16:42:56 -08003496 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003497 main.cleanAndExit()
Jon Hall63604932015-02-26 17:09:50 -08003498
Jon Hall61282e32015-03-19 11:34:11 -07003499 def leaders( self, jsonFormat=True ):
Jon Hall63604932015-02-26 17:09:50 -08003500 """
3501 Returns the output of the leaders command.
Jon Hall61282e32015-03-19 11:34:11 -07003502 Optional argument:
3503 * jsonFormat - boolean indicating if you want output in json
Jon Hall63604932015-02-26 17:09:50 -08003504 """
Jon Hall63604932015-02-26 17:09:50 -08003505 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07003506 cmdStr = "onos:leaders"
Jon Hall61282e32015-03-19 11:34:11 -07003507 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07003508 cmdStr += " -j"
3509 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003510 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003511 assert "Command not found:" not in output, output
Jon Hallc6358dd2015-04-10 12:44:28 -07003512 return output
Jon Hallc6793552016-01-19 14:18:37 -08003513 except AssertionError:
3514 main.log.exception( "" )
3515 return None
Jon Hall63604932015-02-26 17:09:50 -08003516 except TypeError:
3517 main.log.exception( self.name + ": Object not as expected" )
3518 return None
Hari Krishnaa43d4e92014-12-19 13:22:40 -08003519 except pexpect.EOF:
3520 main.log.error( self.name + ": EOF exception found" )
3521 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003522 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003523 except Exception:
Jon Hall63604932015-02-26 17:09:50 -08003524 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003525 main.cleanAndExit()
Jon Hall63604932015-02-26 17:09:50 -08003526
acsmarsa4a4d1e2015-07-10 16:01:24 -07003527 def leaderCandidates( self, jsonFormat=True ):
3528 """
3529 Returns the output of the leaders -c command.
3530 Optional argument:
3531 * jsonFormat - boolean indicating if you want output in json
3532 """
3533 try:
3534 cmdStr = "onos:leaders -c"
3535 if jsonFormat:
3536 cmdStr += " -j"
3537 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003538 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003539 assert "Command not found:" not in output, output
acsmarsa4a4d1e2015-07-10 16:01:24 -07003540 return output
Jon Hallc6793552016-01-19 14:18:37 -08003541 except AssertionError:
3542 main.log.exception( "" )
3543 return None
acsmarsa4a4d1e2015-07-10 16:01:24 -07003544 except TypeError:
3545 main.log.exception( self.name + ": Object not as expected" )
3546 return None
3547 except pexpect.EOF:
3548 main.log.error( self.name + ": EOF exception found" )
3549 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003550 main.cleanAndExit()
acsmarsa4a4d1e2015-07-10 16:01:24 -07003551 except Exception:
3552 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003553 main.cleanAndExit()
acsmarsa4a4d1e2015-07-10 16:01:24 -07003554
Jon Hallc6793552016-01-19 14:18:37 -08003555 def specificLeaderCandidate( self, topic ):
acsmarsa4a4d1e2015-07-10 16:01:24 -07003556 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00003557 Returns a list in format [leader,candidate1,candidate2,...] for a given
acsmarsa4a4d1e2015-07-10 16:01:24 -07003558 topic parameter and an empty list if the topic doesn't exist
3559 If no leader is elected leader in the returned list will be "none"
3560 Returns None if there is a type error processing the json object
3561 """
3562 try:
Jon Hall6e709752016-02-01 13:38:46 -08003563 cmdStr = "onos:leaders -j"
Jon Hallc6793552016-01-19 14:18:37 -08003564 rawOutput = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003565 assert rawOutput is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003566 assert "Command not found:" not in rawOutput, rawOutput
3567 output = json.loads( rawOutput )
acsmarsa4a4d1e2015-07-10 16:01:24 -07003568 results = []
3569 for dict in output:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003570 if dict[ "topic" ] == topic:
3571 leader = dict[ "leader" ]
3572 candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] )
Jon Hallc6793552016-01-19 14:18:37 -08003573 results.append( leader )
3574 results.extend( candidates )
acsmarsa4a4d1e2015-07-10 16:01:24 -07003575 return results
Jon Hallc6793552016-01-19 14:18:37 -08003576 except AssertionError:
3577 main.log.exception( "" )
3578 return None
3579 except ( TypeError, ValueError ):
3580 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) )
acsmarsa4a4d1e2015-07-10 16:01:24 -07003581 return None
3582 except pexpect.EOF:
3583 main.log.error( self.name + ": EOF exception found" )
3584 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003585 main.cleanAndExit()
acsmarsa4a4d1e2015-07-10 16:01:24 -07003586 except Exception:
3587 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003588 main.cleanAndExit()
acsmarsa4a4d1e2015-07-10 16:01:24 -07003589
Jon Hall61282e32015-03-19 11:34:11 -07003590 def pendingMap( self, jsonFormat=True ):
Jon Hall63604932015-02-26 17:09:50 -08003591 """
3592 Returns the output of the intent Pending map.
3593 """
Jon Hall63604932015-02-26 17:09:50 -08003594 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07003595 cmdStr = "onos:intents -p"
Jon Hall61282e32015-03-19 11:34:11 -07003596 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07003597 cmdStr += " -j"
3598 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003599 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003600 assert "Command not found:" not in output, output
Jon Hallc6358dd2015-04-10 12:44:28 -07003601 return output
Jon Hallc6793552016-01-19 14:18:37 -08003602 except AssertionError:
3603 main.log.exception( "" )
3604 return None
Jon Hall63604932015-02-26 17:09:50 -08003605 except TypeError:
3606 main.log.exception( self.name + ": Object not as expected" )
3607 return None
3608 except pexpect.EOF:
3609 main.log.error( self.name + ": EOF exception found" )
3610 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003611 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003612 except Exception:
Jon Hall63604932015-02-26 17:09:50 -08003613 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003614 main.cleanAndExit()
Jon Hall63604932015-02-26 17:09:50 -08003615
Jon Hall2c8959e2016-12-16 12:17:34 -08003616 def partitions( self, candidates=False, jsonFormat=True ):
Jon Hall63604932015-02-26 17:09:50 -08003617 """
3618 Returns the output of the raft partitions command for ONOS.
3619 """
Jon Hall61282e32015-03-19 11:34:11 -07003620 # Sample JSON
3621 # {
3622 # "leader": "tcp://10.128.30.11:7238",
3623 # "members": [
3624 # "tcp://10.128.30.11:7238",
3625 # "tcp://10.128.30.17:7238",
3626 # "tcp://10.128.30.13:7238",
3627 # ],
3628 # "name": "p1",
3629 # "term": 3
3630 # },
Jon Hall63604932015-02-26 17:09:50 -08003631 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07003632 cmdStr = "onos:partitions"
Jon Hall2c8959e2016-12-16 12:17:34 -08003633 if candidates:
3634 cmdStr += " -c"
Jon Hall61282e32015-03-19 11:34:11 -07003635 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07003636 cmdStr += " -j"
3637 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003638 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003639 assert "Command not found:" not in output, output
Jon Hallc6358dd2015-04-10 12:44:28 -07003640 return output
Jon Hallc6793552016-01-19 14:18:37 -08003641 except AssertionError:
3642 main.log.exception( "" )
3643 return None
Jon Hall63604932015-02-26 17:09:50 -08003644 except TypeError:
3645 main.log.exception( self.name + ": Object not as expected" )
3646 return None
3647 except pexpect.EOF:
3648 main.log.error( self.name + ": EOF exception found" )
3649 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003650 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003651 except Exception:
Jon Hall63604932015-02-26 17:09:50 -08003652 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003653 main.cleanAndExit()
Jon Hall63604932015-02-26 17:09:50 -08003654
Jon Halle9f909e2016-09-23 10:43:12 -07003655 def apps( self, summary=False, active=False, jsonFormat=True ):
Jon Hallbe379602015-03-24 13:39:32 -07003656 """
3657 Returns the output of the apps command for ONOS. This command lists
3658 information about installed ONOS applications
3659 """
3660 # Sample JSON object
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00003661 # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0",
Jon Hallbe379602015-03-24 13:39:32 -07003662 # "description":"ONOS OpenFlow protocol southbound providers",
3663 # "origin":"ON.Lab","permissions":"[]","featuresRepo":"",
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00003664 # "features":"[onos-openflow]","state":"ACTIVE"}]
Jon Hallbe379602015-03-24 13:39:32 -07003665 try:
Jon Hallc6358dd2015-04-10 12:44:28 -07003666 cmdStr = "onos:apps"
Jon Halle9f909e2016-09-23 10:43:12 -07003667 if summary:
3668 cmdStr += " -s"
3669 if active:
3670 cmdStr += " -a"
Jon Hallbe379602015-03-24 13:39:32 -07003671 if jsonFormat:
Jon Hallc6358dd2015-04-10 12:44:28 -07003672 cmdStr += " -j"
3673 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003674 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003675 assert "Command not found:" not in output, output
3676 assert "Error executing command" not in output, output
Jon Hallc6358dd2015-04-10 12:44:28 -07003677 return output
Jon Hallbe379602015-03-24 13:39:32 -07003678 # FIXME: look at specific exceptions/Errors
3679 except AssertionError:
Jon Hallc6793552016-01-19 14:18:37 -08003680 main.log.exception( "Error in processing onos:app command." )
Jon Hallbe379602015-03-24 13:39:32 -07003681 return None
3682 except TypeError:
3683 main.log.exception( self.name + ": Object not as expected" )
3684 return None
3685 except pexpect.EOF:
3686 main.log.error( self.name + ": EOF exception found" )
3687 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003688 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003689 except Exception:
Jon Hallbe379602015-03-24 13:39:32 -07003690 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003691 main.cleanAndExit()
Jon Hallbe379602015-03-24 13:39:32 -07003692
Jon Hall146f1522015-03-24 15:33:24 -07003693 def appStatus( self, appName ):
3694 """
3695 Uses the onos:apps cli command to return the status of an application.
3696 Returns:
3697 "ACTIVE" - If app is installed and activated
3698 "INSTALLED" - If app is installed and deactivated
3699 "UNINSTALLED" - If app is not installed
3700 None - on error
3701 """
Jon Hall146f1522015-03-24 15:33:24 -07003702 try:
3703 if not isinstance( appName, types.StringType ):
3704 main.log.error( self.name + ".appStatus(): appName must be" +
3705 " a string" )
3706 return None
3707 output = self.apps( jsonFormat=True )
3708 appsJson = json.loads( output )
3709 state = None
3710 for app in appsJson:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003711 if appName == app.get( 'name' ):
3712 state = app.get( 'state' )
Jon Hall146f1522015-03-24 15:33:24 -07003713 break
3714 if state == "ACTIVE" or state == "INSTALLED":
3715 return state
3716 elif state is None:
Jon Hall8bafdc02017-09-05 11:36:26 -07003717 main.log.warn( "{} app not found", appName )
Jon Hall146f1522015-03-24 15:33:24 -07003718 return "UNINSTALLED"
3719 elif state:
3720 main.log.error( "Unexpected state from 'onos:apps': " +
3721 str( state ) )
3722 return state
Jon Hallc6793552016-01-19 14:18:37 -08003723 except ( TypeError, ValueError ):
3724 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) )
Jon Hall146f1522015-03-24 15:33:24 -07003725 return None
3726 except pexpect.EOF:
3727 main.log.error( self.name + ": EOF exception found" )
3728 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003729 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003730 except Exception:
Jon Hall146f1522015-03-24 15:33:24 -07003731 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003732 main.cleanAndExit()
Jon Hall146f1522015-03-24 15:33:24 -07003733
Jon Hallbe379602015-03-24 13:39:32 -07003734 def app( self, appName, option ):
3735 """
3736 Interacts with the app command for ONOS. This command manages
3737 application inventory.
3738 """
Jon Hallbe379602015-03-24 13:39:32 -07003739 try:
Jon Hallbd16b922015-03-26 17:53:15 -07003740 # Validate argument types
3741 valid = True
3742 if not isinstance( appName, types.StringType ):
3743 main.log.error( self.name + ".app(): appName must be a " +
3744 "string" )
3745 valid = False
3746 if not isinstance( option, types.StringType ):
3747 main.log.error( self.name + ".app(): option must be a string" )
3748 valid = False
3749 if not valid:
3750 return main.FALSE
3751 # Validate Option
3752 option = option.lower()
3753 # NOTE: Install may become a valid option
3754 if option == "activate":
3755 pass
3756 elif option == "deactivate":
3757 pass
3758 elif option == "uninstall":
3759 pass
3760 else:
3761 # Invalid option
3762 main.log.error( "The ONOS app command argument only takes " +
3763 "the values: (activate|deactivate|uninstall)" +
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003764 "; was given '" + option + "'" )
Jon Hallbd16b922015-03-26 17:53:15 -07003765 return main.FALSE
Jon Hall146f1522015-03-24 15:33:24 -07003766 cmdStr = "onos:app " + option + " " + appName
Jon Hallbe379602015-03-24 13:39:32 -07003767 output = self.sendline( cmdStr )
You Wangb5a55f72017-03-03 12:51:05 -08003768 assert output is not None, "Error in sendline"
3769 assert "Command not found:" not in output, output
Jon Hallbe379602015-03-24 13:39:32 -07003770 if "Error executing command" in output:
3771 main.log.error( "Error in processing onos:app command: " +
3772 str( output ) )
Jon Hall146f1522015-03-24 15:33:24 -07003773 return main.FALSE
Jon Hallbe379602015-03-24 13:39:32 -07003774 elif "No such application" in output:
3775 main.log.error( "The application '" + appName +
3776 "' is not installed in ONOS" )
Jon Hall146f1522015-03-24 15:33:24 -07003777 return main.FALSE
3778 elif "Command not found:" in output:
3779 main.log.error( "Error in processing onos:app command: " +
3780 str( output ) )
3781 return main.FALSE
Jon Hallbd16b922015-03-26 17:53:15 -07003782 elif "Unsupported command:" in output:
3783 main.log.error( "Incorrect command given to 'app': " +
3784 str( output ) )
Jon Hallbe379602015-03-24 13:39:32 -07003785 # NOTE: we may need to add more checks here
Jon Hallbd16b922015-03-26 17:53:15 -07003786 # else: Command was successful
Jon Hall08f61bc2015-04-13 16:00:30 -07003787 # main.log.debug( "app response: " + repr( output ) )
Jon Hallbe379602015-03-24 13:39:32 -07003788 return main.TRUE
You Wangb5a55f72017-03-03 12:51:05 -08003789 except AssertionError:
3790 main.log.exception( self.name + ": AssertionError exception found" )
3791 return main.ERROR
Jon Hallbe379602015-03-24 13:39:32 -07003792 except TypeError:
3793 main.log.exception( self.name + ": Object not as expected" )
3794 return main.ERROR
3795 except pexpect.EOF:
3796 main.log.error( self.name + ": EOF exception found" )
3797 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003798 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003799 except Exception:
Jon Hallbe379602015-03-24 13:39:32 -07003800 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003801 main.cleanAndExit()
Jon Hall146f1522015-03-24 15:33:24 -07003802
Jon Hallbd16b922015-03-26 17:53:15 -07003803 def activateApp( self, appName, check=True ):
Jon Hall146f1522015-03-24 15:33:24 -07003804 """
3805 Activate an app that is already installed in ONOS
Jon Hallbd16b922015-03-26 17:53:15 -07003806 appName is the hierarchical app name, not the feature name
3807 If check is True, method will check the status of the app after the
3808 command is issued
Jon Hall146f1522015-03-24 15:33:24 -07003809 Returns main.TRUE if the command was successfully sent
3810 main.FALSE if the cli responded with an error or given
3811 incorrect input
3812 """
3813 try:
3814 if not isinstance( appName, types.StringType ):
3815 main.log.error( self.name + ".activateApp(): appName must be" +
3816 " a string" )
3817 return main.FALSE
3818 status = self.appStatus( appName )
3819 if status == "INSTALLED":
3820 response = self.app( appName, "activate" )
Jon Hallbd16b922015-03-26 17:53:15 -07003821 if check and response == main.TRUE:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003822 for i in range( 10 ): # try 10 times then give up
Jon Hallbd16b922015-03-26 17:53:15 -07003823 status = self.appStatus( appName )
3824 if status == "ACTIVE":
3825 return main.TRUE
3826 else:
Jon Hall050e1bd2015-03-30 13:33:02 -07003827 main.log.debug( "The state of application " +
3828 appName + " is " + status )
Jon Hallbd16b922015-03-26 17:53:15 -07003829 time.sleep( 1 )
3830 return main.FALSE
3831 else: # not 'check' or command didn't succeed
3832 return response
Jon Hall146f1522015-03-24 15:33:24 -07003833 elif status == "ACTIVE":
3834 return main.TRUE
3835 elif status == "UNINSTALLED":
3836 main.log.error( self.name + ": Tried to activate the " +
3837 "application '" + appName + "' which is not " +
3838 "installed." )
3839 else:
3840 main.log.error( "Unexpected return value from appStatus: " +
3841 str( status ) )
3842 return main.ERROR
3843 except TypeError:
3844 main.log.exception( self.name + ": Object not as expected" )
3845 return main.ERROR
3846 except pexpect.EOF:
3847 main.log.error( self.name + ": EOF exception found" )
3848 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003849 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003850 except Exception:
Jon Hall146f1522015-03-24 15:33:24 -07003851 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003852 main.cleanAndExit()
Jon Hall146f1522015-03-24 15:33:24 -07003853
Jon Hallbd16b922015-03-26 17:53:15 -07003854 def deactivateApp( self, appName, check=True ):
Jon Hall146f1522015-03-24 15:33:24 -07003855 """
3856 Deactivate an app that is already activated in ONOS
Jon Hallbd16b922015-03-26 17:53:15 -07003857 appName is the hierarchical app name, not the feature name
3858 If check is True, method will check the status of the app after the
3859 command is issued
Jon Hall146f1522015-03-24 15:33:24 -07003860 Returns main.TRUE if the command was successfully sent
3861 main.FALSE if the cli responded with an error or given
3862 incorrect input
3863 """
3864 try:
3865 if not isinstance( appName, types.StringType ):
3866 main.log.error( self.name + ".deactivateApp(): appName must " +
3867 "be a string" )
3868 return main.FALSE
3869 status = self.appStatus( appName )
3870 if status == "INSTALLED":
3871 return main.TRUE
3872 elif status == "ACTIVE":
3873 response = self.app( appName, "deactivate" )
Jon Hallbd16b922015-03-26 17:53:15 -07003874 if check and response == main.TRUE:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003875 for i in range( 10 ): # try 10 times then give up
Jon Hallbd16b922015-03-26 17:53:15 -07003876 status = self.appStatus( appName )
3877 if status == "INSTALLED":
3878 return main.TRUE
3879 else:
3880 time.sleep( 1 )
3881 return main.FALSE
3882 else: # not check or command didn't succeed
3883 return response
Jon Hall146f1522015-03-24 15:33:24 -07003884 elif status == "UNINSTALLED":
3885 main.log.warn( self.name + ": Tried to deactivate the " +
3886 "application '" + appName + "' which is not " +
3887 "installed." )
3888 return main.TRUE
3889 else:
3890 main.log.error( "Unexpected return value from appStatus: " +
3891 str( status ) )
3892 return main.ERROR
3893 except TypeError:
3894 main.log.exception( self.name + ": Object not as expected" )
3895 return main.ERROR
3896 except pexpect.EOF:
3897 main.log.error( self.name + ": EOF exception found" )
3898 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003899 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003900 except Exception:
Jon Hall146f1522015-03-24 15:33:24 -07003901 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003902 main.cleanAndExit()
Jon Hall146f1522015-03-24 15:33:24 -07003903
Jon Hallbd16b922015-03-26 17:53:15 -07003904 def uninstallApp( self, appName, check=True ):
Jon Hall146f1522015-03-24 15:33:24 -07003905 """
3906 Uninstall an app that is already installed in ONOS
Jon Hallbd16b922015-03-26 17:53:15 -07003907 appName is the hierarchical app name, not the feature name
3908 If check is True, method will check the status of the app after the
3909 command is issued
Jon Hall146f1522015-03-24 15:33:24 -07003910 Returns main.TRUE if the command was successfully sent
3911 main.FALSE if the cli responded with an error or given
3912 incorrect input
3913 """
3914 # TODO: check with Thomas about the state machine for apps
3915 try:
3916 if not isinstance( appName, types.StringType ):
3917 main.log.error( self.name + ".uninstallApp(): appName must " +
3918 "be a string" )
3919 return main.FALSE
3920 status = self.appStatus( appName )
3921 if status == "INSTALLED":
3922 response = self.app( appName, "uninstall" )
Jon Hallbd16b922015-03-26 17:53:15 -07003923 if check and response == main.TRUE:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003924 for i in range( 10 ): # try 10 times then give up
Jon Hallbd16b922015-03-26 17:53:15 -07003925 status = self.appStatus( appName )
3926 if status == "UNINSTALLED":
3927 return main.TRUE
3928 else:
3929 time.sleep( 1 )
3930 return main.FALSE
3931 else: # not check or command didn't succeed
3932 return response
Jon Hall146f1522015-03-24 15:33:24 -07003933 elif status == "ACTIVE":
3934 main.log.warn( self.name + ": Tried to uninstall the " +
3935 "application '" + appName + "' which is " +
3936 "currently active." )
3937 response = self.app( appName, "uninstall" )
Jon Hallbd16b922015-03-26 17:53:15 -07003938 if check and response == main.TRUE:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07003939 for i in range( 10 ): # try 10 times then give up
Jon Hallbd16b922015-03-26 17:53:15 -07003940 status = self.appStatus( appName )
3941 if status == "UNINSTALLED":
3942 return main.TRUE
3943 else:
3944 time.sleep( 1 )
3945 return main.FALSE
3946 else: # not check or command didn't succeed
3947 return response
Jon Hall146f1522015-03-24 15:33:24 -07003948 elif status == "UNINSTALLED":
3949 return main.TRUE
3950 else:
3951 main.log.error( "Unexpected return value from appStatus: " +
3952 str( status ) )
3953 return main.ERROR
3954 except TypeError:
3955 main.log.exception( self.name + ": Object not as expected" )
3956 return main.ERROR
3957 except pexpect.EOF:
3958 main.log.error( self.name + ": EOF exception found" )
3959 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003960 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003961 except Exception:
Jon Hall146f1522015-03-24 15:33:24 -07003962 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003963 main.cleanAndExit()
Jon Hallbd16b922015-03-26 17:53:15 -07003964
3965 def appIDs( self, jsonFormat=True ):
3966 """
3967 Show the mappings between app id and app names given by the 'app-ids'
3968 cli command
3969 """
3970 try:
3971 cmdStr = "app-ids"
3972 if jsonFormat:
3973 cmdStr += " -j"
Jon Hallc6358dd2015-04-10 12:44:28 -07003974 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07003975 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08003976 assert "Command not found:" not in output, output
3977 assert "Error executing command" not in output, output
Jon Hallc6358dd2015-04-10 12:44:28 -07003978 return output
Jon Hallbd16b922015-03-26 17:53:15 -07003979 except AssertionError:
Jon Hallc6793552016-01-19 14:18:37 -08003980 main.log.exception( "Error in processing onos:app-ids command." )
Jon Hallbd16b922015-03-26 17:53:15 -07003981 return None
3982 except TypeError:
3983 main.log.exception( self.name + ": Object not as expected" )
3984 return None
3985 except pexpect.EOF:
3986 main.log.error( self.name + ": EOF exception found" )
3987 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07003988 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07003989 except Exception:
Jon Hallbd16b922015-03-26 17:53:15 -07003990 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07003991 main.cleanAndExit()
Jon Hallbd16b922015-03-26 17:53:15 -07003992
3993 def appToIDCheck( self ):
3994 """
3995 This method will check that each application's ID listed in 'apps' is
3996 the same as the ID listed in 'app-ids'. The check will also check that
3997 there are no duplicate IDs issued. Note that an app ID should be
3998 a globaly unique numerical identifier for app/app-like features. Once
3999 an ID is registered, the ID is never freed up so that if an app is
4000 reinstalled it will have the same ID.
4001
4002 Returns: main.TRUE if the check passes and
4003 main.FALSE if the check fails or
4004 main.ERROR if there is some error in processing the test
4005 """
4006 try:
Jon Hall390696c2015-05-05 17:13:41 -07004007 bail = False
Jon Hallc6793552016-01-19 14:18:37 -08004008 rawJson = self.appIDs( jsonFormat=True )
4009 if rawJson:
4010 ids = json.loads( rawJson )
Jon Hall390696c2015-05-05 17:13:41 -07004011 else:
Jon Hallc6793552016-01-19 14:18:37 -08004012 main.log.error( "app-ids returned nothing:" + repr( rawJson ) )
Jon Hall390696c2015-05-05 17:13:41 -07004013 bail = True
Jon Hallc6793552016-01-19 14:18:37 -08004014 rawJson = self.apps( jsonFormat=True )
4015 if rawJson:
4016 apps = json.loads( rawJson )
Jon Hall390696c2015-05-05 17:13:41 -07004017 else:
Jon Hallc6793552016-01-19 14:18:37 -08004018 main.log.error( "apps returned nothing:" + repr( rawJson ) )
Jon Hall390696c2015-05-05 17:13:41 -07004019 bail = True
4020 if bail:
4021 return main.FALSE
Jon Hallbd16b922015-03-26 17:53:15 -07004022 result = main.TRUE
4023 for app in apps:
4024 appID = app.get( 'id' )
4025 if appID is None:
4026 main.log.error( "Error parsing app: " + str( app ) )
4027 result = main.FALSE
4028 appName = app.get( 'name' )
4029 if appName is None:
4030 main.log.error( "Error parsing app: " + str( app ) )
4031 result = main.FALSE
4032 # get the entry in ids that has the same appID
Jon Hall390696c2015-05-05 17:13:41 -07004033 current = filter( lambda item: item[ 'id' ] == appID, ids )
Jon Hallbd16b922015-03-26 17:53:15 -07004034 if not current: # if ids doesn't have this id
4035 result = main.FALSE
4036 main.log.error( "'app-ids' does not have the ID for " +
4037 str( appName ) + " that apps does." )
Jon Hallb9d381e2018-02-05 12:02:10 -08004038 main.log.debug( "apps command returned: " + str( app ) +
4039 "; app-ids has: " + str( ids ) )
Jon Hallbd16b922015-03-26 17:53:15 -07004040 elif len( current ) > 1:
4041 # there is more than one app with this ID
4042 result = main.FALSE
4043 # We will log this later in the method
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004044 elif not current[ 0 ][ 'name' ] == appName:
4045 currentName = current[ 0 ][ 'name' ]
Jon Hallbd16b922015-03-26 17:53:15 -07004046 result = main.FALSE
4047 main.log.error( "'app-ids' has " + str( currentName ) +
4048 " registered under id:" + str( appID ) +
4049 " but 'apps' has " + str( appName ) )
4050 else:
4051 pass # id and name match!
4052 # now make sure that app-ids has no duplicates
4053 idsList = []
4054 namesList = []
4055 for item in ids:
4056 idsList.append( item[ 'id' ] )
4057 namesList.append( item[ 'name' ] )
4058 if len( idsList ) != len( set( idsList ) ) or\
4059 len( namesList ) != len( set( namesList ) ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004060 main.log.error( "'app-ids' has some duplicate entries: \n"
4061 + json.dumps( ids,
4062 sort_keys=True,
4063 indent=4,
4064 separators=( ',', ': ' ) ) )
4065 result = main.FALSE
Jon Hallbd16b922015-03-26 17:53:15 -07004066 return result
Jon Hallc6793552016-01-19 14:18:37 -08004067 except ( TypeError, ValueError ):
4068 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) )
Jon Hallbd16b922015-03-26 17:53:15 -07004069 return main.ERROR
4070 except pexpect.EOF:
4071 main.log.error( self.name + ": EOF exception found" )
4072 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004073 main.cleanAndExit()
Jon Hall77ba41c2015-04-06 10:25:40 -07004074 except Exception:
Jon Hallbd16b922015-03-26 17:53:15 -07004075 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004076 main.cleanAndExit()
Jon Hallbd16b922015-03-26 17:53:15 -07004077
Jon Hallfb760a02015-04-13 15:35:03 -07004078 def getCfg( self, component=None, propName=None, short=False,
4079 jsonFormat=True ):
4080 """
4081 Get configuration settings from onos cli
4082 Optional arguments:
4083 component - Optionally only list configurations for a specific
4084 component. If None, all components with configurations
4085 are displayed. Case Sensitive string.
4086 propName - If component is specified, propName option will show
4087 only this specific configuration from that component.
4088 Case Sensitive string.
4089 jsonFormat - Returns output as json. Note that this will override
4090 the short option
4091 short - Short, less verbose, version of configurations.
4092 This is overridden by the json option
4093 returns:
4094 Output from cli as a string or None on error
4095 """
4096 try:
4097 baseStr = "cfg"
4098 cmdStr = " get"
4099 componentStr = ""
4100 if component:
4101 componentStr += " " + component
4102 if propName:
4103 componentStr += " " + propName
4104 if jsonFormat:
4105 baseStr += " -j"
4106 elif short:
4107 baseStr += " -s"
4108 output = self.sendline( baseStr + cmdStr + componentStr )
Jon Halla495f562016-05-16 18:03:26 -07004109 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004110 assert "Command not found:" not in output, output
4111 assert "Error executing command" not in output, output
Jon Hallfb760a02015-04-13 15:35:03 -07004112 return output
4113 except AssertionError:
Jon Hallc6793552016-01-19 14:18:37 -08004114 main.log.exception( "Error in processing 'cfg get' command." )
Jon Hallfb760a02015-04-13 15:35:03 -07004115 return None
4116 except TypeError:
4117 main.log.exception( self.name + ": Object not as expected" )
4118 return None
4119 except pexpect.EOF:
4120 main.log.error( self.name + ": EOF exception found" )
4121 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004122 main.cleanAndExit()
Jon Hallfb760a02015-04-13 15:35:03 -07004123 except Exception:
4124 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004125 main.cleanAndExit()
Jon Hallfb760a02015-04-13 15:35:03 -07004126
4127 def setCfg( self, component, propName, value=None, check=True ):
4128 """
4129 Set/Unset configuration settings from ONOS cli
Jon Hall390696c2015-05-05 17:13:41 -07004130 Required arguments:
Jon Hallfb760a02015-04-13 15:35:03 -07004131 component - The case sensitive name of the component whose
4132 property is to be set
4133 propName - The case sensitive name of the property to be set/unset
Jon Hall390696c2015-05-05 17:13:41 -07004134 Optional arguments:
Jon Hallfb760a02015-04-13 15:35:03 -07004135 value - The value to set the property to. If None, will unset the
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004136 property and revert it to it's default value(if applicable)
Jon Hallfb760a02015-04-13 15:35:03 -07004137 check - Boolean, Check whether the option was successfully set this
4138 only applies when a value is given.
4139 returns:
4140 main.TRUE on success or main.FALSE on failure. If check is False,
4141 will return main.TRUE unless there is an error
4142 """
4143 try:
4144 baseStr = "cfg"
4145 cmdStr = " set " + str( component ) + " " + str( propName )
4146 if value is not None:
4147 cmdStr += " " + str( value )
4148 output = self.sendline( baseStr + cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07004149 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004150 assert "Command not found:" not in output, output
4151 assert "Error executing command" not in output, output
Jon Hallfb760a02015-04-13 15:35:03 -07004152 if value and check:
4153 results = self.getCfg( component=str( component ),
4154 propName=str( propName ),
4155 jsonFormat=True )
4156 # Check if current value is what we just set
4157 try:
4158 jsonOutput = json.loads( results )
4159 current = jsonOutput[ 'value' ]
Jon Hallc6793552016-01-19 14:18:37 -08004160 except ( TypeError, ValueError ):
Jon Hallfb760a02015-04-13 15:35:03 -07004161 main.log.exception( "Error parsing cfg output" )
4162 main.log.error( "output:" + repr( results ) )
4163 return main.FALSE
4164 if current == str( value ):
4165 return main.TRUE
4166 return main.FALSE
4167 return main.TRUE
4168 except AssertionError:
Jon Hallc6793552016-01-19 14:18:37 -08004169 main.log.exception( "Error in processing 'cfg set' command." )
Jon Hallfb760a02015-04-13 15:35:03 -07004170 return main.FALSE
Jon Hallc6793552016-01-19 14:18:37 -08004171 except ( TypeError, ValueError ):
4172 main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) )
Jon Hallfb760a02015-04-13 15:35:03 -07004173 return main.FALSE
4174 except pexpect.EOF:
4175 main.log.error( self.name + ": EOF exception found" )
4176 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004177 main.cleanAndExit()
Jon Hallfb760a02015-04-13 15:35:03 -07004178 except Exception:
4179 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004180 main.cleanAndExit()
Jon Hallfb760a02015-04-13 15:35:03 -07004181
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004182 def distPrimitivesSend( self, cmd ):
4183 """
4184 Function to handle sending cli commands for the distributed primitives test app
4185
4186 This command will catch some exceptions and retry the command on some
4187 specific store exceptions.
4188
4189 Required arguments:
4190 cmd - The command to send to the cli
4191 returns:
4192 string containing the cli output
4193 None on Error
4194 """
4195 try:
4196 output = self.sendline( cmd )
4197 try:
4198 assert output is not None, "Error in sendline"
4199 # TODO: Maybe make this less hardcoded
4200 # ConsistentMap Exceptions
4201 assert "org.onosproject.store.service" not in output
4202 # Node not leader
4203 assert "java.lang.IllegalStateException" not in output
4204 except AssertionError:
4205 main.log.error( "Error in processing '" + cmd + "' " +
4206 "command: " + str( output ) )
4207 retryTime = 30 # Conservative time, given by Madan
4208 main.log.info( "Waiting " + str( retryTime ) +
4209 "seconds before retrying." )
4210 time.sleep( retryTime ) # Due to change in mastership
4211 output = self.sendline( cmd )
4212 assert output is not None, "Error in sendline"
4213 assert "Command not found:" not in output, output
4214 assert "Error executing command" not in output, output
4215 main.log.info( self.name + ": " + output )
4216 return output
4217 except AssertionError:
4218 main.log.exception( "Error in processing '" + cmd + "' command." )
4219 return None
4220 except TypeError:
4221 main.log.exception( self.name + ": Object not as expected" )
4222 return None
4223 except pexpect.EOF:
4224 main.log.error( self.name + ": EOF exception found" )
4225 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004226 main.cleanAndExit()
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004227 except Exception:
4228 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004229 main.cleanAndExit()
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004230
Jon Hall390696c2015-05-05 17:13:41 -07004231 def setTestAdd( self, setName, values ):
4232 """
4233 CLI command to add elements to a distributed set.
4234 Arguments:
4235 setName - The name of the set to add to.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004236 values - The value(s) to add to the set, space seperated.
Jon Hall390696c2015-05-05 17:13:41 -07004237 Example usages:
4238 setTestAdd( "set1", "a b c" )
4239 setTestAdd( "set2", "1" )
4240 returns:
4241 main.TRUE on success OR
4242 main.FALSE if elements were already in the set OR
4243 main.ERROR on error
4244 """
4245 try:
4246 cmdStr = "set-test-add " + str( setName ) + " " + str( values )
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004247 output = self.distPrimitivesSend( cmdStr )
Jon Hall390696c2015-05-05 17:13:41 -07004248 positiveMatch = "\[(.*)\] was added to the set " + str( setName )
4249 negativeMatch = "\[(.*)\] was already in set " + str( setName )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004250 if re.search( positiveMatch, output ):
Jon Hall390696c2015-05-05 17:13:41 -07004251 return main.TRUE
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004252 elif re.search( negativeMatch, output ):
Jon Hall390696c2015-05-05 17:13:41 -07004253 return main.FALSE
4254 else:
4255 main.log.error( self.name + ": setTestAdd did not" +
4256 " match expected output" )
Jon Hall390696c2015-05-05 17:13:41 -07004257 main.log.debug( self.name + " actual: " + repr( output ) )
4258 return main.ERROR
Jon Hall390696c2015-05-05 17:13:41 -07004259 except TypeError:
4260 main.log.exception( self.name + ": Object not as expected" )
4261 return main.ERROR
Jon Hall390696c2015-05-05 17:13:41 -07004262 except Exception:
4263 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004264 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07004265
4266 def setTestRemove( self, setName, values, clear=False, retain=False ):
4267 """
4268 CLI command to remove elements from a distributed set.
4269 Required arguments:
4270 setName - The name of the set to remove from.
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004271 values - The value(s) to remove from the set, space seperated.
Jon Hall390696c2015-05-05 17:13:41 -07004272 Optional arguments:
4273 clear - Clear all elements from the set
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004274 retain - Retain only the given values. (intersection of the
4275 original set and the given set)
Jon Hall390696c2015-05-05 17:13:41 -07004276 returns:
4277 main.TRUE on success OR
4278 main.FALSE if the set was not changed OR
4279 main.ERROR on error
4280 """
4281 try:
4282 cmdStr = "set-test-remove "
4283 if clear:
4284 cmdStr += "-c " + str( setName )
4285 elif retain:
4286 cmdStr += "-r " + str( setName ) + " " + str( values )
4287 else:
4288 cmdStr += str( setName ) + " " + str( values )
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004289 output = self.distPrimitivesSend( cmdStr )
Jon Hall390696c2015-05-05 17:13:41 -07004290 if clear:
4291 pattern = "Set " + str( setName ) + " cleared"
4292 if re.search( pattern, output ):
4293 return main.TRUE
4294 elif retain:
4295 positivePattern = str( setName ) + " was pruned to contain " +\
4296 "only elements of set \[(.*)\]"
4297 negativePattern = str( setName ) + " was not changed by " +\
4298 "retaining only elements of the set " +\
4299 "\[(.*)\]"
4300 if re.search( positivePattern, output ):
4301 return main.TRUE
4302 elif re.search( negativePattern, output ):
4303 return main.FALSE
4304 else:
4305 positivePattern = "\[(.*)\] was removed from the set " +\
4306 str( setName )
4307 if ( len( values.split() ) == 1 ):
4308 negativePattern = "\[(.*)\] was not in set " +\
4309 str( setName )
4310 else:
4311 negativePattern = "No element of \[(.*)\] was in set " +\
4312 str( setName )
4313 if re.search( positivePattern, output ):
4314 return main.TRUE
4315 elif re.search( negativePattern, output ):
4316 return main.FALSE
4317 main.log.error( self.name + ": setTestRemove did not" +
4318 " match expected output" )
4319 main.log.debug( self.name + " expected: " + pattern )
4320 main.log.debug( self.name + " actual: " + repr( output ) )
4321 return main.ERROR
Jon Hall390696c2015-05-05 17:13:41 -07004322 except TypeError:
4323 main.log.exception( self.name + ": Object not as expected" )
4324 return main.ERROR
Jon Hall390696c2015-05-05 17:13:41 -07004325 except Exception:
4326 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004327 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07004328
4329 def setTestGet( self, setName, values="" ):
4330 """
4331 CLI command to get the elements in a distributed set.
4332 Required arguments:
4333 setName - The name of the set to remove from.
4334 Optional arguments:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004335 values - The value(s) to check if in the set, space seperated.
Jon Hall390696c2015-05-05 17:13:41 -07004336 returns:
4337 main.ERROR on error OR
4338 A list of elements in the set if no optional arguments are
4339 supplied OR
4340 A tuple containing the list then:
4341 main.FALSE if the given values are not in the set OR
4342 main.TRUE if the given values are in the set OR
4343 """
4344 try:
4345 values = str( values ).strip()
4346 setName = str( setName ).strip()
4347 length = len( values.split() )
4348 containsCheck = None
4349 # Patterns to match
4350 setPattern = "\[(.*)\]"
Jon Hall67253832016-12-05 09:47:13 -08004351 pattern = "Items in set " + setName + ":\r\n" + setPattern
Jon Hall390696c2015-05-05 17:13:41 -07004352 containsTrue = "Set " + setName + " contains the value " + values
4353 containsFalse = "Set " + setName + " did not contain the value " +\
4354 values
4355 containsAllTrue = "Set " + setName + " contains the the subset " +\
4356 setPattern
4357 containsAllFalse = "Set " + setName + " did not contain the the" +\
4358 " subset " + setPattern
4359
4360 cmdStr = "set-test-get "
4361 cmdStr += setName + " " + values
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004362 output = self.distPrimitivesSend( cmdStr )
Jon Hall390696c2015-05-05 17:13:41 -07004363 if length == 0:
4364 match = re.search( pattern, output )
4365 else: # if given values
4366 if length == 1: # Contains output
Jon Hall54b994f2016-12-05 10:48:59 -08004367 patternTrue = pattern + "\r\n" + containsTrue
4368 patternFalse = pattern + "\r\n" + containsFalse
Jon Hall390696c2015-05-05 17:13:41 -07004369 else: # ContainsAll output
Jon Hall54b994f2016-12-05 10:48:59 -08004370 patternTrue = pattern + "\r\n" + containsAllTrue
4371 patternFalse = pattern + "\r\n" + containsAllFalse
Jon Hall390696c2015-05-05 17:13:41 -07004372 matchTrue = re.search( patternTrue, output )
4373 matchFalse = re.search( patternFalse, output )
4374 if matchTrue:
4375 containsCheck = main.TRUE
4376 match = matchTrue
4377 elif matchFalse:
4378 containsCheck = main.FALSE
4379 match = matchFalse
4380 else:
Jon Halle0f0b342017-04-18 11:43:47 -07004381 main.log.error( self.name + " setTestGet did not match " +
Jon Hall390696c2015-05-05 17:13:41 -07004382 "expected output" )
4383 main.log.debug( self.name + " expected: " + pattern )
4384 main.log.debug( self.name + " actual: " + repr( output ) )
4385 match = None
4386 if match:
4387 setMatch = match.group( 1 )
4388 if setMatch == '':
4389 setList = []
4390 else:
4391 setList = setMatch.split( ", " )
4392 if length > 0:
4393 return ( setList, containsCheck )
4394 else:
4395 return setList
4396 else: # no match
4397 main.log.error( self.name + ": setTestGet did not" +
4398 " match expected output" )
4399 main.log.debug( self.name + " expected: " + pattern )
4400 main.log.debug( self.name + " actual: " + repr( output ) )
4401 return main.ERROR
Jon Hall390696c2015-05-05 17:13:41 -07004402 except TypeError:
4403 main.log.exception( self.name + ": Object not as expected" )
4404 return main.ERROR
Jon Hall390696c2015-05-05 17:13:41 -07004405 except Exception:
4406 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004407 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07004408
4409 def setTestSize( self, setName ):
4410 """
4411 CLI command to get the elements in a distributed set.
4412 Required arguments:
4413 setName - The name of the set to remove from.
4414 returns:
Jon Hallfeff3082015-05-19 10:23:26 -07004415 The integer value of the size returned or
Jon Hall390696c2015-05-05 17:13:41 -07004416 None on error
4417 """
4418 try:
4419 # TODO: Should this check against the number of elements returned
4420 # and then return true/false based on that?
4421 setName = str( setName ).strip()
4422 # Patterns to match
4423 setPattern = "\[(.*)\]"
Jon Hall67253832016-12-05 09:47:13 -08004424 pattern = "There are (\d+) items in set " + setName + ":\r\n" +\
Jon Hall390696c2015-05-05 17:13:41 -07004425 setPattern
4426 cmdStr = "set-test-get -s "
4427 cmdStr += setName
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004428 output = self.distPrimitivesSend( cmdStr )
Jon Hall390696c2015-05-05 17:13:41 -07004429 match = re.search( pattern, output )
4430 if match:
4431 setSize = int( match.group( 1 ) )
4432 setMatch = match.group( 2 )
4433 if len( setMatch.split() ) == setSize:
4434 main.log.info( "The size returned by " + self.name +
4435 " matches the number of elements in " +
4436 "the returned set" )
4437 else:
4438 main.log.error( "The size returned by " + self.name +
4439 " does not match the number of " +
4440 "elements in the returned set." )
4441 return setSize
4442 else: # no match
4443 main.log.error( self.name + ": setTestGet did not" +
4444 " match expected output" )
4445 main.log.debug( self.name + " expected: " + pattern )
4446 main.log.debug( self.name + " actual: " + repr( output ) )
4447 return None
Jon Hall390696c2015-05-05 17:13:41 -07004448 except TypeError:
4449 main.log.exception( self.name + ": Object not as expected" )
4450 return None
Jon Hall390696c2015-05-05 17:13:41 -07004451 except Exception:
4452 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004453 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07004454
Jon Hall80daded2015-05-27 16:07:00 -07004455 def counters( self, jsonFormat=True ):
Jon Hall390696c2015-05-05 17:13:41 -07004456 """
4457 Command to list the various counters in the system.
4458 returns:
Jon Hall80daded2015-05-27 16:07:00 -07004459 if jsonFormat, a string of the json object returned by the cli
4460 command
4461 if not jsonFormat, the normal string output of the cli command
Jon Hall390696c2015-05-05 17:13:41 -07004462 None on error
4463 """
Jon Hall390696c2015-05-05 17:13:41 -07004464 try:
Jon Hall390696c2015-05-05 17:13:41 -07004465 cmdStr = "counters"
Jon Hall80daded2015-05-27 16:07:00 -07004466 if jsonFormat:
4467 cmdStr += " -j"
Jon Hall390696c2015-05-05 17:13:41 -07004468 output = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07004469 assert output is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004470 assert "Command not found:" not in output, output
4471 assert "Error executing command" not in output, output
Jon Hall390696c2015-05-05 17:13:41 -07004472 main.log.info( self.name + ": " + output )
Jon Hall80daded2015-05-27 16:07:00 -07004473 return output
Jon Hall390696c2015-05-05 17:13:41 -07004474 except AssertionError:
Jon Hallc6793552016-01-19 14:18:37 -08004475 main.log.exception( "Error in processing 'counters' command." )
Jon Hall80daded2015-05-27 16:07:00 -07004476 return None
Jon Hall390696c2015-05-05 17:13:41 -07004477 except TypeError:
4478 main.log.exception( self.name + ": Object not as expected" )
Jon Hall80daded2015-05-27 16:07:00 -07004479 return None
Jon Hall390696c2015-05-05 17:13:41 -07004480 except pexpect.EOF:
4481 main.log.error( self.name + ": EOF exception found" )
4482 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004483 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07004484 except Exception:
4485 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004486 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07004487
Jon Hall935db192016-04-19 00:22:04 -07004488 def counterTestAddAndGet( self, counter, delta=1 ):
Jon Hall390696c2015-05-05 17:13:41 -07004489 """
Jon Halle1a3b752015-07-22 13:02:46 -07004490 CLI command to add a delta to then get a distributed counter.
Jon Hall390696c2015-05-05 17:13:41 -07004491 Required arguments:
4492 counter - The name of the counter to increment.
4493 Optional arguments:
Jon Halle1a3b752015-07-22 13:02:46 -07004494 delta - The long to add to the counter
Jon Hall390696c2015-05-05 17:13:41 -07004495 returns:
4496 integer value of the counter or
4497 None on Error
4498 """
4499 try:
4500 counter = str( counter )
Jon Halle1a3b752015-07-22 13:02:46 -07004501 delta = int( delta )
Jon Hall390696c2015-05-05 17:13:41 -07004502 cmdStr = "counter-test-increment "
Jon Hall390696c2015-05-05 17:13:41 -07004503 cmdStr += counter
Jon Halle1a3b752015-07-22 13:02:46 -07004504 if delta != 1:
4505 cmdStr += " " + str( delta )
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004506 output = self.distPrimitivesSend( cmdStr )
Jon Halle1a3b752015-07-22 13:02:46 -07004507 pattern = counter + " was updated to (-?\d+)"
Jon Hall390696c2015-05-05 17:13:41 -07004508 match = re.search( pattern, output )
4509 if match:
4510 return int( match.group( 1 ) )
4511 else:
Jon Halle1a3b752015-07-22 13:02:46 -07004512 main.log.error( self.name + ": counterTestAddAndGet did not" +
Jon Hall390696c2015-05-05 17:13:41 -07004513 " match expected output." )
4514 main.log.debug( self.name + " expected: " + pattern )
4515 main.log.debug( self.name + " actual: " + repr( output ) )
4516 return None
Jon Hall390696c2015-05-05 17:13:41 -07004517 except TypeError:
4518 main.log.exception( self.name + ": Object not as expected" )
4519 return None
Jon Hall390696c2015-05-05 17:13:41 -07004520 except Exception:
4521 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004522 main.cleanAndExit()
Jon Hall390696c2015-05-05 17:13:41 -07004523
Jon Hall935db192016-04-19 00:22:04 -07004524 def counterTestGetAndAdd( self, counter, delta=1 ):
Jon Halle1a3b752015-07-22 13:02:46 -07004525 """
4526 CLI command to get a distributed counter then add a delta to it.
4527 Required arguments:
4528 counter - The name of the counter to increment.
4529 Optional arguments:
4530 delta - The long to add to the counter
Jon Halle1a3b752015-07-22 13:02:46 -07004531 returns:
4532 integer value of the counter or
4533 None on Error
4534 """
4535 try:
4536 counter = str( counter )
4537 delta = int( delta )
4538 cmdStr = "counter-test-increment -g "
Jon Halle1a3b752015-07-22 13:02:46 -07004539 cmdStr += counter
4540 if delta != 1:
4541 cmdStr += " " + str( delta )
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004542 output = self.distPrimitivesSend( cmdStr )
Jon Halle1a3b752015-07-22 13:02:46 -07004543 pattern = counter + " was updated to (-?\d+)"
4544 match = re.search( pattern, output )
4545 if match:
4546 return int( match.group( 1 ) )
4547 else:
4548 main.log.error( self.name + ": counterTestGetAndAdd did not" +
4549 " match expected output." )
4550 main.log.debug( self.name + " expected: " + pattern )
4551 main.log.debug( self.name + " actual: " + repr( output ) )
4552 return None
Jon Halle1a3b752015-07-22 13:02:46 -07004553 except TypeError:
4554 main.log.exception( self.name + ": Object not as expected" )
4555 return None
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004556 except Exception:
4557 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004558 main.cleanAndExit()
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004559
4560 def valueTestGet( self, valueName ):
4561 """
4562 CLI command to get the value of an atomic value.
4563 Required arguments:
4564 valueName - The name of the value to get.
4565 returns:
4566 string value of the value or
4567 None on Error
4568 """
4569 try:
4570 valueName = str( valueName )
4571 cmdStr = "value-test "
4572 operation = "get"
4573 cmdStr = "value-test {} {}".format( valueName,
4574 operation )
4575 output = self.distPrimitivesSend( cmdStr )
4576 pattern = "(\w+)"
4577 match = re.search( pattern, output )
4578 if match:
4579 return match.group( 1 )
4580 else:
4581 main.log.error( self.name + ": valueTestGet did not" +
4582 " match expected output." )
4583 main.log.debug( self.name + " expected: " + pattern )
4584 main.log.debug( self.name + " actual: " + repr( output ) )
4585 return None
4586 except TypeError:
4587 main.log.exception( self.name + ": Object not as expected" )
4588 return None
4589 except Exception:
4590 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004591 main.cleanAndExit()
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004592
4593 def valueTestSet( self, valueName, newValue ):
4594 """
4595 CLI command to set the value of an atomic value.
4596 Required arguments:
4597 valueName - The name of the value to set.
4598 newValue - The value to assign to the given value.
4599 returns:
4600 main.TRUE on success or
4601 main.ERROR on Error
4602 """
4603 try:
4604 valueName = str( valueName )
4605 newValue = str( newValue )
4606 operation = "set"
4607 cmdStr = "value-test {} {} {}".format( valueName,
4608 operation,
4609 newValue )
4610 output = self.distPrimitivesSend( cmdStr )
4611 if output is not None:
4612 return main.TRUE
4613 else:
4614 return main.ERROR
4615 except TypeError:
4616 main.log.exception( self.name + ": Object not as expected" )
4617 return main.ERROR
4618 except Exception:
4619 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004620 main.cleanAndExit()
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004621
4622 def valueTestCompareAndSet( self, valueName, oldValue, newValue ):
4623 """
4624 CLI command to compareAndSet the value of an atomic value.
4625 Required arguments:
4626 valueName - The name of the value.
4627 oldValue - Compare the current value of the atomic value to this
4628 newValue - If the value equals oldValue, set the value to newValue
4629 returns:
4630 main.TRUE on success or
4631 main.FALSE on failure or
4632 main.ERROR on Error
4633 """
4634 try:
4635 valueName = str( valueName )
4636 oldValue = str( oldValue )
4637 newValue = str( newValue )
4638 operation = "compareAndSet"
4639 cmdStr = "value-test {} {} {} {}".format( valueName,
4640 operation,
4641 oldValue,
4642 newValue )
4643 output = self.distPrimitivesSend( cmdStr )
4644 pattern = "(\w+)"
4645 match = re.search( pattern, output )
4646 if match:
4647 result = match.group( 1 )
4648 if result == "true":
4649 return main.TRUE
4650 elif result == "false":
4651 return main.FALSE
4652 else:
4653 main.log.error( self.name + ": valueTestCompareAndSet did not" +
4654 " match expected output." )
4655 main.log.debug( self.name + " expected: " + pattern )
4656 main.log.debug( self.name + " actual: " + repr( output ) )
4657 return main.ERROR
4658 except TypeError:
4659 main.log.exception( self.name + ": Object not as expected" )
4660 return main.ERROR
4661 except Exception:
4662 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004663 main.cleanAndExit()
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004664
4665 def valueTestGetAndSet( self, valueName, newValue ):
4666 """
4667 CLI command to getAndSet the value of an atomic value.
4668 Required arguments:
4669 valueName - The name of the value to get.
4670 newValue - The value to assign to the given value
4671 returns:
4672 string value of the value or
4673 None on Error
4674 """
4675 try:
4676 valueName = str( valueName )
4677 cmdStr = "value-test "
4678 operation = "getAndSet"
4679 cmdStr += valueName + " " + operation
4680 cmdStr = "value-test {} {} {}".format( valueName,
4681 operation,
4682 newValue )
4683 output = self.distPrimitivesSend( cmdStr )
4684 pattern = "(\w+)"
4685 match = re.search( pattern, output )
4686 if match:
4687 return match.group( 1 )
4688 else:
4689 main.log.error( self.name + ": valueTestGetAndSet did not" +
4690 " match expected output." )
4691 main.log.debug( self.name + " expected: " + pattern )
4692 main.log.debug( self.name + " actual: " + repr( output ) )
4693 return None
4694 except TypeError:
4695 main.log.exception( self.name + ": Object not as expected" )
4696 return None
4697 except Exception:
4698 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004699 main.cleanAndExit()
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004700
4701 def valueTestDestroy( self, valueName ):
4702 """
4703 CLI command to destroy an atomic value.
4704 Required arguments:
4705 valueName - The name of the value to destroy.
4706 returns:
4707 main.TRUE on success or
4708 main.ERROR on Error
4709 """
4710 try:
4711 valueName = str( valueName )
4712 cmdStr = "value-test "
4713 operation = "destroy"
4714 cmdStr += valueName + " " + operation
4715 output = self.distPrimitivesSend( cmdStr )
4716 if output is not None:
4717 return main.TRUE
4718 else:
4719 return main.ERROR
4720 except TypeError:
4721 main.log.exception( self.name + ": Object not as expected" )
4722 return main.ERROR
Jon Halle1a3b752015-07-22 13:02:46 -07004723 except Exception:
4724 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004725 main.cleanAndExit()
Jon Halle1a3b752015-07-22 13:02:46 -07004726
YPZhangfebf7302016-05-24 16:45:56 -07004727 def summary( self, jsonFormat=True, timeout=30 ):
kelvin-onlaba297c4d2015-06-01 13:53:55 -07004728 """
4729 Description: Execute summary command in onos
4730 Returns: json object ( summary -j ), returns main.FALSE if there is
4731 no output
4732
4733 """
4734 try:
4735 cmdStr = "summary"
4736 if jsonFormat:
4737 cmdStr += " -j"
YPZhangfebf7302016-05-24 16:45:56 -07004738 handle = self.sendline( cmdStr, timeout=timeout )
Jon Halla495f562016-05-16 18:03:26 -07004739 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004740 assert "Command not found:" not in handle, handle
Jon Hall6e709752016-02-01 13:38:46 -08004741 assert "Error:" not in handle, handle
Devin Lima7cfdbd2017-09-29 15:02:22 -07004742 assert "Error executing" not in handle, handle
kelvin-onlaba297c4d2015-06-01 13:53:55 -07004743 if not handle:
4744 main.log.error( self.name + ": There is no output in " +
4745 "summary command" )
4746 return main.FALSE
4747 return handle
Jon Hallc6793552016-01-19 14:18:37 -08004748 except AssertionError:
Jon Hall6e709752016-02-01 13:38:46 -08004749 main.log.exception( "{} Error in summary output:".format( self.name ) )
Jon Hallc6793552016-01-19 14:18:37 -08004750 return None
kelvin-onlaba297c4d2015-06-01 13:53:55 -07004751 except TypeError:
4752 main.log.exception( self.name + ": Object not as expected" )
4753 return None
4754 except pexpect.EOF:
4755 main.log.error( self.name + ": EOF exception found" )
4756 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004757 main.cleanAndExit()
kelvin-onlaba297c4d2015-06-01 13:53:55 -07004758 except Exception:
4759 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004760 main.cleanAndExit()
Jon Hall2a5002c2015-08-21 16:49:11 -07004761
Jon Hall935db192016-04-19 00:22:04 -07004762 def transactionalMapGet( self, keyName ):
Jon Hall2a5002c2015-08-21 16:49:11 -07004763 """
4764 CLI command to get the value of a key in a consistent map using
4765 transactions. This a test function and can only get keys from the
4766 test map hard coded into the cli command
4767 Required arguments:
4768 keyName - The name of the key to get
Jon Hall2a5002c2015-08-21 16:49:11 -07004769 returns:
4770 The string value of the key or
4771 None on Error
4772 """
4773 try:
4774 keyName = str( keyName )
4775 cmdStr = "transactional-map-test-get "
Jon Hall2a5002c2015-08-21 16:49:11 -07004776 cmdStr += keyName
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004777 output = self.distPrimitivesSend( cmdStr )
Jon Hall2a5002c2015-08-21 16:49:11 -07004778 pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found."
4779 if "Key " + keyName + " not found." in output:
Jon Hall9bfadd22016-05-11 14:48:07 -07004780 main.log.warn( output )
Jon Hall2a5002c2015-08-21 16:49:11 -07004781 return None
4782 else:
4783 match = re.search( pattern, output )
4784 if match:
4785 return match.groupdict()[ 'value' ]
4786 else:
4787 main.log.error( self.name + ": transactionlMapGet did not" +
4788 " match expected output." )
4789 main.log.debug( self.name + " expected: " + pattern )
4790 main.log.debug( self.name + " actual: " + repr( output ) )
4791 return None
4792 except TypeError:
4793 main.log.exception( self.name + ": Object not as expected" )
4794 return None
Jon Hall2a5002c2015-08-21 16:49:11 -07004795 except Exception:
4796 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004797 main.cleanAndExit()
Jon Hall2a5002c2015-08-21 16:49:11 -07004798
Jon Hall935db192016-04-19 00:22:04 -07004799 def transactionalMapPut( self, numKeys, value ):
Jon Hall2a5002c2015-08-21 16:49:11 -07004800 """
4801 CLI command to put a value into 'numKeys' number of keys in a
4802 consistent map using transactions. This a test function and can only
4803 put into keys named 'Key#' of the test map hard coded into the cli command
4804 Required arguments:
4805 numKeys - Number of keys to add the value to
4806 value - The string value to put into the keys
Jon Hall2a5002c2015-08-21 16:49:11 -07004807 returns:
4808 A dictionary whose keys are the name of the keys put into the map
4809 and the values of the keys are dictionaries whose key-values are
4810 'value': value put into map and optionaly
4811 'oldValue': Previous value in the key or
4812 None on Error
4813
4814 Example output
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004815 { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'},
4816 'Key2': {'value': 'Testing'} }
Jon Hall2a5002c2015-08-21 16:49:11 -07004817 """
4818 try:
4819 numKeys = str( numKeys )
4820 value = str( value )
4821 cmdStr = "transactional-map-test-put "
Jon Hall2a5002c2015-08-21 16:49:11 -07004822 cmdStr += numKeys + " " + value
Jon Hall7a6ebfd2017-03-13 10:58:58 -07004823 output = self.distPrimitivesSend( cmdStr )
Jon Hall2a5002c2015-08-21 16:49:11 -07004824 newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.'
4825 updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\."
4826 results = {}
4827 for line in output.splitlines():
4828 new = re.search( newPattern, line )
4829 updated = re.search( updatedPattern, line )
4830 if new:
4831 results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] }
4832 elif updated:
4833 results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ],
Jon Hallc6793552016-01-19 14:18:37 -08004834 'oldValue': updated.groupdict()[ 'oldValue' ] }
Jon Hall2a5002c2015-08-21 16:49:11 -07004835 else:
4836 main.log.error( self.name + ": transactionlMapGet did not" +
4837 " match expected output." )
Jon Hallc6793552016-01-19 14:18:37 -08004838 main.log.debug( "{} expected: {!r} or {!r}".format( self.name,
4839 newPattern,
4840 updatedPattern ) )
Jon Hall2a5002c2015-08-21 16:49:11 -07004841 main.log.debug( self.name + " actual: " + repr( output ) )
4842 return results
4843 except TypeError:
4844 main.log.exception( self.name + ": Object not as expected" )
4845 return None
Jon Hall2a5002c2015-08-21 16:49:11 -07004846 except Exception:
4847 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004848 main.cleanAndExit()
Jon Hallc6793552016-01-19 14:18:37 -08004849
acsmarsdaea66c2015-09-03 11:44:06 -07004850 def maps( self, jsonFormat=True ):
4851 """
4852 Description: Returns result of onos:maps
4853 Optional:
4854 * jsonFormat: enable json formatting of output
4855 """
4856 try:
4857 cmdStr = "maps"
4858 if jsonFormat:
4859 cmdStr += " -j"
4860 handle = self.sendline( cmdStr )
Jon Halla495f562016-05-16 18:03:26 -07004861 assert handle is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004862 assert "Command not found:" not in handle, handle
acsmarsdaea66c2015-09-03 11:44:06 -07004863 return handle
Jon Hallc6793552016-01-19 14:18:37 -08004864 except AssertionError:
4865 main.log.exception( "" )
4866 return None
acsmarsdaea66c2015-09-03 11:44:06 -07004867 except TypeError:
4868 main.log.exception( self.name + ": Object not as expected" )
4869 return None
4870 except pexpect.EOF:
4871 main.log.error( self.name + ": EOF exception found" )
4872 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004873 main.cleanAndExit()
acsmarsdaea66c2015-09-03 11:44:06 -07004874 except Exception:
4875 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004876 main.cleanAndExit()
GlennRC050596c2015-11-18 17:06:41 -08004877
4878 def getSwController( self, uri, jsonFormat=True ):
4879 """
4880 Descrition: Gets the controller information from the device
4881 """
4882 try:
4883 cmd = "device-controllers "
4884 if jsonFormat:
4885 cmd += "-j "
4886 response = self.sendline( cmd + uri )
Jon Halla495f562016-05-16 18:03:26 -07004887 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004888 assert "Command not found:" not in response, response
GlennRC050596c2015-11-18 17:06:41 -08004889 return response
Jon Hallc6793552016-01-19 14:18:37 -08004890 except AssertionError:
4891 main.log.exception( "" )
4892 return None
GlennRC050596c2015-11-18 17:06:41 -08004893 except TypeError:
4894 main.log.exception( self.name + ": Object not as expected" )
4895 return None
4896 except pexpect.EOF:
4897 main.log.error( self.name + ": EOF exception found" )
4898 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004899 main.cleanAndExit()
GlennRC050596c2015-11-18 17:06:41 -08004900 except Exception:
4901 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004902 main.cleanAndExit()
GlennRC050596c2015-11-18 17:06:41 -08004903
4904 def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ):
4905 """
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004906 Descrition: sets the controller(s) for the specified device
GlennRC050596c2015-11-18 17:06:41 -08004907
4908 Parameters:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004909 Required: uri - String: The uri of the device(switch).
GlennRC050596c2015-11-18 17:06:41 -08004910 ip - String or List: The ip address of the controller.
4911 This parameter can be formed in a couple of different ways.
4912 VALID:
4913 10.0.0.1 - just the ip address
4914 tcp:10.0.0.1 - the protocol and the ip address
4915 tcp:10.0.0.1:6653 - the protocol and port can be specified,
4916 so that you can add controllers with different
4917 protocols and ports
4918 INVALID:
4919 10.0.0.1:6653 - this is not supported by ONOS
4920
4921 Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given
4922 port - The port number.
4923 jsonFormat - If set ONOS will output in json NOTE: This is currently not supported
4924
4925 Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE
4926 """
4927 try:
4928 cmd = "device-setcontrollers"
4929
4930 if jsonFormat:
4931 cmd += " -j"
4932 cmd += " " + uri
4933 if isinstance( ip, str ):
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004934 ip = [ ip ]
GlennRC050596c2015-11-18 17:06:41 -08004935 for item in ip:
4936 if ":" in item:
4937 sitem = item.split( ":" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004938 if len( sitem ) == 3:
GlennRC050596c2015-11-18 17:06:41 -08004939 cmd += " " + item
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004940 elif "." in sitem[ 1 ]:
4941 cmd += " {}:{}".format( item, port )
GlennRC050596c2015-11-18 17:06:41 -08004942 else:
4943 main.log.error( "Malformed entry: " + item )
4944 raise TypeError
4945 else:
4946 cmd += " {}:{}:{}".format( proto, item, port )
GlennRC050596c2015-11-18 17:06:41 -08004947 response = self.sendline( cmd )
Jon Halla495f562016-05-16 18:03:26 -07004948 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004949 assert "Command not found:" not in response, response
GlennRC050596c2015-11-18 17:06:41 -08004950 if "Error" in response:
4951 main.log.error( response )
4952 return main.FALSE
GlennRC050596c2015-11-18 17:06:41 -08004953 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -08004954 except AssertionError:
4955 main.log.exception( "" )
Jon Hall2c8959e2016-12-16 12:17:34 -08004956 return main.FALSE
GlennRC050596c2015-11-18 17:06:41 -08004957 except TypeError:
4958 main.log.exception( self.name + ": Object not as expected" )
4959 return main.FALSE
4960 except pexpect.EOF:
4961 main.log.error( self.name + ": EOF exception found" )
4962 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07004963 main.cleanAndExit()
GlennRC050596c2015-11-18 17:06:41 -08004964 except Exception:
4965 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07004966 main.cleanAndExit()
GlennRC20fc6522015-12-23 23:26:57 -08004967
4968 def removeDevice( self, device ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004969 '''
GlennRC20fc6522015-12-23 23:26:57 -08004970 Description:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004971 Remove a device from ONOS by passing the uri of the device(s).
GlennRC20fc6522015-12-23 23:26:57 -08004972 Parameters:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004973 device - (str or list) the id or uri of the device ex. "of:0000000000000001"
GlennRC20fc6522015-12-23 23:26:57 -08004974 Returns:
4975 Returns main.FALSE if an exception is thrown or an error is present
4976 in the response. Otherwise, returns main.TRUE.
4977 NOTE:
4978 If a host cannot be removed, then this function will return main.FALSE
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00004979 '''
GlennRC20fc6522015-12-23 23:26:57 -08004980 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07004981 if isinstance( device, str ):
You Wang823f5022016-08-18 15:24:41 -07004982 deviceStr = device
4983 device = []
4984 device.append( deviceStr )
GlennRC20fc6522015-12-23 23:26:57 -08004985
4986 for d in device:
4987 time.sleep( 1 )
4988 response = self.sendline( "device-remove {}".format( d ) )
Jon Halla495f562016-05-16 18:03:26 -07004989 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08004990 assert "Command not found:" not in response, response
GlennRC20fc6522015-12-23 23:26:57 -08004991 if "Error" in response:
4992 main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) )
4993 return main.FALSE
GlennRC20fc6522015-12-23 23:26:57 -08004994 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -08004995 except AssertionError:
4996 main.log.exception( "" )
4997 return main.FALSE
GlennRC20fc6522015-12-23 23:26:57 -08004998 except TypeError:
4999 main.log.exception( self.name + ": Object not as expected" )
5000 return main.FALSE
5001 except pexpect.EOF:
5002 main.log.error( self.name + ": EOF exception found" )
5003 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005004 main.cleanAndExit()
GlennRC20fc6522015-12-23 23:26:57 -08005005 except Exception:
5006 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005007 main.cleanAndExit()
GlennRC20fc6522015-12-23 23:26:57 -08005008
5009 def removeHost( self, host ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005010 '''
GlennRC20fc6522015-12-23 23:26:57 -08005011 Description:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005012 Remove a host from ONOS by passing the id of the host(s)
GlennRC20fc6522015-12-23 23:26:57 -08005013 Parameters:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005014 hostId - (str or list) the id or mac of the host ex. "00:00:00:00:00:01"
GlennRC20fc6522015-12-23 23:26:57 -08005015 Returns:
5016 Returns main.FALSE if an exception is thrown or an error is present
5017 in the response. Otherwise, returns main.TRUE.
5018 NOTE:
5019 If a host cannot be removed, then this function will return main.FALSE
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005020 '''
GlennRC20fc6522015-12-23 23:26:57 -08005021 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005022 if isinstance( host, str ):
GlennRC20fc6522015-12-23 23:26:57 -08005023 host = list( host )
5024
5025 for h in host:
5026 time.sleep( 1 )
5027 response = self.sendline( "host-remove {}".format( h ) )
Jon Halla495f562016-05-16 18:03:26 -07005028 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08005029 assert "Command not found:" not in response, response
GlennRC20fc6522015-12-23 23:26:57 -08005030 if "Error" in response:
5031 main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) )
5032 return main.FALSE
GlennRC20fc6522015-12-23 23:26:57 -08005033 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -08005034 except AssertionError:
5035 main.log.exception( "" )
Jon Hall2c8959e2016-12-16 12:17:34 -08005036 return main.FALSE
GlennRC20fc6522015-12-23 23:26:57 -08005037 except TypeError:
5038 main.log.exception( self.name + ": Object not as expected" )
5039 return main.FALSE
5040 except pexpect.EOF:
5041 main.log.error( self.name + ": EOF exception found" )
5042 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005043 main.cleanAndExit()
GlennRC20fc6522015-12-23 23:26:57 -08005044 except Exception:
5045 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005046 main.cleanAndExit()
GlennRCed771242016-01-13 17:02:47 -08005047
YPZhangfebf7302016-05-24 16:45:56 -07005048 def link( self, begin, end, state, timeout=30, showResponse=True ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005049 '''
GlennRCed771242016-01-13 17:02:47 -08005050 Description:
5051 Bring link down or up in the null-provider.
5052 params:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005053 begin - (string) One end of a device or switch.
5054 end - (string) the other end of the device or switch
GlennRCed771242016-01-13 17:02:47 -08005055 returns:
5056 main.TRUE if no exceptions were thrown and no Errors are
5057 present in the resoponse. Otherwise, returns main.FALSE
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005058 '''
GlennRCed771242016-01-13 17:02:47 -08005059 try:
Jon Halle0f0b342017-04-18 11:43:47 -07005060 cmd = "null-link null:{} null:{} {}".format( begin, end, state )
YPZhangfebf7302016-05-24 16:45:56 -07005061 response = self.sendline( cmd, showResponse=showResponse, timeout=timeout )
Jon Halla495f562016-05-16 18:03:26 -07005062 assert response is not None, "Error in sendline"
Jon Hallc6793552016-01-19 14:18:37 -08005063 assert "Command not found:" not in response, response
GlennRCed771242016-01-13 17:02:47 -08005064 if "Error" in response or "Failure" in response:
5065 main.log.error( response )
5066 return main.FALSE
GlennRCed771242016-01-13 17:02:47 -08005067 return main.TRUE
Jon Hallc6793552016-01-19 14:18:37 -08005068 except AssertionError:
5069 main.log.exception( "" )
Jon Hall2c8959e2016-12-16 12:17:34 -08005070 return main.FALSE
GlennRCed771242016-01-13 17:02:47 -08005071 except TypeError:
5072 main.log.exception( self.name + ": Object not as expected" )
5073 return main.FALSE
5074 except pexpect.EOF:
5075 main.log.error( self.name + ": EOF exception found" )
5076 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005077 main.cleanAndExit()
GlennRCed771242016-01-13 17:02:47 -08005078 except Exception:
5079 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005080 main.cleanAndExit()
GlennRCed771242016-01-13 17:02:47 -08005081
Jon Hall2c8959e2016-12-16 12:17:34 -08005082 def portstate( self, dpid, port, state ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005083 '''
Flavio Castro82ee2f62016-06-07 15:04:12 -07005084 Description:
5085 Changes the state of port in an OF switch by means of the
5086 PORTSTATUS OF messages.
5087 params:
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005088 dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102'
5089 port - (string) target port in the device. Ex: '2'
5090 state - (string) target state (enable or disable)
Flavio Castro82ee2f62016-06-07 15:04:12 -07005091 returns:
5092 main.TRUE if no exceptions were thrown and no Errors are
5093 present in the resoponse. Otherwise, returns main.FALSE
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005094 '''
Flavio Castro82ee2f62016-06-07 15:04:12 -07005095 try:
Jon Hall2c8959e2016-12-16 12:17:34 -08005096 state = state.lower()
5097 assert state == 'enable' or state == 'disable', "Unknown state"
Jon Halle0f0b342017-04-18 11:43:47 -07005098 cmd = "portstate {} {} {}".format( dpid, port, state )
Flavio Castro82ee2f62016-06-07 15:04:12 -07005099 response = self.sendline( cmd, showResponse=True )
5100 assert response is not None, "Error in sendline"
5101 assert "Command not found:" not in response, response
5102 if "Error" in response or "Failure" in response:
5103 main.log.error( response )
5104 return main.FALSE
5105 return main.TRUE
5106 except AssertionError:
5107 main.log.exception( "" )
Jon Hall2c8959e2016-12-16 12:17:34 -08005108 return main.FALSE
Flavio Castro82ee2f62016-06-07 15:04:12 -07005109 except TypeError:
5110 main.log.exception( self.name + ": Object not as expected" )
5111 return main.FALSE
5112 except pexpect.EOF:
5113 main.log.error( self.name + ": EOF exception found" )
5114 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005115 main.cleanAndExit()
Flavio Castro82ee2f62016-06-07 15:04:12 -07005116 except Exception:
5117 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005118 main.cleanAndExit()
Flavio Castro82ee2f62016-06-07 15:04:12 -07005119
5120 def logSet( self, level="INFO", app="org.onosproject" ):
5121 """
5122 Set the logging level to lvl for a specific app
5123 returns main.TRUE on success
5124 returns main.FALSE if Error occurred
5125 if noExit is True, TestON will not exit, but clean up
5126 Available level: DEBUG, TRACE, INFO, WARN, ERROR
5127 Level defaults to INFO
5128 """
5129 try:
Jon Halle0f0b342017-04-18 11:43:47 -07005130 self.handle.sendline( "log:set %s %s" % ( level, app ) )
Flavio Castro82ee2f62016-06-07 15:04:12 -07005131 self.handle.expect( "onos>" )
5132
5133 response = self.handle.before
5134 if re.search( "Error", response ):
5135 return main.FALSE
5136 return main.TRUE
5137 except pexpect.TIMEOUT:
5138 main.log.exception( self.name + ": TIMEOUT exception found" )
Devin Lim44075962017-08-11 10:56:37 -07005139 main.cleanAndExit()
Flavio Castro82ee2f62016-06-07 15:04:12 -07005140 except pexpect.EOF:
5141 main.log.error( self.name + ": EOF exception found" )
5142 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005143 main.cleanAndExit()
Flavio Castro82ee2f62016-06-07 15:04:12 -07005144 except Exception:
5145 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005146 main.cleanAndExit()
You Wangdb8cd0a2016-05-26 15:19:45 -07005147
5148 def getGraphDict( self, timeout=60, includeHost=False ):
5149 """
5150 Return a dictionary which describes the latest network topology data as a
5151 graph.
5152 An example of the dictionary:
5153 { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... },
5154 vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } }
5155 Each vertex should at least have an 'edges' attribute which describes the
5156 adjacency information. The value of 'edges' attribute is also represented by
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005157 a dictionary, which maps each edge (identified by the neighbor vertex) to a
You Wangdb8cd0a2016-05-26 15:19:45 -07005158 list of attributes.
5159 An example of the edges dictionary:
5160 'edges': { vertex2: { 'port': ..., 'weight': ... },
5161 vertex3: { 'port': ..., 'weight': ... } }
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005162 If includeHost == True, all hosts (and host-switch links) will be included
You Wangdb8cd0a2016-05-26 15:19:45 -07005163 in topology data.
5164 """
5165 graphDict = {}
5166 try:
5167 links = self.links()
5168 links = json.loads( links )
5169 devices = self.devices()
5170 devices = json.loads( devices )
5171 idToDevice = {}
5172 for device in devices:
5173 idToDevice[ device[ 'id' ] ] = device
5174 if includeHost:
5175 hosts = self.hosts()
5176 # FIXME: support 'includeHost' argument
5177 for link in links:
5178 nodeA = link[ 'src' ][ 'device' ]
5179 nodeB = link[ 'dst' ][ 'device' ]
5180 assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ]
Jon Halle0f0b342017-04-18 11:43:47 -07005181 if nodeA not in graphDict.keys():
5182 graphDict[ nodeA ] = { 'edges': {},
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005183 'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ],
Jon Halle0f0b342017-04-18 11:43:47 -07005184 'type': idToDevice[ nodeA ][ 'type' ],
5185 'available': idToDevice[ nodeA ][ 'available' ],
5186 'role': idToDevice[ nodeA ][ 'role' ],
5187 'mfr': idToDevice[ nodeA ][ 'mfr' ],
5188 'hw': idToDevice[ nodeA ][ 'hw' ],
5189 'sw': idToDevice[ nodeA ][ 'sw' ],
5190 'serial': idToDevice[ nodeA ][ 'serial' ],
5191 'chassisId': idToDevice[ nodeA ][ 'chassisId' ],
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005192 'annotations': idToDevice[ nodeA ][ 'annotations' ]}
You Wangdb8cd0a2016-05-26 15:19:45 -07005193 else:
5194 # Assert nodeB is not connected to any current links of nodeA
5195 assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys()
Jon Halle0f0b342017-04-18 11:43:47 -07005196 graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ],
5197 'type': link[ 'type' ],
5198 'state': link[ 'state' ] }
You Wangdb8cd0a2016-05-26 15:19:45 -07005199 return graphDict
5200 except ( TypeError, ValueError ):
5201 main.log.exception( self.name + ": Object not as expected" )
5202 return None
5203 except KeyError:
5204 main.log.exception( self.name + ": KeyError exception found" )
5205 return None
5206 except AssertionError:
5207 main.log.exception( self.name + ": AssertionError exception found" )
5208 return None
5209 except pexpect.EOF:
5210 main.log.error( self.name + ": EOF exception found" )
5211 main.log.error( self.name + ": " + self.handle.before )
5212 return None
5213 except Exception:
5214 main.log.exception( self.name + ": Uncaught exception!" )
5215 return None
YPZhangcbc2a062016-07-11 10:55:44 -07005216
5217 def getIntentPerfSummary( self ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005218 '''
YPZhangcbc2a062016-07-11 10:55:44 -07005219 Send command to check intent-perf summary
5220 Returns: dictionary for intent-perf summary
5221 if something wrong, function will return None
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005222 '''
YPZhangcbc2a062016-07-11 10:55:44 -07005223 cmd = "intent-perf -s"
5224 respDic = {}
5225 resp = self.sendline( cmd )
You Wangb5a55f72017-03-03 12:51:05 -08005226 assert resp is not None, "Error in sendline"
5227 assert "Command not found:" not in resp, resp
YPZhangcbc2a062016-07-11 10:55:44 -07005228 try:
5229 # Generate the dictionary to return
5230 for l in resp.split( "\n" ):
5231 # Delete any white space in line
5232 temp = re.sub( r'\s+', '', l )
5233 temp = temp.split( ":" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005234 respDic[ temp[ 0 ] ] = temp[ 1 ]
YPZhangcbc2a062016-07-11 10:55:44 -07005235
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005236 except ( TypeError, ValueError ):
YPZhangcbc2a062016-07-11 10:55:44 -07005237 main.log.exception( self.name + ": Object not as expected" )
5238 return None
5239 except KeyError:
5240 main.log.exception( self.name + ": KeyError exception found" )
5241 return None
5242 except AssertionError:
5243 main.log.exception( self.name + ": AssertionError exception found" )
5244 return None
5245 except pexpect.EOF:
5246 main.log.error( self.name + ": EOF exception found" )
5247 main.log.error( self.name + ": " + self.handle.before )
5248 return None
5249 except Exception:
5250 main.log.exception( self.name + ": Uncaught exception!" )
5251 return None
5252 return respDic
5253
Chiyu Chengec63bde2016-11-17 18:11:36 -08005254 def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ):
chengchiyu08303a02016-09-08 17:40:26 -07005255 """
5256 Searches the latest ONOS log file for the given search term and
5257 return a list that contains all the lines that have the search term.
YPZhangcbc2a062016-07-11 10:55:44 -07005258
chengchiyu08303a02016-09-08 17:40:26 -07005259 Arguments:
Chiyu Chengec63bde2016-11-17 18:11:36 -08005260 searchTerm:
5261 The string to grep from the ONOS log.
5262 startLine:
5263 The term that decides which line is the start to search the searchTerm in
5264 the karaf log. For now, startTerm only works in 'first' mode.
5265 logNum:
5266 In some extreme cases, one karaf log is not big enough to contain all the
5267 information.Because of this, search mutiply logs is necessary to capture
5268 the right result. logNum is the number of karaf logs that we need to search
5269 the searchTerm.
chengchiyu08303a02016-09-08 17:40:26 -07005270 mode:
5271 all: return all the strings that contain the search term
5272 last: return the last string that contains the search term
5273 first: return the first string that contains the search term
Chiyu Chengec63bde2016-11-17 18:11:36 -08005274 num: return the number of times that the searchTerm appears in the log
5275 total: return how many lines in karaf log
chengchiyu08303a02016-09-08 17:40:26 -07005276 """
5277 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005278 assert isinstance( searchTerm, str )
Jon Halle0f0b342017-04-18 11:43:47 -07005279 # Build the log paths string
Chiyu Chengec63bde2016-11-17 18:11:36 -08005280 logPath = '/opt/onos/log/karaf.log.'
5281 logPaths = '/opt/onos/log/karaf.log'
5282 for i in range( 1, logNum ):
5283 logPaths = logPath + str( i ) + " " + logPaths
5284 cmd = "cat " + logPaths
You Wang6d301d42017-04-21 10:49:33 -07005285 if startLine:
Jon Halla478b852017-12-04 15:00:15 -08005286 # 100000000 is just a extreme large number to make sure this function can
5287 # grep all the lines after startLine
You Wang6d301d42017-04-21 10:49:33 -07005288 cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'"
Chiyu Chengec63bde2016-11-17 18:11:36 -08005289 if mode == 'all':
5290 cmd = cmd + " | grep \'" + searchTerm + "\'"
You Wang6d301d42017-04-21 10:49:33 -07005291 elif mode == 'last':
Chiyu Chengec63bde2016-11-17 18:11:36 -08005292 cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1"
You Wang6d301d42017-04-21 10:49:33 -07005293 elif mode == 'first':
5294 cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1"
5295 elif mode == 'num':
Chiyu Chengec63bde2016-11-17 18:11:36 -08005296 cmd = cmd + " | grep -c \'" + searchTerm + "\'"
You Wang118ba582017-01-02 17:14:43 -08005297 num = self.sendline( cmd )
Chiyu Chengb8c2c842016-10-05 12:40:49 -07005298 return num
You Wang6d301d42017-04-21 10:49:33 -07005299 elif mode == 'total':
Chiyu Chengec63bde2016-11-17 18:11:36 -08005300 totalLines = self.sendline( "cat /opt/onos/log/karaf.log | wc -l" )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005301 return int( totalLines )
You Wang6d301d42017-04-21 10:49:33 -07005302 else:
5303 main.log.error( self.name + " unsupported mode" )
5304 return main.ERROR
chengchiyu08303a02016-09-08 17:40:26 -07005305 before = self.sendline( cmd )
5306 before = before.splitlines()
5307 # make sure the returned list only contains the search term
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005308 returnLines = [ line for line in before if searchTerm in line ]
chengchiyu08303a02016-09-08 17:40:26 -07005309 return returnLines
5310 except AssertionError:
5311 main.log.error( self.name + " searchTerm is not string type" )
5312 return None
5313 except pexpect.EOF:
5314 main.log.error( self.name + ": EOF exception found" )
5315 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005316 main.cleanAndExit()
chengchiyu08303a02016-09-08 17:40:26 -07005317 except pexpect.TIMEOUT:
5318 main.log.error( self.name + ": TIMEOUT exception found" )
5319 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005320 main.cleanAndExit()
chengchiyu08303a02016-09-08 17:40:26 -07005321 except Exception:
5322 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005323 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005324
5325 def vplsShow( self, jsonFormat=True ):
5326 """
5327 Description: Returns result of onos:vpls show, which should list the
5328 configured VPLS networks and the assigned interfaces.
5329 Optional:
5330 * jsonFormat: enable json formatting of output
5331 Returns:
5332 The output of the command or None on error.
5333 """
5334 try:
5335 cmdStr = "vpls show"
5336 if jsonFormat:
5337 raise NotImplementedError
5338 cmdStr += " -j"
5339 handle = self.sendline( cmdStr )
5340 assert handle is not None, "Error in sendline"
5341 assert "Command not found:" not in handle, handle
5342 return handle
5343 except AssertionError:
5344 main.log.exception( "" )
5345 return None
5346 except TypeError:
5347 main.log.exception( self.name + ": Object not as expected" )
5348 return None
5349 except pexpect.EOF:
5350 main.log.error( self.name + ": EOF exception found" )
5351 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005352 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005353 except NotImplementedError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005354 main.log.exception( self.name + ": Json output not supported" )
Jon Hall2c8959e2016-12-16 12:17:34 -08005355 return None
5356 except Exception:
5357 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005358 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005359
5360 def parseVplsShow( self ):
5361 """
5362 Parse the cli output of 'vpls show' into json output. This is required
5363 as there is currently no json output available.
5364 """
5365 try:
5366 output = []
5367 raw = self.vplsShow( jsonFormat=False )
5368 namePat = "VPLS name: (?P<name>\w+)"
5369 interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]"
5370 encapPat = "Encapsulation: (?P<encap>\w+)"
5371 pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] )
5372 mIter = re.finditer( pattern, raw )
5373 for match in mIter:
5374 item = {}
5375 item[ 'name' ] = match.group( 'name' )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005376 ifaces = match.group( 'interfaces' ).split( ', ' )
Jon Hall2c8959e2016-12-16 12:17:34 -08005377 if ifaces == [ "" ]:
5378 ifaces = []
5379 item[ 'interfaces' ] = ifaces
5380 encap = match.group( 'encap' )
5381 if encap != 'NONE':
5382 item[ 'encapsulation' ] = encap.lower()
5383 output.append( item )
5384 return output
5385 except Exception:
5386 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005387 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005388
5389 def vplsList( self, jsonFormat=True ):
5390 """
5391 Description: Returns result of onos:vpls list, which should list the
5392 configured VPLS networks.
5393 Optional:
5394 * jsonFormat: enable json formatting of output
5395 """
5396 try:
5397 cmdStr = "vpls list"
5398 if jsonFormat:
5399 raise NotImplementedError
5400 cmdStr += " -j"
5401 handle = self.sendline( cmdStr )
5402 assert handle is not None, "Error in sendline"
5403 assert "Command not found:" not in handle, handle
5404 return handle
5405 except AssertionError:
5406 main.log.exception( "" )
5407 return None
5408 except TypeError:
5409 main.log.exception( self.name + ": Object not as expected" )
5410 return None
5411 except pexpect.EOF:
5412 main.log.error( self.name + ": EOF exception found" )
5413 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005414 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005415 except NotImplementedError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005416 main.log.exception( self.name + ": Json output not supported" )
Jon Hall2c8959e2016-12-16 12:17:34 -08005417 return None
5418 except Exception:
5419 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005420 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005421
5422 def vplsCreate( self, network ):
5423 """
5424 CLI command to create a new VPLS network.
5425 Required arguments:
5426 network - String name of the network to create.
5427 returns:
5428 main.TRUE on success and main.FALSE on failure
5429 """
5430 try:
5431 network = str( network )
5432 cmdStr = "vpls create "
5433 cmdStr += network
5434 output = self.sendline( cmdStr )
5435 assert output is not None, "Error in sendline"
5436 assert "Command not found:" not in output, output
5437 assert "Error executing command" not in output, output
5438 assert "VPLS already exists:" not in output, output
5439 return main.TRUE
5440 except AssertionError:
5441 main.log.exception( "" )
5442 return main.FALSE
5443 except TypeError:
5444 main.log.exception( self.name + ": Object not as expected" )
5445 return main.FALSE
5446 except pexpect.EOF:
5447 main.log.error( self.name + ": EOF exception found" )
5448 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005449 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005450 except Exception:
5451 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005452 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005453
5454 def vplsDelete( self, network ):
5455 """
5456 CLI command to delete a VPLS network.
5457 Required arguments:
5458 network - Name of the network to delete.
5459 returns:
5460 main.TRUE on success and main.FALSE on failure
5461 """
5462 try:
5463 network = str( network )
5464 cmdStr = "vpls delete "
5465 cmdStr += network
5466 output = self.sendline( cmdStr )
5467 assert output is not None, "Error in sendline"
5468 assert "Command not found:" not in output, output
5469 assert "Error executing command" not in output, output
5470 assert " not found" not in output, output
Jon Hallcf97cf12017-06-06 09:37:51 -07005471 assert "still updating" not in output, output
Jon Hall2c8959e2016-12-16 12:17:34 -08005472 return main.TRUE
5473 except AssertionError:
5474 main.log.exception( "" )
5475 return main.FALSE
5476 except TypeError:
5477 main.log.exception( self.name + ": Object not as expected" )
5478 return main.FALSE
5479 except pexpect.EOF:
5480 main.log.error( self.name + ": EOF exception found" )
5481 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005482 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005483 except Exception:
5484 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005485 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005486
5487 def vplsAddIface( self, network, iface ):
5488 """
5489 CLI command to add an interface to a VPLS network.
5490 Required arguments:
5491 network - Name of the network to add the interface to.
5492 iface - The ONOS name for an interface.
5493 returns:
5494 main.TRUE on success and main.FALSE on failure
5495 """
5496 try:
5497 network = str( network )
5498 iface = str( iface )
5499 cmdStr = "vpls add-if "
5500 cmdStr += network + " " + iface
5501 output = self.sendline( cmdStr )
5502 assert output is not None, "Error in sendline"
5503 assert "Command not found:" not in output, output
5504 assert "Error executing command" not in output, output
5505 assert "already associated to network" not in output, output
5506 assert "Interface cannot be added." not in output, output
Jon Hallcf97cf12017-06-06 09:37:51 -07005507 assert "still updating" not in output, output
Jon Hall2c8959e2016-12-16 12:17:34 -08005508 return main.TRUE
5509 except AssertionError:
5510 main.log.exception( "" )
5511 return main.FALSE
5512 except TypeError:
5513 main.log.exception( self.name + ": Object not as expected" )
5514 return main.FALSE
5515 except pexpect.EOF:
5516 main.log.error( self.name + ": EOF exception found" )
5517 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005518 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005519 except Exception:
5520 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005521 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005522
5523 def vplsRemIface( self, network, iface ):
5524 """
5525 CLI command to remove an interface from a VPLS network.
5526 Required arguments:
5527 network - Name of the network to remove the interface from.
5528 iface - Name of the interface to remove.
5529 returns:
5530 main.TRUE on success and main.FALSE on failure
5531 """
5532 try:
5533 iface = str( iface )
5534 cmdStr = "vpls rem-if "
5535 cmdStr += network + " " + iface
5536 output = self.sendline( cmdStr )
5537 assert output is not None, "Error in sendline"
5538 assert "Command not found:" not in output, output
5539 assert "Error executing command" not in output, output
5540 assert "is not configured" not in output, output
Jon Hallcf97cf12017-06-06 09:37:51 -07005541 assert "still updating" not in output, output
Jon Hall2c8959e2016-12-16 12:17:34 -08005542 return main.TRUE
5543 except AssertionError:
5544 main.log.exception( "" )
5545 return main.FALSE
5546 except TypeError:
5547 main.log.exception( self.name + ": Object not as expected" )
5548 return main.FALSE
5549 except pexpect.EOF:
5550 main.log.error( self.name + ": EOF exception found" )
5551 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005552 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005553 except Exception:
5554 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005555 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005556
5557 def vplsClean( self ):
5558 """
5559 Description: Clears the VPLS app configuration.
5560 Returns: main.TRUE on success and main.FALSE on failure
5561 """
5562 try:
5563 cmdStr = "vpls clean"
5564 handle = self.sendline( cmdStr )
5565 assert handle is not None, "Error in sendline"
5566 assert "Command not found:" not in handle, handle
Jon Hallcf97cf12017-06-06 09:37:51 -07005567 assert "still updating" not in handle, handle
Jon Hall2c8959e2016-12-16 12:17:34 -08005568 return handle
5569 except AssertionError:
5570 main.log.exception( "" )
5571 return main.FALSE
5572 except TypeError:
5573 main.log.exception( self.name + ": Object not as expected" )
5574 return main.FALSE
5575 except pexpect.EOF:
5576 main.log.error( self.name + ": EOF exception found" )
5577 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005578 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005579 except Exception:
5580 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005581 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005582
5583 def vplsSetEncap( self, network, encapType ):
5584 """
5585 CLI command to add an interface to a VPLS network.
5586 Required arguments:
5587 network - Name of the network to create.
5588 encapType - Type of encapsulation.
5589 returns:
5590 main.TRUE on success and main.FALSE on failure
5591 """
5592 try:
5593 network = str( network )
5594 encapType = str( encapType ).upper()
5595 assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type"
5596 cmdStr = "vpls set-encap "
5597 cmdStr += network + " " + encapType
5598 output = self.sendline( cmdStr )
5599 assert output is not None, "Error in sendline"
5600 assert "Command not found:" not in output, output
5601 assert "Error executing command" not in output, output
5602 assert "already associated to network" not in output, output
5603 assert "Encapsulation type " not in output, output
Jon Hallcf97cf12017-06-06 09:37:51 -07005604 assert "still updating" not in output, output
Jon Hall2c8959e2016-12-16 12:17:34 -08005605 return main.TRUE
5606 except AssertionError:
5607 main.log.exception( "" )
5608 return main.FALSE
5609 except TypeError:
5610 main.log.exception( self.name + ": Object not as expected" )
5611 return main.FALSE
5612 except pexpect.EOF:
5613 main.log.error( self.name + ": EOF exception found" )
5614 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005615 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005616 except Exception:
5617 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005618 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005619
5620 def interfaces( self, jsonFormat=True ):
5621 """
5622 Description: Returns result of interfaces command.
5623 Optional:
5624 * jsonFormat: enable json formatting of output
5625 Returns:
5626 The output of the command or None on error.
5627 """
5628 try:
5629 cmdStr = "interfaces"
5630 if jsonFormat:
Jon Halle0f0b342017-04-18 11:43:47 -07005631 raise NotImplementedError
Jon Hall2c8959e2016-12-16 12:17:34 -08005632 cmdStr += " -j"
5633 handle = self.sendline( cmdStr )
5634 assert handle is not None, "Error in sendline"
5635 assert "Command not found:" not in handle, handle
5636 return handle
5637 except AssertionError:
5638 main.log.exception( "" )
5639 return None
5640 except TypeError:
5641 main.log.exception( self.name + ": Object not as expected" )
5642 return None
5643 except pexpect.EOF:
5644 main.log.error( self.name + ": EOF exception found" )
5645 main.log.error( self.name + ": " + self.handle.before )
Devin Lim44075962017-08-11 10:56:37 -07005646 main.cleanAndExit()
Jon Hall2c8959e2016-12-16 12:17:34 -08005647 except NotImplementedError:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005648 main.log.exception( self.name + ": Json output not supported" )
Jon Hall2c8959e2016-12-16 12:17:34 -08005649 return None
5650 except Exception:
5651 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005652 main.cleanAndExit()
Chiyu Chengec63bde2016-11-17 18:11:36 -08005653
5654 def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ):
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005655 '''
Chiyu Chengec63bde2016-11-17 18:11:36 -08005656 Get the timestamp of searchTerm from karaf log.
5657
5658 Arguments:
5659 splitTerm_before and splitTerm_after:
5660
5661 The terms that split the string that contains the timeStamp of
5662 searchTerm. For example, if that string is "xxxxxxxcreationTime =
5663 1419510501xxxxxx", then the splitTerm_before is "CreationTime = "
5664 and the splitTerm_after is "x"
5665
5666 others:
Jon Halle0f0b342017-04-18 11:43:47 -07005667 Please look at the "logsearch" Function in onosclidriver.py
Jeremy Ronquillo4d5f1d02017-10-13 20:23:57 +00005668 '''
Chiyu Chengec63bde2016-11-17 18:11:36 -08005669 if logNum < 0:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005670 main.log.error( "Get wrong log number ")
Chiyu Chengec63bde2016-11-17 18:11:36 -08005671 return main.ERROR
5672 lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005673 if len( lines ) == 0:
Chiyu Chengec63bde2016-11-17 18:11:36 -08005674 main.log.warn( "Captured timestamp string is empty" )
5675 return main.ERROR
5676 lines = lines[ 0 ]
5677 try:
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005678 assert isinstance( lines, str )
Chiyu Chengec63bde2016-11-17 18:11:36 -08005679 # get the target value
5680 line = lines.split( splitTerm_before )
5681 key = line[ 1 ].split( splitTerm_after )
5682 return int( key[ 0 ] )
5683 except IndexError:
5684 main.log.warn( "Index Error!" )
5685 return main.ERROR
5686 except AssertionError:
5687 main.log.warn( "Search Term Not Found " )
5688 return main.ERROR
Jon Halle0f0b342017-04-18 11:43:47 -07005689
5690 def workQueueAdd( self, queueName, value ):
5691 """
5692 CLI command to add a string to the specified Work Queue.
5693 This function uses the distributed primitives test app, which
5694 gives some cli access to distributed primitives for testing
5695 purposes only.
5696
5697 Required arguments:
5698 queueName - The name of the queue to add to
5699 value - The value to add to the queue
5700 returns:
5701 main.TRUE on success, main.FALSE on failure and
5702 main.ERROR on error.
5703 """
5704 try:
5705 queueName = str( queueName )
5706 value = str( value )
5707 prefix = "work-queue-test"
5708 operation = "add"
5709 cmdStr = " ".join( [ prefix, queueName, operation, value ] )
5710 output = self.distPrimitivesSend( cmdStr )
5711 if "Invalid operation name" in output:
5712 main.log.warn( output )
5713 return main.ERROR
5714 elif "Done" in output:
5715 return main.TRUE
5716 except TypeError:
5717 main.log.exception( self.name + ": Object not as expected" )
5718 return main.ERROR
5719 except Exception:
5720 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005721 main.cleanAndExit()
Jon Halle0f0b342017-04-18 11:43:47 -07005722
5723 def workQueueAddMultiple( self, queueName, value1, value2 ):
5724 """
5725 CLI command to add two strings to the specified Work Queue.
5726 This function uses the distributed primitives test app, which
5727 gives some cli access to distributed primitives for testing
5728 purposes only.
5729
5730 Required arguments:
5731 queueName - The name of the queue to add to
5732 value1 - The first value to add to the queue
5733 value2 - The second value to add to the queue
5734 returns:
5735 main.TRUE on success, main.FALSE on failure and
5736 main.ERROR on error.
5737 """
5738 try:
5739 queueName = str( queueName )
5740 value1 = str( value1 )
5741 value2 = str( value2 )
5742 prefix = "work-queue-test"
5743 operation = "addMultiple"
5744 cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] )
5745 output = self.distPrimitivesSend( cmdStr )
5746 if "Invalid operation name" in output:
5747 main.log.warn( output )
5748 return main.ERROR
5749 elif "Done" in output:
5750 return main.TRUE
5751 except TypeError:
5752 main.log.exception( self.name + ": Object not as expected" )
5753 return main.ERROR
5754 except Exception:
5755 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005756 main.cleanAndExit()
Jon Halle0f0b342017-04-18 11:43:47 -07005757
5758 def workQueueTakeAndComplete( self, queueName, number=1 ):
5759 """
5760 CLI command to take a value from the specified Work Queue and compelte it.
5761 This function uses the distributed primitives test app, which
5762 gives some cli access to distributed primitives for testing
5763 purposes only.
5764
5765 Required arguments:
5766 queueName - The name of the queue to add to
5767 number - The number of items to take and complete
5768 returns:
5769 main.TRUE on success, main.FALSE on failure and
5770 main.ERROR on error.
5771 """
5772 try:
5773 queueName = str( queueName )
5774 number = str( int( number ) )
5775 prefix = "work-queue-test"
5776 operation = "takeAndComplete"
5777 cmdStr = " ".join( [ prefix, queueName, operation, number ] )
5778 output = self.distPrimitivesSend( cmdStr )
5779 if "Invalid operation name" in output:
5780 main.log.warn( output )
5781 return main.ERROR
5782 elif "Done" in output:
5783 return main.TRUE
5784 except TypeError:
5785 main.log.exception( self.name + ": Object not as expected" )
5786 return main.ERROR
5787 except Exception:
5788 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005789 main.cleanAndExit()
Jon Halle0f0b342017-04-18 11:43:47 -07005790
5791 def workQueueDestroy( self, queueName ):
5792 """
5793 CLI command to destroy the specified Work Queue.
5794 This function uses the distributed primitives test app, which
5795 gives some cli access to distributed primitives for testing
5796 purposes only.
5797
5798 Required arguments:
5799 queueName - The name of the queue to add to
5800 returns:
5801 main.TRUE on success, main.FALSE on failure and
5802 main.ERROR on error.
5803 """
5804 try:
5805 queueName = str( queueName )
5806 prefix = "work-queue-test"
5807 operation = "destroy"
5808 cmdStr = " ".join( [ prefix, queueName, operation ] )
5809 output = self.distPrimitivesSend( cmdStr )
5810 if "Invalid operation name" in output:
5811 main.log.warn( output )
5812 return main.ERROR
5813 return main.TRUE
5814 except TypeError:
5815 main.log.exception( self.name + ": Object not as expected" )
5816 return main.ERROR
5817 except Exception:
5818 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005819 main.cleanAndExit()
Jon Halle0f0b342017-04-18 11:43:47 -07005820
5821 def workQueueTotalPending( self, queueName ):
5822 """
5823 CLI command to get the Total Pending items of the specified Work Queue.
5824 This function uses the distributed primitives test app, which
5825 gives some cli access to distributed primitives for testing
5826 purposes only.
5827
5828 Required arguments:
5829 queueName - The name of the queue to add to
5830 returns:
5831 The number of Pending items in the specified work queue or
5832 None on error
5833 """
5834 try:
5835 queueName = str( queueName )
5836 prefix = "work-queue-test"
5837 operation = "totalPending"
5838 cmdStr = " ".join( [ prefix, queueName, operation ] )
5839 output = self.distPrimitivesSend( cmdStr )
5840 pattern = r'\d+'
5841 if "Invalid operation name" in output:
5842 main.log.warn( output )
5843 return None
5844 else:
5845 match = re.search( pattern, output )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005846 return match.group( 0 )
Jon Halle0f0b342017-04-18 11:43:47 -07005847 except ( AttributeError, TypeError ):
5848 main.log.exception( self.name + ": Object not as expected; " + str( output ) )
5849 return None
5850 except Exception:
5851 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005852 main.cleanAndExit()
Jon Halle0f0b342017-04-18 11:43:47 -07005853
5854 def workQueueTotalCompleted( self, queueName ):
5855 """
5856 CLI command to get the Total Completed items of the specified Work Queue.
5857 This function uses the distributed primitives test app, which
5858 gives some cli access to distributed primitives for testing
5859 purposes only.
5860
5861 Required arguments:
5862 queueName - The name of the queue to add to
5863 returns:
5864 The number of complete items in the specified work queue or
5865 None on error
5866 """
5867 try:
5868 queueName = str( queueName )
5869 prefix = "work-queue-test"
5870 operation = "totalCompleted"
5871 cmdStr = " ".join( [ prefix, queueName, operation ] )
5872 output = self.distPrimitivesSend( cmdStr )
5873 pattern = r'\d+'
5874 if "Invalid operation name" in output:
5875 main.log.warn( output )
5876 return None
5877 else:
5878 match = re.search( pattern, output )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005879 return match.group( 0 )
Jon Halle0f0b342017-04-18 11:43:47 -07005880 except ( AttributeError, TypeError ):
5881 main.log.exception( self.name + ": Object not as expected; " + str( output ) )
5882 return None
5883 except Exception:
5884 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005885 main.cleanAndExit()
Jon Halle0f0b342017-04-18 11:43:47 -07005886
5887 def workQueueTotalInProgress( self, queueName ):
5888 """
5889 CLI command to get the Total In Progress items of the specified Work Queue.
5890 This function uses the distributed primitives test app, which
5891 gives some cli access to distributed primitives for testing
5892 purposes only.
5893
5894 Required arguments:
5895 queueName - The name of the queue to add to
5896 returns:
5897 The number of In Progress items in the specified work queue or
5898 None on error
5899 """
5900 try:
5901 queueName = str( queueName )
5902 prefix = "work-queue-test"
5903 operation = "totalInProgress"
5904 cmdStr = " ".join( [ prefix, queueName, operation ] )
5905 output = self.distPrimitivesSend( cmdStr )
5906 pattern = r'\d+'
5907 if "Invalid operation name" in output:
5908 main.log.warn( output )
5909 return None
5910 else:
5911 match = re.search( pattern, output )
Jeremy Ronquillo82705492017-10-18 14:19:55 -07005912 return match.group( 0 )
Jon Halle0f0b342017-04-18 11:43:47 -07005913 except ( AttributeError, TypeError ):
5914 main.log.exception( self.name + ": Object not as expected; " + str( output ) )
5915 return None
5916 except Exception:
5917 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lim44075962017-08-11 10:56:37 -07005918 main.cleanAndExit()
Jeremy Ronquillo818bc7c2017-08-09 17:14:53 +00005919
5920 def events( self, args='-a' ):
5921 """
5922 Description: Returns events -a command output
5923 Optional:
5924 add other arguments
5925 """
5926 try:
5927 cmdStr = "events"
5928 if args:
5929 cmdStr += " " + args
5930 handle = self.sendline( cmdStr )
5931 assert handle is not None, "Error in sendline"
5932 assert "Command not found:" not in handle, handle
5933 return handle
5934 except AssertionError:
5935 main.log.exception( "" )
5936 return None
5937 except TypeError:
5938 main.log.exception( self.name + ": Object not as expected" )
5939 return None
5940 except pexpect.EOF:
5941 main.log.error( self.name + ": EOF exception found" )
5942 main.log.error( self.name + ": " + self.handle.before )
5943 main.cleanAndExit()
5944 except Exception:
5945 main.log.exception( self.name + ": Uncaught exception!" )
5946 main.cleanAndExit()
5947
5948 def getMaster( self, deviceID ):
5949 """
5950 Description: Obtains current master using "roles" command for a specific deviceID
5951 """
5952 try:
5953 return str( self.getRole( deviceID )[ 'master' ] )
5954 except AssertionError:
5955 main.log.exception( "" )
5956 return None
5957 except TypeError:
5958 main.log.exception( self.name + ": Object not as expected" )
5959 return None
5960 except pexpect.EOF:
5961 main.log.error( self.name + ": EOF exception found" )
5962 main.log.error( self.name + ": " + self.handle.before )
5963 main.cleanAndExit()
5964 except Exception:
5965 main.log.exception( self.name + ": Uncaught exception!" )
Devin Lime6fe3c42017-10-18 16:28:40 -07005966 main.cleanAndExit()
Jon Halla478b852017-12-04 15:00:15 -08005967
5968 def issu( self ):
5969 """
5970 Short summary of In-Service Software Upgrade status
5971
5972 Returns the output of the cli command or None on Error
5973 """
5974 try:
5975 cmdStr = "issu"
5976 handle = self.sendline( cmdStr )
5977 assert handle is not None, "Error in sendline"
5978 assert "Command not found:" not in handle, handle
5979 assert "Unsupported command:" not in handle, handle
5980 return handle
5981 except AssertionError:
5982 main.log.exception( "" )
5983 return None
5984 except TypeError:
5985 main.log.exception( self.name + ": Object not as expected" )
5986 return None
5987 except pexpect.EOF:
5988 main.log.error( self.name + ": EOF exception found" )
5989 main.log.error( self.name + ": " + self.handle.before )
5990 main.cleanAndExit()
5991 except Exception:
5992 main.log.exception( self.name + ": Uncaught exception!" )
5993 main.cleanAndExit()
5994
5995 def issuInit( self ):
5996 """
5997 Initiates an In-Service Software Upgrade
5998
5999 Returns main.TRUE on success, main.ERROR on error, else main.FALSE
6000 """
6001 try:
6002 cmdStr = "issu init"
6003 handle = self.sendline( cmdStr )
6004 assert handle is not None, "Error in sendline"
6005 assert "Command not found:" not in handle, handle
6006 assert "Unsupported command:" not in handle, handle
6007 if "Initialized" in handle:
6008 return main.TRUE
6009 else:
6010 return main.FALSE
6011 except AssertionError:
6012 main.log.exception( "" )
6013 return main.ERROR
6014 except TypeError:
6015 main.log.exception( self.name + ": Object not as expected" )
6016 return main.ERROR
6017 except pexpect.EOF:
6018 main.log.error( self.name + ": EOF exception found" )
6019 main.log.error( self.name + ": " + self.handle.before )
6020 main.cleanAndExit()
6021 except Exception:
6022 main.log.exception( self.name + ": Uncaught exception!" )
6023 main.cleanAndExit()
6024
6025 def issuUpgrade( self ):
6026 """
6027 Transitions stores to upgraded nodes
6028
6029 Returns main.TRUE on success, main.ERROR on error, else main.FALSE
6030 """
6031 try:
6032 cmdStr = "issu upgrade"
6033 handle = self.sendline( cmdStr )
6034 assert handle is not None, "Error in sendline"
6035 assert "Command not found:" not in handle, handle
6036 assert "Unsupported command:" not in handle, handle
6037 if "Upgraded" in handle:
6038 return main.TRUE
6039 else:
6040 return main.FALSE
6041 except AssertionError:
6042 main.log.exception( "" )
6043 return main.ERROR
6044 except TypeError:
6045 main.log.exception( self.name + ": Object not as expected" )
6046 return main.ERROR
6047 except pexpect.EOF:
6048 main.log.error( self.name + ": EOF exception found" )
6049 main.log.error( self.name + ": " + self.handle.before )
6050 main.cleanAndExit()
6051 except Exception:
6052 main.log.exception( self.name + ": Uncaught exception!" )
6053 main.cleanAndExit()
6054
6055 def issuCommit( self ):
6056 """
6057 Finalizes an In-Service Software Upgrade
6058
6059 Returns main.TRUE on success, main.ERROR on error, else main.FALSE
6060 """
6061 try:
6062 cmdStr = "issu commit"
6063 handle = self.sendline( cmdStr )
6064 assert handle is not None, "Error in sendline"
6065 assert "Command not found:" not in handle, handle
6066 assert "Unsupported command:" not in handle, handle
6067 # TODO: Check the version returned by this command
6068 if "Committed version" in handle:
6069 return main.TRUE
6070 else:
6071 return main.FALSE
6072 except AssertionError:
6073 main.log.exception( "" )
6074 return main.ERROR
6075 except TypeError:
6076 main.log.exception( self.name + ": Object not as expected" )
6077 return main.ERROR
6078 except pexpect.EOF:
6079 main.log.error( self.name + ": EOF exception found" )
6080 main.log.error( self.name + ": " + self.handle.before )
6081 main.cleanAndExit()
6082 except Exception:
6083 main.log.exception( self.name + ": Uncaught exception!" )
6084 main.cleanAndExit()
6085
6086 def issuRollback( self ):
6087 """
6088 Rolls back an In-Service Software Upgrade
6089
6090 Returns main.TRUE on success, main.ERROR on error, else main.FALSE
6091 """
6092 try:
6093 cmdStr = "issu rollback"
6094 handle = self.sendline( cmdStr )
6095 assert handle is not None, "Error in sendline"
6096 assert "Command not found:" not in handle, handle
6097 assert "Unsupported command:" not in handle, handle
6098 # TODO: Check the version returned by this command
6099 if "Rolled back to version" in handle:
6100 return main.TRUE
6101 else:
6102 return main.FALSE
6103 except AssertionError:
6104 main.log.exception( "" )
6105 return main.ERROR
6106 except TypeError:
6107 main.log.exception( self.name + ": Object not as expected" )
6108 return main.ERROR
6109 except pexpect.EOF:
6110 main.log.error( self.name + ": EOF exception found" )
6111 main.log.error( self.name + ": " + self.handle.before )
6112 main.cleanAndExit()
6113 except Exception:
6114 main.log.exception( self.name + ": Uncaught exception!" )
6115 main.cleanAndExit()
6116
6117 def issuReset( self ):
6118 """
6119 Resets the In-Service Software Upgrade status after a rollback
6120
6121 Returns main.TRUE on success, main.ERROR on error, else main.FALSE
6122 """
6123 try:
6124 cmdStr = "issu reset"
6125 handle = self.sendline( cmdStr )
6126 assert handle is not None, "Error in sendline"
6127 assert "Command not found:" not in handle, handle
6128 assert "Unsupported command:" not in handle, handle
6129 # TODO: Check the version returned by this command
6130 if "Reset version" in handle:
6131 return main.TRUE
6132 else:
6133 return main.FALSE
6134 except AssertionError:
6135 main.log.exception( "" )
6136 return main.ERROR
6137 except TypeError:
6138 main.log.exception( self.name + ": Object not as expected" )
6139 return main.ERROR
6140 except pexpect.EOF:
6141 main.log.error( self.name + ": EOF exception found" )
6142 main.log.error( self.name + ": " + self.handle.before )
6143 main.cleanAndExit()
6144 except Exception:
6145 main.log.exception( self.name + ": Uncaught exception!" )
6146 main.cleanAndExit()
6147
6148 def issuStatus( self ):
6149 """
6150 Status of an In-Service Software Upgrade
6151
6152 Returns the output of the cli command or None on Error
6153 """
6154 try:
6155 cmdStr = "issu status"
6156 handle = self.sendline( cmdStr )
6157 assert handle is not None, "Error in sendline"
6158 assert "Command not found:" not in handle, handle
6159 assert "Unsupported command:" not in handle, handle
6160 return handle
6161 except AssertionError:
6162 main.log.exception( "" )
6163 return None
6164 except TypeError:
6165 main.log.exception( self.name + ": Object not as expected" )
6166 return None
6167 except pexpect.EOF:
6168 main.log.error( self.name + ": EOF exception found" )
6169 main.log.error( self.name + ": " + self.handle.before )
6170 main.cleanAndExit()
6171 except Exception:
6172 main.log.exception( self.name + ": Uncaught exception!" )
6173 main.cleanAndExit()
6174
6175 def issuVersion( self ):
6176 """
6177 Get the version of an In-Service Software Upgrade
6178
6179 Returns the output of the cli command or None on Error
6180 """
6181 try:
6182 cmdStr = "issu version"
6183 handle = self.sendline( cmdStr )
6184 assert handle is not None, "Error in sendline"
6185 assert "Command not found:" not in handle, handle
6186 assert "Unsupported command:" not in handle, handle
6187 return handle
6188 except AssertionError:
6189 main.log.exception( "" )
6190 return None
6191 except TypeError:
6192 main.log.exception( self.name + ": Object not as expected" )
6193 return None
6194 except pexpect.EOF:
6195 main.log.error( self.name + ": EOF exception found" )
6196 main.log.error( self.name + ": " + self.handle.before )
6197 main.cleanAndExit()
6198 except Exception:
6199 main.log.exception( self.name + ": Uncaught exception!" )
6200 main.cleanAndExit()
You Wange24d6272018-03-27 21:18:50 -07006201
6202 def mcastJoin( self, sIP, groupIP, sPort, dPorts ):
6203 """
6204 Create a multicast route by calling 'mcast-join' command
6205 sIP: source IP of the multicast route
6206 groupIP: group IP of the multicast route
6207 sPort: source port (e.g. of:0000000000000001/3 ) of the multicast route
6208 dPorts: a list of destination ports of the multicast route
6209 Returns main.TRUE if mcast route is added; Otherwise main.FALSE
6210 """
6211 try:
6212 cmdStr = "mcast-join"
6213 cmdStr += " " + str( sIP )
6214 cmdStr += " " + str( groupIP )
6215 cmdStr += " " + str( sPort )
6216 assert isinstance( dPorts, list )
6217 for dPort in dPorts:
6218 cmdStr += " " + str( dPort )
6219 handle = self.sendline( cmdStr )
6220 assert handle is not None, "Error in sendline"
6221 assert "Command not found:" not in handle, handle
6222 assert "Unsupported command:" not in handle, handle
6223 assert "Error executing command" not in handle, handle
6224 if "Added the mcast route" in handle:
6225 return main.TRUE
6226 else:
6227 return main.FALSE
6228 except AssertionError:
6229 main.log.exception( "" )
6230 return None
6231 except TypeError:
6232 main.log.exception( self.name + ": Object not as expected" )
6233 return None
6234 except pexpect.EOF:
6235 main.log.error( self.name + ": EOF exception found" )
6236 main.log.error( self.name + ": " + self.handle.before )
6237 main.cleanAndExit()
6238 except Exception:
6239 main.log.exception( self.name + ": Uncaught exception!" )
6240 main.cleanAndExit()
6241
6242 def mcastDelete( self, sIP, groupIP, dPorts ):
6243 """
6244 Delete a multicast route by calling 'mcast-delete' command
6245 sIP: source IP of the multicast route
6246 groupIP: group IP of the multicast route
6247 dPorts: a list of destination ports of the multicast route
6248 Returns main.TRUE if mcast route is deleted; Otherwise main.FALSE
6249 """
6250 try:
6251 cmdStr = "mcast-delete"
6252 cmdStr += " " + str( sIP )
6253 cmdStr += " " + str( groupIP )
6254 assert isinstance( dPorts, list )
6255 for dPort in dPorts:
6256 cmdStr += " " + str( dPort )
6257 handle = self.sendline( cmdStr )
6258 assert handle is not None, "Error in sendline"
6259 assert "Command not found:" not in handle, handle
6260 assert "Unsupported command:" not in handle, handle
6261 assert "Error executing command" not in handle, handle
6262 if "Updated the mcast route" in handle:
6263 return main.TRUE
6264 else:
6265 return main.FALSE
6266 except AssertionError:
6267 main.log.exception( "" )
6268 return None
6269 except TypeError:
6270 main.log.exception( self.name + ": Object not as expected" )
6271 return None
6272 except pexpect.EOF:
6273 main.log.error( self.name + ": EOF exception found" )
6274 main.log.error( self.name + ": " + self.handle.before )
6275 main.cleanAndExit()
6276 except Exception:
6277 main.log.exception( self.name + ": Uncaught exception!" )
6278 main.cleanAndExit()
6279
6280 def mcastHostJoin( self, sAddr, gAddr, srcs, sinks ):
6281 """
6282 Create a multicast route by calling 'mcast-host-join' command
6283 sAddr: we can provide * for ASM or a specific address for SSM
6284 gAddr: specifies multicast group address
You Wang547893e2018-05-08 13:34:59 -07006285 srcs: a list of HostId of the sources e.g. ["00:AA:00:00:00:01/None"]
You Wange24d6272018-03-27 21:18:50 -07006286 sinks: a list of HostId of the sinks e.g. ["00:AA:00:00:01:05/40"]
6287 Returns main.TRUE if mcast route is added; Otherwise main.FALSE
6288 """
6289 try:
6290 cmdStr = "mcast-host-join"
6291 cmdStr += " -sAddr " + str( sAddr )
6292 cmdStr += " -gAddr " + str( gAddr )
6293 assert isinstance( srcs, list )
6294 for src in srcs:
6295 cmdStr += " -srcs " + str( src )
6296 assert isinstance( sinks, list )
6297 for sink in sinks:
6298 cmdStr += " -sinks " + str( sink )
6299 handle = self.sendline( cmdStr )
6300 assert handle is not None, "Error in sendline"
6301 assert "Command not found:" not in handle, handle
6302 assert "Unsupported command:" not in handle, handle
6303 assert "Error executing command" not in handle, handle
6304 if "Added the mcast route" in handle:
6305 return main.TRUE
6306 else:
6307 return main.FALSE
6308 except AssertionError:
6309 main.log.exception( "" )
6310 return None
6311 except TypeError:
6312 main.log.exception( self.name + ": Object not as expected" )
6313 return None
6314 except pexpect.EOF:
6315 main.log.error( self.name + ": EOF exception found" )
6316 main.log.error( self.name + ": " + self.handle.before )
6317 main.cleanAndExit()
6318 except Exception:
6319 main.log.exception( self.name + ": Uncaught exception!" )
6320 main.cleanAndExit()
6321
6322 def mcastHostDelete( self, sAddr, gAddr, host=None ):
6323 """
6324 Delete multicast sink(s) by calling 'mcast-host-delete' command
6325 sAddr: we can provide * for ASM or a specific address for SSM
6326 gAddr: specifies multicast group address
You Wangc02d8352018-04-17 16:42:10 -07006327 host: HostId of the sink e.g. "00:AA:00:00:01:05/40",
You Wange24d6272018-03-27 21:18:50 -07006328 will delete the route if not specified
6329 Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE
6330 """
6331 try:
6332 cmdStr = "mcast-host-delete"
6333 cmdStr += " -sAddr " + str( sAddr )
6334 cmdStr += " -gAddr " + str( gAddr )
6335 if host:
6336 cmdStr += " -h " + str( host )
6337 handle = self.sendline( cmdStr )
6338 assert handle is not None, "Error in sendline"
6339 assert "Command not found:" not in handle, handle
6340 assert "Unsupported command:" not in handle, handle
6341 assert "Error executing command" not in handle, handle
6342 if "Updated the mcast route" in handle:
6343 return main.TRUE
6344 elif "Deleted the mcast route" in handle:
6345 return main.TRUE
6346 else:
6347 return main.FALSE
6348 except AssertionError:
6349 main.log.exception( "" )
6350 return None
6351 except TypeError:
6352 main.log.exception( self.name + ": Object not as expected" )
6353 return None
6354 except pexpect.EOF:
6355 main.log.error( self.name + ": EOF exception found" )
6356 main.log.error( self.name + ": " + self.handle.before )
6357 main.cleanAndExit()
6358 except Exception:
6359 main.log.exception( self.name + ": Uncaught exception!" )
6360 main.cleanAndExit()
6361
You Wang547893e2018-05-08 13:34:59 -07006362 def mcastSinkDelete( self, sAddr, gAddr, sink=None ):
6363 """
6364 Delete multicast sink(s) by calling 'mcast-sink-delete' command
6365 sAddr: we can provide * for ASM or a specific address for SSM
6366 gAddr: specifies multicast group address
6367 host: HostId of the sink e.g. "00:AA:00:00:01:05/40",
6368 will delete the route if not specified
6369 Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE
6370 """
6371 try:
6372 cmdStr = "mcast-sink-delete"
6373 cmdStr += " -sAddr " + str( sAddr )
6374 cmdStr += " -gAddr " + str( gAddr )
6375 if sink:
6376 cmdStr += " -s " + str( sink )
6377 handle = self.sendline( cmdStr )
6378 assert handle is not None, "Error in sendline"
6379 assert "Command not found:" not in handle, handle
6380 assert "Unsupported command:" not in handle, handle
6381 assert "Error executing command" not in handle, handle
6382 if "Updated the mcast route" in handle:
6383 return main.TRUE
6384 elif "Deleted the mcast route" in handle:
6385 return main.TRUE
6386 else:
6387 return main.FALSE
6388 except AssertionError:
6389 main.log.exception( "" )
6390 return None
6391 except TypeError:
6392 main.log.exception( self.name + ": Object not as expected" )
6393 return None
6394 except pexpect.EOF:
6395 main.log.error( self.name + ": EOF exception found" )
6396 main.log.error( self.name + ": " + self.handle.before )
6397 main.cleanAndExit()
6398 except Exception:
6399 main.log.exception( self.name + ": Uncaught exception!" )
6400 main.cleanAndExit()
6401
You Wange24d6272018-03-27 21:18:50 -07006402 def mcastSourceDelete( self, sAddr, gAddr, srcs=None ):
6403 """
6404 Delete multicast src(s) by calling 'mcast-source-delete' command
6405 sAddr: we can provide * for ASM or a specific address for SSM
6406 gAddr: specifies multicast group address
You Wang547893e2018-05-08 13:34:59 -07006407 srcs: a list of host IDs of the sources e.g. ["00:AA:00:00:01:05/40"],
You Wange24d6272018-03-27 21:18:50 -07006408 will delete the route if not specified
6409 Returns main.TRUE if mcast sink is deleted; Otherwise main.FALSE
6410 """
6411 try:
6412 cmdStr = "mcast-source-delete"
6413 cmdStr += " -sAddr " + str( sAddr )
6414 cmdStr += " -gAddr " + str( gAddr )
6415 if srcs:
6416 assert isinstance( srcs, list )
6417 for src in srcs:
6418 cmdStr += " -src " + str( src )
6419 handle = self.sendline( cmdStr )
6420 assert handle is not None, "Error in sendline"
6421 assert "Command not found:" not in handle, handle
6422 assert "Unsupported command:" not in handle, handle
6423 assert "Error executing command" not in handle, handle
6424 if "Updated the mcast route" in handle:
6425 return main.TRUE
6426 elif "Deleted the mcast route" in handle:
6427 return main.TRUE
6428 else:
6429 return main.FALSE
6430 except AssertionError:
6431 main.log.exception( "" )
6432 return None
6433 except TypeError:
6434 main.log.exception( self.name + ": Object not as expected" )
6435 return None
6436 except pexpect.EOF:
6437 main.log.error( self.name + ": EOF exception found" )
6438 main.log.error( self.name + ": " + self.handle.before )
6439 main.cleanAndExit()
6440 except Exception:
6441 main.log.exception( self.name + ": Uncaught exception!" )
6442 main.cleanAndExit()
You Wang5da39c82018-04-26 22:55:08 -07006443
6444 def netcfg( self, jsonFormat=True, args="" ):
6445 """
6446 Run netcfg cli command with given args
6447 """
6448 try:
6449 cmdStr = "netcfg"
6450 if jsonFormat:
6451 cmdStr = cmdStr + " -j"
6452 if args:
6453 cmdStr = cmdStr + " " + str( args )
6454 handle = self.sendline( cmdStr )
6455 assert handle is not None, "Error in sendline"
6456 assert "Command not found:" not in handle, handle
6457 assert "Unsupported command:" not in handle, handle
6458 assert "Error executing command" not in handle, handle
6459 return handle
6460 except AssertionError:
6461 main.log.exception( "" )
6462 return None
6463 except TypeError:
6464 main.log.exception( self.name + ": Object not as expected" )
6465 return None
6466 except pexpect.EOF:
6467 main.log.error( self.name + ": EOF exception found" )
6468 main.log.error( self.name + ": " + self.handle.before )
6469 main.cleanAndExit()
6470 except Exception:
6471 main.log.exception( self.name + ": Uncaught exception!" )
6472 main.cleanAndExit()
6473
6474 def composeT3Command( self, sAddr, dAddr, ipv6=False, verbose=True ):
6475 """
6476 Compose and return t3-troubleshoot cli command for given source and destination addresses
6477 Options:
6478 sAddr: IP address of the source host
6479 dAddr: IP address of the destination host
6480 """
6481 try:
6482 # Collect information of both hosts from onos
6483 hosts = self.hosts()
6484 hosts = json.loads( hosts )
6485 sHost = None
6486 dHost = None
6487 for host in hosts:
6488 if sAddr in host[ "ipAddresses" ]:
6489 sHost = host
6490 elif dAddr in host[ "ipAddresses" ]:
6491 dHost = host
6492 if sHost and dHost:
6493 break
6494 assert sHost, "Not able to find host with IP {}".format( sAddr )
You Wang5da39c82018-04-26 22:55:08 -07006495 cmdStr = "t3-troubleshoot"
6496 if verbose:
6497 cmdStr += " -vv"
6498 cmdStr += " -s " + str( sAddr )
6499 # TODO: collect t3 for all locations of source host?
6500 cmdStr += " -sp " + str( sHost[ "locations" ][ 0 ][ "elementId" ] ) + "/" + str( sHost[ "locations" ][ 0 ][ "port" ] )
6501 cmdStr += " -sm " + str( sHost[ "mac" ] )
You Wangc9faf4c2018-05-02 12:05:50 -07006502 if sHost[ "vlan" ] != "None":
6503 cmdStr += " -vid " + sHost[ "vlan" ]
You Wang5da39c82018-04-26 22:55:08 -07006504 cmdStr += " -d " + str( dAddr )
6505 netcfg = self.netcfg( args="devices {}".format( sHost[ "locations" ][ 0 ][ "elementId" ] ) )
6506 netcfg = json.loads( netcfg )
6507 assert netcfg, "Failed to get netcfg"
6508 cmdStr += " -dm " + str( netcfg[ "segmentrouting" ][ "routerMac" ] )
6509 if ipv6:
6510 cmdStr += " -et ipv6"
6511 return cmdStr
6512 except AssertionError:
6513 main.log.exception( "" )
6514 return None
6515 except ( KeyError, TypeError ):
6516 main.log.exception( self.name + ": Object not as expected" )
6517 return None
6518 except Exception:
6519 main.log.exception( self.name + ": Uncaught exception!" )
6520 main.cleanAndExit()
6521
6522 def t3( self, sAddr, dAddr, ipv6=False ):
6523 """
6524 Run t3-troubleshoot cli command for given source and destination addresses
6525 Options:
6526 sAddr: IP address of the source host
6527 dAddr: IP address of the destination host
6528 """
6529 try:
6530 cmdStr = self.composeT3Command( sAddr, dAddr, ipv6 )
6531 handle = self.sendline( cmdStr )
6532 assert handle is not None, "Error in sendline"
6533 assert "Command not found:" not in handle, handle
6534 assert "Unsupported command:" not in handle, handle
6535 assert "Error executing command" not in handle, handle
6536 assert "Tracing packet" in handle
6537 return handle
6538 except AssertionError:
6539 main.log.exception( "" )
6540 return None
6541 except pexpect.EOF:
6542 main.log.error( self.name + ": EOF exception found" )
6543 main.log.error( self.name + ": " + self.handle.before )
6544 main.cleanAndExit()
6545 except Exception:
6546 main.log.exception( self.name + ": Uncaught exception!" )
6547 main.cleanAndExit()