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