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