andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 4 | This driver enters the onos> prompt to issue commands. |
| 5 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 6 | Please follow the coding style demonstrated by existing |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 7 | functions and document properly. |
| 8 | |
| 9 | If you are a contributor to the driver, please |
| 10 | list your email here for future contact: |
| 11 | |
| 12 | jhall@onlab.us |
| 13 | andrew@onlab.us |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 14 | shreya@onlab.us |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 15 | |
| 16 | OCT 13 2014 |
| 17 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 18 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 19 | import sys |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 20 | import pexpect |
| 21 | import re |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 22 | import json |
| 23 | import types |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 24 | import time |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 25 | import os |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 26 | sys.path.append( "../" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 27 | from drivers.common.clidriver import CLI |
| 28 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 29 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 30 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 31 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 32 | def __init__( self ): |
| 33 | """ |
| 34 | Initialize client |
| 35 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 36 | self.name = None |
| 37 | self.home = None |
| 38 | self.handle = None |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 39 | super( CLI, self ).__init__() |
| 40 | |
| 41 | def connect( self, **connectargs ): |
| 42 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 43 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 44 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 45 | try: |
| 46 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 47 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 658ec01 | 2015-03-11 15:13:09 -0700 | [diff] [blame] | 48 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 49 | for key in self.options: |
| 50 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 51 | self.home = self.options[ 'home' ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 52 | break |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 53 | if self.home is None or self.home == "": |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 54 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 55 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 56 | for key in self.options: |
| 57 | if key == 'onosIp': |
| 58 | self.onosIp = self.options[ 'onosIp' ] |
| 59 | break |
| 60 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 61 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 62 | |
| 63 | try: |
| 64 | if os.getenv( str( self.ip_address ) ) != None: |
| 65 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 66 | else: |
| 67 | main.log.info( self.name + |
| 68 | ": Trying to connect to " + |
| 69 | self.ip_address ) |
| 70 | |
| 71 | except KeyError: |
| 72 | main.log.info( "Invalid host name," + |
| 73 | " connecting to local host instead" ) |
| 74 | self.ip_address = 'localhost' |
| 75 | except Exception as inst: |
| 76 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 77 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 78 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 79 | user_name=self.user_name, |
| 80 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 81 | port=self.port, |
| 82 | pwd=self.pwd, |
| 83 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 84 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 85 | self.handle.sendline( "cd " + self.home ) |
| 86 | self.handle.expect( "\$" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 87 | if self.handle: |
| 88 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 89 | else: |
| 90 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 91 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 92 | except TypeError: |
| 93 | main.log.exception( self.name + ": Object not as expected" ) |
| 94 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 95 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 96 | main.log.error( self.name + ": EOF exception found" ) |
| 97 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 98 | main.cleanup() |
| 99 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 100 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 101 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 102 | main.cleanup() |
| 103 | main.exit() |
| 104 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 105 | def disconnect( self ): |
| 106 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 107 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 108 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 109 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 110 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 111 | if self.handle: |
| 112 | i = self.logout() |
| 113 | if i == main.TRUE: |
| 114 | self.handle.sendline( "" ) |
| 115 | self.handle.expect( "\$" ) |
| 116 | self.handle.sendline( "exit" ) |
| 117 | self.handle.expect( "closed" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 118 | except TypeError: |
| 119 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 120 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 121 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 122 | main.log.error( self.name + ": EOF exception found" ) |
| 123 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 124 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 125 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 126 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 127 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 128 | main.log.exception( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 129 | response = main.FALSE |
| 130 | return response |
| 131 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 132 | def logout( self ): |
| 133 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 134 | Sends 'logout' command to ONOS cli |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 135 | Returns main.TRUE if exited CLI and |
| 136 | main.FALSE on timeout (not guranteed you are disconnected) |
| 137 | None on TypeError |
| 138 | Exits test on unknown error or pexpect exits unexpectedly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 139 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 140 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 141 | if self.handle: |
| 142 | self.handle.sendline( "" ) |
| 143 | i = self.handle.expect( [ "onos>", "\$", pexpect.TIMEOUT ], |
| 144 | timeout=10 ) |
| 145 | if i == 0: # In ONOS CLI |
| 146 | self.handle.sendline( "logout" ) |
| 147 | self.handle.expect( "\$" ) |
| 148 | return main.TRUE |
| 149 | elif i == 1: # not in CLI |
| 150 | return main.TRUE |
| 151 | elif i == 3: # Timeout |
| 152 | return main.FALSE |
| 153 | else: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 154 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 155 | except TypeError: |
| 156 | main.log.exception( self.name + ": Object not as expected" ) |
| 157 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 158 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 159 | main.log.error( self.name + ": eof exception found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 160 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 161 | main.cleanup() |
| 162 | main.exit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 163 | except ValueError: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 164 | main.log.error( self.name + |
| 165 | "ValueError exception in logout method" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 166 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 167 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 168 | main.cleanup() |
| 169 | main.exit() |
| 170 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 171 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 172 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 173 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 174 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 175 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 176 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 177 | try: |
| 178 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 179 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 180 | main.cleanup() |
| 181 | main.exit() |
| 182 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 183 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 184 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 185 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 186 | # and that this driver will have to change accordingly |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 187 | self.handle.expect(str(cellname)) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 188 | handleBefore = self.handle.before |
| 189 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 190 | # Get the rest of the handle |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 191 | self.handle.sendline("") |
| 192 | self.handle.expect("\$") |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 193 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 194 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 195 | main.log.info( "Cell call returned: " + handleBefore + |
| 196 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 197 | |
| 198 | return main.TRUE |
| 199 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 200 | except TypeError: |
| 201 | main.log.exception( self.name + ": Object not as expected" ) |
| 202 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 203 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 204 | main.log.error( self.name + ": eof exception found" ) |
| 205 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 206 | main.cleanup() |
| 207 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 208 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 209 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 210 | main.cleanup() |
| 211 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 212 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 213 | def startOnosCli( self, ONOSIp, karafTimeout="", |
| 214 | commandlineTimeout=10, onosStartTimeout=60 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 215 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 216 | karafTimeout is an optional argument. karafTimeout value passed |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 217 | by user would be used to set the current karaf shell idle timeout. |
| 218 | Note that when ever this property is modified the shell will exit and |
Hari Krishna | d7b9c20 | 2015-01-05 10:38:14 -0800 | [diff] [blame] | 219 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 220 | Below is an example to start a session with 60 seconds idle timeout |
| 221 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 222 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 223 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 224 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 225 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 226 | Note: karafTimeout is left as str so that this could be read |
| 227 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 228 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 229 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 230 | self.handle.sendline( "" ) |
| 231 | x = self.handle.expect( [ |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 232 | "\$", "onos>" ], commandlineTimeout) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 233 | |
| 234 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 235 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 236 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 237 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 238 | # Wait for onos start ( -w ) and enter onos cli |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 239 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 240 | i = self.handle.expect( [ |
| 241 | "onos>", |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 242 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 243 | |
| 244 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 245 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 246 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 247 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 248 | "config:property-set -p org.apache.karaf.shell\ |
| 249 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 250 | karafTimeout ) |
| 251 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 252 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 253 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 254 | return main.TRUE |
| 255 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 256 | # If failed, send ctrl+c to process and try again |
| 257 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 258 | self.handle.send( "\x03" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 259 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 260 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 261 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 262 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 263 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 264 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 265 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 266 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 267 | "config:property-set -p org.apache.karaf.shell\ |
| 268 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 269 | karafTimeout ) |
| 270 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 271 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 272 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 273 | return main.TRUE |
| 274 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 275 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 276 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 277 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 278 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 279 | except TypeError: |
| 280 | main.log.exception( self.name + ": Object not as expected" ) |
| 281 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 282 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 283 | main.log.error( self.name + ": EOF exception found" ) |
| 284 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 285 | main.cleanup() |
| 286 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 287 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 288 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 289 | main.cleanup() |
| 290 | main.exit() |
| 291 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 292 | def log( self, cmdStr, level="" ): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 293 | """ |
| 294 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 295 | returns main.TRUE on success |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 296 | returns main.FALSE if Error occurred |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 297 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 298 | Level defaults to INFO |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 299 | """ |
| 300 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 301 | lvlStr = "" |
| 302 | if level: |
| 303 | lvlStr = "--level=" + level |
| 304 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 305 | self.handle.sendline( "" ) |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 306 | i = self.handle.expect( [ "onos>","\$", pexpect.TIMEOUT ] ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 307 | if i == 1: |
Jon Hall | c9eabec | 2015-06-10 14:33:14 -0700 | [diff] [blame] | 308 | main.log.error( self.name + ": onos cli session closed." ) |
| 309 | main.cleanup() |
| 310 | main.exit() |
| 311 | if i == 2: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 312 | self.handle.sendline( "" ) |
| 313 | self.handle.expect( "onos>" ) |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 314 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 315 | self.handle.expect( "log:log" ) |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 316 | self.handle.expect( "onos>" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 317 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 318 | response = self.handle.before |
| 319 | if re.search( "Error", response ): |
| 320 | return main.FALSE |
| 321 | return main.TRUE |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 322 | except pexpect.TIMEOUT: |
| 323 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
| 324 | main.cleanup() |
| 325 | main.exit() |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 326 | except pexpect.EOF: |
| 327 | main.log.error( self.name + ": EOF exception found" ) |
| 328 | main.log.error( self.name + ": " + self.handle.before ) |
| 329 | main.cleanup() |
| 330 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 331 | except Exception: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 332 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 333 | main.cleanup() |
| 334 | main.exit() |
| 335 | |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 336 | def sendline( self, cmdStr, debug=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 337 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 338 | Send a completely user specified string to |
| 339 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 340 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 341 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 342 | Warning: There are no sanity checking to commands |
| 343 | sent using this method. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 344 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 345 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 346 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
| 347 | self.log( logStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 348 | self.handle.sendline( cmdStr ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 349 | i = self.handle.expect( ["onos>", "\$", pexpect.TIMEOUT] ) |
| 350 | response = self.handle.before |
| 351 | if i == 2: |
| 352 | self.handle.sendline() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 353 | self.handle.expect( ["\$", pexpect.TIMEOUT] ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 354 | response += self.handle.before |
| 355 | print response |
| 356 | try: |
| 357 | print self.handle.after |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 358 | except TypeError: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 359 | pass |
| 360 | # TODO: do something with i |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 361 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 362 | + self.name + "." ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 363 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 364 | main.log.debug( self.name + ": Raw output" ) |
| 365 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 366 | |
| 367 | # Remove ANSI color control strings from output |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 368 | ansiEscape = re.compile( r'\x1b[^m]*m' ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 369 | response = ansiEscape.sub( '', response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 370 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 371 | main.log.debug( self.name + ": ansiEscape output" ) |
| 372 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 373 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 374 | # Remove extra return chars that get added |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 375 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 376 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 377 | main.log.debug( self.name + ": Removed extra returns " + |
| 378 | "from output" ) |
| 379 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 380 | |
| 381 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 382 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 383 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 384 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 385 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 386 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 387 | # parse for just the output, remove the cmd from response |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 388 | output = response.split( cmdStr.strip(), 1 ) |
| 389 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 390 | main.log.debug( self.name + ": split output" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 391 | for r in output: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 392 | main.log.debug( self.name + ": " + repr( r ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 393 | return output[1].strip() |
| 394 | except IndexError: |
| 395 | main.log.exception( self.name + ": Object not as expected" ) |
| 396 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 397 | except TypeError: |
| 398 | main.log.exception( self.name + ": Object not as expected" ) |
| 399 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 400 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 401 | main.log.error( self.name + ": EOF exception found" ) |
| 402 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 403 | main.cleanup() |
| 404 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 405 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 406 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 407 | main.cleanup() |
| 408 | main.exit() |
| 409 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 410 | # IMPORTANT NOTE: |
| 411 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 412 | # the cli command changing 'a:b' with 'aB'. |
| 413 | # Ex ) onos:topology > onosTopology |
| 414 | # onos:links > onosLinks |
| 415 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 416 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 417 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 418 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 419 | Adds a new cluster node by ID and address information. |
| 420 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 421 | * nodeId |
| 422 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 423 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 424 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 425 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 426 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 427 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 428 | str( ONOSIp ) + " " + str( tcpPort ) |
| 429 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 430 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 431 | main.log.error( "Error in adding node" ) |
| 432 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 433 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 434 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 435 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 436 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 437 | except TypeError: |
| 438 | main.log.exception( self.name + ": Object not as expected" ) |
| 439 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 440 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 441 | main.log.error( self.name + ": EOF exception found" ) |
| 442 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 443 | main.cleanup() |
| 444 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 445 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 446 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 447 | main.cleanup() |
| 448 | main.exit() |
| 449 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 450 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 451 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 452 | Removes a cluster by ID |
| 453 | Issues command: 'remove-node [<node-id>]' |
| 454 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 455 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 456 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 457 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 458 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 459 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 460 | handle = self.sendline( cmdStr ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 461 | if re.search( "Error", handle ): |
| 462 | main.log.error( "Error in removing node" ) |
| 463 | main.log.error( handle ) |
| 464 | return main.FALSE |
| 465 | else: |
| 466 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 467 | except TypeError: |
| 468 | main.log.exception( self.name + ": Object not as expected" ) |
| 469 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 470 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 471 | main.log.error( self.name + ": EOF exception found" ) |
| 472 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 473 | main.cleanup() |
| 474 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 475 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 476 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 477 | main.cleanup() |
| 478 | main.exit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 479 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 480 | def nodes( self, jsonFormat=True): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 481 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 482 | List the nodes currently visible |
| 483 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 484 | Optional argument: |
| 485 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 486 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 487 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 488 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 489 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 490 | cmdStr += " -j" |
| 491 | output = self.sendline( cmdStr ) |
| 492 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 493 | except TypeError: |
| 494 | main.log.exception( self.name + ": Object not as expected" ) |
| 495 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 496 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 497 | main.log.error( self.name + ": EOF exception found" ) |
| 498 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 499 | main.cleanup() |
| 500 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 501 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 502 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 503 | main.cleanup() |
| 504 | main.exit() |
| 505 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 506 | def topology( self ): |
| 507 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 508 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 509 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 510 | Return: |
| 511 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 512 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 513 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 514 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 515 | handle = self.sendline( cmdStr ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 516 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 517 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 518 | except TypeError: |
| 519 | main.log.exception( self.name + ": Object not as expected" ) |
| 520 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 521 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 522 | main.log.error( self.name + ": EOF exception found" ) |
| 523 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 524 | main.cleanup() |
| 525 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 526 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 527 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 528 | main.cleanup() |
| 529 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 530 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 531 | def featureInstall( self, featureStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 532 | """ |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 533 | Installs a specified feature by issuing command: |
| 534 | 'feature:install <feature_str>' |
| 535 | NOTE: This is now deprecated, you should use the activateApp method |
| 536 | instead |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 537 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 538 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 539 | cmdStr = "feature:install " + str( featureStr ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 540 | handle = self.sendline( cmdStr ) |
| 541 | if re.search( "Error", handle ): |
| 542 | main.log.error( "Error in installing feature" ) |
| 543 | main.log.error( handle ) |
| 544 | return main.FALSE |
| 545 | else: |
| 546 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 547 | except TypeError: |
| 548 | main.log.exception( self.name + ": Object not as expected" ) |
| 549 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 550 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 551 | main.log.error( self.name + ": EOF exception found" ) |
| 552 | main.log.error( self.name + ": " + self.handle.before ) |
| 553 | main.log.report( "Failed to install feature" ) |
| 554 | main.log.report( "Exiting test" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 555 | main.cleanup() |
| 556 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 557 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 558 | main.log.exception( self.name + ": Uncaught exception!" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 559 | main.log.report( "Failed to install feature" ) |
| 560 | main.log.report( "Exiting test" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 561 | main.cleanup() |
| 562 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 563 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 564 | def featureUninstall( self, featureStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 565 | """ |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 566 | Uninstalls a specified feature by issuing command: |
| 567 | 'feature:uninstall <feature_str>' |
| 568 | NOTE: This is now deprecated, you should use the deactivateApp method |
| 569 | instead |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 570 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 571 | try: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 572 | cmdStr = 'feature:list -i | grep "' + featureStr + '"' |
| 573 | handle = self.sendline( cmdStr ) |
| 574 | if handle != '': |
| 575 | cmdStr = "feature:uninstall " + str( featureStr ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 576 | output = self.sendline( cmdStr ) |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 577 | # TODO: Check for possible error responses from karaf |
| 578 | else: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 579 | main.log.info( "Feature needs to be installed before " + |
| 580 | "uninstalling it" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 581 | return main.TRUE |
| 582 | if re.search( "Error", output ): |
| 583 | main.log.error( "Error in uninstalling feature" ) |
| 584 | main.log.error( output ) |
| 585 | return main.FALSE |
| 586 | else: |
| 587 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 588 | except TypeError: |
| 589 | main.log.exception( self.name + ": Object not as expected" ) |
| 590 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 591 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 592 | main.log.error( self.name + ": EOF exception found" ) |
| 593 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 594 | main.cleanup() |
| 595 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 596 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 597 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 598 | main.cleanup() |
| 599 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 600 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 601 | def deviceRemove( self, deviceId ): |
| 602 | """ |
| 603 | Removes particular device from storage |
| 604 | |
| 605 | TODO: refactor this function |
| 606 | """ |
| 607 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 608 | cmdStr = "device-remove " + str( deviceId ) |
| 609 | handle = self.sendline( cmdStr ) |
| 610 | if re.search( "Error", handle ): |
| 611 | main.log.error( "Error in removing device" ) |
| 612 | main.log.error( handle ) |
| 613 | return main.FALSE |
| 614 | else: |
| 615 | return main.TRUE |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 616 | except TypeError: |
| 617 | main.log.exception( self.name + ": Object not as expected" ) |
| 618 | return None |
| 619 | except pexpect.EOF: |
| 620 | main.log.error( self.name + ": EOF exception found" ) |
| 621 | main.log.error( self.name + ": " + self.handle.before ) |
| 622 | main.cleanup() |
| 623 | main.exit() |
| 624 | except Exception: |
| 625 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 626 | main.cleanup() |
| 627 | main.exit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 628 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 629 | def devices( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 630 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 631 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 632 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 633 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 634 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 635 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 636 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 637 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 638 | cmdStr += " -j" |
| 639 | handle = self.sendline( cmdStr ) |
| 640 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 641 | except TypeError: |
| 642 | main.log.exception( self.name + ": Object not as expected" ) |
| 643 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 644 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 645 | main.log.error( self.name + ": EOF exception found" ) |
| 646 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 647 | main.cleanup() |
| 648 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 649 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 650 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 651 | main.cleanup() |
| 652 | main.exit() |
| 653 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 654 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 655 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 656 | This balances the devices across all controllers |
| 657 | by issuing command: 'onos> onos:balance-masters' |
| 658 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 659 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 660 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 661 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 662 | handle = self.sendline( cmdStr ) |
| 663 | if re.search( "Error", handle ): |
| 664 | main.log.error( "Error in balancing masters" ) |
| 665 | main.log.error( handle ) |
| 666 | return main.FALSE |
| 667 | else: |
| 668 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 669 | except TypeError: |
| 670 | main.log.exception( self.name + ": Object not as expected" ) |
| 671 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 672 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 673 | main.log.error( self.name + ": EOF exception found" ) |
| 674 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 675 | main.cleanup() |
| 676 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 677 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 678 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 679 | main.cleanup() |
| 680 | main.exit() |
| 681 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 682 | def links( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 683 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 684 | Lists all core links |
| 685 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 686 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 687 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 688 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 689 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 690 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 691 | cmdStr += " -j" |
| 692 | handle = self.sendline( cmdStr ) |
| 693 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 694 | except TypeError: |
| 695 | main.log.exception( self.name + ": Object not as expected" ) |
| 696 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 697 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 698 | main.log.error( self.name + ": EOF exception found" ) |
| 699 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 700 | main.cleanup() |
| 701 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 702 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 703 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 704 | main.cleanup() |
| 705 | main.exit() |
| 706 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 707 | def ports( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 708 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 709 | Lists all ports |
| 710 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 711 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 712 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 713 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 714 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 715 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 716 | cmdStr += " -j" |
| 717 | handle = self.sendline( cmdStr ) |
| 718 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 719 | except TypeError: |
| 720 | main.log.exception( self.name + ": Object not as expected" ) |
| 721 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 722 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 723 | main.log.error( self.name + ": EOF exception found" ) |
| 724 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 725 | main.cleanup() |
| 726 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 727 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 728 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 729 | main.cleanup() |
| 730 | main.exit() |
| 731 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 732 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 733 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 734 | Lists all devices and the controllers with roles assigned to them |
| 735 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 736 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 737 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 738 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 739 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 740 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 741 | cmdStr += " -j" |
| 742 | handle = self.sendline( cmdStr ) |
| 743 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 744 | except TypeError: |
| 745 | main.log.exception( self.name + ": Object not as expected" ) |
| 746 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 747 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 748 | main.log.error( self.name + ": EOF exception found" ) |
| 749 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 750 | main.cleanup() |
| 751 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 752 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 753 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 754 | main.cleanup() |
| 755 | main.exit() |
| 756 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 757 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 758 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 759 | Given the a string containing the json representation of the "roles" |
| 760 | cli command and a partial or whole device id, returns a json object |
| 761 | containing the roles output for the first device whose id contains |
| 762 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 763 | |
| 764 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 765 | A dict of the role assignments for the given device or |
| 766 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 767 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 768 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 769 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 770 | return None |
| 771 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 772 | rawRoles = self.roles() |
| 773 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 774 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 775 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 776 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 777 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 778 | return device |
| 779 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 780 | except TypeError: |
| 781 | main.log.exception( self.name + ": Object not as expected" ) |
| 782 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 783 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 784 | main.log.error( self.name + ": EOF exception found" ) |
| 785 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 786 | main.cleanup() |
| 787 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 788 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 789 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 790 | main.cleanup() |
| 791 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 792 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 793 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 794 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 795 | Iterates through each device and checks if there is a master assigned |
| 796 | Returns: main.TRUE if each device has a master |
| 797 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 798 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 799 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 800 | rawRoles = self.roles() |
| 801 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 802 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 803 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 804 | # print device |
| 805 | if device[ 'master' ] == "none": |
| 806 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 807 | return main.FALSE |
| 808 | return main.TRUE |
| 809 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 810 | except TypeError: |
| 811 | main.log.exception( self.name + ": Object not as expected" ) |
| 812 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 813 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 814 | main.log.error( self.name + ": EOF exception found" ) |
| 815 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 816 | main.cleanup() |
| 817 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 818 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 819 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 820 | main.cleanup() |
| 821 | main.exit() |
| 822 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 823 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 824 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 825 | Returns string of paths, and the cost. |
| 826 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 827 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 828 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 829 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 830 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 831 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 832 | main.log.error( "Error in getting paths" ) |
| 833 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 834 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 835 | path = handle.split( ";" )[ 0 ] |
| 836 | cost = handle.split( ";" )[ 1 ] |
| 837 | return ( path, cost ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 838 | except TypeError: |
| 839 | main.log.exception( self.name + ": Object not as expected" ) |
| 840 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 841 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 842 | main.log.error( self.name + ": EOF exception found" ) |
| 843 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 844 | main.cleanup() |
| 845 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 846 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 847 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 848 | main.cleanup() |
| 849 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 850 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 851 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 852 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 853 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 854 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 855 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 856 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 857 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 858 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 859 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 860 | cmdStr += " -j" |
| 861 | handle = self.sendline( cmdStr ) |
| 862 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 863 | except TypeError: |
| 864 | main.log.exception( self.name + ": Object not as expected" ) |
| 865 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 866 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 867 | main.log.error( self.name + ": EOF exception found" ) |
| 868 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 869 | main.cleanup() |
| 870 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 871 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 872 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 873 | main.cleanup() |
| 874 | main.exit() |
| 875 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 876 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 877 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 878 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 879 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 880 | Note: mac must be a colon separated mac address, but could be a |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 881 | partial mac address |
| 882 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 883 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 884 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 885 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 886 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 887 | return None |
| 888 | else: |
| 889 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 890 | rawHosts = self.hosts() |
| 891 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 892 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 893 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 894 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 895 | if not host: |
| 896 | pass |
| 897 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 898 | return host |
| 899 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 900 | except TypeError: |
| 901 | main.log.exception( self.name + ": Object not as expected" ) |
| 902 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 903 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 904 | main.log.error( self.name + ": EOF exception found" ) |
| 905 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 906 | main.cleanup() |
| 907 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 908 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 909 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 910 | main.cleanup() |
| 911 | main.exit() |
| 912 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 913 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 914 | """ |
| 915 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 916 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 917 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 918 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 919 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 920 | IMPORTANT: |
| 921 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 922 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 923 | Furthermore, it assumes that value of VLAN is '-1' |
| 924 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 925 | Converts mininet hosts ( h1, h2, h3... ) into |
| 926 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 927 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 928 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 929 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 930 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 931 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 932 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 933 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 934 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 935 | i = iter( str( hostHex ) ) |
| 936 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 937 | hostHex = hostHex + "/-1" |
| 938 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 939 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 940 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 941 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 942 | except TypeError: |
| 943 | main.log.exception( self.name + ": Object not as expected" ) |
| 944 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 945 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 946 | main.log.error( self.name + ": EOF exception found" ) |
| 947 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 948 | main.cleanup() |
| 949 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 950 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 951 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 952 | main.cleanup() |
| 953 | main.exit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 954 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 955 | def addHostIntent( self, hostIdOne, hostIdTwo ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 956 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 957 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 958 | * hostIdOne: ONOS host id for host1 |
| 959 | * hostIdTwo: ONOS host id for host2 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 960 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 961 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 962 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 963 | Returns: |
| 964 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 965 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 966 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 967 | cmdStr = "add-host-intent " + str( hostIdOne ) +\ |
| 968 | " " + str( hostIdTwo ) |
| 969 | handle = self.sendline( cmdStr ) |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 970 | if re.search( "Error", handle ): |
| 971 | main.log.error( "Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 972 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 973 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 974 | else: |
| 975 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 976 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
| 977 | match = re.search('id=0x([\da-f]+),', handle) |
| 978 | if match: |
| 979 | return match.group()[3:-1] |
| 980 | else: |
| 981 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 982 | main.log.debug( "Response from ONOS was: " + |
| 983 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 984 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 985 | except TypeError: |
| 986 | main.log.exception( self.name + ": Object not as expected" ) |
| 987 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 988 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 989 | main.log.error( self.name + ": EOF exception found" ) |
| 990 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 991 | main.cleanup() |
| 992 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 993 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 994 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 995 | main.cleanup() |
| 996 | main.exit() |
| 997 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 998 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 999 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1000 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1001 | * ingressDevice: device id of ingress device |
| 1002 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1003 | Optional: |
| 1004 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1005 | Description: |
| 1006 | Adds an optical intent by specifying an ingress and egress device |
| 1007 | Returns: |
| 1008 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1009 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1010 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1011 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1012 | " " + str( egressDevice ) |
| 1013 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1014 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1015 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1016 | main.log.error( "Error in adding Optical intent" ) |
| 1017 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1018 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1019 | main.log.info( "Optical intent installed between " + |
| 1020 | str( ingressDevice ) + " and " + |
| 1021 | str( egressDevice ) ) |
| 1022 | match = re.search('id=0x([\da-f]+),', handle) |
| 1023 | if match: |
| 1024 | return match.group()[3:-1] |
| 1025 | else: |
| 1026 | main.log.error( "Error, intent ID not found" ) |
| 1027 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1028 | except TypeError: |
| 1029 | main.log.exception( self.name + ": Object not as expected" ) |
| 1030 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1031 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1032 | main.log.error( self.name + ": EOF exception found" ) |
| 1033 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1034 | main.cleanup() |
| 1035 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1036 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1037 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1038 | main.cleanup() |
| 1039 | main.exit() |
| 1040 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1041 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1042 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1043 | ingressDevice, |
| 1044 | egressDevice, |
| 1045 | portIngress="", |
| 1046 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1047 | ethType="", |
| 1048 | ethSrc="", |
| 1049 | ethDst="", |
| 1050 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1051 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1052 | ipProto="", |
| 1053 | ipSrc="", |
| 1054 | ipDst="", |
| 1055 | tcpSrc="", |
| 1056 | tcpDst="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1057 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1058 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1059 | * ingressDevice: device id of ingress device |
| 1060 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1061 | Optional: |
| 1062 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1063 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1064 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1065 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1066 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1067 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1068 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1069 | * ipSrc: specify ip source address |
| 1070 | * ipDst: specify ip destination address |
| 1071 | * tcpSrc: specify tcp source port |
| 1072 | * tcpDst: specify tcp destination port |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1073 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1074 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1075 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1076 | Returns: |
| 1077 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1078 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1079 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1080 | options developers provide for point-to-point |
| 1081 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1082 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1083 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1084 | # If there are no optional arguments |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1085 | if not ethType and not ethSrc and not ethDst\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1086 | and not bandwidth and not lambdaAlloc \ |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1087 | and not ipProto and not ipSrc and not ipDst \ |
| 1088 | and not tcpSrc and not tcpDst: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1089 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1090 | |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1091 | else: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1092 | cmd = "add-point-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1093 | |
andrewonlab | 0c0a677 | 2014-10-22 12:31:18 -0400 | [diff] [blame] | 1094 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1095 | cmd += " --ethType " + str( ethType ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1096 | if ethSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1097 | cmd += " --ethSrc " + str( ethSrc ) |
| 1098 | if ethDst: |
| 1099 | cmd += " --ethDst " + str( ethDst ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1100 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1101 | cmd += " --bandwidth " + str( bandwidth ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1102 | if lambdaAlloc: |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1103 | cmd += " --lambda " |
| 1104 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1105 | cmd += " --ipProto " + str( ipProto ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1106 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1107 | cmd += " --ipSrc " + str( ipSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1108 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1109 | cmd += " --ipDst " + str( ipDst ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1110 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1111 | cmd += " --tcpSrc " + str( tcpSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1112 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1113 | cmd += " --tcpDst " + str( tcpDst ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1114 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1115 | # Check whether the user appended the port |
| 1116 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1117 | if "/" in ingressDevice: |
| 1118 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1119 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1120 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1121 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1122 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1123 | # Would it make sense to throw an exception and exit |
| 1124 | # the test? |
| 1125 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1126 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1127 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1128 | str( ingressDevice ) + "/" +\ |
| 1129 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1130 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1131 | if "/" in egressDevice: |
| 1132 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1133 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1134 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1135 | main.log.error( "You must specify the egress port" ) |
| 1136 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1137 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1138 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1139 | str( egressDevice ) + "/" +\ |
| 1140 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1141 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1142 | handle = self.sendline( cmd ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1143 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1144 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1145 | main.log.error( "Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1146 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1147 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1148 | # TODO: print out all the options in this message? |
| 1149 | main.log.info( "Point-to-point intent installed between " + |
| 1150 | str( ingressDevice ) + " and " + |
| 1151 | str( egressDevice ) ) |
| 1152 | match = re.search('id=0x([\da-f]+),', handle) |
| 1153 | if match: |
| 1154 | return match.group()[3:-1] |
| 1155 | else: |
| 1156 | main.log.error( "Error, intent ID not found" ) |
| 1157 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1158 | except TypeError: |
| 1159 | main.log.exception( self.name + ": Object not as expected" ) |
| 1160 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1161 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1162 | main.log.error( self.name + ": EOF exception found" ) |
| 1163 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1164 | main.cleanup() |
| 1165 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1166 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1167 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1168 | main.cleanup() |
| 1169 | main.exit() |
| 1170 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1171 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1172 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1173 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1174 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1175 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1176 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1177 | ethType="", |
| 1178 | ethSrc="", |
| 1179 | ethDst="", |
| 1180 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1181 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1182 | ipProto="", |
| 1183 | ipSrc="", |
| 1184 | ipDst="", |
| 1185 | tcpSrc="", |
| 1186 | tcpDst="", |
| 1187 | setEthSrc="", |
| 1188 | setEthDst="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1189 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1190 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1191 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1192 | is same. That is, all ingress devices include port numbers |
| 1193 | with a "/" or all ingress devices could specify device |
| 1194 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1195 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1196 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1197 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1198 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1199 | Optional: |
| 1200 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1201 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1202 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1203 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1204 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1205 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1206 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1207 | * ipSrc: specify ip source address |
| 1208 | * ipDst: specify ip destination address |
| 1209 | * tcpSrc: specify tcp source port |
| 1210 | * tcpDst: specify tcp destination port |
| 1211 | * setEthSrc: action to Rewrite Source MAC Address |
| 1212 | * setEthDst: action to Rewrite Destination MAC Address |
| 1213 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1214 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1215 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1216 | Returns: |
| 1217 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1218 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1219 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1220 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1221 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1222 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1223 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1224 | # If there are no optional arguments |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1225 | if not ethType and not ethSrc and not ethDst\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1226 | and not bandwidth and not lambdaAlloc\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1227 | and not ipProto and not ipSrc and not ipDst\ |
| 1228 | and not tcpSrc and not tcpDst and not setEthSrc\ |
| 1229 | and not setEthDst: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1230 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1231 | |
| 1232 | else: |
| 1233 | cmd = "add-multi-to-single-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1234 | |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1235 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1236 | cmd += " --ethType " + str( ethType ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1237 | if ethSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1238 | cmd += " --ethSrc " + str( ethSrc ) |
| 1239 | if ethDst: |
| 1240 | cmd += " --ethDst " + str( ethDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1241 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1242 | cmd += " --bandwidth " + str( bandwidth ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1243 | if lambdaAlloc: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1244 | cmd += " --lambda " |
| 1245 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1246 | cmd += " --ipProto " + str( ipProto ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1247 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1248 | cmd += " --ipSrc " + str( ipSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1249 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1250 | cmd += " --ipDst " + str( ipDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1251 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1252 | cmd += " --tcpSrc " + str( tcpSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1253 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1254 | cmd += " --tcpDst " + str( tcpDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1255 | if setEthSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1256 | cmd += " --setEthSrc " + str( setEthSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1257 | if setEthDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1258 | cmd += " --setEthDst " + str( setEthDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1259 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1260 | # Check whether the user appended the port |
| 1261 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1262 | |
| 1263 | if portIngressList is None: |
| 1264 | for ingressDevice in ingressDeviceList: |
| 1265 | if "/" in ingressDevice: |
| 1266 | cmd += " " + str( ingressDevice ) |
| 1267 | else: |
| 1268 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1269 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1270 | # TODO: perhaps more meaningful return |
| 1271 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1272 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1273 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1274 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1275 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1276 | cmd += " " + \ |
| 1277 | str( ingressDevice ) + "/" +\ |
| 1278 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1279 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1280 | main.log.error( "Device list and port list does not " + |
| 1281 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1282 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1283 | if "/" in egressDevice: |
| 1284 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1285 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1286 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1287 | main.log.error( "You must specify " + |
| 1288 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1289 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1290 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1291 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1292 | str( egressDevice ) + "/" +\ |
| 1293 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1294 | handle = self.sendline( cmd ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1295 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1296 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1297 | main.log.error( "Error in adding multipoint-to-singlepoint " + |
| 1298 | "intent" ) |
| 1299 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1300 | else: |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1301 | match = re.search('id=0x([\da-f]+),', handle) |
| 1302 | if match: |
| 1303 | return match.group()[3:-1] |
| 1304 | else: |
| 1305 | main.log.error( "Error, intent ID not found" ) |
| 1306 | return None |
| 1307 | except TypeError: |
| 1308 | main.log.exception( self.name + ": Object not as expected" ) |
| 1309 | return None |
| 1310 | except pexpect.EOF: |
| 1311 | main.log.error( self.name + ": EOF exception found" ) |
| 1312 | main.log.error( self.name + ": " + self.handle.before ) |
| 1313 | main.cleanup() |
| 1314 | main.exit() |
| 1315 | except Exception: |
| 1316 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1317 | main.cleanup() |
| 1318 | main.exit() |
| 1319 | |
| 1320 | def addSinglepointToMultipointIntent( |
| 1321 | self, |
| 1322 | ingressDevice, |
| 1323 | egressDeviceList, |
| 1324 | portIngress="", |
| 1325 | portEgressList=None, |
| 1326 | ethType="", |
| 1327 | ethSrc="", |
| 1328 | ethDst="", |
| 1329 | bandwidth="", |
| 1330 | lambdaAlloc=False, |
| 1331 | ipProto="", |
| 1332 | ipSrc="", |
| 1333 | ipDst="", |
| 1334 | tcpSrc="", |
| 1335 | tcpDst="", |
| 1336 | setEthSrc="", |
| 1337 | setEthDst="" ): |
| 1338 | """ |
| 1339 | Note: |
| 1340 | This function assumes the format of all egress devices |
| 1341 | is same. That is, all egress devices include port numbers |
| 1342 | with a "/" or all egress devices could specify device |
| 1343 | ids and port numbers seperately. |
| 1344 | Required: |
| 1345 | * EgressDeviceList: List of device ids of egress device |
| 1346 | ( Atleast 2 eress devices required in the list ) |
| 1347 | * ingressDevice: device id of ingress device |
| 1348 | Optional: |
| 1349 | * ethType: specify ethType |
| 1350 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1351 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1352 | * bandwidth: specify bandwidth capacity of link |
| 1353 | * lambdaAlloc: if True, intent will allocate lambda |
| 1354 | for the specified intent |
| 1355 | * ipProto: specify ip protocol |
| 1356 | * ipSrc: specify ip source address |
| 1357 | * ipDst: specify ip destination address |
| 1358 | * tcpSrc: specify tcp source port |
| 1359 | * tcpDst: specify tcp destination port |
| 1360 | * setEthSrc: action to Rewrite Source MAC Address |
| 1361 | * setEthDst: action to Rewrite Destination MAC Address |
| 1362 | Description: |
| 1363 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1364 | specifying device id's and optional fields |
| 1365 | Returns: |
| 1366 | A string of the intent id or None on error |
| 1367 | |
| 1368 | NOTE: This function may change depending on the |
| 1369 | options developers provide for singlepoint-to-multipoint |
| 1370 | intent via cli |
| 1371 | """ |
| 1372 | try: |
| 1373 | # If there are no optional arguments |
| 1374 | if not ethType and not ethSrc and not ethDst\ |
| 1375 | and not bandwidth and not lambdaAlloc\ |
| 1376 | and not ipProto and not ipSrc and not ipDst\ |
| 1377 | and not tcpSrc and not tcpDst and not setEthSrc\ |
| 1378 | and not setEthDst: |
| 1379 | cmd = "add-single-to-multi-intent" |
| 1380 | |
| 1381 | else: |
| 1382 | cmd = "add-single-to-multi-intent" |
| 1383 | |
| 1384 | if ethType: |
| 1385 | cmd += " --ethType " + str( ethType ) |
| 1386 | if ethSrc: |
| 1387 | cmd += " --ethSrc " + str( ethSrc ) |
| 1388 | if ethDst: |
| 1389 | cmd += " --ethDst " + str( ethDst ) |
| 1390 | if bandwidth: |
| 1391 | cmd += " --bandwidth " + str( bandwidth ) |
| 1392 | if lambdaAlloc: |
| 1393 | cmd += " --lambda " |
| 1394 | if ipProto: |
| 1395 | cmd += " --ipProto " + str( ipProto ) |
| 1396 | if ipSrc: |
| 1397 | cmd += " --ipSrc " + str( ipSrc ) |
| 1398 | if ipDst: |
| 1399 | cmd += " --ipDst " + str( ipDst ) |
| 1400 | if tcpSrc: |
| 1401 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1402 | if tcpDst: |
| 1403 | cmd += " --tcpDst " + str( tcpDst ) |
| 1404 | if setEthSrc: |
| 1405 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1406 | if setEthDst: |
| 1407 | cmd += " --setEthDst " + str( setEthDst ) |
| 1408 | |
| 1409 | # Check whether the user appended the port |
| 1410 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1411 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1412 | if "/" in ingressDevice: |
| 1413 | cmd += " " + str( ingressDevice ) |
| 1414 | else: |
| 1415 | if not portIngress: |
| 1416 | main.log.error( "You must specify " + |
| 1417 | "the Ingress port" ) |
| 1418 | return main.FALSE |
| 1419 | |
| 1420 | cmd += " " +\ |
| 1421 | str( ingressDevice ) + "/" +\ |
| 1422 | str( portIngress ) |
| 1423 | |
| 1424 | if portEgressList is None: |
| 1425 | for egressDevice in egressDeviceList: |
| 1426 | if "/" in egressDevice: |
| 1427 | cmd += " " + str( egressDevice ) |
| 1428 | else: |
| 1429 | main.log.error( "You must specify " + |
| 1430 | "the egress port" ) |
| 1431 | # TODO: perhaps more meaningful return |
| 1432 | return main.FALSE |
| 1433 | else: |
| 1434 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1435 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1436 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1437 | cmd += " " + \ |
| 1438 | str( egressDevice ) + "/" +\ |
| 1439 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1440 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1441 | main.log.error( "Device list and port list does not " + |
| 1442 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1443 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1444 | handle = self.sendline( cmd ) |
| 1445 | # If error, return error message |
| 1446 | if re.search( "Error", handle ): |
| 1447 | main.log.error( "Error in adding singlepoint-to-multipoint " + |
| 1448 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1449 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1450 | else: |
| 1451 | match = re.search('id=0x([\da-f]+),', handle) |
| 1452 | if match: |
| 1453 | return match.group()[3:-1] |
| 1454 | else: |
| 1455 | main.log.error( "Error, intent ID not found" ) |
| 1456 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1457 | except TypeError: |
| 1458 | main.log.exception( self.name + ": Object not as expected" ) |
| 1459 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1460 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1461 | main.log.error( self.name + ": EOF exception found" ) |
| 1462 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1463 | main.cleanup() |
| 1464 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1465 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1466 | main.log.exception( self.name + ": Uncaught exception!" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1467 | main.cleanup() |
| 1468 | main.exit() |
| 1469 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1470 | def addMplsIntent( |
| 1471 | self, |
| 1472 | ingressDevice, |
| 1473 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1474 | ingressPort="", |
| 1475 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1476 | ethType="", |
| 1477 | ethSrc="", |
| 1478 | ethDst="", |
| 1479 | bandwidth="", |
| 1480 | lambdaAlloc=False, |
| 1481 | ipProto="", |
| 1482 | ipSrc="", |
| 1483 | ipDst="", |
| 1484 | tcpSrc="", |
| 1485 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1486 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1487 | egressLabel="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1488 | priority=""): |
| 1489 | """ |
| 1490 | Required: |
| 1491 | * ingressDevice: device id of ingress device |
| 1492 | * egressDevice: device id of egress device |
| 1493 | Optional: |
| 1494 | * ethType: specify ethType |
| 1495 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1496 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1497 | * bandwidth: specify bandwidth capacity of link |
| 1498 | * lambdaAlloc: if True, intent will allocate lambda |
| 1499 | for the specified intent |
| 1500 | * ipProto: specify ip protocol |
| 1501 | * ipSrc: specify ip source address |
| 1502 | * ipDst: specify ip destination address |
| 1503 | * tcpSrc: specify tcp source port |
| 1504 | * tcpDst: specify tcp destination port |
| 1505 | * ingressLabel: Ingress MPLS label |
| 1506 | * egressLabel: Egress MPLS label |
| 1507 | Description: |
| 1508 | Adds MPLS intent by |
| 1509 | specifying device id's and optional fields |
| 1510 | Returns: |
| 1511 | A string of the intent id or None on error |
| 1512 | |
| 1513 | NOTE: This function may change depending on the |
| 1514 | options developers provide for MPLS |
| 1515 | intent via cli |
| 1516 | """ |
| 1517 | try: |
| 1518 | # If there are no optional arguments |
| 1519 | if not ethType and not ethSrc and not ethDst\ |
| 1520 | and not bandwidth and not lambdaAlloc \ |
| 1521 | and not ipProto and not ipSrc and not ipDst \ |
| 1522 | and not tcpSrc and not tcpDst and not ingressLabel \ |
| 1523 | and not egressLabel: |
| 1524 | cmd = "add-mpls-intent" |
| 1525 | |
| 1526 | else: |
| 1527 | cmd = "add-mpls-intent" |
| 1528 | |
| 1529 | if ethType: |
| 1530 | cmd += " --ethType " + str( ethType ) |
| 1531 | if ethSrc: |
| 1532 | cmd += " --ethSrc " + str( ethSrc ) |
| 1533 | if ethDst: |
| 1534 | cmd += " --ethDst " + str( ethDst ) |
| 1535 | if bandwidth: |
| 1536 | cmd += " --bandwidth " + str( bandwidth ) |
| 1537 | if lambdaAlloc: |
| 1538 | cmd += " --lambda " |
| 1539 | if ipProto: |
| 1540 | cmd += " --ipProto " + str( ipProto ) |
| 1541 | if ipSrc: |
| 1542 | cmd += " --ipSrc " + str( ipSrc ) |
| 1543 | if ipDst: |
| 1544 | cmd += " --ipDst " + str( ipDst ) |
| 1545 | if tcpSrc: |
| 1546 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1547 | if tcpDst: |
| 1548 | cmd += " --tcpDst " + str( tcpDst ) |
| 1549 | if ingressLabel: |
| 1550 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 1551 | if egressLabel: |
| 1552 | cmd += " --egressLabel " + str( egressLabel ) |
| 1553 | if priority: |
| 1554 | cmd += " --priority " + str( priority ) |
| 1555 | |
| 1556 | # Check whether the user appended the port |
| 1557 | # or provided it as an input |
| 1558 | if "/" in ingressDevice: |
| 1559 | cmd += " " + str( ingressDevice ) |
| 1560 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1561 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1562 | main.log.error( "You must specify the ingress port" ) |
| 1563 | return None |
| 1564 | |
| 1565 | cmd += " " + \ |
| 1566 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1567 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1568 | |
| 1569 | if "/" in egressDevice: |
| 1570 | cmd += " " + str( egressDevice ) |
| 1571 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1572 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1573 | main.log.error( "You must specify the egress port" ) |
| 1574 | return None |
| 1575 | |
| 1576 | cmd += " " +\ |
| 1577 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1578 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1579 | |
| 1580 | handle = self.sendline( cmd ) |
| 1581 | # If error, return error message |
| 1582 | if re.search( "Error", handle ): |
| 1583 | main.log.error( "Error in adding mpls intent" ) |
| 1584 | return None |
| 1585 | else: |
| 1586 | # TODO: print out all the options in this message? |
| 1587 | main.log.info( "MPLS intent installed between " + |
| 1588 | str( ingressDevice ) + " and " + |
| 1589 | str( egressDevice ) ) |
| 1590 | match = re.search('id=0x([\da-f]+),', handle) |
| 1591 | if match: |
| 1592 | return match.group()[3:-1] |
| 1593 | else: |
| 1594 | main.log.error( "Error, intent ID not found" ) |
| 1595 | return None |
| 1596 | except TypeError: |
| 1597 | main.log.exception( self.name + ": Object not as expected" ) |
| 1598 | return None |
| 1599 | except pexpect.EOF: |
| 1600 | main.log.error( self.name + ": EOF exception found" ) |
| 1601 | main.log.error( self.name + ": " + self.handle.before ) |
| 1602 | main.cleanup() |
| 1603 | main.exit() |
| 1604 | except Exception: |
| 1605 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1606 | main.cleanup() |
| 1607 | main.exit() |
| 1608 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1609 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 1610 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1611 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1612 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1613 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1614 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1615 | -p or --purge: Purge the intent from the store after removal |
| 1616 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1617 | Returns: |
| 1618 | main.False on error and |
| 1619 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1620 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1621 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1622 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1623 | if purge: |
| 1624 | cmdStr += " -p" |
| 1625 | if sync: |
| 1626 | cmdStr += " -s" |
| 1627 | |
| 1628 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1629 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1630 | if re.search( "Error", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1631 | main.log.error( "Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1632 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1633 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1634 | # TODO: Should this be main.TRUE |
| 1635 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1636 | except TypeError: |
| 1637 | main.log.exception( self.name + ": Object not as expected" ) |
| 1638 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1639 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1640 | main.log.error( self.name + ": EOF exception found" ) |
| 1641 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1642 | main.cleanup() |
| 1643 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1644 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1645 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1646 | main.cleanup() |
| 1647 | main.exit() |
| 1648 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 1649 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1650 | """ |
| 1651 | Purges all WITHDRAWN Intents |
| 1652 | """ |
| 1653 | try: |
| 1654 | cmdStr = "purge-intents" |
| 1655 | handle = self.sendline( cmdStr ) |
| 1656 | if re.search( "Error", handle ): |
| 1657 | main.log.error( "Error in purging intents" ) |
| 1658 | return main.FALSE |
| 1659 | else: |
| 1660 | return main.TRUE |
| 1661 | except TypeError: |
| 1662 | main.log.exception( self.name + ": Object not as expected" ) |
| 1663 | return None |
| 1664 | except pexpect.EOF: |
| 1665 | main.log.error( self.name + ": EOF exception found" ) |
| 1666 | main.log.error( self.name + ": " + self.handle.before ) |
| 1667 | main.cleanup() |
| 1668 | main.exit() |
| 1669 | except Exception: |
| 1670 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1671 | main.cleanup() |
| 1672 | main.exit() |
| 1673 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1674 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1675 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1676 | NOTE: This method should be used after installing application: |
| 1677 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1678 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1679 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1680 | Description: |
| 1681 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1682 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1683 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1684 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1685 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1686 | cmdStr += " -j" |
| 1687 | handle = self.sendline( cmdStr ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1688 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1689 | except TypeError: |
| 1690 | main.log.exception( self.name + ": Object not as expected" ) |
| 1691 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1692 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1693 | main.log.error( self.name + ": EOF exception found" ) |
| 1694 | main.log.error( self.name + ": " + self.handle.before ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1695 | main.cleanup() |
| 1696 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1697 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1698 | main.log.exception( self.name + ": Uncaught exception!" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1699 | main.cleanup() |
| 1700 | main.exit() |
| 1701 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1702 | def intents( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1703 | """ |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1704 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1705 | * jsonFormat: enable output formatting in json |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1706 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1707 | Obtain intents currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1708 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1709 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1710 | cmdStr = "intents" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1711 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1712 | cmdStr += " -j" |
| 1713 | handle = self.sendline( cmdStr ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1714 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1715 | except TypeError: |
| 1716 | main.log.exception( self.name + ": Object not as expected" ) |
| 1717 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1718 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1719 | main.log.error( self.name + ": EOF exception found" ) |
| 1720 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1721 | main.cleanup() |
| 1722 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1723 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1724 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1725 | main.cleanup() |
| 1726 | main.exit() |
| 1727 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1728 | def getIntentState(self, intentsId, intentsJson=None): |
| 1729 | """ |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1730 | Check intent state. |
| 1731 | Accepts a single intent ID (string type) or a list of intent IDs. |
| 1732 | Returns the state(string type) of the id if a single intent ID is |
| 1733 | accepted. |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1734 | Returns a dictionary with intent IDs as the key and its |
| 1735 | corresponding states as the values |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1736 | Parameters: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1737 | intentId: intent ID (string type) |
| 1738 | intentsJson: parsed json object from the onos:intents api |
| 1739 | Returns: |
| 1740 | state = An intent's state- INSTALL,WITHDRAWN etc. |
| 1741 | stateDict = Dictionary of intent's state. intent ID as the keys and |
| 1742 | state as the values. |
| 1743 | """ |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1744 | try: |
| 1745 | state = "State is Undefined" |
| 1746 | if not intentsJson: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1747 | intentsJsonTemp = json.loads( self.intents() ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1748 | else: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1749 | intentsJsonTemp = json.loads( intentsJson ) |
| 1750 | if isinstance( intentsId, types.StringType ): |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1751 | for intent in intentsJsonTemp: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1752 | if intentsId == intent[ 'id' ]: |
| 1753 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1754 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1755 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
| 1756 | " on the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1757 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1758 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 1759 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1760 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 1761 | stateDict = {} |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1762 | for intents in intentsJsonTemp: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1763 | if intentsId[ i ] == intents[ 'id' ]: |
| 1764 | stateDict[ 'state' ] = intents[ 'state' ] |
| 1765 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1766 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1767 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1768 | if len( intentsId ) != len( dictList ): |
| 1769 | main.log.info( "Cannot find some of the intent ID state" ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 1770 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1771 | else: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1772 | main.log.info( "Invalid intents ID entry" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1773 | return None |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1774 | except TypeError: |
| 1775 | main.log.exception( self.name + ": Object not as expected" ) |
| 1776 | return None |
| 1777 | except pexpect.EOF: |
| 1778 | main.log.error( self.name + ": EOF exception found" ) |
| 1779 | main.log.error( self.name + ": " + self.handle.before ) |
| 1780 | main.cleanup() |
| 1781 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1782 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1783 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1784 | main.cleanup() |
| 1785 | main.exit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1786 | |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1787 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1788 | """ |
| 1789 | Description: |
| 1790 | Check intents state |
| 1791 | Required: |
| 1792 | intentsId - List of intents ID to be checked |
| 1793 | Optional: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1794 | expectedState - Check the expected state(s) of each intents |
| 1795 | state in the list. |
| 1796 | *NOTE: You can pass in a list of expected state, |
| 1797 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1798 | Return: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1799 | Returns main.TRUE only if all intent are the same as expected states |
| 1800 | , otherwise, returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1801 | """ |
| 1802 | try: |
| 1803 | # Generating a dictionary: intent id as a key and state as value |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1804 | returnValue = main.TRUE |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1805 | intentsDict = self.getIntentState( intentsId ) |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1806 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1807 | #print "len of intentsDict ", str( len( intentsDict ) ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1808 | if len( intentsId ) != len( intentsDict ): |
| 1809 | main.log.info( self.name + "There is something wrong " + |
| 1810 | "getting intents state" ) |
| 1811 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1812 | |
| 1813 | if isinstance( expectedState, types.StringType ): |
| 1814 | for intents in intentsDict: |
| 1815 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 1816 | main.log.debug( self.name + " : Intent ID - " + |
| 1817 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1818 | " actual state = " + |
| 1819 | intents.get( 'state' ) |
| 1820 | + " does not equal expected state = " |
| 1821 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 1822 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1823 | |
| 1824 | elif isinstance( expectedState, types.ListType ): |
| 1825 | for intents in intentsDict: |
| 1826 | if not any( state == intents.get( 'state' ) for state in |
| 1827 | expectedState ): |
| 1828 | main.log.debug( self.name + " : Intent ID - " + |
| 1829 | intents.get( 'id' ) + |
| 1830 | " actual state = " + |
| 1831 | intents.get( 'state' ) + |
| 1832 | " does not equal expected states = " |
| 1833 | + str( expectedState ) ) |
| 1834 | returnValue = main.FALSE |
| 1835 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1836 | if returnValue == main.TRUE: |
| 1837 | main.log.info( self.name + ": All " + |
| 1838 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 1839 | " intents are in " + str( expectedState ) + |
| 1840 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1841 | return returnValue |
| 1842 | except TypeError: |
| 1843 | main.log.exception( self.name + ": Object not as expected" ) |
| 1844 | return None |
| 1845 | except pexpect.EOF: |
| 1846 | main.log.error( self.name + ": EOF exception found" ) |
| 1847 | main.log.error( self.name + ": " + self.handle.before ) |
| 1848 | main.cleanup() |
| 1849 | main.exit() |
| 1850 | except Exception: |
| 1851 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1852 | main.cleanup() |
| 1853 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1854 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1855 | def flows( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1856 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1857 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1858 | * jsonFormat: enable output formatting in json |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1859 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1860 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1861 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1862 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1863 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1864 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1865 | cmdStr += " -j" |
| 1866 | handle = self.sendline( cmdStr ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1867 | if re.search( "Error:", handle ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 1868 | main.log.error( self.name + ": flows() response: " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1869 | str( handle ) ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1870 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1871 | except TypeError: |
| 1872 | main.log.exception( self.name + ": Object not as expected" ) |
| 1873 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1874 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1875 | main.log.error( self.name + ": EOF exception found" ) |
| 1876 | main.log.error( self.name + ": " + self.handle.before ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1877 | main.cleanup() |
| 1878 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1879 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1880 | main.log.exception( self.name + ": Uncaught exception!" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1881 | main.cleanup() |
| 1882 | main.exit() |
| 1883 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1884 | def checkFlowsState( self ): |
| 1885 | """ |
| 1886 | Description: |
| 1887 | Check the if all the current flows are in ADDED state or |
| 1888 | PENDING_ADD state |
| 1889 | Return: |
| 1890 | returnValue - Returns main.TRUE only if all flows are in |
| 1891 | ADDED state or PENDING_ADD, return main.FALSE |
| 1892 | otherwise. |
| 1893 | """ |
| 1894 | try: |
| 1895 | tempFlows = json.loads( self.flows() ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1896 | #print tempFlows[0] |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1897 | returnValue = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1898 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1899 | for device in tempFlows: |
| 1900 | for flow in device.get( 'flows' ): |
| 1901 | if flow.get( 'state' ) != 'ADDED' and flow.get( 'state' ) != \ |
| 1902 | 'PENDING_ADD': |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 1903 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1904 | main.log.info( self.name + ": flow Id: " + |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 1905 | str( flow.get( 'groupId' ) ) + |
| 1906 | " | state:" + |
| 1907 | str( flow.get( 'state' ) ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1908 | returnValue = main.FALSE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1909 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1910 | return returnValue |
| 1911 | except TypeError: |
| 1912 | main.log.exception( self.name + ": Object not as expected" ) |
| 1913 | return None |
| 1914 | except pexpect.EOF: |
| 1915 | main.log.error( self.name + ": EOF exception found" ) |
| 1916 | main.log.error( self.name + ": " + self.handle.before ) |
| 1917 | main.cleanup() |
| 1918 | main.exit() |
| 1919 | except Exception: |
| 1920 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1921 | main.cleanup() |
| 1922 | main.exit() |
| 1923 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1924 | def pushTestIntents( self, dpidSrc, dpidDst, numIntents, |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1925 | numMult="", appId="", report=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1926 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1927 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1928 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1929 | a specific point-to-point intent definition |
| 1930 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1931 | * dpidSrc: specify source dpid |
| 1932 | * dpidDst: specify destination dpid |
| 1933 | * numIntents: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1934 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1935 | * numMult: number multiplier for multiplying |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1936 | the number of intents specified |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1937 | * appId: specify the application id init to further |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1938 | modularize the intents |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1939 | * report: default True, returns latency information |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1940 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1941 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1942 | cmd = "push-test-intents " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1943 | str( dpidSrc ) + " " + str( dpidDst ) + " " +\ |
| 1944 | str( numIntents ) |
| 1945 | if numMult: |
| 1946 | cmd += " " + str( numMult ) |
| 1947 | # If app id is specified, then numMult |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1948 | # must exist because of the way this command |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1949 | if appId: |
| 1950 | cmd += " " + str( appId ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1951 | handle = self.sendline( cmd ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1952 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1953 | latResult = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1954 | main.log.info( handle ) |
| 1955 | # Split result by newline |
| 1956 | newline = handle.split( "\r\r\n" ) |
| 1957 | # Ignore the first object of list, which is empty |
| 1958 | newline = newline[ 1: ] |
| 1959 | # Some sloppy parsing method to get the latency |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1960 | for result in newline: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1961 | result = result.split( ": " ) |
| 1962 | # Append the first result of second parse |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1963 | latResult.append( result[ 1 ].split( " " )[ 0 ] ) |
| 1964 | main.log.info( latResult ) |
| 1965 | return latResult |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1966 | else: |
| 1967 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1968 | except TypeError: |
| 1969 | main.log.exception( self.name + ": Object not as expected" ) |
| 1970 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1971 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1972 | main.log.error( self.name + ": EOF exception found" ) |
| 1973 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1974 | main.cleanup() |
| 1975 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1976 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1977 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1978 | main.cleanup() |
| 1979 | main.exit() |
| 1980 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1981 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1982 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1983 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1984 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1985 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1986 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1987 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1988 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1989 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1990 | cmdStr += " -j" |
| 1991 | handle = self.sendline( cmdStr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1992 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1993 | except TypeError: |
| 1994 | main.log.exception( self.name + ": Object not as expected" ) |
| 1995 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1996 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1997 | main.log.error( self.name + ": EOF exception found" ) |
| 1998 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1999 | main.cleanup() |
| 2000 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2001 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2002 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2003 | main.cleanup() |
| 2004 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2005 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2006 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2007 | """ |
| 2008 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2009 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2010 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2011 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2012 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2013 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2014 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2015 | cmdStr += " -j" |
| 2016 | handle = self.sendline( cmdStr ) |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2017 | if handle: |
| 2018 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2019 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2020 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2021 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2022 | else: |
| 2023 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2024 | except TypeError: |
| 2025 | main.log.exception( self.name + ": Object not as expected" ) |
| 2026 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2027 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2028 | main.log.error( self.name + ": EOF exception found" ) |
| 2029 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2030 | main.cleanup() |
| 2031 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2032 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2033 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2034 | main.cleanup() |
| 2035 | main.exit() |
| 2036 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2037 | # Wrapper functions **************** |
| 2038 | # Wrapper functions use existing driver |
| 2039 | # functions and extends their use case. |
| 2040 | # For example, we may use the output of |
| 2041 | # a normal driver function, and parse it |
| 2042 | # using a wrapper function |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2043 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2044 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2045 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2046 | Description: |
| 2047 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2048 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2049 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2050 | # Obtain output of intents function |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 2051 | intentsStr = self.intents(jsonFormat=False) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2052 | intentIdList = [] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2053 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2054 | # Parse the intents output for ID's |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2055 | intentsList = [ s.strip() for s in intentsStr.splitlines() ] |
| 2056 | for intents in intentsList: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 2057 | match = re.search('id=0x([\da-f]+),', intents) |
| 2058 | if match: |
| 2059 | tmpId = match.group()[3:-1] |
| 2060 | intentIdList.append( tmpId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2061 | return intentIdList |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2062 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2063 | except TypeError: |
| 2064 | main.log.exception( self.name + ": Object not as expected" ) |
| 2065 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2066 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2067 | main.log.error( self.name + ": EOF exception found" ) |
| 2068 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2069 | main.cleanup() |
| 2070 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2071 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2072 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2073 | main.cleanup() |
| 2074 | main.exit() |
| 2075 | |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2076 | def FlowAddedCount( self, deviceId ): |
| 2077 | """ |
| 2078 | Determine the number of flow rules for the given device id that are |
| 2079 | in the added state |
| 2080 | """ |
| 2081 | try: |
| 2082 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2083 | "grep 'state=ADDED' | wc -l" |
| 2084 | handle = self.sendline( cmdStr ) |
| 2085 | return handle |
| 2086 | except pexpect.EOF: |
| 2087 | main.log.error( self.name + ": EOF exception found" ) |
| 2088 | main.log.error( self.name + ": " + self.handle.before ) |
| 2089 | main.cleanup() |
| 2090 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2091 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2092 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2093 | main.cleanup() |
| 2094 | main.exit() |
| 2095 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2096 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2097 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2098 | Use 'devices' function to obtain list of all devices |
| 2099 | and parse the result to obtain a list of all device |
| 2100 | id's. Returns this list. Returns empty list if no |
| 2101 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2102 | List is ordered sequentially |
| 2103 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2104 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2105 | device id, and wish to execute other commands using |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2106 | the ids. By obtaining the list of device ids on the fly, |
| 2107 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2108 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2109 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2110 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2111 | devicesStr = self.devices( jsonFormat=False ) |
| 2112 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2113 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2114 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2115 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2116 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2117 | |
| 2118 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2119 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2120 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2121 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2122 | # Split list further into arguments before and after string |
| 2123 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2124 | # append to idList |
| 2125 | for arg in tempList: |
| 2126 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 2127 | return idList |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2128 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2129 | except TypeError: |
| 2130 | main.log.exception( self.name + ": Object not as expected" ) |
| 2131 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2132 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2133 | main.log.error( self.name + ": EOF exception found" ) |
| 2134 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2135 | main.cleanup() |
| 2136 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2137 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2138 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2139 | main.cleanup() |
| 2140 | main.exit() |
| 2141 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2142 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2143 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2144 | Uses 'nodes' function to obtain list of all nodes |
| 2145 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2146 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2147 | Returns: |
| 2148 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2149 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2150 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2151 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2152 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2153 | # Sample nodesStr output |
| 2154 | # id=local, address=127.0.0.1:9876, state=ACTIVE * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2155 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2156 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2157 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2158 | nodesJson = json.loads( nodesStr ) |
| 2159 | idList = [ node.get('id') for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2160 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2161 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2162 | except TypeError: |
| 2163 | main.log.exception( self.name + ": Object not as expected" ) |
| 2164 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2165 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2166 | main.log.error( self.name + ": EOF exception found" ) |
| 2167 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2168 | main.cleanup() |
| 2169 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2170 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2171 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2172 | main.cleanup() |
| 2173 | main.exit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2174 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2175 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2176 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2177 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 2178 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2179 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2180 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2181 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2182 | return None |
| 2183 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2184 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2185 | rawDevices = self.devices() |
| 2186 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2187 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2188 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2189 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 2190 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2191 | return device |
| 2192 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2193 | except TypeError: |
| 2194 | main.log.exception( self.name + ": Object not as expected" ) |
| 2195 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2196 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2197 | main.log.error( self.name + ": EOF exception found" ) |
| 2198 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2199 | main.cleanup() |
| 2200 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2201 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2202 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2203 | main.cleanup() |
| 2204 | main.exit() |
| 2205 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2206 | def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2207 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2208 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2209 | supplied values. By default this will report to main.log, but the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2210 | log level can be specified. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2211 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2212 | Params: ip = ip used for the onos cli |
| 2213 | numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2214 | numolink = expected number of links |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2215 | logLevel = level to log to. Currently accepts |
| 2216 | 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2217 | |
| 2218 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2219 | logLevel can |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2220 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2221 | Returns: main.TRUE if the number of switches and links are correct, |
| 2222 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2223 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2224 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2225 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2226 | topology = self.getTopology( ip ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2227 | if topology == {}: |
| 2228 | return main.ERROR |
| 2229 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2230 | # Is the number of switches is what we expected |
| 2231 | devices = topology.get( 'devices', False ) |
| 2232 | links = topology.get( 'links', False ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 2233 | if devices is False or links is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2234 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2235 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2236 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2237 | linkCheck = ( int( links ) == int( numolink ) ) |
| 2238 | if ( switchCheck and linkCheck ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2239 | # We expected the correct numbers |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2240 | output += "The number of links and switches match " +\ |
| 2241 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2242 | result = main.TRUE |
| 2243 | else: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2244 | output += "The number of links and switches does not match " +\ |
| 2245 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2246 | result = main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2247 | output = output + "\n ONOS sees %i devices (%i expected) \ |
| 2248 | and %i links (%i expected)" % ( |
| 2249 | int( devices ), int( numoswitch ), int( links ), |
| 2250 | int( numolink ) ) |
| 2251 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2252 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2253 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2254 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2255 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2256 | main.log.info( self.name + ": " + output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2257 | return result |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2258 | except TypeError: |
| 2259 | main.log.exception( self.name + ": Object not as expected" ) |
| 2260 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2261 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2262 | main.log.error( self.name + ": EOF exception found" ) |
| 2263 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2264 | main.cleanup() |
| 2265 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2266 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2267 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2268 | main.cleanup() |
| 2269 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2270 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2271 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2272 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2273 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2274 | deviceId must be the id of a device as seen in the onos devices command |
| 2275 | onosNode is the ip of one of the onos nodes in the cluster |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2276 | role must be either master, standby, or none |
| 2277 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2278 | Returns: |
| 2279 | main.TRUE or main.FALSE based on argument verification and |
| 2280 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2281 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2282 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2283 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2284 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2285 | cmdStr = "device-role " +\ |
| 2286 | str( deviceId ) + " " +\ |
| 2287 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2288 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2289 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2290 | if re.search( "Error", handle ): |
| 2291 | # end color output to escape any colours |
| 2292 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2293 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2294 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2295 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2296 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2297 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2298 | main.log.error( "Invalid 'role' given to device_role(). " + |
| 2299 | "Value was '" + str(role) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2300 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2301 | except TypeError: |
| 2302 | main.log.exception( self.name + ": Object not as expected" ) |
| 2303 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2304 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2305 | main.log.error( self.name + ": EOF exception found" ) |
| 2306 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2307 | main.cleanup() |
| 2308 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2309 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2310 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2311 | main.cleanup() |
| 2312 | main.exit() |
| 2313 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2314 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2315 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2316 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 2317 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2318 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2319 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2320 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2321 | cmdStr = "clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2322 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2323 | cmdStr += " -j" |
| 2324 | handle = self.sendline( cmdStr ) |
| 2325 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2326 | except TypeError: |
| 2327 | main.log.exception( self.name + ": Object not as expected" ) |
| 2328 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2329 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2330 | main.log.error( self.name + ": EOF exception found" ) |
| 2331 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2332 | main.cleanup() |
| 2333 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2334 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2335 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2336 | main.cleanup() |
| 2337 | main.exit() |
| 2338 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2339 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2340 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2341 | CLI command to get the current leader for the Election test application |
| 2342 | NOTE: Requires installation of the onos-app-election feature |
| 2343 | Returns: Node IP of the leader if one exists |
| 2344 | None if none exists |
| 2345 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2346 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2347 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2348 | cmdStr = "election-test-leader" |
| 2349 | response = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2350 | # Leader |
| 2351 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2352 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2353 | nodeSearch = re.search( leaderPattern, response ) |
| 2354 | if nodeSearch: |
| 2355 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2356 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2357 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2358 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2359 | # no leader |
| 2360 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2361 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2362 | nullSearch = re.search( nullPattern, response ) |
| 2363 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2364 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2365 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2366 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2367 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2368 | errorPattern = "Command\snot\sfound" |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2369 | if re.search( errorPattern, response ): |
| 2370 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2371 | # TODO: Should this be main.ERROR? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2372 | return main.FALSE |
| 2373 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2374 | main.log.error( "Error in electionTestLeader on " + self.name + |
| 2375 | ": " + "unexpected response" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2376 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2377 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2378 | except TypeError: |
| 2379 | main.log.exception( self.name + ": Object not as expected" ) |
| 2380 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2381 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2382 | main.log.error( self.name + ": EOF exception found" ) |
| 2383 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2384 | main.cleanup() |
| 2385 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2386 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2387 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2388 | main.cleanup() |
| 2389 | main.exit() |
| 2390 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2391 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2392 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2393 | CLI command to run for leadership of the Election test application. |
| 2394 | NOTE: Requires installation of the onos-app-election feature |
| 2395 | Returns: Main.TRUE on success |
| 2396 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2397 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2398 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2399 | cmdStr = "election-test-run" |
| 2400 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2401 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2402 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2403 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2404 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2405 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2406 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2407 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2408 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2409 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2410 | errorPattern = "Command\snot\sfound" |
| 2411 | if re.search( errorPattern, response ): |
| 2412 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2413 | return main.FALSE |
| 2414 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2415 | main.log.error( "Error in electionTestRun on " + self.name + |
| 2416 | ": " + "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2417 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2418 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2419 | except TypeError: |
| 2420 | main.log.exception( self.name + ": Object not as expected" ) |
| 2421 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2422 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2423 | main.log.error( self.name + ": EOF exception found" ) |
| 2424 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2425 | main.cleanup() |
| 2426 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2427 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2428 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2429 | main.cleanup() |
| 2430 | main.exit() |
| 2431 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2432 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2433 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2434 | * CLI command to withdraw the local node from leadership election for |
| 2435 | * the Election test application. |
| 2436 | #NOTE: Requires installation of the onos-app-election feature |
| 2437 | Returns: Main.TRUE on success |
| 2438 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2439 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2440 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2441 | cmdStr = "election-test-withdraw" |
| 2442 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2443 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2444 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2445 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2446 | if re.search( successPattern, response ): |
| 2447 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2448 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2449 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2450 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2451 | errorPattern = "Command\snot\sfound" |
| 2452 | if re.search( errorPattern, response ): |
| 2453 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2454 | return main.FALSE |
| 2455 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2456 | main.log.error( "Error in electionTestWithdraw on " + |
| 2457 | self.name + ": " + "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2458 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2459 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2460 | except TypeError: |
| 2461 | main.log.exception( self.name + ": Object not as expected" ) |
| 2462 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2463 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2464 | main.log.error( self.name + ": EOF exception found" ) |
| 2465 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2466 | main.cleanup() |
| 2467 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2468 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2469 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2470 | main.cleanup() |
| 2471 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2472 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2473 | def getDevicePortsEnabledCount( self, dpid ): |
| 2474 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2475 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2476 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2477 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2478 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2479 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 2480 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2481 | if re.search( "No such device", output ): |
| 2482 | main.log.error( "Error in getting ports" ) |
| 2483 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2484 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2485 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2486 | except TypeError: |
| 2487 | main.log.exception( self.name + ": Object not as expected" ) |
| 2488 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2489 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2490 | main.log.error( self.name + ": EOF exception found" ) |
| 2491 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2492 | main.cleanup() |
| 2493 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2494 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2495 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2496 | main.cleanup() |
| 2497 | main.exit() |
| 2498 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2499 | def getDeviceLinksActiveCount( self, dpid ): |
| 2500 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2501 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2502 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2503 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2504 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2505 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 2506 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2507 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2508 | main.log.error( "Error in getting ports " ) |
| 2509 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2510 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2511 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2512 | except TypeError: |
| 2513 | main.log.exception( self.name + ": Object not as expected" ) |
| 2514 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2515 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2516 | main.log.error( self.name + ": EOF exception found" ) |
| 2517 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2518 | main.cleanup() |
| 2519 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2520 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2521 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2522 | main.cleanup() |
| 2523 | main.exit() |
| 2524 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2525 | def getAllIntentIds( self ): |
| 2526 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2527 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2528 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2529 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2530 | cmdStr = "onos:intents | grep id=" |
| 2531 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2532 | if re.search( "Error", output ): |
| 2533 | main.log.error( "Error in getting ports" ) |
| 2534 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2535 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2536 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2537 | except TypeError: |
| 2538 | main.log.exception( self.name + ": Object not as expected" ) |
| 2539 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2540 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2541 | main.log.error( self.name + ": EOF exception found" ) |
| 2542 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2543 | main.cleanup() |
| 2544 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2545 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2546 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2547 | main.cleanup() |
| 2548 | main.exit() |
| 2549 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2550 | def intentSummary( self ): |
| 2551 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2552 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2553 | """ |
| 2554 | try: |
| 2555 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 2556 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2557 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 2558 | states.append( intent.get( 'state', None ) ) |
| 2559 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2560 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2561 | return dict( out ) |
| 2562 | except TypeError: |
| 2563 | main.log.exception( self.name + ": Object not as expected" ) |
| 2564 | return None |
| 2565 | except pexpect.EOF: |
| 2566 | main.log.error( self.name + ": EOF exception found" ) |
| 2567 | main.log.error( self.name + ": " + self.handle.before ) |
| 2568 | main.cleanup() |
| 2569 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2570 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2571 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2572 | main.cleanup() |
| 2573 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2574 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2575 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2576 | """ |
| 2577 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2578 | Optional argument: |
| 2579 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2580 | """ |
| 2581 | # FIXME: add json output |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2582 | # Sample JSON |
| 2583 | # { |
| 2584 | # "electedTime": "13m ago", |
| 2585 | # "epoch": 4, |
| 2586 | # "leader": "10.128.30.17", |
| 2587 | # "topic": "intent-partition-3" |
| 2588 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2589 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2590 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2591 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2592 | cmdStr += " -j" |
| 2593 | output = self.sendline( cmdStr ) |
| 2594 | return output |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2595 | except TypeError: |
| 2596 | main.log.exception( self.name + ": Object not as expected" ) |
| 2597 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2598 | except pexpect.EOF: |
| 2599 | main.log.error( self.name + ": EOF exception found" ) |
| 2600 | main.log.error( self.name + ": " + self.handle.before ) |
| 2601 | main.cleanup() |
| 2602 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2603 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2604 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2605 | main.cleanup() |
| 2606 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2607 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2608 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2609 | """ |
| 2610 | Returns the output of the intent Pending map. |
| 2611 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2612 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2613 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2614 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2615 | cmdStr += " -j" |
| 2616 | output = self.sendline( cmdStr ) |
| 2617 | return output |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2618 | except TypeError: |
| 2619 | main.log.exception( self.name + ": Object not as expected" ) |
| 2620 | return None |
| 2621 | except pexpect.EOF: |
| 2622 | main.log.error( self.name + ": EOF exception found" ) |
| 2623 | main.log.error( self.name + ": " + self.handle.before ) |
| 2624 | main.cleanup() |
| 2625 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2626 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2627 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2628 | main.cleanup() |
| 2629 | main.exit() |
| 2630 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2631 | def partitions( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2632 | """ |
| 2633 | Returns the output of the raft partitions command for ONOS. |
| 2634 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2635 | # Sample JSON |
| 2636 | # { |
| 2637 | # "leader": "tcp://10.128.30.11:7238", |
| 2638 | # "members": [ |
| 2639 | # "tcp://10.128.30.11:7238", |
| 2640 | # "tcp://10.128.30.17:7238", |
| 2641 | # "tcp://10.128.30.13:7238", |
| 2642 | # ], |
| 2643 | # "name": "p1", |
| 2644 | # "term": 3 |
| 2645 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2646 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2647 | cmdStr = "onos:partitions" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2648 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2649 | cmdStr += " -j" |
| 2650 | output = self.sendline( cmdStr ) |
| 2651 | return output |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2652 | except TypeError: |
| 2653 | main.log.exception( self.name + ": Object not as expected" ) |
| 2654 | return None |
| 2655 | except pexpect.EOF: |
| 2656 | main.log.error( self.name + ": EOF exception found" ) |
| 2657 | main.log.error( self.name + ": " + self.handle.before ) |
| 2658 | main.cleanup() |
| 2659 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2660 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2661 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2662 | main.cleanup() |
| 2663 | main.exit() |
| 2664 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2665 | def apps( self, jsonFormat=True ): |
| 2666 | """ |
| 2667 | Returns the output of the apps command for ONOS. This command lists |
| 2668 | information about installed ONOS applications |
| 2669 | """ |
| 2670 | # Sample JSON object |
| 2671 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
| 2672 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 2673 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
| 2674 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
| 2675 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2676 | cmdStr = "onos:apps" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2677 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2678 | cmdStr += " -j" |
| 2679 | output = self.sendline( cmdStr ) |
| 2680 | assert "Error executing command" not in output |
| 2681 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2682 | # FIXME: look at specific exceptions/Errors |
| 2683 | except AssertionError: |
| 2684 | main.log.error( "Error in processing onos:app command: " + |
| 2685 | str( output ) ) |
| 2686 | return None |
| 2687 | except TypeError: |
| 2688 | main.log.exception( self.name + ": Object not as expected" ) |
| 2689 | return None |
| 2690 | except pexpect.EOF: |
| 2691 | main.log.error( self.name + ": EOF exception found" ) |
| 2692 | main.log.error( self.name + ": " + self.handle.before ) |
| 2693 | main.cleanup() |
| 2694 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2695 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2696 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2697 | main.cleanup() |
| 2698 | main.exit() |
| 2699 | |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2700 | def appStatus( self, appName ): |
| 2701 | """ |
| 2702 | Uses the onos:apps cli command to return the status of an application. |
| 2703 | Returns: |
| 2704 | "ACTIVE" - If app is installed and activated |
| 2705 | "INSTALLED" - If app is installed and deactivated |
| 2706 | "UNINSTALLED" - If app is not installed |
| 2707 | None - on error |
| 2708 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2709 | try: |
| 2710 | if not isinstance( appName, types.StringType ): |
| 2711 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 2712 | " a string" ) |
| 2713 | return None |
| 2714 | output = self.apps( jsonFormat=True ) |
| 2715 | appsJson = json.loads( output ) |
| 2716 | state = None |
| 2717 | for app in appsJson: |
| 2718 | if appName == app.get('name'): |
| 2719 | state = app.get('state') |
| 2720 | break |
| 2721 | if state == "ACTIVE" or state == "INSTALLED": |
| 2722 | return state |
| 2723 | elif state is None: |
| 2724 | return "UNINSTALLED" |
| 2725 | elif state: |
| 2726 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 2727 | str( state ) ) |
| 2728 | return state |
| 2729 | except TypeError: |
| 2730 | main.log.exception( self.name + ": Object not as expected" ) |
| 2731 | return None |
| 2732 | except pexpect.EOF: |
| 2733 | main.log.error( self.name + ": EOF exception found" ) |
| 2734 | main.log.error( self.name + ": " + self.handle.before ) |
| 2735 | main.cleanup() |
| 2736 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2737 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2738 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2739 | main.cleanup() |
| 2740 | main.exit() |
| 2741 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2742 | def app( self, appName, option ): |
| 2743 | """ |
| 2744 | Interacts with the app command for ONOS. This command manages |
| 2745 | application inventory. |
| 2746 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2747 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2748 | # Validate argument types |
| 2749 | valid = True |
| 2750 | if not isinstance( appName, types.StringType ): |
| 2751 | main.log.error( self.name + ".app(): appName must be a " + |
| 2752 | "string" ) |
| 2753 | valid = False |
| 2754 | if not isinstance( option, types.StringType ): |
| 2755 | main.log.error( self.name + ".app(): option must be a string" ) |
| 2756 | valid = False |
| 2757 | if not valid: |
| 2758 | return main.FALSE |
| 2759 | # Validate Option |
| 2760 | option = option.lower() |
| 2761 | # NOTE: Install may become a valid option |
| 2762 | if option == "activate": |
| 2763 | pass |
| 2764 | elif option == "deactivate": |
| 2765 | pass |
| 2766 | elif option == "uninstall": |
| 2767 | pass |
| 2768 | else: |
| 2769 | # Invalid option |
| 2770 | main.log.error( "The ONOS app command argument only takes " + |
| 2771 | "the values: (activate|deactivate|uninstall)" + |
| 2772 | "; was given '" + option + "'") |
| 2773 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2774 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2775 | output = self.sendline( cmdStr ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2776 | if "Error executing command" in output: |
| 2777 | main.log.error( "Error in processing onos:app command: " + |
| 2778 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2779 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2780 | elif "No such application" in output: |
| 2781 | main.log.error( "The application '" + appName + |
| 2782 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2783 | return main.FALSE |
| 2784 | elif "Command not found:" in output: |
| 2785 | main.log.error( "Error in processing onos:app command: " + |
| 2786 | str( output ) ) |
| 2787 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2788 | elif "Unsupported command:" in output: |
| 2789 | main.log.error( "Incorrect command given to 'app': " + |
| 2790 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2791 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2792 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 2793 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2794 | return main.TRUE |
| 2795 | except TypeError: |
| 2796 | main.log.exception( self.name + ": Object not as expected" ) |
| 2797 | return main.ERROR |
| 2798 | except pexpect.EOF: |
| 2799 | main.log.error( self.name + ": EOF exception found" ) |
| 2800 | main.log.error( self.name + ": " + self.handle.before ) |
| 2801 | main.cleanup() |
| 2802 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2803 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2804 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2805 | main.cleanup() |
| 2806 | main.exit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2807 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2808 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2809 | """ |
| 2810 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2811 | appName is the hierarchical app name, not the feature name |
| 2812 | If check is True, method will check the status of the app after the |
| 2813 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2814 | Returns main.TRUE if the command was successfully sent |
| 2815 | main.FALSE if the cli responded with an error or given |
| 2816 | incorrect input |
| 2817 | """ |
| 2818 | try: |
| 2819 | if not isinstance( appName, types.StringType ): |
| 2820 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 2821 | " a string" ) |
| 2822 | return main.FALSE |
| 2823 | status = self.appStatus( appName ) |
| 2824 | if status == "INSTALLED": |
| 2825 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2826 | if check and response == main.TRUE: |
| 2827 | for i in range(10): # try 10 times then give up |
| 2828 | # TODO: Check with Thomas about this delay |
| 2829 | status = self.appStatus( appName ) |
| 2830 | if status == "ACTIVE": |
| 2831 | return main.TRUE |
| 2832 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 2833 | main.log.debug( "The state of application " + |
| 2834 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2835 | time.sleep( 1 ) |
| 2836 | return main.FALSE |
| 2837 | else: # not 'check' or command didn't succeed |
| 2838 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2839 | elif status == "ACTIVE": |
| 2840 | return main.TRUE |
| 2841 | elif status == "UNINSTALLED": |
| 2842 | main.log.error( self.name + ": Tried to activate the " + |
| 2843 | "application '" + appName + "' which is not " + |
| 2844 | "installed." ) |
| 2845 | else: |
| 2846 | main.log.error( "Unexpected return value from appStatus: " + |
| 2847 | str( status ) ) |
| 2848 | return main.ERROR |
| 2849 | except TypeError: |
| 2850 | main.log.exception( self.name + ": Object not as expected" ) |
| 2851 | return main.ERROR |
| 2852 | except pexpect.EOF: |
| 2853 | main.log.error( self.name + ": EOF exception found" ) |
| 2854 | main.log.error( self.name + ": " + self.handle.before ) |
| 2855 | main.cleanup() |
| 2856 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2857 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2858 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2859 | main.cleanup() |
| 2860 | main.exit() |
| 2861 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2862 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2863 | """ |
| 2864 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2865 | appName is the hierarchical app name, not the feature name |
| 2866 | If check is True, method will check the status of the app after the |
| 2867 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2868 | Returns main.TRUE if the command was successfully sent |
| 2869 | main.FALSE if the cli responded with an error or given |
| 2870 | incorrect input |
| 2871 | """ |
| 2872 | try: |
| 2873 | if not isinstance( appName, types.StringType ): |
| 2874 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 2875 | "be a string" ) |
| 2876 | return main.FALSE |
| 2877 | status = self.appStatus( appName ) |
| 2878 | if status == "INSTALLED": |
| 2879 | return main.TRUE |
| 2880 | elif status == "ACTIVE": |
| 2881 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2882 | if check and response == main.TRUE: |
| 2883 | for i in range(10): # try 10 times then give up |
| 2884 | status = self.appStatus( appName ) |
| 2885 | if status == "INSTALLED": |
| 2886 | return main.TRUE |
| 2887 | else: |
| 2888 | time.sleep( 1 ) |
| 2889 | return main.FALSE |
| 2890 | else: # not check or command didn't succeed |
| 2891 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2892 | elif status == "UNINSTALLED": |
| 2893 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 2894 | "application '" + appName + "' which is not " + |
| 2895 | "installed." ) |
| 2896 | return main.TRUE |
| 2897 | else: |
| 2898 | main.log.error( "Unexpected return value from appStatus: " + |
| 2899 | str( status ) ) |
| 2900 | return main.ERROR |
| 2901 | except TypeError: |
| 2902 | main.log.exception( self.name + ": Object not as expected" ) |
| 2903 | return main.ERROR |
| 2904 | except pexpect.EOF: |
| 2905 | main.log.error( self.name + ": EOF exception found" ) |
| 2906 | main.log.error( self.name + ": " + self.handle.before ) |
| 2907 | main.cleanup() |
| 2908 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2909 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2910 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2911 | main.cleanup() |
| 2912 | main.exit() |
| 2913 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2914 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2915 | """ |
| 2916 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2917 | appName is the hierarchical app name, not the feature name |
| 2918 | If check is True, method will check the status of the app after the |
| 2919 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2920 | Returns main.TRUE if the command was successfully sent |
| 2921 | main.FALSE if the cli responded with an error or given |
| 2922 | incorrect input |
| 2923 | """ |
| 2924 | # TODO: check with Thomas about the state machine for apps |
| 2925 | try: |
| 2926 | if not isinstance( appName, types.StringType ): |
| 2927 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 2928 | "be a string" ) |
| 2929 | return main.FALSE |
| 2930 | status = self.appStatus( appName ) |
| 2931 | if status == "INSTALLED": |
| 2932 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2933 | if check and response == main.TRUE: |
| 2934 | for i in range(10): # try 10 times then give up |
| 2935 | status = self.appStatus( appName ) |
| 2936 | if status == "UNINSTALLED": |
| 2937 | return main.TRUE |
| 2938 | else: |
| 2939 | time.sleep( 1 ) |
| 2940 | return main.FALSE |
| 2941 | else: # not check or command didn't succeed |
| 2942 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2943 | elif status == "ACTIVE": |
| 2944 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 2945 | "application '" + appName + "' which is " + |
| 2946 | "currently active." ) |
| 2947 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2948 | if check and response == main.TRUE: |
| 2949 | for i in range(10): # try 10 times then give up |
| 2950 | status = self.appStatus( appName ) |
| 2951 | if status == "UNINSTALLED": |
| 2952 | return main.TRUE |
| 2953 | else: |
| 2954 | time.sleep( 1 ) |
| 2955 | return main.FALSE |
| 2956 | else: # not check or command didn't succeed |
| 2957 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2958 | elif status == "UNINSTALLED": |
| 2959 | return main.TRUE |
| 2960 | else: |
| 2961 | main.log.error( "Unexpected return value from appStatus: " + |
| 2962 | str( status ) ) |
| 2963 | return main.ERROR |
| 2964 | except TypeError: |
| 2965 | main.log.exception( self.name + ": Object not as expected" ) |
| 2966 | return main.ERROR |
| 2967 | except pexpect.EOF: |
| 2968 | main.log.error( self.name + ": EOF exception found" ) |
| 2969 | main.log.error( self.name + ": " + self.handle.before ) |
| 2970 | main.cleanup() |
| 2971 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2972 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2973 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2974 | main.cleanup() |
| 2975 | main.exit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2976 | |
| 2977 | def appIDs( self, jsonFormat=True ): |
| 2978 | """ |
| 2979 | Show the mappings between app id and app names given by the 'app-ids' |
| 2980 | cli command |
| 2981 | """ |
| 2982 | try: |
| 2983 | cmdStr = "app-ids" |
| 2984 | if jsonFormat: |
| 2985 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2986 | output = self.sendline( cmdStr ) |
| 2987 | assert "Error executing command" not in output |
| 2988 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2989 | except AssertionError: |
| 2990 | main.log.error( "Error in processing onos:app-ids command: " + |
| 2991 | str( output ) ) |
| 2992 | return None |
| 2993 | except TypeError: |
| 2994 | main.log.exception( self.name + ": Object not as expected" ) |
| 2995 | return None |
| 2996 | except pexpect.EOF: |
| 2997 | main.log.error( self.name + ": EOF exception found" ) |
| 2998 | main.log.error( self.name + ": " + self.handle.before ) |
| 2999 | main.cleanup() |
| 3000 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3001 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3002 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3003 | main.cleanup() |
| 3004 | main.exit() |
| 3005 | |
| 3006 | def appToIDCheck( self ): |
| 3007 | """ |
| 3008 | This method will check that each application's ID listed in 'apps' is |
| 3009 | the same as the ID listed in 'app-ids'. The check will also check that |
| 3010 | there are no duplicate IDs issued. Note that an app ID should be |
| 3011 | a globaly unique numerical identifier for app/app-like features. Once |
| 3012 | an ID is registered, the ID is never freed up so that if an app is |
| 3013 | reinstalled it will have the same ID. |
| 3014 | |
| 3015 | Returns: main.TRUE if the check passes and |
| 3016 | main.FALSE if the check fails or |
| 3017 | main.ERROR if there is some error in processing the test |
| 3018 | """ |
| 3019 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3020 | bail = False |
| 3021 | ids = self.appIDs( jsonFormat=True ) |
| 3022 | if ids: |
| 3023 | ids = json.loads( ids ) |
| 3024 | else: |
| 3025 | main.log.error( "app-ids returned nothing:" + repr( ids ) ) |
| 3026 | bail = True |
| 3027 | apps = self.apps( jsonFormat=True ) |
| 3028 | if apps: |
| 3029 | apps = json.loads( apps ) |
| 3030 | else: |
| 3031 | main.log.error( "apps returned nothing:" + repr( apps ) ) |
| 3032 | bail = True |
| 3033 | if bail: |
| 3034 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3035 | result = main.TRUE |
| 3036 | for app in apps: |
| 3037 | appID = app.get( 'id' ) |
| 3038 | if appID is None: |
| 3039 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3040 | result = main.FALSE |
| 3041 | appName = app.get( 'name' ) |
| 3042 | if appName is None: |
| 3043 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3044 | result = main.FALSE |
| 3045 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3046 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3047 | # main.log.debug( "Comparing " + str( app ) + " to " + |
| 3048 | # str( current ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3049 | if not current: # if ids doesn't have this id |
| 3050 | result = main.FALSE |
| 3051 | main.log.error( "'app-ids' does not have the ID for " + |
| 3052 | str( appName ) + " that apps does." ) |
| 3053 | elif len( current ) > 1: |
| 3054 | # there is more than one app with this ID |
| 3055 | result = main.FALSE |
| 3056 | # We will log this later in the method |
| 3057 | elif not current[0][ 'name' ] == appName: |
| 3058 | currentName = current[0][ 'name' ] |
| 3059 | result = main.FALSE |
| 3060 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 3061 | " registered under id:" + str( appID ) + |
| 3062 | " but 'apps' has " + str( appName ) ) |
| 3063 | else: |
| 3064 | pass # id and name match! |
| 3065 | # now make sure that app-ids has no duplicates |
| 3066 | idsList = [] |
| 3067 | namesList = [] |
| 3068 | for item in ids: |
| 3069 | idsList.append( item[ 'id' ] ) |
| 3070 | namesList.append( item[ 'name' ] ) |
| 3071 | if len( idsList ) != len( set( idsList ) ) or\ |
| 3072 | len( namesList ) != len( set( namesList ) ): |
| 3073 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 3074 | + json.dumps( ids, |
| 3075 | sort_keys=True, |
| 3076 | indent=4, |
| 3077 | separators=( ',', ': ' ) ) ) |
| 3078 | result = main.FALSE |
| 3079 | return result |
| 3080 | except ( ValueError, TypeError ): |
| 3081 | main.log.exception( self.name + ": Object not as expected" ) |
| 3082 | return main.ERROR |
| 3083 | except pexpect.EOF: |
| 3084 | main.log.error( self.name + ": EOF exception found" ) |
| 3085 | main.log.error( self.name + ": " + self.handle.before ) |
| 3086 | main.cleanup() |
| 3087 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3088 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3089 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3090 | main.cleanup() |
| 3091 | main.exit() |
| 3092 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3093 | def getCfg( self, component=None, propName=None, short=False, |
| 3094 | jsonFormat=True ): |
| 3095 | """ |
| 3096 | Get configuration settings from onos cli |
| 3097 | Optional arguments: |
| 3098 | component - Optionally only list configurations for a specific |
| 3099 | component. If None, all components with configurations |
| 3100 | are displayed. Case Sensitive string. |
| 3101 | propName - If component is specified, propName option will show |
| 3102 | only this specific configuration from that component. |
| 3103 | Case Sensitive string. |
| 3104 | jsonFormat - Returns output as json. Note that this will override |
| 3105 | the short option |
| 3106 | short - Short, less verbose, version of configurations. |
| 3107 | This is overridden by the json option |
| 3108 | returns: |
| 3109 | Output from cli as a string or None on error |
| 3110 | """ |
| 3111 | try: |
| 3112 | baseStr = "cfg" |
| 3113 | cmdStr = " get" |
| 3114 | componentStr = "" |
| 3115 | if component: |
| 3116 | componentStr += " " + component |
| 3117 | if propName: |
| 3118 | componentStr += " " + propName |
| 3119 | if jsonFormat: |
| 3120 | baseStr += " -j" |
| 3121 | elif short: |
| 3122 | baseStr += " -s" |
| 3123 | output = self.sendline( baseStr + cmdStr + componentStr ) |
| 3124 | assert "Error executing command" not in output |
| 3125 | return output |
| 3126 | except AssertionError: |
| 3127 | main.log.error( "Error in processing 'cfg get' command: " + |
| 3128 | str( output ) ) |
| 3129 | return None |
| 3130 | except TypeError: |
| 3131 | main.log.exception( self.name + ": Object not as expected" ) |
| 3132 | return None |
| 3133 | except pexpect.EOF: |
| 3134 | main.log.error( self.name + ": EOF exception found" ) |
| 3135 | main.log.error( self.name + ": " + self.handle.before ) |
| 3136 | main.cleanup() |
| 3137 | main.exit() |
| 3138 | except Exception: |
| 3139 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3140 | main.cleanup() |
| 3141 | main.exit() |
| 3142 | |
| 3143 | def setCfg( self, component, propName, value=None, check=True ): |
| 3144 | """ |
| 3145 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3146 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3147 | component - The case sensitive name of the component whose |
| 3148 | property is to be set |
| 3149 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3150 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3151 | value - The value to set the property to. If None, will unset the |
| 3152 | property and revert it to it's default value(if applicable) |
| 3153 | check - Boolean, Check whether the option was successfully set this |
| 3154 | only applies when a value is given. |
| 3155 | returns: |
| 3156 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 3157 | will return main.TRUE unless there is an error |
| 3158 | """ |
| 3159 | try: |
| 3160 | baseStr = "cfg" |
| 3161 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 3162 | if value is not None: |
| 3163 | cmdStr += " " + str( value ) |
| 3164 | output = self.sendline( baseStr + cmdStr ) |
| 3165 | assert "Error executing command" not in output |
| 3166 | if value and check: |
| 3167 | results = self.getCfg( component=str( component ), |
| 3168 | propName=str( propName ), |
| 3169 | jsonFormat=True ) |
| 3170 | # Check if current value is what we just set |
| 3171 | try: |
| 3172 | jsonOutput = json.loads( results ) |
| 3173 | current = jsonOutput[ 'value' ] |
| 3174 | except ( ValueError, TypeError ): |
| 3175 | main.log.exception( "Error parsing cfg output" ) |
| 3176 | main.log.error( "output:" + repr( results ) ) |
| 3177 | return main.FALSE |
| 3178 | if current == str( value ): |
| 3179 | return main.TRUE |
| 3180 | return main.FALSE |
| 3181 | return main.TRUE |
| 3182 | except AssertionError: |
| 3183 | main.log.error( "Error in processing 'cfg set' command: " + |
| 3184 | str( output ) ) |
| 3185 | return main.FALSE |
| 3186 | except TypeError: |
| 3187 | main.log.exception( self.name + ": Object not as expected" ) |
| 3188 | return main.FALSE |
| 3189 | except pexpect.EOF: |
| 3190 | main.log.error( self.name + ": EOF exception found" ) |
| 3191 | main.log.error( self.name + ": " + self.handle.before ) |
| 3192 | main.cleanup() |
| 3193 | main.exit() |
| 3194 | except Exception: |
| 3195 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3196 | main.cleanup() |
| 3197 | main.exit() |
| 3198 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3199 | def setTestAdd( self, setName, values ): |
| 3200 | """ |
| 3201 | CLI command to add elements to a distributed set. |
| 3202 | Arguments: |
| 3203 | setName - The name of the set to add to. |
| 3204 | values - The value(s) to add to the set, space seperated. |
| 3205 | Example usages: |
| 3206 | setTestAdd( "set1", "a b c" ) |
| 3207 | setTestAdd( "set2", "1" ) |
| 3208 | returns: |
| 3209 | main.TRUE on success OR |
| 3210 | main.FALSE if elements were already in the set OR |
| 3211 | main.ERROR on error |
| 3212 | """ |
| 3213 | try: |
| 3214 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
| 3215 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3216 | try: |
| 3217 | # TODO: Maybe make this less hardcoded |
| 3218 | # ConsistentMap Exceptions |
| 3219 | assert "org.onosproject.store.service" not in output |
| 3220 | # Node not leader |
| 3221 | assert "java.lang.IllegalStateException" not in output |
| 3222 | except AssertionError: |
| 3223 | main.log.error( "Error in processing 'set-test-add' " + |
| 3224 | "command: " + str( output ) ) |
| 3225 | retryTime = 30 # Conservative time, given by Madan |
| 3226 | main.log.info( "Waiting " + str( retryTime ) + |
| 3227 | "seconds before retrying." ) |
| 3228 | time.sleep( retryTime ) # Due to change in mastership |
| 3229 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3230 | assert "Error executing command" not in output |
| 3231 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 3232 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
| 3233 | main.log.info( self.name + ": " + output ) |
| 3234 | if re.search( positiveMatch, output): |
| 3235 | return main.TRUE |
| 3236 | elif re.search( negativeMatch, output): |
| 3237 | return main.FALSE |
| 3238 | else: |
| 3239 | main.log.error( self.name + ": setTestAdd did not" + |
| 3240 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3241 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3242 | return main.ERROR |
| 3243 | except AssertionError: |
| 3244 | main.log.error( "Error in processing 'set-test-add' command: " + |
| 3245 | str( output ) ) |
| 3246 | return main.ERROR |
| 3247 | except TypeError: |
| 3248 | main.log.exception( self.name + ": Object not as expected" ) |
| 3249 | return main.ERROR |
| 3250 | except pexpect.EOF: |
| 3251 | main.log.error( self.name + ": EOF exception found" ) |
| 3252 | main.log.error( self.name + ": " + self.handle.before ) |
| 3253 | main.cleanup() |
| 3254 | main.exit() |
| 3255 | except Exception: |
| 3256 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3257 | main.cleanup() |
| 3258 | main.exit() |
| 3259 | |
| 3260 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 3261 | """ |
| 3262 | CLI command to remove elements from a distributed set. |
| 3263 | Required arguments: |
| 3264 | setName - The name of the set to remove from. |
| 3265 | values - The value(s) to remove from the set, space seperated. |
| 3266 | Optional arguments: |
| 3267 | clear - Clear all elements from the set |
| 3268 | retain - Retain only the given values. (intersection of the |
| 3269 | original set and the given set) |
| 3270 | returns: |
| 3271 | main.TRUE on success OR |
| 3272 | main.FALSE if the set was not changed OR |
| 3273 | main.ERROR on error |
| 3274 | """ |
| 3275 | try: |
| 3276 | cmdStr = "set-test-remove " |
| 3277 | if clear: |
| 3278 | cmdStr += "-c " + str( setName ) |
| 3279 | elif retain: |
| 3280 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 3281 | else: |
| 3282 | cmdStr += str( setName ) + " " + str( values ) |
| 3283 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3284 | try: |
| 3285 | # TODO: Maybe make this less hardcoded |
| 3286 | # ConsistentMap Exceptions |
| 3287 | assert "org.onosproject.store.service" not in output |
| 3288 | # Node not leader |
| 3289 | assert "java.lang.IllegalStateException" not in output |
| 3290 | except AssertionError: |
| 3291 | main.log.error( "Error in processing 'set-test-add' " + |
| 3292 | "command: " + str( output ) ) |
| 3293 | retryTime = 30 # Conservative time, given by Madan |
| 3294 | main.log.info( "Waiting " + str( retryTime ) + |
| 3295 | "seconds before retrying." ) |
| 3296 | time.sleep( retryTime ) # Due to change in mastership |
| 3297 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3298 | assert "Error executing command" not in output |
| 3299 | main.log.info( self.name + ": " + output ) |
| 3300 | if clear: |
| 3301 | pattern = "Set " + str( setName ) + " cleared" |
| 3302 | if re.search( pattern, output ): |
| 3303 | return main.TRUE |
| 3304 | elif retain: |
| 3305 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 3306 | "only elements of set \[(.*)\]" |
| 3307 | negativePattern = str( setName ) + " was not changed by " +\ |
| 3308 | "retaining only elements of the set " +\ |
| 3309 | "\[(.*)\]" |
| 3310 | if re.search( positivePattern, output ): |
| 3311 | return main.TRUE |
| 3312 | elif re.search( negativePattern, output ): |
| 3313 | return main.FALSE |
| 3314 | else: |
| 3315 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 3316 | str( setName ) |
| 3317 | if ( len( values.split() ) == 1 ): |
| 3318 | negativePattern = "\[(.*)\] was not in set " +\ |
| 3319 | str( setName ) |
| 3320 | else: |
| 3321 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 3322 | str( setName ) |
| 3323 | if re.search( positivePattern, output ): |
| 3324 | return main.TRUE |
| 3325 | elif re.search( negativePattern, output ): |
| 3326 | return main.FALSE |
| 3327 | main.log.error( self.name + ": setTestRemove did not" + |
| 3328 | " match expected output" ) |
| 3329 | main.log.debug( self.name + " expected: " + pattern ) |
| 3330 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3331 | return main.ERROR |
| 3332 | except AssertionError: |
| 3333 | main.log.error( "Error in processing 'set-test-remove' command: " + |
| 3334 | str( output ) ) |
| 3335 | return main.ERROR |
| 3336 | except TypeError: |
| 3337 | main.log.exception( self.name + ": Object not as expected" ) |
| 3338 | return main.ERROR |
| 3339 | except pexpect.EOF: |
| 3340 | main.log.error( self.name + ": EOF exception found" ) |
| 3341 | main.log.error( self.name + ": " + self.handle.before ) |
| 3342 | main.cleanup() |
| 3343 | main.exit() |
| 3344 | except Exception: |
| 3345 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3346 | main.cleanup() |
| 3347 | main.exit() |
| 3348 | |
| 3349 | def setTestGet( self, setName, values="" ): |
| 3350 | """ |
| 3351 | CLI command to get the elements in a distributed set. |
| 3352 | Required arguments: |
| 3353 | setName - The name of the set to remove from. |
| 3354 | Optional arguments: |
| 3355 | values - The value(s) to check if in the set, space seperated. |
| 3356 | returns: |
| 3357 | main.ERROR on error OR |
| 3358 | A list of elements in the set if no optional arguments are |
| 3359 | supplied OR |
| 3360 | A tuple containing the list then: |
| 3361 | main.FALSE if the given values are not in the set OR |
| 3362 | main.TRUE if the given values are in the set OR |
| 3363 | """ |
| 3364 | try: |
| 3365 | values = str( values ).strip() |
| 3366 | setName = str( setName ).strip() |
| 3367 | length = len( values.split() ) |
| 3368 | containsCheck = None |
| 3369 | # Patterns to match |
| 3370 | setPattern = "\[(.*)\]" |
| 3371 | pattern = "Items in set " + setName + ":\n" + setPattern |
| 3372 | containsTrue = "Set " + setName + " contains the value " + values |
| 3373 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 3374 | values |
| 3375 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 3376 | setPattern |
| 3377 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 3378 | " subset " + setPattern |
| 3379 | |
| 3380 | cmdStr = "set-test-get " |
| 3381 | cmdStr += setName + " " + values |
| 3382 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3383 | try: |
| 3384 | # TODO: Maybe make this less hardcoded |
| 3385 | # ConsistentMap Exceptions |
| 3386 | assert "org.onosproject.store.service" not in output |
| 3387 | # Node not leader |
| 3388 | assert "java.lang.IllegalStateException" not in output |
| 3389 | except AssertionError: |
| 3390 | main.log.error( "Error in processing 'set-test-add' " + |
| 3391 | "command: " + str( output ) ) |
| 3392 | retryTime = 30 # Conservative time, given by Madan |
| 3393 | main.log.info( "Waiting " + str( retryTime ) + |
| 3394 | "seconds before retrying." ) |
| 3395 | time.sleep( retryTime ) # Due to change in mastership |
| 3396 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3397 | assert "Error executing command" not in output |
| 3398 | main.log.info( self.name + ": " + output ) |
| 3399 | |
| 3400 | if length == 0: |
| 3401 | match = re.search( pattern, output ) |
| 3402 | else: # if given values |
| 3403 | if length == 1: # Contains output |
| 3404 | patternTrue = pattern + "\n" + containsTrue |
| 3405 | patternFalse = pattern + "\n" + containsFalse |
| 3406 | else: # ContainsAll output |
| 3407 | patternTrue = pattern + "\n" + containsAllTrue |
| 3408 | patternFalse = pattern + "\n" + containsAllFalse |
| 3409 | matchTrue = re.search( patternTrue, output ) |
| 3410 | matchFalse = re.search( patternFalse, output ) |
| 3411 | if matchTrue: |
| 3412 | containsCheck = main.TRUE |
| 3413 | match = matchTrue |
| 3414 | elif matchFalse: |
| 3415 | containsCheck = main.FALSE |
| 3416 | match = matchFalse |
| 3417 | else: |
| 3418 | main.log.error( self.name + " setTestGet did not match " +\ |
| 3419 | "expected output" ) |
| 3420 | main.log.debug( self.name + " expected: " + pattern ) |
| 3421 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3422 | match = None |
| 3423 | if match: |
| 3424 | setMatch = match.group( 1 ) |
| 3425 | if setMatch == '': |
| 3426 | setList = [] |
| 3427 | else: |
| 3428 | setList = setMatch.split( ", " ) |
| 3429 | if length > 0: |
| 3430 | return ( setList, containsCheck ) |
| 3431 | else: |
| 3432 | return setList |
| 3433 | else: # no match |
| 3434 | main.log.error( self.name + ": setTestGet did not" + |
| 3435 | " match expected output" ) |
| 3436 | main.log.debug( self.name + " expected: " + pattern ) |
| 3437 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3438 | return main.ERROR |
| 3439 | except AssertionError: |
| 3440 | main.log.error( "Error in processing 'set-test-get' command: " + |
| 3441 | str( output ) ) |
| 3442 | return main.ERROR |
| 3443 | except TypeError: |
| 3444 | main.log.exception( self.name + ": Object not as expected" ) |
| 3445 | return main.ERROR |
| 3446 | except pexpect.EOF: |
| 3447 | main.log.error( self.name + ": EOF exception found" ) |
| 3448 | main.log.error( self.name + ": " + self.handle.before ) |
| 3449 | main.cleanup() |
| 3450 | main.exit() |
| 3451 | except Exception: |
| 3452 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3453 | main.cleanup() |
| 3454 | main.exit() |
| 3455 | |
| 3456 | def setTestSize( self, setName ): |
| 3457 | """ |
| 3458 | CLI command to get the elements in a distributed set. |
| 3459 | Required arguments: |
| 3460 | setName - The name of the set to remove from. |
| 3461 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3462 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3463 | None on error |
| 3464 | """ |
| 3465 | try: |
| 3466 | # TODO: Should this check against the number of elements returned |
| 3467 | # and then return true/false based on that? |
| 3468 | setName = str( setName ).strip() |
| 3469 | # Patterns to match |
| 3470 | setPattern = "\[(.*)\]" |
| 3471 | pattern = "There are (\d+) items in set " + setName + ":\n" +\ |
| 3472 | setPattern |
| 3473 | cmdStr = "set-test-get -s " |
| 3474 | cmdStr += setName |
| 3475 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3476 | try: |
| 3477 | # TODO: Maybe make this less hardcoded |
| 3478 | # ConsistentMap Exceptions |
| 3479 | assert "org.onosproject.store.service" not in output |
| 3480 | # Node not leader |
| 3481 | assert "java.lang.IllegalStateException" not in output |
| 3482 | except AssertionError: |
| 3483 | main.log.error( "Error in processing 'set-test-add' " + |
| 3484 | "command: " + str( output ) ) |
| 3485 | retryTime = 30 # Conservative time, given by Madan |
| 3486 | main.log.info( "Waiting " + str( retryTime ) + |
| 3487 | "seconds before retrying." ) |
| 3488 | time.sleep( retryTime ) # Due to change in mastership |
| 3489 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3490 | assert "Error executing command" not in output |
| 3491 | main.log.info( self.name + ": " + output ) |
| 3492 | match = re.search( pattern, output ) |
| 3493 | if match: |
| 3494 | setSize = int( match.group( 1 ) ) |
| 3495 | setMatch = match.group( 2 ) |
| 3496 | if len( setMatch.split() ) == setSize: |
| 3497 | main.log.info( "The size returned by " + self.name + |
| 3498 | " matches the number of elements in " + |
| 3499 | "the returned set" ) |
| 3500 | else: |
| 3501 | main.log.error( "The size returned by " + self.name + |
| 3502 | " does not match the number of " + |
| 3503 | "elements in the returned set." ) |
| 3504 | return setSize |
| 3505 | else: # no match |
| 3506 | main.log.error( self.name + ": setTestGet did not" + |
| 3507 | " match expected output" ) |
| 3508 | main.log.debug( self.name + " expected: " + pattern ) |
| 3509 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3510 | return None |
| 3511 | except AssertionError: |
| 3512 | main.log.error( "Error in processing 'set-test-get' command: " + |
| 3513 | str( output ) ) |
| 3514 | return None |
| 3515 | except TypeError: |
| 3516 | main.log.exception( self.name + ": Object not as expected" ) |
| 3517 | return None |
| 3518 | except pexpect.EOF: |
| 3519 | main.log.error( self.name + ": EOF exception found" ) |
| 3520 | main.log.error( self.name + ": " + self.handle.before ) |
| 3521 | main.cleanup() |
| 3522 | main.exit() |
| 3523 | except Exception: |
| 3524 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3525 | main.cleanup() |
| 3526 | main.exit() |
| 3527 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3528 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3529 | """ |
| 3530 | Command to list the various counters in the system. |
| 3531 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3532 | if jsonFormat, a string of the json object returned by the cli |
| 3533 | command |
| 3534 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3535 | None on error |
| 3536 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3537 | try: |
| 3538 | counters = {} |
| 3539 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3540 | if jsonFormat: |
| 3541 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3542 | output = self.sendline( cmdStr ) |
| 3543 | assert "Error executing command" not in output |
| 3544 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3545 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3546 | except AssertionError: |
| 3547 | main.log.error( "Error in processing 'counters' command: " + |
| 3548 | str( output ) ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3549 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3550 | except TypeError: |
| 3551 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3552 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3553 | except pexpect.EOF: |
| 3554 | main.log.error( self.name + ": EOF exception found" ) |
| 3555 | main.log.error( self.name + ": " + self.handle.before ) |
| 3556 | main.cleanup() |
| 3557 | main.exit() |
| 3558 | except Exception: |
| 3559 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3560 | main.cleanup() |
| 3561 | main.exit() |
| 3562 | |
| 3563 | def counterTestIncrement( self, counter, inMemory=False ): |
| 3564 | """ |
| 3565 | CLI command to increment and get a distributed counter. |
| 3566 | Required arguments: |
| 3567 | counter - The name of the counter to increment. |
| 3568 | Optional arguments: |
| 3569 | inMemory - use in memory map for the counter |
| 3570 | returns: |
| 3571 | integer value of the counter or |
| 3572 | None on Error |
| 3573 | """ |
| 3574 | try: |
| 3575 | counter = str( counter ) |
| 3576 | cmdStr = "counter-test-increment " |
| 3577 | if inMemory: |
| 3578 | cmdStr += "-i " |
| 3579 | cmdStr += counter |
| 3580 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3581 | try: |
| 3582 | # TODO: Maybe make this less hardcoded |
| 3583 | # ConsistentMap Exceptions |
| 3584 | assert "org.onosproject.store.service" not in output |
| 3585 | # Node not leader |
| 3586 | assert "java.lang.IllegalStateException" not in output |
| 3587 | except AssertionError: |
| 3588 | main.log.error( "Error in processing 'set-test-add' " + |
| 3589 | "command: " + str( output ) ) |
| 3590 | retryTime = 30 # Conservative time, given by Madan |
| 3591 | main.log.info( "Waiting " + str( retryTime ) + |
| 3592 | "seconds before retrying." ) |
| 3593 | time.sleep( retryTime ) # Due to change in mastership |
| 3594 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3595 | assert "Error executing command" not in output |
| 3596 | main.log.info( self.name + ": " + output ) |
| 3597 | pattern = counter + " was incremented to (\d+)" |
| 3598 | match = re.search( pattern, output ) |
| 3599 | if match: |
| 3600 | return int( match.group( 1 ) ) |
| 3601 | else: |
| 3602 | main.log.error( self.name + ": counterTestIncrement did not" + |
| 3603 | " match expected output." ) |
| 3604 | main.log.debug( self.name + " expected: " + pattern ) |
| 3605 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3606 | return None |
| 3607 | except AssertionError: |
| 3608 | main.log.error( "Error in processing 'counter-test-increment'" + |
| 3609 | " command: " + str( output ) ) |
| 3610 | return None |
| 3611 | except TypeError: |
| 3612 | main.log.exception( self.name + ": Object not as expected" ) |
| 3613 | return None |
| 3614 | except pexpect.EOF: |
| 3615 | main.log.error( self.name + ": EOF exception found" ) |
| 3616 | main.log.error( self.name + ": " + self.handle.before ) |
| 3617 | main.cleanup() |
| 3618 | main.exit() |
| 3619 | except Exception: |
| 3620 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3621 | main.cleanup() |
| 3622 | main.exit() |
| 3623 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 3624 | def summary( self, jsonFormat=True ): |
| 3625 | """ |
| 3626 | Description: Execute summary command in onos |
| 3627 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 3628 | no output |
| 3629 | |
| 3630 | """ |
| 3631 | try: |
| 3632 | cmdStr = "summary" |
| 3633 | if jsonFormat: |
| 3634 | cmdStr += " -j" |
| 3635 | handle = self.sendline( cmdStr ) |
| 3636 | |
| 3637 | if re.search( "Error:", handle ): |
| 3638 | main.log.error( self.name + ": summary() response: " + |
| 3639 | str( handle ) ) |
| 3640 | if not handle: |
| 3641 | main.log.error( self.name + ": There is no output in " + |
| 3642 | "summary command" ) |
| 3643 | return main.FALSE |
| 3644 | return handle |
| 3645 | except TypeError: |
| 3646 | main.log.exception( self.name + ": Object not as expected" ) |
| 3647 | return None |
| 3648 | except pexpect.EOF: |
| 3649 | main.log.error( self.name + ": EOF exception found" ) |
| 3650 | main.log.error( self.name + ": " + self.handle.before ) |
| 3651 | main.cleanup() |
| 3652 | main.exit() |
| 3653 | except Exception: |
| 3654 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3655 | main.cleanup() |
| 3656 | main.exit() |