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 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 22 | sys.path.append( "../" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 23 | from drivers.common.clidriver import CLI |
| 24 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 25 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 26 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 27 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 28 | def __init__( self ): |
| 29 | """ |
| 30 | Initialize client |
| 31 | """ |
| 32 | super( CLI, self ).__init__() |
| 33 | |
| 34 | def connect( self, **connectargs ): |
| 35 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 36 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 37 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 38 | try: |
| 39 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 40 | vars( self )[ key ] = connectargs[ key ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 41 | self.home = "~/ONOS" |
| 42 | for key in self.options: |
| 43 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 44 | self.home = self.options[ 'home' ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 45 | break |
kelvin-onlab | d6634ac | 2015-01-29 14:23:10 -0800 | [diff] [blame] | 46 | if self.home == None or self.home == "": |
| 47 | self.home = "~/ONOS" |
| 48 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 49 | self.name = self.options[ 'name' ] |
| 50 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 51 | user_name=self.user_name, |
| 52 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 53 | port=self.port, |
| 54 | pwd=self.pwd, |
| 55 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 56 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 57 | self.handle.sendline( "cd " + self.home ) |
| 58 | self.handle.expect( "\$" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 59 | if self.handle: |
| 60 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 61 | else: |
| 62 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 63 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 64 | except TypeError: |
| 65 | main.log.exception( self.name + ": Object not as expected" ) |
| 66 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 67 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 68 | main.log.error( self.name + ": EOF exception found" ) |
| 69 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 70 | main.cleanup() |
| 71 | main.exit() |
| 72 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 73 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 74 | main.cleanup() |
| 75 | main.exit() |
| 76 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 77 | def disconnect( self ): |
| 78 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 79 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 80 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 81 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 82 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 83 | self.handle.sendline( "" ) |
| 84 | i = self.handle.expect( [ "onos>", "\$" ] ) |
Jon Hall | 7e5b917 | 2014-10-22 12:32:47 -0400 | [diff] [blame] | 85 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 86 | self.handle.sendline( "system:shutdown" ) |
| 87 | self.handle.expect( "Confirm" ) |
| 88 | self.handle.sendline( "yes" ) |
| 89 | self.handle.expect( "\$" ) |
| 90 | self.handle.sendline( "" ) |
| 91 | self.handle.expect( "\$" ) |
| 92 | self.handle.sendline( "exit" ) |
| 93 | self.handle.expect( "closed" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 94 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 95 | except TypeError: |
| 96 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 97 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 98 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 99 | main.log.error( self.name + ": EOF exception found" ) |
| 100 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 101 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 102 | main.log.exception( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 103 | response = main.FALSE |
| 104 | return response |
| 105 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 106 | def logout( self ): |
| 107 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 108 | Sends 'logout' command to ONOS cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 109 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 110 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 111 | self.handle.sendline( "" ) |
| 112 | i = self.handle.expect( [ |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 113 | "onos>", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 114 | "\$" ], timeout=10 ) |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 115 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 116 | self.handle.sendline( "logout" ) |
| 117 | self.handle.expect( "\$" ) |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 118 | elif i == 1: |
| 119 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 120 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 121 | except TypeError: |
| 122 | main.log.exception( self.name + ": Object not as expected" ) |
| 123 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 124 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 125 | main.log.error( self.name + ": eof exception found" ) |
| 126 | main.log.error( self.name + ": " + |
| 127 | self.handle.before ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 128 | main.cleanup() |
| 129 | main.exit() |
| 130 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 131 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 132 | main.cleanup() |
| 133 | main.exit() |
| 134 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 135 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 136 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 137 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 138 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 139 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 140 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 141 | try: |
| 142 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 143 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 144 | main.cleanup() |
| 145 | main.exit() |
| 146 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 147 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 148 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 149 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 150 | # and that this driver will have to change accordingly |
Jon Hall | 1e03cb6 | 2015-02-19 12:07:12 -0800 | [diff] [blame] | 151 | self.handle.expect( "ONOS_CELL" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 152 | handleBefore = self.handle.before |
| 153 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 154 | # Get the rest of the handle |
| 155 | self.handle.sendline( "" ) |
| 156 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 157 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 158 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 159 | main.log.info( "Cell call returned: " + handleBefore + |
| 160 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 161 | |
| 162 | return main.TRUE |
| 163 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 164 | except TypeError: |
| 165 | main.log.exception( self.name + ": Object not as expected" ) |
| 166 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 167 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 168 | main.log.error( self.name + ": eof exception found" ) |
| 169 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 170 | main.cleanup() |
| 171 | main.exit() |
| 172 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 173 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 174 | main.cleanup() |
| 175 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 176 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 177 | def startOnosCli( self, ONOSIp, karafTimeout="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 178 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 179 | karafTimeout is an optional arugument. karafTimeout value passed |
| 180 | by user would be used to set the current karaf shell idle timeout. |
| 181 | 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] | 182 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 183 | Below is an example to start a session with 60 seconds idle timeout |
| 184 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 185 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 186 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 187 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 188 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 189 | Note: karafTimeout is left as str so that this could be read |
| 190 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 191 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 192 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 193 | self.handle.sendline( "" ) |
| 194 | x = self.handle.expect( [ |
| 195 | "\$", "onos>" ], timeout=10 ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 196 | |
| 197 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 198 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 199 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 200 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 201 | # Wait for onos start ( -w ) and enter onos cli |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 202 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 203 | i = self.handle.expect( [ |
| 204 | "onos>", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 205 | pexpect.TIMEOUT ], timeout=60 ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 206 | |
| 207 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 208 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 209 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 210 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 211 | "config:property-set -p org.apache.karaf.shell\ |
| 212 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 213 | karafTimeout ) |
| 214 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 215 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 216 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 217 | return main.TRUE |
| 218 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 219 | # If failed, send ctrl+c to process and try again |
| 220 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 221 | self.handle.send( "\x03" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 222 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 223 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 224 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 225 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 226 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 227 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 228 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 229 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 230 | "config:property-set -p org.apache.karaf.shell\ |
| 231 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 232 | karafTimeout ) |
| 233 | self.handle.expect( "\$" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 234 | self.handle.sendline( "onos -w " + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 235 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 236 | return main.TRUE |
| 237 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 238 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 239 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 240 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 241 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 242 | except TypeError: |
| 243 | main.log.exception( self.name + ": Object not as expected" ) |
| 244 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 245 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 246 | main.log.error( self.name + ": EOF exception found" ) |
| 247 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 248 | main.cleanup() |
| 249 | main.exit() |
| 250 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 251 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 252 | main.cleanup() |
| 253 | main.exit() |
| 254 | |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 255 | def log( self, cmdStr , level = "" ): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 256 | """ |
| 257 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 258 | returns main.TRUE on success |
| 259 | returns main.FALSE if Error occured |
| 260 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 261 | Level defaults to INFO |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 262 | """ |
| 263 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 264 | lvlStr = "" |
| 265 | if level: |
| 266 | lvlStr = "--level=" + level |
| 267 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 268 | self.handle.sendline( "" ) |
| 269 | self.handle.expect( "onos>" ) |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 270 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 271 | self.handle.expect( "onos>" ) |
| 272 | |
| 273 | response = self.handle.before |
| 274 | if re.search( "Error", response ): |
| 275 | return main.FALSE |
| 276 | return main.TRUE |
| 277 | |
| 278 | except pexpect.EOF: |
| 279 | main.log.error( self.name + ": EOF exception found" ) |
| 280 | main.log.error( self.name + ": " + self.handle.before ) |
| 281 | main.cleanup() |
| 282 | main.exit() |
| 283 | except: |
| 284 | main.log.info( self.name + " ::::::" ) |
| 285 | main.log.error( traceback.print_exc() ) |
| 286 | main.log.info( self.name + " ::::::" ) |
| 287 | main.cleanup() |
| 288 | main.exit() |
| 289 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 290 | def sendline( self, cmdStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 291 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 292 | Send a completely user specified string to |
| 293 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 294 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 295 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 296 | Warning: There are no sanity checking to commands |
| 297 | sent using this method. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 298 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 299 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 300 | |
| 301 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
| 302 | self.log( logStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 303 | self.handle.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 304 | self.handle.expect( "onos>" ) |
Jon Hall | aea67aa | 2015-01-23 13:30:57 -0800 | [diff] [blame] | 305 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
| 306 | + self.name + "." ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 307 | |
| 308 | handle = self.handle.before |
Jon Hall | 7bdfc12 | 2015-01-23 11:45:32 -0800 | [diff] [blame] | 309 | # Remove control strings from output |
| 310 | ansiEscape = re.compile( r'\x1b[^m]*m' ) |
| 311 | handle = ansiEscape.sub( '', handle ) |
Jon Hall | 44225f8 | 2015-01-23 13:45:14 -0800 | [diff] [blame] | 312 | #Remove extra return chars that get added |
Jon Hall | aea67aa | 2015-01-23 13:30:57 -0800 | [diff] [blame] | 313 | handle = re.sub( r"\s\r", "", handle ) |
| 314 | handle = handle.strip() |
Jon Hall | 7bdfc12 | 2015-01-23 11:45:32 -0800 | [diff] [blame] | 315 | # parse for just the output, remove the cmd from handle |
| 316 | output = handle.split( cmdStr, 1 )[1] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 317 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 318 | |
Jon Hall | 7bdfc12 | 2015-01-23 11:45:32 -0800 | [diff] [blame] | 319 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 320 | except TypeError: |
| 321 | main.log.exception( self.name + ": Object not as expected" ) |
| 322 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 323 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 324 | main.log.error( self.name + ": EOF exception found" ) |
| 325 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 326 | main.cleanup() |
| 327 | main.exit() |
| 328 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 329 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 330 | main.cleanup() |
| 331 | main.exit() |
| 332 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 333 | # IMPORTANT NOTE: |
| 334 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 335 | # the cli command changing 'a:b' with 'aB'. |
| 336 | # Ex ) onos:topology > onosTopology |
| 337 | # onos:links > onosLinks |
| 338 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 339 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 340 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 341 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 342 | Adds a new cluster node by ID and address information. |
| 343 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 344 | * nodeId |
| 345 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 346 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 347 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 348 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 349 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 350 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 351 | str( ONOSIp ) + " " + str( tcpPort ) |
| 352 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 353 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 354 | main.log.error( "Error in adding node" ) |
| 355 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 356 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 357 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 358 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 359 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 360 | except TypeError: |
| 361 | main.log.exception( self.name + ": Object not as expected" ) |
| 362 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 363 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 364 | main.log.error( self.name + ": EOF exception found" ) |
| 365 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 366 | main.cleanup() |
| 367 | main.exit() |
| 368 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 369 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 370 | main.cleanup() |
| 371 | main.exit() |
| 372 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 373 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 374 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 375 | Removes a cluster by ID |
| 376 | Issues command: 'remove-node [<node-id>]' |
| 377 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 378 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 379 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 380 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 381 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 382 | cmdStr = "remove-node " + str( nodeId ) |
| 383 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 384 | # TODO: add error checking. Does ONOS give any errors? |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 385 | |
| 386 | return main.TRUE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 387 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 388 | except TypeError: |
| 389 | main.log.exception( self.name + ": Object not as expected" ) |
| 390 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 391 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 392 | main.log.error( self.name + ": EOF exception found" ) |
| 393 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 394 | main.cleanup() |
| 395 | main.exit() |
| 396 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 397 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 398 | main.cleanup() |
| 399 | main.exit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 400 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 401 | def nodes( self ): |
| 402 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 403 | List the nodes currently visible |
| 404 | Issues command: 'nodes' |
| 405 | Returns: entire handle of list of nodes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 406 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 407 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 408 | cmdStr = "nodes" |
| 409 | handle = self.sendline( cmdStr ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 410 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 411 | except TypeError: |
| 412 | main.log.exception( self.name + ": Object not as expected" ) |
| 413 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 414 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 415 | main.log.error( self.name + ": EOF exception found" ) |
| 416 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 417 | main.cleanup() |
| 418 | main.exit() |
| 419 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 420 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 421 | main.cleanup() |
| 422 | main.exit() |
| 423 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 424 | def topology( self ): |
| 425 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 426 | Shows the current state of the topology |
| 427 | by issusing command: 'onos> onos:topology' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 428 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 429 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 430 | # either onos:topology or 'topology' will work in CLI |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 431 | cmdStr = "onos:topology" |
| 432 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 433 | main.log.info( "onos:topology returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 434 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 435 | except TypeError: |
| 436 | main.log.exception( self.name + ": Object not as expected" ) |
| 437 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 438 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 439 | main.log.error( self.name + ": EOF exception found" ) |
| 440 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 441 | main.cleanup() |
| 442 | main.exit() |
| 443 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 444 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 445 | main.cleanup() |
| 446 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 447 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 448 | def featureInstall( self, featureStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 449 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 450 | Installs a specified feature |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 451 | by issuing command: 'onos> feature:install <feature_str>' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 452 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 453 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 454 | cmdStr = "feature:install " + str( featureStr ) |
| 455 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 456 | # TODO: Check for possible error responses from karaf |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 457 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 458 | except TypeError: |
| 459 | main.log.exception( self.name + ": Object not as expected" ) |
| 460 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 461 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 462 | main.log.error( self.name + ": EOF exception found" ) |
| 463 | main.log.error( self.name + ": " + self.handle.before ) |
| 464 | main.log.report( "Failed to install feature" ) |
| 465 | main.log.report( "Exiting test" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 466 | main.cleanup() |
| 467 | main.exit() |
| 468 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 469 | main.log.exception( self.name + ": Uncaught exception!" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 470 | main.log.report( "Failed to install feature" ) |
| 471 | main.log.report( "Exiting test" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 472 | main.cleanup() |
| 473 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 474 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 475 | def featureUninstall( self, featureStr ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 476 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 477 | Uninstalls a specified feature |
| 478 | by issuing command: 'onos> feature:uninstall <feature_str>' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 479 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 480 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 481 | cmdStr = "feature:uninstall " + str( featureStr ) |
| 482 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 483 | # TODO: Check for possible error responses from karaf |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 484 | return main.TRUE |
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 | c2d05aa | 2014-10-13 16:51:10 -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 | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 491 | main.cleanup() |
| 492 | main.exit() |
| 493 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 494 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 495 | main.cleanup() |
| 496 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 497 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 498 | def devices( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 499 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 500 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 501 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 502 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 503 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 504 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 505 | if jsonFormat: |
| 506 | cmdStr = "devices -j" |
| 507 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 508 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 509 | handle variable here contains some ANSI escape color code |
| 510 | sequences at the end which are invisible in the print command |
| 511 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 512 | function. The repr( handle ) output when printed shows the |
| 513 | ANSI escape sequences. In json.loads( somestring ), this |
| 514 | somestring variable is actually repr( somestring ) and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 515 | json.loads would fail with the escape sequence. So we take off |
| 516 | that escape sequence using: |
| 517 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 518 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 519 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 520 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 521 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 522 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 523 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 524 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 525 | cmdStr = "devices" |
| 526 | handle = self.sendline( cmdStr ) |
Jon Hall | cd70729 | 2014-10-17 19:06:17 -0400 | [diff] [blame] | 527 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 528 | except TypeError: |
| 529 | main.log.exception( self.name + ": Object not as expected" ) |
| 530 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 531 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 532 | main.log.error( self.name + ": EOF exception found" ) |
| 533 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 534 | main.cleanup() |
| 535 | main.exit() |
| 536 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 537 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 538 | main.cleanup() |
| 539 | main.exit() |
| 540 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 541 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 542 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 543 | This balances the devices across all controllers |
| 544 | by issuing command: 'onos> onos:balance-masters' |
| 545 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 546 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 547 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 548 | cmdStr = "onos:balance-masters" |
| 549 | self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 550 | # TODO: Check for error responses from ONOS |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 551 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 552 | except TypeError: |
| 553 | main.log.exception( self.name + ": Object not as expected" ) |
| 554 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 555 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 556 | main.log.error( self.name + ": EOF exception found" ) |
| 557 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 558 | main.cleanup() |
| 559 | main.exit() |
| 560 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 561 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 562 | main.cleanup() |
| 563 | main.exit() |
| 564 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 565 | def links( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 566 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 567 | Lists all core links |
| 568 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 569 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 570 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 571 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 572 | if jsonFormat: |
| 573 | cmdStr = "links -j" |
| 574 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 575 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 576 | handle variable here contains some ANSI escape color code |
| 577 | sequences at the end which are invisible in the print command |
| 578 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 579 | function. The repr( handle ) output when printed shows the ANSI |
| 580 | escape sequences. In json.loads( somestring ), this somestring |
| 581 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 582 | fail with the escape sequence. So we take off that escape |
| 583 | sequence using: |
| 584 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 585 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 586 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 587 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 588 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 589 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 590 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 591 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 592 | cmdStr = "links" |
| 593 | handle = self.sendline( cmdStr ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 594 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 595 | except TypeError: |
| 596 | main.log.exception( self.name + ": Object not as expected" ) |
| 597 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 598 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 599 | main.log.error( self.name + ": EOF exception found" ) |
| 600 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 601 | main.cleanup() |
| 602 | main.exit() |
| 603 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 604 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 605 | main.cleanup() |
| 606 | main.exit() |
| 607 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 608 | def ports( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 609 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 610 | Lists all ports |
| 611 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 612 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 613 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 614 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 615 | if jsonFormat: |
| 616 | cmdStr = "ports -j" |
| 617 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 618 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 619 | handle variable here contains some ANSI escape color code |
| 620 | sequences at the end which are invisible in the print command |
| 621 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 622 | function. The repr( handle ) output when printed shows the ANSI |
| 623 | escape sequences. In json.loads( somestring ), this somestring |
| 624 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 625 | fail with the escape sequence. So we take off that escape |
| 626 | sequence using the following commads: |
| 627 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 628 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 629 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 630 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 631 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 632 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 633 | return handle1 |
| 634 | |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 635 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 636 | cmdStr = "ports" |
| 637 | handle = self.sendline( cmdStr ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 638 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 639 | except TypeError: |
| 640 | main.log.exception( self.name + ": Object not as expected" ) |
| 641 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 642 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 643 | main.log.error( self.name + ": EOF exception found" ) |
| 644 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 645 | main.cleanup() |
| 646 | main.exit() |
| 647 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 648 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 649 | main.cleanup() |
| 650 | main.exit() |
| 651 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 652 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 653 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 654 | Lists all devices and the controllers with roles assigned to them |
| 655 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 656 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 657 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 658 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 659 | if jsonFormat: |
| 660 | cmdStr = "roles -j" |
| 661 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 662 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 663 | handle variable here contains some ANSI escape color code |
| 664 | sequences at the end which are invisible in the print command |
| 665 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 666 | function. The repr( handle ) output when printed shows the ANSI |
| 667 | escape sequences. In json.loads( somestring ), this somestring |
| 668 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 669 | fail with the escape sequence. |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 670 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 671 | So we take off that escape sequence using the following |
| 672 | commads: |
| 673 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 674 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 675 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 676 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 677 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 678 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 679 | return handle1 |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 680 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 681 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 682 | cmdStr = "roles" |
| 683 | handle = self.sendline( cmdStr ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 684 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 685 | except TypeError: |
| 686 | main.log.exception( self.name + ": Object not as expected" ) |
| 687 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 688 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 689 | main.log.error( self.name + ": EOF exception found" ) |
| 690 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 691 | main.cleanup() |
| 692 | main.exit() |
| 693 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 694 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 695 | main.cleanup() |
| 696 | main.exit() |
| 697 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 698 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 699 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 700 | Given the a string containing the json representation of the "roles" |
| 701 | cli command and a partial or whole device id, returns a json object |
| 702 | containing the roles output for the first device whose id contains |
| 703 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 704 | |
| 705 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 706 | A dict of the role assignments for the given device or |
| 707 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 708 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 709 | try: |
| 710 | import json |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 711 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 712 | return None |
| 713 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 714 | rawRoles = self.roles() |
| 715 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 716 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 717 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 718 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 719 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 720 | return device |
| 721 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 722 | except TypeError: |
| 723 | main.log.exception( self.name + ": Object not as expected" ) |
| 724 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 725 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 726 | main.log.error( self.name + ": EOF exception found" ) |
| 727 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 728 | main.cleanup() |
| 729 | main.exit() |
| 730 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 731 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 732 | main.cleanup() |
| 733 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 734 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 735 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 736 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 737 | Iterates through each device and checks if there is a master assigned |
| 738 | Returns: main.TRUE if each device has a master |
| 739 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 740 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 741 | try: |
| 742 | import json |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 743 | rawRoles = self.roles() |
| 744 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 745 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 746 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 747 | # print device |
| 748 | if device[ 'master' ] == "none": |
| 749 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 750 | return main.FALSE |
| 751 | return main.TRUE |
| 752 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 753 | except TypeError: |
| 754 | main.log.exception( self.name + ": Object not as expected" ) |
| 755 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 756 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 757 | main.log.error( self.name + ": EOF exception found" ) |
| 758 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 759 | main.cleanup() |
| 760 | main.exit() |
| 761 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 762 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 763 | main.cleanup() |
| 764 | main.exit() |
| 765 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 766 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 767 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 768 | Returns string of paths, and the cost. |
| 769 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 770 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 771 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 772 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 773 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 774 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 775 | main.log.error( "Error in getting paths" ) |
| 776 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 777 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 778 | path = handle.split( ";" )[ 0 ] |
| 779 | cost = handle.split( ";" )[ 1 ] |
| 780 | return ( path, cost ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 781 | except TypeError: |
| 782 | main.log.exception( self.name + ": Object not as expected" ) |
| 783 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 784 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 785 | main.log.error( self.name + ": EOF exception found" ) |
| 786 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 787 | main.cleanup() |
| 788 | main.exit() |
| 789 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 790 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 791 | main.cleanup() |
| 792 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 793 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 794 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 795 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 796 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 797 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 798 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 799 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 800 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 801 | if jsonFormat: |
| 802 | cmdStr = "hosts -j" |
| 803 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 804 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 805 | handle variable here contains some ANSI escape color code |
| 806 | sequences at the end which are invisible in the print command |
| 807 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 808 | function. The repr( handle ) output when printed shows the ANSI |
| 809 | escape sequences. In json.loads( somestring ), this somestring |
| 810 | variable is actually repr( somestring ) and json.loads would |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 811 | fail with the escape sequence. So we take off that escape |
| 812 | sequence using: |
| 813 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 814 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 815 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 816 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 817 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 818 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 819 | return handle1 |
| 820 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 821 | cmdStr = "hosts" |
| 822 | handle = self.sendline( cmdStr ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 823 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 824 | except TypeError: |
| 825 | main.log.exception( self.name + ": Object not as expected" ) |
| 826 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 827 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 828 | main.log.error( self.name + ": EOF exception found" ) |
| 829 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 830 | main.cleanup() |
| 831 | main.exit() |
| 832 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 833 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 834 | main.cleanup() |
| 835 | main.exit() |
| 836 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 837 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 838 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 839 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 840 | |
| 841 | Note: mac must be a colon seperated mac address, but could be a |
| 842 | partial mac address |
| 843 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 844 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 845 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 846 | import json |
| 847 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 848 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 849 | return None |
| 850 | else: |
| 851 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 852 | rawHosts = self.hosts() |
| 853 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 854 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 855 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 856 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 857 | if not host: |
| 858 | pass |
| 859 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 860 | return host |
| 861 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 862 | except TypeError: |
| 863 | main.log.exception( self.name + ": Object not as expected" ) |
| 864 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 865 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 866 | main.log.error( self.name + ": EOF exception found" ) |
| 867 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 868 | main.cleanup() |
| 869 | main.exit() |
| 870 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 871 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 872 | main.cleanup() |
| 873 | main.exit() |
| 874 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 875 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 876 | """ |
| 877 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 878 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 879 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 880 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 881 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 882 | IMPORTANT: |
| 883 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 884 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 885 | Furthermore, it assumes that value of VLAN is '-1' |
| 886 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 887 | Converts mininet hosts ( h1, h2, h3... ) into |
| 888 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 889 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 890 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 891 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 892 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 893 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 894 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 895 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 896 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 897 | i = iter( str( hostHex ) ) |
| 898 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 899 | hostHex = hostHex + "/-1" |
| 900 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 901 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 902 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 903 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 904 | except TypeError: |
| 905 | main.log.exception( self.name + ": Object not as expected" ) |
| 906 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 907 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 908 | main.log.error( self.name + ": EOF exception found" ) |
| 909 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 910 | main.cleanup() |
| 911 | main.exit() |
| 912 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 913 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 914 | main.cleanup() |
| 915 | main.exit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 916 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 917 | def addHostIntent( self, hostIdOne, hostIdTwo ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 918 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 919 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 920 | * hostIdOne: ONOS host id for host1 |
| 921 | * hostIdTwo: ONOS host id for host2 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 922 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 923 | Adds a host-to-host intent ( bidrectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 924 | specifying the two hosts. |
Jon Hall | a5cb617 | 2015-02-23 09:28:28 -0800 | [diff] [blame^] | 925 | returns a string of the intent id or an Error message |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 926 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 927 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 928 | cmdStr = "add-host-intent " + str( hostIdOne ) +\ |
| 929 | " " + str( hostIdTwo ) |
| 930 | handle = self.sendline( cmdStr ) |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 931 | if re.search( "Error", handle ): |
| 932 | main.log.error( "Error in adding Host intent" ) |
| 933 | return handle |
| 934 | else: |
| 935 | main.log.info( "Host intent installed between " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 936 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Jon Hall | a5cb617 | 2015-02-23 09:28:28 -0800 | [diff] [blame^] | 937 | match = re.search('id=0x([\da-f]+),', handle) |
| 938 | if match: |
| 939 | return match.group()[3:-1] |
| 940 | else: |
| 941 | return handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 942 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 943 | except TypeError: |
| 944 | main.log.exception( self.name + ": Object not as expected" ) |
| 945 | return None |
Hari Krishna | ccfb0d5 | 2015-02-19 09:38:29 -0800 | [diff] [blame] | 946 | |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 947 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 948 | main.log.error( self.name + ": EOF exception found" ) |
| 949 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 950 | main.cleanup() |
| 951 | main.exit() |
| 952 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 953 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 954 | main.cleanup() |
| 955 | main.exit() |
| 956 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 957 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 958 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 959 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 960 | * ingressDevice: device id of ingress device |
| 961 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 962 | Optional: |
| 963 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 964 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 965 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 966 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 967 | " " + str( egressDevice ) |
| 968 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 969 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 970 | if re.search( "Error", handle ): |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 971 | return handle |
| 972 | else: |
| 973 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 974 | except TypeError: |
| 975 | main.log.exception( self.name + ": Object not as expected" ) |
| 976 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 977 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 978 | main.log.error( self.name + ": EOF exception found" ) |
| 979 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 980 | main.cleanup() |
| 981 | main.exit() |
| 982 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 983 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 984 | main.cleanup() |
| 985 | main.exit() |
| 986 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 987 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 988 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 989 | ingressDevice, |
| 990 | egressDevice, |
| 991 | portIngress="", |
| 992 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 993 | ethType="", |
| 994 | ethSrc="", |
| 995 | ethDst="", |
| 996 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 997 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 998 | ipProto="", |
| 999 | ipSrc="", |
| 1000 | ipDst="", |
| 1001 | tcpSrc="", |
| 1002 | tcpDst="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1003 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1004 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1005 | * ingressDevice: device id of ingress device |
| 1006 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1007 | Optional: |
| 1008 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1009 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1010 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1011 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1012 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1013 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1014 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1015 | * ipSrc: specify ip source address |
| 1016 | * ipDst: specify ip destination address |
| 1017 | * tcpSrc: specify tcp source port |
| 1018 | * tcpDst: specify tcp destination port |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1019 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1020 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1021 | specifying device id's and optional fields |
| 1022 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1023 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1024 | options developers provide for point-to-point |
| 1025 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1026 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1027 | try: |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1028 | cmd = "" |
| 1029 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1030 | # If there are no optional arguments |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1031 | if not ethType and not ethSrc and not ethDst\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1032 | and not bandwidth and not lambdaAlloc \ |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1033 | and not ipProto and not ipSrc and not ipDst \ |
| 1034 | and not tcpSrc and not tcpDst: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1035 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1036 | |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1037 | else: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1038 | cmd = "add-point-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1039 | |
andrewonlab | 0c0a677 | 2014-10-22 12:31:18 -0400 | [diff] [blame] | 1040 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1041 | cmd += " --ethType " + str( ethType ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1042 | if ethSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1043 | cmd += " --ethSrc " + str( ethSrc ) |
| 1044 | if ethDst: |
| 1045 | cmd += " --ethDst " + str( ethDst ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1046 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1047 | cmd += " --bandwidth " + str( bandwidth ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1048 | if lambdaAlloc: |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1049 | cmd += " --lambda " |
| 1050 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1051 | cmd += " --ipProto " + str( ipProto ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1052 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1053 | cmd += " --ipSrc " + str( ipSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1054 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1055 | cmd += " --ipDst " + str( ipDst ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1056 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1057 | cmd += " --tcpSrc " + str( tcpSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1058 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1059 | cmd += " --tcpDst " + str( tcpDst ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1060 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1061 | # Check whether the user appended the port |
| 1062 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1063 | if "/" in ingressDevice: |
| 1064 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1065 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1066 | if not portIngress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1067 | main.log.error( "You must specify " + |
| 1068 | "the ingress port" ) |
| 1069 | # TODO: perhaps more meaningful return |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1070 | return main.FALSE |
| 1071 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1072 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1073 | str( ingressDevice ) + "/" +\ |
| 1074 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1075 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1076 | if "/" in egressDevice: |
| 1077 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1078 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1079 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1080 | main.log.error( "You must specify " + |
| 1081 | "the egress port" ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1082 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1083 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1084 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1085 | str( egressDevice ) + "/" +\ |
| 1086 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1087 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1088 | handle = self.sendline( cmd ) |
| 1089 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1090 | main.log.error( "Error in adding point-to-point intent" ) |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 1091 | return main.FALSE |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1092 | else: |
| 1093 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1094 | except TypeError: |
| 1095 | main.log.exception( self.name + ": Object not as expected" ) |
| 1096 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1097 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1098 | main.log.error( self.name + ": EOF exception found" ) |
| 1099 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1100 | main.cleanup() |
| 1101 | main.exit() |
| 1102 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1103 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1104 | main.cleanup() |
| 1105 | main.exit() |
| 1106 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1107 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1108 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1109 | ingressDevice1, |
| 1110 | ingressDevice2, |
| 1111 | egressDevice, |
| 1112 | portIngress="", |
| 1113 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1114 | ethType="", |
| 1115 | ethSrc="", |
| 1116 | ethDst="", |
| 1117 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1118 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1119 | ipProto="", |
| 1120 | ipSrc="", |
| 1121 | ipDst="", |
| 1122 | tcpSrc="", |
| 1123 | tcpDst="", |
| 1124 | setEthSrc="", |
| 1125 | setEthDst="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1126 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1127 | Note: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1128 | This function assumes that there would be 2 ingress devices and |
| 1129 | one egress device. For more number of ingress devices, this |
| 1130 | function needs to be modified |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1131 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1132 | * ingressDevice1: device id of ingress device1 |
| 1133 | * ingressDevice2: device id of ingress device2 |
| 1134 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1135 | Optional: |
| 1136 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1137 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1138 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1139 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1140 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1141 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1142 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1143 | * ipSrc: specify ip source address |
| 1144 | * ipDst: specify ip destination address |
| 1145 | * tcpSrc: specify tcp source port |
| 1146 | * tcpDst: specify tcp destination port |
| 1147 | * setEthSrc: action to Rewrite Source MAC Address |
| 1148 | * setEthDst: action to Rewrite Destination MAC Address |
| 1149 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1150 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1151 | specifying device id's and optional fields |
| 1152 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1153 | NOTE: This function may change depending on the |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1154 | options developers provide for multipointpoint-to-singlepoint |
| 1155 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1156 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1157 | try: |
| 1158 | cmd = "" |
| 1159 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1160 | # If there are no optional arguments |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1161 | if not ethType and not ethSrc and not ethDst\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1162 | and not bandwidth and not lambdaAlloc\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1163 | and not ipProto and not ipSrc and not ipDst\ |
| 1164 | and not tcpSrc and not tcpDst and not setEthSrc\ |
| 1165 | and not setEthDst: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1166 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1167 | |
| 1168 | else: |
| 1169 | cmd = "add-multi-to-single-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1170 | |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1171 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1172 | cmd += " --ethType " + str( ethType ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1173 | if ethSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1174 | cmd += " --ethSrc " + str( ethSrc ) |
| 1175 | if ethDst: |
| 1176 | cmd += " --ethDst " + str( ethDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1177 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1178 | cmd += " --bandwidth " + str( bandwidth ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1179 | if lambdaAlloc: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1180 | cmd += " --lambda " |
| 1181 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1182 | cmd += " --ipProto " + str( ipProto ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1183 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1184 | cmd += " --ipSrc " + str( ipSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1185 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1186 | cmd += " --ipDst " + str( ipDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1187 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1188 | cmd += " --tcpSrc " + str( tcpSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1189 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1190 | cmd += " --tcpDst " + str( tcpDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1191 | if setEthSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1192 | cmd += " --setEthSrc " + str( setEthSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1193 | if setEthDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1194 | cmd += " --setEthDst " + str( setEthDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1195 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1196 | # Check whether the user appended the port |
| 1197 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1198 | if "/" in ingressDevice1: |
| 1199 | cmd += " " + str( ingressDevice1 ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1200 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1201 | if not portIngress1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1202 | main.log.error( "You must specify " + |
| 1203 | "the ingress port1" ) |
| 1204 | # TODO: perhaps more meaningful return |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1205 | return main.FALSE |
| 1206 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1207 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1208 | str( ingressDevice1 ) + "/" +\ |
| 1209 | str( portIngress1 ) + " " |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1210 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1211 | if "/" in ingressDevice2: |
| 1212 | cmd += " " + str( ingressDevice2 ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1213 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1214 | if not portIngress2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1215 | main.log.error( "You must specify " + |
| 1216 | "the ingress port2" ) |
| 1217 | # TODO: perhaps more meaningful return |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1218 | return main.FALSE |
| 1219 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1220 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1221 | str( ingressDevice2 ) + "/" +\ |
| 1222 | str( portIngress2 ) + " " |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1223 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1224 | if "/" in egressDevice: |
| 1225 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1226 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1227 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1228 | main.log.error( "You must specify " + |
| 1229 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1230 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1231 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1232 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1233 | str( egressDevice ) + "/" +\ |
| 1234 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1235 | print "cmd= ", cmd |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1236 | handle = self.sendline( cmd ) |
| 1237 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1238 | main.log.error( "Error in adding point-to-point intent" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1239 | return self.handle |
| 1240 | else: |
| 1241 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1242 | except TypeError: |
| 1243 | main.log.exception( self.name + ": Object not as expected" ) |
| 1244 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1245 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1246 | main.log.error( self.name + ": EOF exception found" ) |
| 1247 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1248 | main.cleanup() |
| 1249 | main.exit() |
| 1250 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1251 | main.log.exception( self.name + ": Uncaught exception!" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1252 | main.cleanup() |
| 1253 | main.exit() |
| 1254 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1255 | def removeIntent( self, intentId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1256 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1257 | Remove intent for specified intent id |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1258 | |
| 1259 | Returns: |
| 1260 | main.False on error and |
| 1261 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1262 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1263 | try: |
shahshreya | c033d02 | 2015-02-20 16:10:19 -0800 | [diff] [blame] | 1264 | cmdStr = "remove-intent org.onosproject.cli " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1265 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1266 | if re.search( "Error", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1267 | main.log.error( "Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1268 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1269 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1270 | # TODO: Should this be main.TRUE |
| 1271 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1272 | except TypeError: |
| 1273 | main.log.exception( self.name + ": Object not as expected" ) |
| 1274 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1275 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1276 | main.log.error( self.name + ": EOF exception found" ) |
| 1277 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1278 | main.cleanup() |
| 1279 | main.exit() |
| 1280 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1281 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1282 | main.cleanup() |
| 1283 | main.exit() |
| 1284 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1285 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1286 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1287 | NOTE: This method should be used after installing application: |
| 1288 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1289 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1290 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1291 | Description: |
| 1292 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1293 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1294 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1295 | if jsonFormat: |
| 1296 | cmdStr = "routes -j" |
| 1297 | handleTmp = self.sendline( cmdStr ) |
| 1298 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1299 | handle = ansiEscape.sub( '', handleTmp ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1300 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1301 | cmdStr = "routes" |
| 1302 | handle = self.sendline( cmdStr ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1303 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1304 | except TypeError: |
| 1305 | main.log.exception( self.name + ": Object not as expected" ) |
| 1306 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1307 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1308 | main.log.error( self.name + ": EOF exception found" ) |
| 1309 | main.log.error( self.name + ": " + self.handle.before ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1310 | main.cleanup() |
| 1311 | main.exit() |
| 1312 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1313 | main.log.exception( self.name + ": Uncaught exception!" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1314 | main.cleanup() |
| 1315 | main.exit() |
| 1316 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1317 | def intents( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1318 | """ |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1319 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1320 | * jsonFormat: enable output formatting in json |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1321 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1322 | Obtain intents currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1323 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1324 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1325 | if jsonFormat: |
| 1326 | cmdStr = "intents -j" |
| 1327 | handle = self.sendline( cmdStr ) |
| 1328 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1329 | handle = ansiEscape.sub( '', handle ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1330 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1331 | cmdStr = "intents" |
| 1332 | handle = self.sendline( cmdStr ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1333 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1334 | except TypeError: |
| 1335 | main.log.exception( self.name + ": Object not as expected" ) |
| 1336 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1337 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1338 | main.log.error( self.name + ": EOF exception found" ) |
| 1339 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1340 | main.cleanup() |
| 1341 | main.exit() |
| 1342 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1343 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1344 | main.cleanup() |
| 1345 | main.exit() |
| 1346 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1347 | def flows( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1348 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1349 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1350 | * jsonFormat: enable output formatting in json |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1351 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1352 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1353 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1354 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1355 | if jsonFormat: |
| 1356 | cmdStr = "flows -j" |
| 1357 | handle = self.sendline( cmdStr ) |
| 1358 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1359 | handle = ansiEscape.sub( '', handle ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1360 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1361 | cmdStr = "flows" |
| 1362 | handle = self.sendline( cmdStr ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1363 | if re.search( "Error\sexecuting\scommand:", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1364 | main.log.error( self.name + ".flows() response: " + |
| 1365 | str( handle ) ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1366 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1367 | except TypeError: |
| 1368 | main.log.exception( self.name + ": Object not as expected" ) |
| 1369 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1370 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1371 | main.log.error( self.name + ": EOF exception found" ) |
| 1372 | main.log.error( self.name + ": " + self.handle.before ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1373 | main.cleanup() |
| 1374 | main.exit() |
| 1375 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1376 | main.log.exception( self.name + ": Uncaught exception!" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1377 | main.cleanup() |
| 1378 | main.exit() |
| 1379 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1380 | def pushTestIntents( self, dpidSrc, dpidDst, numIntents, |
| 1381 | numMult="", appId="", report=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1382 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1383 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1384 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1385 | a specific point-to-point intent definition |
| 1386 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1387 | * dpidSrc: specify source dpid |
| 1388 | * dpidDst: specify destination dpid |
| 1389 | * numIntents: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1390 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1391 | * numMult: number multiplier for multiplying |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1392 | the number of intents specified |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1393 | * appId: specify the application id init to further |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1394 | modularize the intents |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1395 | * report: default True, returns latency information |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1396 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1397 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1398 | cmd = "push-test-intents " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1399 | str( dpidSrc ) + " " + str( dpidDst ) + " " +\ |
| 1400 | str( numIntents ) |
| 1401 | if numMult: |
| 1402 | cmd += " " + str( numMult ) |
| 1403 | # If app id is specified, then numMult |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1404 | # must exist because of the way this command |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1405 | if appId: |
| 1406 | cmd += " " + str( appId ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1407 | handle = self.sendline( cmd ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1408 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1409 | handle = ansiEscape.sub( '', handle ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1410 | if report: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1411 | latResult = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1412 | main.log.info( handle ) |
| 1413 | # Split result by newline |
| 1414 | newline = handle.split( "\r\r\n" ) |
| 1415 | # Ignore the first object of list, which is empty |
| 1416 | newline = newline[ 1: ] |
| 1417 | # Some sloppy parsing method to get the latency |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1418 | for result in newline: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1419 | result = result.split( ": " ) |
| 1420 | # Append the first result of second parse |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1421 | latResult.append( result[ 1 ].split( " " )[ 0 ] ) |
| 1422 | main.log.info( latResult ) |
| 1423 | return latResult |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1424 | else: |
| 1425 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1426 | except TypeError: |
| 1427 | main.log.exception( self.name + ": Object not as expected" ) |
| 1428 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1429 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1430 | main.log.error( self.name + ": EOF exception found" ) |
| 1431 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1432 | main.cleanup() |
| 1433 | main.exit() |
| 1434 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1435 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1436 | main.cleanup() |
| 1437 | main.exit() |
| 1438 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1439 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1440 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1441 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1442 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1443 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1444 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1445 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1446 | if jsonFormat: |
| 1447 | cmdStr = "intents-events-metrics -j" |
| 1448 | handle = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1449 | # Some color thing that we want to escape |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1450 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1451 | handle = ansiEscape.sub( '', handle ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1452 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1453 | cmdStr = "intents-events-metrics" |
| 1454 | handle = self.sendline( cmdStr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1455 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1456 | except TypeError: |
| 1457 | main.log.exception( self.name + ": Object not as expected" ) |
| 1458 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1459 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1460 | main.log.error( self.name + ": EOF exception found" ) |
| 1461 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1462 | main.cleanup() |
| 1463 | main.exit() |
| 1464 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1465 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1466 | main.cleanup() |
| 1467 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1468 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1469 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1470 | """ |
| 1471 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1472 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1473 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1474 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1475 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1476 | if jsonFormat: |
| 1477 | cmdStr = "topology-events-metrics -j" |
| 1478 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1479 | # Some color thing that we want to escape |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1480 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1481 | handle = ansiEscape.sub( '', handle ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1482 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1483 | cmdStr = "topology-events-metrics" |
| 1484 | handle = self.sendline( cmdStr ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1485 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1486 | except TypeError: |
| 1487 | main.log.exception( self.name + ": Object not as expected" ) |
| 1488 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1489 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1490 | main.log.error( self.name + ": EOF exception found" ) |
| 1491 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1492 | main.cleanup() |
| 1493 | main.exit() |
| 1494 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1495 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1496 | main.cleanup() |
| 1497 | main.exit() |
| 1498 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1499 | # Wrapper functions **************** |
| 1500 | # Wrapper functions use existing driver |
| 1501 | # functions and extends their use case. |
| 1502 | # For example, we may use the output of |
| 1503 | # a normal driver function, and parse it |
| 1504 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 1505 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1506 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1507 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1508 | Description: |
| 1509 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1510 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1511 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1512 | # Obtain output of intents function |
Jon Hall | a5cb617 | 2015-02-23 09:28:28 -0800 | [diff] [blame^] | 1513 | intentsStr = self.intents(jsonFormat=False) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1514 | intentIdList = [] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1515 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1516 | # Parse the intents output for ID's |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1517 | intentsList = [ s.strip() for s in intentsStr.splitlines() ] |
| 1518 | for intents in intentsList: |
Jon Hall | a5cb617 | 2015-02-23 09:28:28 -0800 | [diff] [blame^] | 1519 | match = re.search('id=0x([\da-f]+),', intents) |
| 1520 | if match: |
| 1521 | tmpId = match.group()[3:-1] |
| 1522 | intentIdList.append( tmpId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1523 | return intentIdList |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1524 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1525 | except TypeError: |
| 1526 | main.log.exception( self.name + ": Object not as expected" ) |
| 1527 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1528 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1529 | main.log.error( self.name + ": EOF exception found" ) |
| 1530 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1531 | main.cleanup() |
| 1532 | main.exit() |
| 1533 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1534 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1535 | main.cleanup() |
| 1536 | main.exit() |
| 1537 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1538 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1539 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1540 | Use 'devices' function to obtain list of all devices |
| 1541 | and parse the result to obtain a list of all device |
| 1542 | id's. Returns this list. Returns empty list if no |
| 1543 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1544 | List is ordered sequentially |
| 1545 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1546 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1547 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1548 | the ids. By obtaining the list of device ids on the fly, |
| 1549 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1550 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1551 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1552 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1553 | devicesStr = self.devices( jsonFormat=False ) |
| 1554 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1555 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1556 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1557 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1558 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1559 | |
| 1560 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1561 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1562 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1563 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1564 | # Split list further into arguments before and after string |
| 1565 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1566 | # append to idList |
| 1567 | for arg in tempList: |
| 1568 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 1569 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1570 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1571 | except TypeError: |
| 1572 | main.log.exception( self.name + ": Object not as expected" ) |
| 1573 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1574 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1575 | main.log.error( self.name + ": EOF exception found" ) |
| 1576 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1577 | main.cleanup() |
| 1578 | main.exit() |
| 1579 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1580 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1581 | main.cleanup() |
| 1582 | main.exit() |
| 1583 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1584 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1585 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1586 | Uses 'nodes' function to obtain list of all nodes |
| 1587 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1588 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1589 | Returns: |
| 1590 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1591 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1592 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1593 | nodesStr = self.nodes() |
| 1594 | idList = [] |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1595 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1596 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1597 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1598 | return idList |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1599 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1600 | # Sample nodesStr output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1601 | # id=local, address=127.0.0.1:9876, state=ACTIVE * |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1602 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1603 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1604 | nodesList = nodesStr.split( "," ) |
| 1605 | tempList = [ node for node in nodesList if "id=" in node ] |
| 1606 | for arg in tempList: |
| 1607 | idList.append( arg.split( "id=" )[ 1 ] ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1608 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1609 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1610 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1611 | except TypeError: |
| 1612 | main.log.exception( self.name + ": Object not as expected" ) |
| 1613 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1614 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1615 | main.log.error( self.name + ": EOF exception found" ) |
| 1616 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1617 | main.cleanup() |
| 1618 | main.exit() |
| 1619 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1620 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1621 | main.cleanup() |
| 1622 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 1623 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1624 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1625 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1626 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 1627 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1628 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1629 | import json |
| 1630 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1631 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1632 | return None |
| 1633 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1634 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1635 | rawDevices = self.devices() |
| 1636 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1637 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1638 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1639 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 1640 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1641 | return device |
| 1642 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1643 | except TypeError: |
| 1644 | main.log.exception( self.name + ": Object not as expected" ) |
| 1645 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1646 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1647 | main.log.error( self.name + ": EOF exception found" ) |
| 1648 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1649 | main.cleanup() |
| 1650 | main.exit() |
| 1651 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1652 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 1653 | main.cleanup() |
| 1654 | main.exit() |
| 1655 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1656 | def checkStatus( self, ip, numoswitch, numolink, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1657 | """ |
| 1658 | Checks the number of swithes & links that ONOS sees against the |
| 1659 | supplied values. By default this will report to main.log, but the |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1660 | log level can be specifid. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1661 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1662 | Params: ip = ip used for the onos cli |
| 1663 | numoswitch = expected number of switches |
| 1664 | numlink = expected number of links |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1665 | logLevel = level to log to. Currently accepts |
| 1666 | 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1667 | |
| 1668 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1669 | logLevel can |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1670 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1671 | Returns: main.TRUE if the number of switchs and links are correct, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1672 | main.FALSE if the numer of switches and links is incorrect, |
| 1673 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1674 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1675 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1676 | topology = self.getTopology( ip ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1677 | if topology == {}: |
| 1678 | return main.ERROR |
| 1679 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1680 | # Is the number of switches is what we expected |
| 1681 | devices = topology.get( 'devices', False ) |
| 1682 | links = topology.get( 'links', False ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1683 | if devices == False or links == False: |
| 1684 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1685 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1686 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1687 | linkCheck = ( int( links ) == int( numolink ) ) |
| 1688 | if ( switchCheck and linkCheck ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1689 | # We expected the correct numbers |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1690 | output = output + "The number of links and switches match "\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1691 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1692 | result = main.TRUE |
| 1693 | else: |
| 1694 | output = output + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1695 | "The number of links and switches does not matc\ |
| 1696 | h what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1697 | result = main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1698 | output = output + "\n ONOS sees %i devices (%i expected) \ |
| 1699 | and %i links (%i expected)" % ( |
| 1700 | int( devices ), int( numoswitch ), int( links ), |
| 1701 | int( numolink ) ) |
| 1702 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1703 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1704 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1705 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1706 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1707 | main.log.info( output ) |
| 1708 | return result |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1709 | except TypeError: |
| 1710 | main.log.exception( self.name + ": Object not as expected" ) |
| 1711 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1712 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1713 | main.log.error( self.name + ": EOF exception found" ) |
| 1714 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1715 | main.cleanup() |
| 1716 | main.exit() |
| 1717 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1718 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1719 | main.cleanup() |
| 1720 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1721 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1722 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1723 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1724 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1725 | deviceId must be the id of a device as seen in the onos devices command |
| 1726 | 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] | 1727 | role must be either master, standby, or none |
| 1728 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1729 | Returns: |
| 1730 | main.TRUE or main.FALSE based on argument verification and |
| 1731 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1732 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1733 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1734 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1735 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1736 | cmdStr = "device-role " +\ |
| 1737 | str( deviceId ) + " " +\ |
| 1738 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1739 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1740 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1741 | if re.search( "Error", handle ): |
| 1742 | # end color output to escape any colours |
| 1743 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1744 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1745 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1746 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1747 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1748 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1749 | main.log.error( "Invalid 'role' given to device_role(). " + |
| 1750 | "Value was '" + str(role) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1751 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1752 | except TypeError: |
| 1753 | main.log.exception( self.name + ": Object not as expected" ) |
| 1754 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1755 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1756 | main.log.error( self.name + ": EOF exception found" ) |
| 1757 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1758 | main.cleanup() |
| 1759 | main.exit() |
| 1760 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1761 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1762 | main.cleanup() |
| 1763 | main.exit() |
| 1764 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1765 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1766 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1767 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1768 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1769 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1770 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1771 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1772 | if jsonFormat: |
| 1773 | cmdStr = "clusters -j" |
| 1774 | handle = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1775 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1776 | handle variable here contains some ANSI escape color code |
| 1777 | sequences at the end which are invisible in the print command |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1778 | output. To make that escape sequence visible, use repr() |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1779 | function. The repr( handle ) output when printed shows the ANSI |
| 1780 | escape sequences. In json.loads( somestring ), this somestring |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1781 | variable is actually repr( somestring ) and json.loads would |
| 1782 | fail with the escape sequence. So we take off that escape |
| 1783 | sequence using: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1784 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1785 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1786 | handle1 = ansiEscape.sub( '', handle ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1787 | """ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1788 | ansiEscape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1789 | handle1 = ansiEscape.sub( '', handle ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1790 | return handle1 |
| 1791 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1792 | cmdStr = "clusters" |
| 1793 | handle = self.sendline( cmdStr ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1794 | return handle |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1795 | except TypeError: |
| 1796 | main.log.exception( self.name + ": Object not as expected" ) |
| 1797 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1798 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1799 | main.log.error( self.name + ": EOF exception found" ) |
| 1800 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1801 | main.cleanup() |
| 1802 | main.exit() |
| 1803 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1804 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1805 | main.cleanup() |
| 1806 | main.exit() |
| 1807 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1808 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1809 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1810 | CLI command to get the current leader for the Election test application |
| 1811 | NOTE: Requires installation of the onos-app-election feature |
| 1812 | Returns: Node IP of the leader if one exists |
| 1813 | None if none exists |
| 1814 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1815 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1816 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1817 | cmdStr = "election-test-leader" |
| 1818 | response = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1819 | # Leader |
| 1820 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1821 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1822 | nodeSearch = re.search( leaderPattern, response ) |
| 1823 | if nodeSearch: |
| 1824 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1825 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1826 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1827 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1828 | # no leader |
| 1829 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1830 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1831 | nullSearch = re.search( nullPattern, response ) |
| 1832 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1833 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1834 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1835 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1836 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1837 | errorPattern = "Command\snot\sfound" |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1838 | if re.search( errorPattern, response ): |
| 1839 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1840 | # TODO: Should this be main.ERROR? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1841 | return main.FALSE |
| 1842 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1843 | main.log.error( "Error in election_test_leader: " + |
| 1844 | "unexpected response" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1845 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1846 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1847 | except TypeError: |
| 1848 | main.log.exception( self.name + ": Object not as expected" ) |
| 1849 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1850 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1851 | main.log.error( self.name + ": EOF exception found" ) |
| 1852 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1853 | main.cleanup() |
| 1854 | main.exit() |
| 1855 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1856 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1857 | main.cleanup() |
| 1858 | main.exit() |
| 1859 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1860 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1861 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1862 | CLI command to run for leadership of the Election test application. |
| 1863 | NOTE: Requires installation of the onos-app-election feature |
| 1864 | Returns: Main.TRUE on success |
| 1865 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1866 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1867 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1868 | cmdStr = "election-test-run" |
| 1869 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1870 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1871 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1872 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1873 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1874 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1875 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1876 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1877 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1878 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1879 | errorPattern = "Command\snot\sfound" |
| 1880 | if re.search( errorPattern, response ): |
| 1881 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1882 | return main.FALSE |
| 1883 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1884 | main.log.error( "Error in election_test_run: " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1885 | "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1886 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1887 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1888 | except TypeError: |
| 1889 | main.log.exception( self.name + ": Object not as expected" ) |
| 1890 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1891 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1892 | main.log.error( self.name + ": EOF exception found" ) |
| 1893 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1894 | main.cleanup() |
| 1895 | main.exit() |
| 1896 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1897 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1898 | main.cleanup() |
| 1899 | main.exit() |
| 1900 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1901 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1902 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1903 | * CLI command to withdraw the local node from leadership election for |
| 1904 | * the Election test application. |
| 1905 | #NOTE: Requires installation of the onos-app-election feature |
| 1906 | Returns: Main.TRUE on success |
| 1907 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1908 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1909 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1910 | cmdStr = "election-test-withdraw" |
| 1911 | response = self.sendline( cmdStr ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1912 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1913 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1914 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1915 | if re.search( successPattern, response ): |
| 1916 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1917 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1918 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1919 | # error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1920 | errorPattern = "Command\snot\sfound" |
| 1921 | if re.search( errorPattern, response ): |
| 1922 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1923 | return main.FALSE |
| 1924 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1925 | main.log.error( "Error in election_test_withdraw: " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1926 | "unexpected response" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1927 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1928 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1929 | except TypeError: |
| 1930 | main.log.exception( self.name + ": Object not as expected" ) |
| 1931 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1932 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1933 | main.log.error( self.name + ": EOF exception found" ) |
| 1934 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1935 | main.cleanup() |
| 1936 | main.exit() |
| 1937 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1938 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1939 | main.cleanup() |
| 1940 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 1941 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1942 | def getDevicePortsEnabledCount( self, dpid ): |
| 1943 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1944 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1945 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1946 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1947 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1948 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 1949 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1950 | if re.search( "No such device", output ): |
| 1951 | main.log.error( "Error in getting ports" ) |
| 1952 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1953 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1954 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1955 | except TypeError: |
| 1956 | main.log.exception( self.name + ": Object not as expected" ) |
| 1957 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1958 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1959 | main.log.error( self.name + ": EOF exception found" ) |
| 1960 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1961 | main.cleanup() |
| 1962 | main.exit() |
| 1963 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1964 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1965 | main.cleanup() |
| 1966 | main.exit() |
| 1967 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1968 | def getDeviceLinksActiveCount( self, dpid ): |
| 1969 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1970 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1971 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1972 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1973 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1974 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 1975 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1976 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1977 | main.log.error( "Error in getting ports " ) |
| 1978 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1979 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1980 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1981 | except TypeError: |
| 1982 | main.log.exception( self.name + ": Object not as expected" ) |
| 1983 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1984 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1985 | main.log.error( self.name + ": EOF exception found" ) |
| 1986 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1987 | main.cleanup() |
| 1988 | main.exit() |
| 1989 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1990 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1991 | main.cleanup() |
| 1992 | main.exit() |
| 1993 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1994 | def getAllIntentIds( self ): |
| 1995 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1996 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1997 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1998 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1999 | cmdStr = "onos:intents | grep id=" |
| 2000 | output = self.sendline( cmdStr ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2001 | if re.search( "Error", output ): |
| 2002 | main.log.error( "Error in getting ports" ) |
| 2003 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2004 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2005 | return output |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2006 | except TypeError: |
| 2007 | main.log.exception( self.name + ": Object not as expected" ) |
| 2008 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2009 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2010 | main.log.error( self.name + ": EOF exception found" ) |
| 2011 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2012 | main.cleanup() |
| 2013 | main.exit() |
| 2014 | except: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2015 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2016 | main.cleanup() |
| 2017 | main.exit() |
| 2018 | |
| 2019 | def testExceptions( self, obj ): |
| 2020 | """ |
| 2021 | Test exception logging |
| 2022 | """ |
| 2023 | # FIXME: Remove this before you commit |
| 2024 | |
| 2025 | try: |
| 2026 | return obj[ 'dedf' ] |
| 2027 | except TypeError: |
| 2028 | main.log.exception( self.name + ": Object not as expected" ) |
| 2029 | return None |
| 2030 | except pexpect.EOF: |
| 2031 | main.log.error( self.name + ": EOF exception found" ) |
| 2032 | main.log.error( self.name + ": " + self.handle.before ) |
| 2033 | main.cleanup() |
| 2034 | main.exit() |
| 2035 | except: |
| 2036 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2037 | main.cleanup() |
| 2038 | main.exit() |