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