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 | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1737 | def checkIntentState( self, intentsId, expectedState = 'INSTALLED' ): |
| 1738 | """ |
| 1739 | Description: |
| 1740 | Check intents state |
| 1741 | Required: |
| 1742 | intentsId - List of intents ID to be checked |
| 1743 | Optional: |
| 1744 | expectedState - Check this expected state of each intents state |
| 1745 | in the list. Defaults to INSTALLED |
| 1746 | Return: |
| 1747 | Returns main.TRUE only if all intent are the same as expectedState, |
| 1748 | , otherwise,returns main.FALSE. |
| 1749 | """ |
| 1750 | try: |
| 1751 | # Generating a dictionary: intent id as a key and state as value |
| 1752 | intentsDict = self.getIntentState( intentsId ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 1753 | #print "len of intentsDict ", str( len( intentsDict ) ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1754 | if len( intentsId ) != len( intentsDict ): |
| 1755 | main.log.info( self.name + "There is something wrong " + |
| 1756 | "getting intents state" ) |
| 1757 | return main.FALSE |
| 1758 | returnValue = main.TRUE |
| 1759 | for intents in intentsDict: |
| 1760 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 1761 | if intents.get( 'state' ) == "INSTALLING": |
| 1762 | main.log.debug( self.name + " : Intent ID - " + |
| 1763 | intents.get( 'id' ) + |
| 1764 | " is in INSTALLING state" ) |
| 1765 | returnValue = main.TRUE |
| 1766 | else: |
| 1767 | main.log.info( self.name + " : Intent ID - " + |
| 1768 | intents.get( 'id' ) + |
| 1769 | " actual state = " + |
| 1770 | intents.get( 'state' ) |
| 1771 | + " does not equal expected state = " |
| 1772 | + expectedState ) |
| 1773 | returnValue = main.FALSE |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 1774 | if returnValue == main.TRUE: |
| 1775 | main.log.info( self.name + ": All " + |
| 1776 | str( len( intentsDict ) ) + |
| 1777 | " intents are in " + expectedState + " state") |
| 1778 | return returnValue |
| 1779 | except TypeError: |
| 1780 | main.log.exception( self.name + ": Object not as expected" ) |
| 1781 | return None |
| 1782 | except pexpect.EOF: |
| 1783 | main.log.error( self.name + ": EOF exception found" ) |
| 1784 | main.log.error( self.name + ": " + self.handle.before ) |
| 1785 | main.cleanup() |
| 1786 | main.exit() |
| 1787 | except Exception: |
| 1788 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1789 | main.cleanup() |
| 1790 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1791 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1792 | def flows( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1793 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1794 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1795 | * jsonFormat: enable output formatting in json |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1796 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1797 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1798 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1799 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1800 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1801 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1802 | cmdStr += " -j" |
| 1803 | handle = self.sendline( cmdStr ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1804 | if re.search( "Error:", handle ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 1805 | main.log.error( self.name + ": flows() response: " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1806 | str( handle ) ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1807 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1808 | except TypeError: |
| 1809 | main.log.exception( self.name + ": Object not as expected" ) |
| 1810 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1811 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1812 | main.log.error( self.name + ": EOF exception found" ) |
| 1813 | main.log.error( self.name + ": " + self.handle.before ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1814 | main.cleanup() |
| 1815 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1816 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1817 | main.log.exception( self.name + ": Uncaught exception!" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1818 | main.cleanup() |
| 1819 | main.exit() |
| 1820 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1821 | def checkFlowsState( self ): |
| 1822 | """ |
| 1823 | Description: |
| 1824 | Check the if all the current flows are in ADDED state or |
| 1825 | PENDING_ADD state |
| 1826 | Return: |
| 1827 | returnValue - Returns main.TRUE only if all flows are in |
| 1828 | ADDED state or PENDING_ADD, return main.FALSE |
| 1829 | otherwise. |
| 1830 | """ |
| 1831 | try: |
| 1832 | tempFlows = json.loads( self.flows() ) |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1833 | #print tempFlows[0] |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1834 | returnValue = main.TRUE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1835 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1836 | for device in tempFlows: |
| 1837 | for flow in device.get( 'flows' ): |
| 1838 | if flow.get( 'state' ) != 'ADDED' and flow.get( 'state' ) != \ |
| 1839 | 'PENDING_ADD': |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 1840 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1841 | main.log.info( self.name + ": flow Id: " + |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 1842 | str( flow.get( 'groupId' ) ) + |
| 1843 | " | state:" + |
| 1844 | str( flow.get( 'state' ) ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1845 | returnValue = main.FALSE |
kelvin-onlab | f0594d7 | 2015-05-19 17:25:12 -0700 | [diff] [blame] | 1846 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 1847 | return returnValue |
| 1848 | except TypeError: |
| 1849 | main.log.exception( self.name + ": Object not as expected" ) |
| 1850 | return None |
| 1851 | except pexpect.EOF: |
| 1852 | main.log.error( self.name + ": EOF exception found" ) |
| 1853 | main.log.error( self.name + ": " + self.handle.before ) |
| 1854 | main.cleanup() |
| 1855 | main.exit() |
| 1856 | except Exception: |
| 1857 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1858 | main.cleanup() |
| 1859 | main.exit() |
| 1860 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1861 | def pushTestIntents( self, dpidSrc, dpidDst, numIntents, |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1862 | numMult="", appId="", report=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1863 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1864 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1865 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1866 | a specific point-to-point intent definition |
| 1867 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1868 | * dpidSrc: specify source dpid |
| 1869 | * dpidDst: specify destination dpid |
| 1870 | * numIntents: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1871 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1872 | * numMult: number multiplier for multiplying |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1873 | the number of intents specified |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1874 | * appId: specify the application id init to further |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1875 | modularize the intents |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1876 | * report: default True, returns latency information |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1877 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1878 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1879 | cmd = "push-test-intents " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1880 | str( dpidSrc ) + " " + str( dpidDst ) + " " +\ |
| 1881 | str( numIntents ) |
| 1882 | if numMult: |
| 1883 | cmd += " " + str( numMult ) |
| 1884 | # If app id is specified, then numMult |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1885 | # must exist because of the way this command |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1886 | if appId: |
| 1887 | cmd += " " + str( appId ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1888 | handle = self.sendline( cmd ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1889 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1890 | latResult = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1891 | main.log.info( handle ) |
| 1892 | # Split result by newline |
| 1893 | newline = handle.split( "\r\r\n" ) |
| 1894 | # Ignore the first object of list, which is empty |
| 1895 | newline = newline[ 1: ] |
| 1896 | # Some sloppy parsing method to get the latency |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1897 | for result in newline: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1898 | result = result.split( ": " ) |
| 1899 | # Append the first result of second parse |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1900 | latResult.append( result[ 1 ].split( " " )[ 0 ] ) |
| 1901 | main.log.info( latResult ) |
| 1902 | return latResult |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1903 | else: |
| 1904 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1905 | except TypeError: |
| 1906 | main.log.exception( self.name + ": Object not as expected" ) |
| 1907 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1908 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1909 | main.log.error( self.name + ": EOF exception found" ) |
| 1910 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1911 | main.cleanup() |
| 1912 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1913 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1914 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1915 | main.cleanup() |
| 1916 | main.exit() |
| 1917 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1918 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1919 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1920 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1921 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1922 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1923 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1924 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1925 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1926 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1927 | cmdStr += " -j" |
| 1928 | handle = self.sendline( cmdStr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1929 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1930 | except TypeError: |
| 1931 | main.log.exception( self.name + ": Object not as expected" ) |
| 1932 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1933 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1934 | main.log.error( self.name + ": EOF exception found" ) |
| 1935 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1936 | main.cleanup() |
| 1937 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1938 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1939 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1940 | main.cleanup() |
| 1941 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1942 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1943 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1944 | """ |
| 1945 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1946 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1947 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1948 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1949 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1950 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1951 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1952 | cmdStr += " -j" |
| 1953 | handle = self.sendline( cmdStr ) |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 1954 | if handle: |
| 1955 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1956 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1957 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 1958 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1959 | else: |
| 1960 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1961 | except TypeError: |
| 1962 | main.log.exception( self.name + ": Object not as expected" ) |
| 1963 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1964 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1965 | main.log.error( self.name + ": EOF exception found" ) |
| 1966 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1967 | main.cleanup() |
| 1968 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1969 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1970 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1971 | main.cleanup() |
| 1972 | main.exit() |
| 1973 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1974 | # Wrapper functions **************** |
| 1975 | # Wrapper functions use existing driver |
| 1976 | # functions and extends their use case. |
| 1977 | # For example, we may use the output of |
| 1978 | # a normal driver function, and parse it |
| 1979 | # using a wrapper function |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1980 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1981 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1982 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1983 | Description: |
| 1984 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1985 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1986 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1987 | # Obtain output of intents function |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1988 | intentsStr = self.intents(jsonFormat=False) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1989 | intentIdList = [] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1990 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1991 | # Parse the intents output for ID's |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1992 | intentsList = [ s.strip() for s in intentsStr.splitlines() ] |
| 1993 | for intents in intentsList: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1994 | match = re.search('id=0x([\da-f]+),', intents) |
| 1995 | if match: |
| 1996 | tmpId = match.group()[3:-1] |
| 1997 | intentIdList.append( tmpId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1998 | return intentIdList |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1999 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2000 | except TypeError: |
| 2001 | main.log.exception( self.name + ": Object not as expected" ) |
| 2002 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2003 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2004 | main.log.error( self.name + ": EOF exception found" ) |
| 2005 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2006 | main.cleanup() |
| 2007 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2008 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2009 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2010 | main.cleanup() |
| 2011 | main.exit() |
| 2012 | |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2013 | def FlowAddedCount( self, deviceId ): |
| 2014 | """ |
| 2015 | Determine the number of flow rules for the given device id that are |
| 2016 | in the added state |
| 2017 | """ |
| 2018 | try: |
| 2019 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2020 | "grep 'state=ADDED' | wc -l" |
| 2021 | handle = self.sendline( cmdStr ) |
| 2022 | return handle |
| 2023 | except pexpect.EOF: |
| 2024 | main.log.error( self.name + ": EOF exception found" ) |
| 2025 | main.log.error( self.name + ": " + self.handle.before ) |
| 2026 | main.cleanup() |
| 2027 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2028 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2029 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2030 | main.cleanup() |
| 2031 | main.exit() |
| 2032 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2033 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2034 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2035 | Use 'devices' function to obtain list of all devices |
| 2036 | and parse the result to obtain a list of all device |
| 2037 | id's. Returns this list. Returns empty list if no |
| 2038 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2039 | List is ordered sequentially |
| 2040 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2041 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2042 | device id, and wish to execute other commands using |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2043 | the ids. By obtaining the list of device ids on the fly, |
| 2044 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2045 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2046 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2047 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2048 | devicesStr = self.devices( jsonFormat=False ) |
| 2049 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2050 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2051 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2052 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2053 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2054 | |
| 2055 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2056 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2057 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2058 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2059 | # Split list further into arguments before and after string |
| 2060 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2061 | # append to idList |
| 2062 | for arg in tempList: |
| 2063 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 2064 | return idList |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2065 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2066 | except TypeError: |
| 2067 | main.log.exception( self.name + ": Object not as expected" ) |
| 2068 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2069 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2070 | main.log.error( self.name + ": EOF exception found" ) |
| 2071 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2072 | main.cleanup() |
| 2073 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2074 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2075 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2076 | main.cleanup() |
| 2077 | main.exit() |
| 2078 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2079 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2080 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2081 | Uses 'nodes' function to obtain list of all nodes |
| 2082 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2083 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2084 | Returns: |
| 2085 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2086 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2087 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2088 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2089 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2090 | # Sample nodesStr output |
| 2091 | # id=local, address=127.0.0.1:9876, state=ACTIVE * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2092 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2093 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2094 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2095 | nodesJson = json.loads( nodesStr ) |
| 2096 | idList = [ node.get('id') for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2097 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2098 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2099 | except TypeError: |
| 2100 | main.log.exception( self.name + ": Object not as expected" ) |
| 2101 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2102 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2103 | main.log.error( self.name + ": EOF exception found" ) |
| 2104 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2105 | main.cleanup() |
| 2106 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2107 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2108 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2109 | main.cleanup() |
| 2110 | main.exit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2111 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2112 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2113 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2114 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 2115 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2116 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2117 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2118 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2119 | return None |
| 2120 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2121 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2122 | rawDevices = self.devices() |
| 2123 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2124 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2125 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2126 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 2127 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2128 | return device |
| 2129 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2130 | except TypeError: |
| 2131 | main.log.exception( self.name + ": Object not as expected" ) |
| 2132 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2133 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2134 | main.log.error( self.name + ": EOF exception found" ) |
| 2135 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2136 | main.cleanup() |
| 2137 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2138 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2139 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2140 | main.cleanup() |
| 2141 | main.exit() |
| 2142 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2143 | def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2144 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2145 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2146 | supplied values. By default this will report to main.log, but the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2147 | log level can be specified. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2148 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2149 | Params: ip = ip used for the onos cli |
| 2150 | numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2151 | numolink = expected number of links |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2152 | logLevel = level to log to. Currently accepts |
| 2153 | 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2154 | |
| 2155 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2156 | logLevel can |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2157 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2158 | Returns: main.TRUE if the number of switches and links are correct, |
| 2159 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2160 | and main.ERROR otherwise |
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 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2163 | topology = self.getTopology( ip ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2164 | if topology == {}: |
| 2165 | return main.ERROR |
| 2166 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2167 | # Is the number of switches is what we expected |
| 2168 | devices = topology.get( 'devices', False ) |
| 2169 | links = topology.get( 'links', False ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 2170 | if devices is False or links is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2171 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2172 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2173 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2174 | linkCheck = ( int( links ) == int( numolink ) ) |
| 2175 | if ( switchCheck and linkCheck ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2176 | # We expected the correct numbers |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2177 | output += "The number of links and switches match " +\ |
| 2178 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2179 | result = main.TRUE |
| 2180 | else: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2181 | output += "The number of links and switches does not match " +\ |
| 2182 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2183 | result = main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2184 | output = output + "\n ONOS sees %i devices (%i expected) \ |
| 2185 | and %i links (%i expected)" % ( |
| 2186 | int( devices ), int( numoswitch ), int( links ), |
| 2187 | int( numolink ) ) |
| 2188 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2189 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2190 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2191 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2192 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2193 | main.log.info( self.name + ": " + output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2194 | return result |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2195 | except TypeError: |
| 2196 | main.log.exception( self.name + ": Object not as expected" ) |
| 2197 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2198 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2199 | main.log.error( self.name + ": EOF exception found" ) |
| 2200 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2201 | main.cleanup() |
| 2202 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2203 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2204 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2205 | main.cleanup() |
| 2206 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2207 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2208 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2209 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2210 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2211 | deviceId must be the id of a device as seen in the onos devices command |
| 2212 | 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] | 2213 | role must be either master, standby, or none |
| 2214 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2215 | Returns: |
| 2216 | main.TRUE or main.FALSE based on argument verification and |
| 2217 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2218 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2219 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2220 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2221 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2222 | cmdStr = "device-role " +\ |
| 2223 | str( deviceId ) + " " +\ |
| 2224 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2225 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2226 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2227 | if re.search( "Error", handle ): |
| 2228 | # end color output to escape any colours |
| 2229 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2230 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2231 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2232 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2233 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2234 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2235 | main.log.error( "Invalid 'role' given to device_role(). " + |
| 2236 | "Value was '" + str(role) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2237 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2238 | except TypeError: |
| 2239 | main.log.exception( self.name + ": Object not as expected" ) |
| 2240 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2241 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2242 | main.log.error( self.name + ": EOF exception found" ) |
| 2243 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2244 | main.cleanup() |
| 2245 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2246 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2247 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2248 | main.cleanup() |
| 2249 | main.exit() |
| 2250 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2251 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2252 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2253 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 2254 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2255 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2256 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2257 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2258 | cmdStr = "clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2259 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2260 | cmdStr += " -j" |
| 2261 | handle = self.sendline( cmdStr ) |
| 2262 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2263 | except TypeError: |
| 2264 | main.log.exception( self.name + ": Object not as expected" ) |
| 2265 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2266 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2267 | main.log.error( self.name + ": EOF exception found" ) |
| 2268 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2269 | main.cleanup() |
| 2270 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2271 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2272 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2273 | main.cleanup() |
| 2274 | main.exit() |
| 2275 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2276 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2277 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2278 | CLI command to get the current leader for the Election test application |
| 2279 | NOTE: Requires installation of the onos-app-election feature |
| 2280 | Returns: Node IP of the leader if one exists |
| 2281 | None if none exists |
| 2282 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2283 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2284 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2285 | cmdStr = "election-test-leader" |
| 2286 | response = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2287 | # Leader |
| 2288 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2289 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2290 | nodeSearch = re.search( leaderPattern, response ) |
| 2291 | if nodeSearch: |
| 2292 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2293 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2294 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2295 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2296 | # no leader |
| 2297 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2298 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2299 | nullSearch = re.search( nullPattern, response ) |
| 2300 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2301 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2302 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2303 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2304 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2305 | errorPattern = "Command\snot\sfound" |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2306 | if re.search( errorPattern, response ): |
| 2307 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2308 | # TODO: Should this be main.ERROR? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2309 | return main.FALSE |
| 2310 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2311 | main.log.error( "Error in electionTestLeader on " + self.name + |
| 2312 | ": " + "unexpected response" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2313 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2314 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2315 | except TypeError: |
| 2316 | main.log.exception( self.name + ": Object not as expected" ) |
| 2317 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2318 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2319 | main.log.error( self.name + ": EOF exception found" ) |
| 2320 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2321 | main.cleanup() |
| 2322 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2323 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2324 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2325 | main.cleanup() |
| 2326 | main.exit() |
| 2327 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2328 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2329 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2330 | CLI command to run for leadership of the Election test application. |
| 2331 | NOTE: Requires installation of the onos-app-election feature |
| 2332 | Returns: Main.TRUE on success |
| 2333 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2334 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2335 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2336 | cmdStr = "election-test-run" |
| 2337 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2338 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2339 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2340 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2341 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2342 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2343 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2344 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2345 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2346 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2347 | errorPattern = "Command\snot\sfound" |
| 2348 | if re.search( errorPattern, response ): |
| 2349 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2350 | return main.FALSE |
| 2351 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2352 | main.log.error( "Error in electionTestRun on " + self.name + |
| 2353 | ": " + "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2354 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2355 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2356 | except TypeError: |
| 2357 | main.log.exception( self.name + ": Object not as expected" ) |
| 2358 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2359 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2360 | main.log.error( self.name + ": EOF exception found" ) |
| 2361 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2362 | main.cleanup() |
| 2363 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2364 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2365 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2366 | main.cleanup() |
| 2367 | main.exit() |
| 2368 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2369 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2370 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2371 | * CLI command to withdraw the local node from leadership election for |
| 2372 | * the Election test application. |
| 2373 | #NOTE: Requires installation of the onos-app-election feature |
| 2374 | Returns: Main.TRUE on success |
| 2375 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2376 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2377 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2378 | cmdStr = "election-test-withdraw" |
| 2379 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2380 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2381 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2382 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2383 | if re.search( successPattern, response ): |
| 2384 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2385 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2386 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2387 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2388 | errorPattern = "Command\snot\sfound" |
| 2389 | if re.search( errorPattern, response ): |
| 2390 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2391 | return main.FALSE |
| 2392 | else: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2393 | main.log.error( "Error in electionTestWithdraw on " + |
| 2394 | self.name + ": " + "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2395 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2396 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2397 | except TypeError: |
| 2398 | main.log.exception( self.name + ": Object not as expected" ) |
| 2399 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2400 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2401 | main.log.error( self.name + ": EOF exception found" ) |
| 2402 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2403 | main.cleanup() |
| 2404 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2405 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2406 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2407 | main.cleanup() |
| 2408 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2409 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2410 | def getDevicePortsEnabledCount( self, dpid ): |
| 2411 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2412 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2413 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2414 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2415 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2416 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 2417 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2418 | if re.search( "No such device", output ): |
| 2419 | main.log.error( "Error in getting ports" ) |
| 2420 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2421 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2422 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2423 | except TypeError: |
| 2424 | main.log.exception( self.name + ": Object not as expected" ) |
| 2425 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2426 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2427 | main.log.error( self.name + ": EOF exception found" ) |
| 2428 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2429 | main.cleanup() |
| 2430 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2431 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2432 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2433 | main.cleanup() |
| 2434 | main.exit() |
| 2435 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2436 | def getDeviceLinksActiveCount( self, dpid ): |
| 2437 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2438 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2439 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2440 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2441 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2442 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 2443 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2444 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2445 | main.log.error( "Error in getting ports " ) |
| 2446 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2447 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2448 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2449 | except TypeError: |
| 2450 | main.log.exception( self.name + ": Object not as expected" ) |
| 2451 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2452 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2453 | main.log.error( self.name + ": EOF exception found" ) |
| 2454 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2455 | main.cleanup() |
| 2456 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2457 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2458 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2459 | main.cleanup() |
| 2460 | main.exit() |
| 2461 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2462 | def getAllIntentIds( self ): |
| 2463 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2464 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2465 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2466 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2467 | cmdStr = "onos:intents | grep id=" |
| 2468 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2469 | if re.search( "Error", output ): |
| 2470 | main.log.error( "Error in getting ports" ) |
| 2471 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2472 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2473 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2474 | except TypeError: |
| 2475 | main.log.exception( self.name + ": Object not as expected" ) |
| 2476 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2477 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2478 | main.log.error( self.name + ": EOF exception found" ) |
| 2479 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2480 | main.cleanup() |
| 2481 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2482 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2483 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2484 | main.cleanup() |
| 2485 | main.exit() |
| 2486 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2487 | def intentSummary( self ): |
| 2488 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2489 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2490 | """ |
| 2491 | try: |
| 2492 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 2493 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2494 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 2495 | states.append( intent.get( 'state', None ) ) |
| 2496 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2497 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2498 | return dict( out ) |
| 2499 | except TypeError: |
| 2500 | main.log.exception( self.name + ": Object not as expected" ) |
| 2501 | return None |
| 2502 | except pexpect.EOF: |
| 2503 | main.log.error( self.name + ": EOF exception found" ) |
| 2504 | main.log.error( self.name + ": " + self.handle.before ) |
| 2505 | main.cleanup() |
| 2506 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2507 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 2508 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2509 | main.cleanup() |
| 2510 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2511 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2512 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2513 | """ |
| 2514 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2515 | Optional argument: |
| 2516 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2517 | """ |
| 2518 | # FIXME: add json output |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2519 | # Sample JSON |
| 2520 | # { |
| 2521 | # "electedTime": "13m ago", |
| 2522 | # "epoch": 4, |
| 2523 | # "leader": "10.128.30.17", |
| 2524 | # "topic": "intent-partition-3" |
| 2525 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2526 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2527 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2528 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2529 | cmdStr += " -j" |
| 2530 | output = self.sendline( cmdStr ) |
| 2531 | return output |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2532 | except TypeError: |
| 2533 | main.log.exception( self.name + ": Object not as expected" ) |
| 2534 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2535 | except pexpect.EOF: |
| 2536 | main.log.error( self.name + ": EOF exception found" ) |
| 2537 | main.log.error( self.name + ": " + self.handle.before ) |
| 2538 | main.cleanup() |
| 2539 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2540 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2541 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2542 | main.cleanup() |
| 2543 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2544 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2545 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2546 | """ |
| 2547 | Returns the output of the intent Pending map. |
| 2548 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2549 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2550 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2551 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2552 | cmdStr += " -j" |
| 2553 | output = self.sendline( cmdStr ) |
| 2554 | return output |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2555 | except TypeError: |
| 2556 | main.log.exception( self.name + ": Object not as expected" ) |
| 2557 | return None |
| 2558 | except pexpect.EOF: |
| 2559 | main.log.error( self.name + ": EOF exception found" ) |
| 2560 | main.log.error( self.name + ": " + self.handle.before ) |
| 2561 | main.cleanup() |
| 2562 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2563 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2564 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2565 | main.cleanup() |
| 2566 | main.exit() |
| 2567 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2568 | def partitions( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2569 | """ |
| 2570 | Returns the output of the raft partitions command for ONOS. |
| 2571 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2572 | # Sample JSON |
| 2573 | # { |
| 2574 | # "leader": "tcp://10.128.30.11:7238", |
| 2575 | # "members": [ |
| 2576 | # "tcp://10.128.30.11:7238", |
| 2577 | # "tcp://10.128.30.17:7238", |
| 2578 | # "tcp://10.128.30.13:7238", |
| 2579 | # ], |
| 2580 | # "name": "p1", |
| 2581 | # "term": 3 |
| 2582 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2583 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2584 | cmdStr = "onos:partitions" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2585 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2586 | cmdStr += " -j" |
| 2587 | output = self.sendline( cmdStr ) |
| 2588 | return output |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2589 | except TypeError: |
| 2590 | main.log.exception( self.name + ": Object not as expected" ) |
| 2591 | return None |
| 2592 | except pexpect.EOF: |
| 2593 | main.log.error( self.name + ": EOF exception found" ) |
| 2594 | main.log.error( self.name + ": " + self.handle.before ) |
| 2595 | main.cleanup() |
| 2596 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2597 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 2598 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2599 | main.cleanup() |
| 2600 | main.exit() |
| 2601 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2602 | def apps( self, jsonFormat=True ): |
| 2603 | """ |
| 2604 | Returns the output of the apps command for ONOS. This command lists |
| 2605 | information about installed ONOS applications |
| 2606 | """ |
| 2607 | # Sample JSON object |
| 2608 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
| 2609 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 2610 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
| 2611 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
| 2612 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2613 | cmdStr = "onos:apps" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2614 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2615 | cmdStr += " -j" |
| 2616 | output = self.sendline( cmdStr ) |
| 2617 | assert "Error executing command" not in output |
| 2618 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2619 | # FIXME: look at specific exceptions/Errors |
| 2620 | except AssertionError: |
| 2621 | main.log.error( "Error in processing onos:app command: " + |
| 2622 | str( output ) ) |
| 2623 | return None |
| 2624 | except TypeError: |
| 2625 | main.log.exception( self.name + ": Object not as expected" ) |
| 2626 | return None |
| 2627 | except pexpect.EOF: |
| 2628 | main.log.error( self.name + ": EOF exception found" ) |
| 2629 | main.log.error( self.name + ": " + self.handle.before ) |
| 2630 | main.cleanup() |
| 2631 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2632 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2633 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2634 | main.cleanup() |
| 2635 | main.exit() |
| 2636 | |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2637 | def appStatus( self, appName ): |
| 2638 | """ |
| 2639 | Uses the onos:apps cli command to return the status of an application. |
| 2640 | Returns: |
| 2641 | "ACTIVE" - If app is installed and activated |
| 2642 | "INSTALLED" - If app is installed and deactivated |
| 2643 | "UNINSTALLED" - If app is not installed |
| 2644 | None - on error |
| 2645 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2646 | try: |
| 2647 | if not isinstance( appName, types.StringType ): |
| 2648 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 2649 | " a string" ) |
| 2650 | return None |
| 2651 | output = self.apps( jsonFormat=True ) |
| 2652 | appsJson = json.loads( output ) |
| 2653 | state = None |
| 2654 | for app in appsJson: |
| 2655 | if appName == app.get('name'): |
| 2656 | state = app.get('state') |
| 2657 | break |
| 2658 | if state == "ACTIVE" or state == "INSTALLED": |
| 2659 | return state |
| 2660 | elif state is None: |
| 2661 | return "UNINSTALLED" |
| 2662 | elif state: |
| 2663 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 2664 | str( state ) ) |
| 2665 | return state |
| 2666 | except TypeError: |
| 2667 | main.log.exception( self.name + ": Object not as expected" ) |
| 2668 | return None |
| 2669 | except pexpect.EOF: |
| 2670 | main.log.error( self.name + ": EOF exception found" ) |
| 2671 | main.log.error( self.name + ": " + self.handle.before ) |
| 2672 | main.cleanup() |
| 2673 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2674 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2675 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2676 | main.cleanup() |
| 2677 | main.exit() |
| 2678 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2679 | def app( self, appName, option ): |
| 2680 | """ |
| 2681 | Interacts with the app command for ONOS. This command manages |
| 2682 | application inventory. |
| 2683 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2684 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2685 | # Validate argument types |
| 2686 | valid = True |
| 2687 | if not isinstance( appName, types.StringType ): |
| 2688 | main.log.error( self.name + ".app(): appName must be a " + |
| 2689 | "string" ) |
| 2690 | valid = False |
| 2691 | if not isinstance( option, types.StringType ): |
| 2692 | main.log.error( self.name + ".app(): option must be a string" ) |
| 2693 | valid = False |
| 2694 | if not valid: |
| 2695 | return main.FALSE |
| 2696 | # Validate Option |
| 2697 | option = option.lower() |
| 2698 | # NOTE: Install may become a valid option |
| 2699 | if option == "activate": |
| 2700 | pass |
| 2701 | elif option == "deactivate": |
| 2702 | pass |
| 2703 | elif option == "uninstall": |
| 2704 | pass |
| 2705 | else: |
| 2706 | # Invalid option |
| 2707 | main.log.error( "The ONOS app command argument only takes " + |
| 2708 | "the values: (activate|deactivate|uninstall)" + |
| 2709 | "; was given '" + option + "'") |
| 2710 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2711 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2712 | output = self.sendline( cmdStr ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2713 | if "Error executing command" in output: |
| 2714 | main.log.error( "Error in processing onos:app command: " + |
| 2715 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2716 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2717 | elif "No such application" in output: |
| 2718 | main.log.error( "The application '" + appName + |
| 2719 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2720 | return main.FALSE |
| 2721 | elif "Command not found:" in output: |
| 2722 | main.log.error( "Error in processing onos:app command: " + |
| 2723 | str( output ) ) |
| 2724 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2725 | elif "Unsupported command:" in output: |
| 2726 | main.log.error( "Incorrect command given to 'app': " + |
| 2727 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2728 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2729 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 2730 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2731 | return main.TRUE |
| 2732 | except TypeError: |
| 2733 | main.log.exception( self.name + ": Object not as expected" ) |
| 2734 | return main.ERROR |
| 2735 | except pexpect.EOF: |
| 2736 | main.log.error( self.name + ": EOF exception found" ) |
| 2737 | main.log.error( self.name + ": " + self.handle.before ) |
| 2738 | main.cleanup() |
| 2739 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2740 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2741 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2742 | main.cleanup() |
| 2743 | main.exit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2744 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2745 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2746 | """ |
| 2747 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2748 | appName is the hierarchical app name, not the feature name |
| 2749 | If check is True, method will check the status of the app after the |
| 2750 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2751 | Returns main.TRUE if the command was successfully sent |
| 2752 | main.FALSE if the cli responded with an error or given |
| 2753 | incorrect input |
| 2754 | """ |
| 2755 | try: |
| 2756 | if not isinstance( appName, types.StringType ): |
| 2757 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 2758 | " a string" ) |
| 2759 | return main.FALSE |
| 2760 | status = self.appStatus( appName ) |
| 2761 | if status == "INSTALLED": |
| 2762 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2763 | if check and response == main.TRUE: |
| 2764 | for i in range(10): # try 10 times then give up |
| 2765 | # TODO: Check with Thomas about this delay |
| 2766 | status = self.appStatus( appName ) |
| 2767 | if status == "ACTIVE": |
| 2768 | return main.TRUE |
| 2769 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 2770 | main.log.debug( "The state of application " + |
| 2771 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2772 | time.sleep( 1 ) |
| 2773 | return main.FALSE |
| 2774 | else: # not 'check' or command didn't succeed |
| 2775 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2776 | elif status == "ACTIVE": |
| 2777 | return main.TRUE |
| 2778 | elif status == "UNINSTALLED": |
| 2779 | main.log.error( self.name + ": Tried to activate the " + |
| 2780 | "application '" + appName + "' which is not " + |
| 2781 | "installed." ) |
| 2782 | else: |
| 2783 | main.log.error( "Unexpected return value from appStatus: " + |
| 2784 | str( status ) ) |
| 2785 | return main.ERROR |
| 2786 | except TypeError: |
| 2787 | main.log.exception( self.name + ": Object not as expected" ) |
| 2788 | return main.ERROR |
| 2789 | except pexpect.EOF: |
| 2790 | main.log.error( self.name + ": EOF exception found" ) |
| 2791 | main.log.error( self.name + ": " + self.handle.before ) |
| 2792 | main.cleanup() |
| 2793 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2794 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2795 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2796 | main.cleanup() |
| 2797 | main.exit() |
| 2798 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2799 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2800 | """ |
| 2801 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2802 | appName is the hierarchical app name, not the feature name |
| 2803 | If check is True, method will check the status of the app after the |
| 2804 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2805 | Returns main.TRUE if the command was successfully sent |
| 2806 | main.FALSE if the cli responded with an error or given |
| 2807 | incorrect input |
| 2808 | """ |
| 2809 | try: |
| 2810 | if not isinstance( appName, types.StringType ): |
| 2811 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 2812 | "be a string" ) |
| 2813 | return main.FALSE |
| 2814 | status = self.appStatus( appName ) |
| 2815 | if status == "INSTALLED": |
| 2816 | return main.TRUE |
| 2817 | elif status == "ACTIVE": |
| 2818 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2819 | if check and response == main.TRUE: |
| 2820 | for i in range(10): # try 10 times then give up |
| 2821 | status = self.appStatus( appName ) |
| 2822 | if status == "INSTALLED": |
| 2823 | return main.TRUE |
| 2824 | else: |
| 2825 | time.sleep( 1 ) |
| 2826 | return main.FALSE |
| 2827 | else: # not check or command didn't succeed |
| 2828 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2829 | elif status == "UNINSTALLED": |
| 2830 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 2831 | "application '" + appName + "' which is not " + |
| 2832 | "installed." ) |
| 2833 | return main.TRUE |
| 2834 | else: |
| 2835 | main.log.error( "Unexpected return value from appStatus: " + |
| 2836 | str( status ) ) |
| 2837 | return main.ERROR |
| 2838 | except TypeError: |
| 2839 | main.log.exception( self.name + ": Object not as expected" ) |
| 2840 | return main.ERROR |
| 2841 | except pexpect.EOF: |
| 2842 | main.log.error( self.name + ": EOF exception found" ) |
| 2843 | main.log.error( self.name + ": " + self.handle.before ) |
| 2844 | main.cleanup() |
| 2845 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2846 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2847 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2848 | main.cleanup() |
| 2849 | main.exit() |
| 2850 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2851 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2852 | """ |
| 2853 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2854 | appName is the hierarchical app name, not the feature name |
| 2855 | If check is True, method will check the status of the app after the |
| 2856 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2857 | Returns main.TRUE if the command was successfully sent |
| 2858 | main.FALSE if the cli responded with an error or given |
| 2859 | incorrect input |
| 2860 | """ |
| 2861 | # TODO: check with Thomas about the state machine for apps |
| 2862 | try: |
| 2863 | if not isinstance( appName, types.StringType ): |
| 2864 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 2865 | "be a string" ) |
| 2866 | return main.FALSE |
| 2867 | status = self.appStatus( appName ) |
| 2868 | if status == "INSTALLED": |
| 2869 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2870 | if check and response == main.TRUE: |
| 2871 | for i in range(10): # try 10 times then give up |
| 2872 | status = self.appStatus( appName ) |
| 2873 | if status == "UNINSTALLED": |
| 2874 | return main.TRUE |
| 2875 | else: |
| 2876 | time.sleep( 1 ) |
| 2877 | return main.FALSE |
| 2878 | else: # not check or command didn't succeed |
| 2879 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2880 | elif status == "ACTIVE": |
| 2881 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 2882 | "application '" + appName + "' which is " + |
| 2883 | "currently active." ) |
| 2884 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2885 | if check and response == main.TRUE: |
| 2886 | for i in range(10): # try 10 times then give up |
| 2887 | status = self.appStatus( appName ) |
| 2888 | if status == "UNINSTALLED": |
| 2889 | return main.TRUE |
| 2890 | else: |
| 2891 | time.sleep( 1 ) |
| 2892 | return main.FALSE |
| 2893 | else: # not check or command didn't succeed |
| 2894 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2895 | elif status == "UNINSTALLED": |
| 2896 | return main.TRUE |
| 2897 | else: |
| 2898 | main.log.error( "Unexpected return value from appStatus: " + |
| 2899 | str( status ) ) |
| 2900 | return main.ERROR |
| 2901 | except TypeError: |
| 2902 | main.log.exception( self.name + ": Object not as expected" ) |
| 2903 | return main.ERROR |
| 2904 | except pexpect.EOF: |
| 2905 | main.log.error( self.name + ": EOF exception found" ) |
| 2906 | main.log.error( self.name + ": " + self.handle.before ) |
| 2907 | main.cleanup() |
| 2908 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2909 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 2910 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2911 | main.cleanup() |
| 2912 | main.exit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2913 | |
| 2914 | def appIDs( self, jsonFormat=True ): |
| 2915 | """ |
| 2916 | Show the mappings between app id and app names given by the 'app-ids' |
| 2917 | cli command |
| 2918 | """ |
| 2919 | try: |
| 2920 | cmdStr = "app-ids" |
| 2921 | if jsonFormat: |
| 2922 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2923 | output = self.sendline( cmdStr ) |
| 2924 | assert "Error executing command" not in output |
| 2925 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2926 | except AssertionError: |
| 2927 | main.log.error( "Error in processing onos:app-ids command: " + |
| 2928 | str( output ) ) |
| 2929 | return None |
| 2930 | except TypeError: |
| 2931 | main.log.exception( self.name + ": Object not as expected" ) |
| 2932 | return None |
| 2933 | except pexpect.EOF: |
| 2934 | main.log.error( self.name + ": EOF exception found" ) |
| 2935 | main.log.error( self.name + ": " + self.handle.before ) |
| 2936 | main.cleanup() |
| 2937 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 2938 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2939 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2940 | main.cleanup() |
| 2941 | main.exit() |
| 2942 | |
| 2943 | def appToIDCheck( self ): |
| 2944 | """ |
| 2945 | This method will check that each application's ID listed in 'apps' is |
| 2946 | the same as the ID listed in 'app-ids'. The check will also check that |
| 2947 | there are no duplicate IDs issued. Note that an app ID should be |
| 2948 | a globaly unique numerical identifier for app/app-like features. Once |
| 2949 | an ID is registered, the ID is never freed up so that if an app is |
| 2950 | reinstalled it will have the same ID. |
| 2951 | |
| 2952 | Returns: main.TRUE if the check passes and |
| 2953 | main.FALSE if the check fails or |
| 2954 | main.ERROR if there is some error in processing the test |
| 2955 | """ |
| 2956 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2957 | bail = False |
| 2958 | ids = self.appIDs( jsonFormat=True ) |
| 2959 | if ids: |
| 2960 | ids = json.loads( ids ) |
| 2961 | else: |
| 2962 | main.log.error( "app-ids returned nothing:" + repr( ids ) ) |
| 2963 | bail = True |
| 2964 | apps = self.apps( jsonFormat=True ) |
| 2965 | if apps: |
| 2966 | apps = json.loads( apps ) |
| 2967 | else: |
| 2968 | main.log.error( "apps returned nothing:" + repr( apps ) ) |
| 2969 | bail = True |
| 2970 | if bail: |
| 2971 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2972 | result = main.TRUE |
| 2973 | for app in apps: |
| 2974 | appID = app.get( 'id' ) |
| 2975 | if appID is None: |
| 2976 | main.log.error( "Error parsing app: " + str( app ) ) |
| 2977 | result = main.FALSE |
| 2978 | appName = app.get( 'name' ) |
| 2979 | if appName is None: |
| 2980 | main.log.error( "Error parsing app: " + str( app ) ) |
| 2981 | result = main.FALSE |
| 2982 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2983 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 2984 | # main.log.debug( "Comparing " + str( app ) + " to " + |
| 2985 | # str( current ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 2986 | if not current: # if ids doesn't have this id |
| 2987 | result = main.FALSE |
| 2988 | main.log.error( "'app-ids' does not have the ID for " + |
| 2989 | str( appName ) + " that apps does." ) |
| 2990 | elif len( current ) > 1: |
| 2991 | # there is more than one app with this ID |
| 2992 | result = main.FALSE |
| 2993 | # We will log this later in the method |
| 2994 | elif not current[0][ 'name' ] == appName: |
| 2995 | currentName = current[0][ 'name' ] |
| 2996 | result = main.FALSE |
| 2997 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 2998 | " registered under id:" + str( appID ) + |
| 2999 | " but 'apps' has " + str( appName ) ) |
| 3000 | else: |
| 3001 | pass # id and name match! |
| 3002 | # now make sure that app-ids has no duplicates |
| 3003 | idsList = [] |
| 3004 | namesList = [] |
| 3005 | for item in ids: |
| 3006 | idsList.append( item[ 'id' ] ) |
| 3007 | namesList.append( item[ 'name' ] ) |
| 3008 | if len( idsList ) != len( set( idsList ) ) or\ |
| 3009 | len( namesList ) != len( set( namesList ) ): |
| 3010 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 3011 | + json.dumps( ids, |
| 3012 | sort_keys=True, |
| 3013 | indent=4, |
| 3014 | separators=( ',', ': ' ) ) ) |
| 3015 | result = main.FALSE |
| 3016 | return result |
| 3017 | except ( ValueError, TypeError ): |
| 3018 | main.log.exception( self.name + ": Object not as expected" ) |
| 3019 | return main.ERROR |
| 3020 | except pexpect.EOF: |
| 3021 | main.log.error( self.name + ": EOF exception found" ) |
| 3022 | main.log.error( self.name + ": " + self.handle.before ) |
| 3023 | main.cleanup() |
| 3024 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3025 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3026 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3027 | main.cleanup() |
| 3028 | main.exit() |
| 3029 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3030 | def getCfg( self, component=None, propName=None, short=False, |
| 3031 | jsonFormat=True ): |
| 3032 | """ |
| 3033 | Get configuration settings from onos cli |
| 3034 | Optional arguments: |
| 3035 | component - Optionally only list configurations for a specific |
| 3036 | component. If None, all components with configurations |
| 3037 | are displayed. Case Sensitive string. |
| 3038 | propName - If component is specified, propName option will show |
| 3039 | only this specific configuration from that component. |
| 3040 | Case Sensitive string. |
| 3041 | jsonFormat - Returns output as json. Note that this will override |
| 3042 | the short option |
| 3043 | short - Short, less verbose, version of configurations. |
| 3044 | This is overridden by the json option |
| 3045 | returns: |
| 3046 | Output from cli as a string or None on error |
| 3047 | """ |
| 3048 | try: |
| 3049 | baseStr = "cfg" |
| 3050 | cmdStr = " get" |
| 3051 | componentStr = "" |
| 3052 | if component: |
| 3053 | componentStr += " " + component |
| 3054 | if propName: |
| 3055 | componentStr += " " + propName |
| 3056 | if jsonFormat: |
| 3057 | baseStr += " -j" |
| 3058 | elif short: |
| 3059 | baseStr += " -s" |
| 3060 | output = self.sendline( baseStr + cmdStr + componentStr ) |
| 3061 | assert "Error executing command" not in output |
| 3062 | return output |
| 3063 | except AssertionError: |
| 3064 | main.log.error( "Error in processing 'cfg get' command: " + |
| 3065 | str( output ) ) |
| 3066 | return None |
| 3067 | except TypeError: |
| 3068 | main.log.exception( self.name + ": Object not as expected" ) |
| 3069 | return None |
| 3070 | except pexpect.EOF: |
| 3071 | main.log.error( self.name + ": EOF exception found" ) |
| 3072 | main.log.error( self.name + ": " + self.handle.before ) |
| 3073 | main.cleanup() |
| 3074 | main.exit() |
| 3075 | except Exception: |
| 3076 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3077 | main.cleanup() |
| 3078 | main.exit() |
| 3079 | |
| 3080 | def setCfg( self, component, propName, value=None, check=True ): |
| 3081 | """ |
| 3082 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3083 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3084 | component - The case sensitive name of the component whose |
| 3085 | property is to be set |
| 3086 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3087 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3088 | value - The value to set the property to. If None, will unset the |
| 3089 | property and revert it to it's default value(if applicable) |
| 3090 | check - Boolean, Check whether the option was successfully set this |
| 3091 | only applies when a value is given. |
| 3092 | returns: |
| 3093 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 3094 | will return main.TRUE unless there is an error |
| 3095 | """ |
| 3096 | try: |
| 3097 | baseStr = "cfg" |
| 3098 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 3099 | if value is not None: |
| 3100 | cmdStr += " " + str( value ) |
| 3101 | output = self.sendline( baseStr + cmdStr ) |
| 3102 | assert "Error executing command" not in output |
| 3103 | if value and check: |
| 3104 | results = self.getCfg( component=str( component ), |
| 3105 | propName=str( propName ), |
| 3106 | jsonFormat=True ) |
| 3107 | # Check if current value is what we just set |
| 3108 | try: |
| 3109 | jsonOutput = json.loads( results ) |
| 3110 | current = jsonOutput[ 'value' ] |
| 3111 | except ( ValueError, TypeError ): |
| 3112 | main.log.exception( "Error parsing cfg output" ) |
| 3113 | main.log.error( "output:" + repr( results ) ) |
| 3114 | return main.FALSE |
| 3115 | if current == str( value ): |
| 3116 | return main.TRUE |
| 3117 | return main.FALSE |
| 3118 | return main.TRUE |
| 3119 | except AssertionError: |
| 3120 | main.log.error( "Error in processing 'cfg set' command: " + |
| 3121 | str( output ) ) |
| 3122 | return main.FALSE |
| 3123 | except TypeError: |
| 3124 | main.log.exception( self.name + ": Object not as expected" ) |
| 3125 | return main.FALSE |
| 3126 | except pexpect.EOF: |
| 3127 | main.log.error( self.name + ": EOF exception found" ) |
| 3128 | main.log.error( self.name + ": " + self.handle.before ) |
| 3129 | main.cleanup() |
| 3130 | main.exit() |
| 3131 | except Exception: |
| 3132 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3133 | main.cleanup() |
| 3134 | main.exit() |
| 3135 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3136 | def setTestAdd( self, setName, values ): |
| 3137 | """ |
| 3138 | CLI command to add elements to a distributed set. |
| 3139 | Arguments: |
| 3140 | setName - The name of the set to add to. |
| 3141 | values - The value(s) to add to the set, space seperated. |
| 3142 | Example usages: |
| 3143 | setTestAdd( "set1", "a b c" ) |
| 3144 | setTestAdd( "set2", "1" ) |
| 3145 | returns: |
| 3146 | main.TRUE on success OR |
| 3147 | main.FALSE if elements were already in the set OR |
| 3148 | main.ERROR on error |
| 3149 | """ |
| 3150 | try: |
| 3151 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
| 3152 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3153 | try: |
| 3154 | # TODO: Maybe make this less hardcoded |
| 3155 | # ConsistentMap Exceptions |
| 3156 | assert "org.onosproject.store.service" not in output |
| 3157 | # Node not leader |
| 3158 | assert "java.lang.IllegalStateException" not in output |
| 3159 | except AssertionError: |
| 3160 | main.log.error( "Error in processing 'set-test-add' " + |
| 3161 | "command: " + str( output ) ) |
| 3162 | retryTime = 30 # Conservative time, given by Madan |
| 3163 | main.log.info( "Waiting " + str( retryTime ) + |
| 3164 | "seconds before retrying." ) |
| 3165 | time.sleep( retryTime ) # Due to change in mastership |
| 3166 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3167 | assert "Error executing command" not in output |
| 3168 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 3169 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
| 3170 | main.log.info( self.name + ": " + output ) |
| 3171 | if re.search( positiveMatch, output): |
| 3172 | return main.TRUE |
| 3173 | elif re.search( negativeMatch, output): |
| 3174 | return main.FALSE |
| 3175 | else: |
| 3176 | main.log.error( self.name + ": setTestAdd did not" + |
| 3177 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3178 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3179 | return main.ERROR |
| 3180 | except AssertionError: |
| 3181 | main.log.error( "Error in processing 'set-test-add' command: " + |
| 3182 | str( output ) ) |
| 3183 | return main.ERROR |
| 3184 | except TypeError: |
| 3185 | main.log.exception( self.name + ": Object not as expected" ) |
| 3186 | return main.ERROR |
| 3187 | except pexpect.EOF: |
| 3188 | main.log.error( self.name + ": EOF exception found" ) |
| 3189 | main.log.error( self.name + ": " + self.handle.before ) |
| 3190 | main.cleanup() |
| 3191 | main.exit() |
| 3192 | except Exception: |
| 3193 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3194 | main.cleanup() |
| 3195 | main.exit() |
| 3196 | |
| 3197 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 3198 | """ |
| 3199 | CLI command to remove elements from a distributed set. |
| 3200 | Required arguments: |
| 3201 | setName - The name of the set to remove from. |
| 3202 | values - The value(s) to remove from the set, space seperated. |
| 3203 | Optional arguments: |
| 3204 | clear - Clear all elements from the set |
| 3205 | retain - Retain only the given values. (intersection of the |
| 3206 | original set and the given set) |
| 3207 | returns: |
| 3208 | main.TRUE on success OR |
| 3209 | main.FALSE if the set was not changed OR |
| 3210 | main.ERROR on error |
| 3211 | """ |
| 3212 | try: |
| 3213 | cmdStr = "set-test-remove " |
| 3214 | if clear: |
| 3215 | cmdStr += "-c " + str( setName ) |
| 3216 | elif retain: |
| 3217 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 3218 | else: |
| 3219 | cmdStr += str( setName ) + " " + str( values ) |
| 3220 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3221 | try: |
| 3222 | # TODO: Maybe make this less hardcoded |
| 3223 | # ConsistentMap Exceptions |
| 3224 | assert "org.onosproject.store.service" not in output |
| 3225 | # Node not leader |
| 3226 | assert "java.lang.IllegalStateException" not in output |
| 3227 | except AssertionError: |
| 3228 | main.log.error( "Error in processing 'set-test-add' " + |
| 3229 | "command: " + str( output ) ) |
| 3230 | retryTime = 30 # Conservative time, given by Madan |
| 3231 | main.log.info( "Waiting " + str( retryTime ) + |
| 3232 | "seconds before retrying." ) |
| 3233 | time.sleep( retryTime ) # Due to change in mastership |
| 3234 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3235 | assert "Error executing command" not in output |
| 3236 | main.log.info( self.name + ": " + output ) |
| 3237 | if clear: |
| 3238 | pattern = "Set " + str( setName ) + " cleared" |
| 3239 | if re.search( pattern, output ): |
| 3240 | return main.TRUE |
| 3241 | elif retain: |
| 3242 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 3243 | "only elements of set \[(.*)\]" |
| 3244 | negativePattern = str( setName ) + " was not changed by " +\ |
| 3245 | "retaining only elements of the set " +\ |
| 3246 | "\[(.*)\]" |
| 3247 | if re.search( positivePattern, output ): |
| 3248 | return main.TRUE |
| 3249 | elif re.search( negativePattern, output ): |
| 3250 | return main.FALSE |
| 3251 | else: |
| 3252 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 3253 | str( setName ) |
| 3254 | if ( len( values.split() ) == 1 ): |
| 3255 | negativePattern = "\[(.*)\] was not in set " +\ |
| 3256 | str( setName ) |
| 3257 | else: |
| 3258 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 3259 | str( setName ) |
| 3260 | if re.search( positivePattern, output ): |
| 3261 | return main.TRUE |
| 3262 | elif re.search( negativePattern, output ): |
| 3263 | return main.FALSE |
| 3264 | main.log.error( self.name + ": setTestRemove did not" + |
| 3265 | " match expected output" ) |
| 3266 | main.log.debug( self.name + " expected: " + pattern ) |
| 3267 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3268 | return main.ERROR |
| 3269 | except AssertionError: |
| 3270 | main.log.error( "Error in processing 'set-test-remove' command: " + |
| 3271 | str( output ) ) |
| 3272 | return main.ERROR |
| 3273 | except TypeError: |
| 3274 | main.log.exception( self.name + ": Object not as expected" ) |
| 3275 | return main.ERROR |
| 3276 | except pexpect.EOF: |
| 3277 | main.log.error( self.name + ": EOF exception found" ) |
| 3278 | main.log.error( self.name + ": " + self.handle.before ) |
| 3279 | main.cleanup() |
| 3280 | main.exit() |
| 3281 | except Exception: |
| 3282 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3283 | main.cleanup() |
| 3284 | main.exit() |
| 3285 | |
| 3286 | def setTestGet( self, setName, values="" ): |
| 3287 | """ |
| 3288 | CLI command to get the elements in a distributed set. |
| 3289 | Required arguments: |
| 3290 | setName - The name of the set to remove from. |
| 3291 | Optional arguments: |
| 3292 | values - The value(s) to check if in the set, space seperated. |
| 3293 | returns: |
| 3294 | main.ERROR on error OR |
| 3295 | A list of elements in the set if no optional arguments are |
| 3296 | supplied OR |
| 3297 | A tuple containing the list then: |
| 3298 | main.FALSE if the given values are not in the set OR |
| 3299 | main.TRUE if the given values are in the set OR |
| 3300 | """ |
| 3301 | try: |
| 3302 | values = str( values ).strip() |
| 3303 | setName = str( setName ).strip() |
| 3304 | length = len( values.split() ) |
| 3305 | containsCheck = None |
| 3306 | # Patterns to match |
| 3307 | setPattern = "\[(.*)\]" |
| 3308 | pattern = "Items in set " + setName + ":\n" + setPattern |
| 3309 | containsTrue = "Set " + setName + " contains the value " + values |
| 3310 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 3311 | values |
| 3312 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 3313 | setPattern |
| 3314 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 3315 | " subset " + setPattern |
| 3316 | |
| 3317 | cmdStr = "set-test-get " |
| 3318 | cmdStr += setName + " " + values |
| 3319 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3320 | try: |
| 3321 | # TODO: Maybe make this less hardcoded |
| 3322 | # ConsistentMap Exceptions |
| 3323 | assert "org.onosproject.store.service" not in output |
| 3324 | # Node not leader |
| 3325 | assert "java.lang.IllegalStateException" not in output |
| 3326 | except AssertionError: |
| 3327 | main.log.error( "Error in processing 'set-test-add' " + |
| 3328 | "command: " + str( output ) ) |
| 3329 | retryTime = 30 # Conservative time, given by Madan |
| 3330 | main.log.info( "Waiting " + str( retryTime ) + |
| 3331 | "seconds before retrying." ) |
| 3332 | time.sleep( retryTime ) # Due to change in mastership |
| 3333 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3334 | assert "Error executing command" not in output |
| 3335 | main.log.info( self.name + ": " + output ) |
| 3336 | |
| 3337 | if length == 0: |
| 3338 | match = re.search( pattern, output ) |
| 3339 | else: # if given values |
| 3340 | if length == 1: # Contains output |
| 3341 | patternTrue = pattern + "\n" + containsTrue |
| 3342 | patternFalse = pattern + "\n" + containsFalse |
| 3343 | else: # ContainsAll output |
| 3344 | patternTrue = pattern + "\n" + containsAllTrue |
| 3345 | patternFalse = pattern + "\n" + containsAllFalse |
| 3346 | matchTrue = re.search( patternTrue, output ) |
| 3347 | matchFalse = re.search( patternFalse, output ) |
| 3348 | if matchTrue: |
| 3349 | containsCheck = main.TRUE |
| 3350 | match = matchTrue |
| 3351 | elif matchFalse: |
| 3352 | containsCheck = main.FALSE |
| 3353 | match = matchFalse |
| 3354 | else: |
| 3355 | main.log.error( self.name + " setTestGet did not match " +\ |
| 3356 | "expected output" ) |
| 3357 | main.log.debug( self.name + " expected: " + pattern ) |
| 3358 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3359 | match = None |
| 3360 | if match: |
| 3361 | setMatch = match.group( 1 ) |
| 3362 | if setMatch == '': |
| 3363 | setList = [] |
| 3364 | else: |
| 3365 | setList = setMatch.split( ", " ) |
| 3366 | if length > 0: |
| 3367 | return ( setList, containsCheck ) |
| 3368 | else: |
| 3369 | return setList |
| 3370 | else: # no match |
| 3371 | main.log.error( self.name + ": setTestGet did not" + |
| 3372 | " match expected output" ) |
| 3373 | main.log.debug( self.name + " expected: " + pattern ) |
| 3374 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3375 | return main.ERROR |
| 3376 | except AssertionError: |
| 3377 | main.log.error( "Error in processing 'set-test-get' command: " + |
| 3378 | str( output ) ) |
| 3379 | return main.ERROR |
| 3380 | except TypeError: |
| 3381 | main.log.exception( self.name + ": Object not as expected" ) |
| 3382 | return main.ERROR |
| 3383 | except pexpect.EOF: |
| 3384 | main.log.error( self.name + ": EOF exception found" ) |
| 3385 | main.log.error( self.name + ": " + self.handle.before ) |
| 3386 | main.cleanup() |
| 3387 | main.exit() |
| 3388 | except Exception: |
| 3389 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3390 | main.cleanup() |
| 3391 | main.exit() |
| 3392 | |
| 3393 | def setTestSize( self, setName ): |
| 3394 | """ |
| 3395 | CLI command to get the elements in a distributed set. |
| 3396 | Required arguments: |
| 3397 | setName - The name of the set to remove from. |
| 3398 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3399 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3400 | None on error |
| 3401 | """ |
| 3402 | try: |
| 3403 | # TODO: Should this check against the number of elements returned |
| 3404 | # and then return true/false based on that? |
| 3405 | setName = str( setName ).strip() |
| 3406 | # Patterns to match |
| 3407 | setPattern = "\[(.*)\]" |
| 3408 | pattern = "There are (\d+) items in set " + setName + ":\n" +\ |
| 3409 | setPattern |
| 3410 | cmdStr = "set-test-get -s " |
| 3411 | cmdStr += setName |
| 3412 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3413 | try: |
| 3414 | # TODO: Maybe make this less hardcoded |
| 3415 | # ConsistentMap Exceptions |
| 3416 | assert "org.onosproject.store.service" not in output |
| 3417 | # Node not leader |
| 3418 | assert "java.lang.IllegalStateException" not in output |
| 3419 | except AssertionError: |
| 3420 | main.log.error( "Error in processing 'set-test-add' " + |
| 3421 | "command: " + str( output ) ) |
| 3422 | retryTime = 30 # Conservative time, given by Madan |
| 3423 | main.log.info( "Waiting " + str( retryTime ) + |
| 3424 | "seconds before retrying." ) |
| 3425 | time.sleep( retryTime ) # Due to change in mastership |
| 3426 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3427 | assert "Error executing command" not in output |
| 3428 | main.log.info( self.name + ": " + output ) |
| 3429 | match = re.search( pattern, output ) |
| 3430 | if match: |
| 3431 | setSize = int( match.group( 1 ) ) |
| 3432 | setMatch = match.group( 2 ) |
| 3433 | if len( setMatch.split() ) == setSize: |
| 3434 | main.log.info( "The size returned by " + self.name + |
| 3435 | " matches the number of elements in " + |
| 3436 | "the returned set" ) |
| 3437 | else: |
| 3438 | main.log.error( "The size returned by " + self.name + |
| 3439 | " does not match the number of " + |
| 3440 | "elements in the returned set." ) |
| 3441 | return setSize |
| 3442 | else: # no match |
| 3443 | main.log.error( self.name + ": setTestGet did not" + |
| 3444 | " match expected output" ) |
| 3445 | main.log.debug( self.name + " expected: " + pattern ) |
| 3446 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3447 | return None |
| 3448 | except AssertionError: |
| 3449 | main.log.error( "Error in processing 'set-test-get' command: " + |
| 3450 | str( output ) ) |
| 3451 | return None |
| 3452 | except TypeError: |
| 3453 | main.log.exception( self.name + ": Object not as expected" ) |
| 3454 | return None |
| 3455 | except pexpect.EOF: |
| 3456 | main.log.error( self.name + ": EOF exception found" ) |
| 3457 | main.log.error( self.name + ": " + self.handle.before ) |
| 3458 | main.cleanup() |
| 3459 | main.exit() |
| 3460 | except Exception: |
| 3461 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3462 | main.cleanup() |
| 3463 | main.exit() |
| 3464 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3465 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3466 | """ |
| 3467 | Command to list the various counters in the system. |
| 3468 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3469 | if jsonFormat, a string of the json object returned by the cli |
| 3470 | command |
| 3471 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3472 | None on error |
| 3473 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3474 | try: |
| 3475 | counters = {} |
| 3476 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3477 | if jsonFormat: |
| 3478 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3479 | output = self.sendline( cmdStr ) |
| 3480 | assert "Error executing command" not in output |
| 3481 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3482 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3483 | except AssertionError: |
| 3484 | main.log.error( "Error in processing 'counters' command: " + |
| 3485 | str( output ) ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3486 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3487 | except TypeError: |
| 3488 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 3489 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3490 | except pexpect.EOF: |
| 3491 | main.log.error( self.name + ": EOF exception found" ) |
| 3492 | main.log.error( self.name + ": " + self.handle.before ) |
| 3493 | main.cleanup() |
| 3494 | main.exit() |
| 3495 | except Exception: |
| 3496 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3497 | main.cleanup() |
| 3498 | main.exit() |
| 3499 | |
| 3500 | def counterTestIncrement( self, counter, inMemory=False ): |
| 3501 | """ |
| 3502 | CLI command to increment and get a distributed counter. |
| 3503 | Required arguments: |
| 3504 | counter - The name of the counter to increment. |
| 3505 | Optional arguments: |
| 3506 | inMemory - use in memory map for the counter |
| 3507 | returns: |
| 3508 | integer value of the counter or |
| 3509 | None on Error |
| 3510 | """ |
| 3511 | try: |
| 3512 | counter = str( counter ) |
| 3513 | cmdStr = "counter-test-increment " |
| 3514 | if inMemory: |
| 3515 | cmdStr += "-i " |
| 3516 | cmdStr += counter |
| 3517 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3518 | try: |
| 3519 | # TODO: Maybe make this less hardcoded |
| 3520 | # ConsistentMap Exceptions |
| 3521 | assert "org.onosproject.store.service" not in output |
| 3522 | # Node not leader |
| 3523 | assert "java.lang.IllegalStateException" not in output |
| 3524 | except AssertionError: |
| 3525 | main.log.error( "Error in processing 'set-test-add' " + |
| 3526 | "command: " + str( output ) ) |
| 3527 | retryTime = 30 # Conservative time, given by Madan |
| 3528 | main.log.info( "Waiting " + str( retryTime ) + |
| 3529 | "seconds before retrying." ) |
| 3530 | time.sleep( retryTime ) # Due to change in mastership |
| 3531 | output = self.sendline( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3532 | assert "Error executing command" not in output |
| 3533 | main.log.info( self.name + ": " + output ) |
| 3534 | pattern = counter + " was incremented to (\d+)" |
| 3535 | match = re.search( pattern, output ) |
| 3536 | if match: |
| 3537 | return int( match.group( 1 ) ) |
| 3538 | else: |
| 3539 | main.log.error( self.name + ": counterTestIncrement did not" + |
| 3540 | " match expected output." ) |
| 3541 | main.log.debug( self.name + " expected: " + pattern ) |
| 3542 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3543 | return None |
| 3544 | except AssertionError: |
| 3545 | main.log.error( "Error in processing 'counter-test-increment'" + |
| 3546 | " command: " + str( output ) ) |
| 3547 | return None |
| 3548 | except TypeError: |
| 3549 | main.log.exception( self.name + ": Object not as expected" ) |
| 3550 | return None |
| 3551 | except pexpect.EOF: |
| 3552 | main.log.error( self.name + ": EOF exception found" ) |
| 3553 | main.log.error( self.name + ": " + self.handle.before ) |
| 3554 | main.cleanup() |
| 3555 | main.exit() |
| 3556 | except Exception: |
| 3557 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3558 | main.cleanup() |
| 3559 | main.exit() |
| 3560 | |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 3561 | def summary( self, jsonFormat=True ): |
| 3562 | """ |
| 3563 | Description: Execute summary command in onos |
| 3564 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 3565 | no output |
| 3566 | |
| 3567 | """ |
| 3568 | try: |
| 3569 | cmdStr = "summary" |
| 3570 | if jsonFormat: |
| 3571 | cmdStr += " -j" |
| 3572 | handle = self.sendline( cmdStr ) |
| 3573 | |
| 3574 | if re.search( "Error:", handle ): |
| 3575 | main.log.error( self.name + ": summary() response: " + |
| 3576 | str( handle ) ) |
| 3577 | if not handle: |
| 3578 | main.log.error( self.name + ": There is no output in " + |
| 3579 | "summary command" ) |
| 3580 | return main.FALSE |
| 3581 | return handle |
| 3582 | except TypeError: |
| 3583 | main.log.exception( self.name + ": Object not as expected" ) |
| 3584 | return None |
| 3585 | except pexpect.EOF: |
| 3586 | main.log.error( self.name + ": EOF exception found" ) |
| 3587 | main.log.error( self.name + ": " + self.handle.before ) |
| 3588 | main.cleanup() |
| 3589 | main.exit() |
| 3590 | except Exception: |
| 3591 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3592 | main.cleanup() |
| 3593 | main.exit() |