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