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