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 |
| 22 | import traceback |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 23 | # import os.path |
| 24 | sys.path.append( "../" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 25 | from drivers.common.clidriver import CLI |
| 26 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 27 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 28 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 29 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 30 | def __init__( self ): |
| 31 | """ |
| 32 | Initialize client |
| 33 | """ |
| 34 | super( CLI, self ).__init__() |
| 35 | |
| 36 | def connect( self, **connectargs ): |
| 37 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 38 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 39 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 40 | try: |
| 41 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 42 | vars( self )[ key ] = connectargs[ key ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 43 | self.home = "~/ONOS" |
| 44 | for key in self.options: |
| 45 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 46 | self.home = self.options[ 'home' ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 47 | break |
| 48 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 49 | self.name = self.options[ 'name' ] |
| 50 | self.handle = super( OnosCliDriver, self ).connect( |
| 51 | user_name=self.user_name, |
| 52 | ip_address=self.ip_address, |
| 53 | port=self.port, |
| 54 | pwd=self.pwd, |
| 55 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 56 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 57 | self.handle.sendline( "cd " + self.home ) |
| 58 | self.handle.expect( "\$" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 59 | if self.handle: |
| 60 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 61 | else: |
| 62 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 63 | return main.FALSE |
| 64 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 65 | main.log.error( self.name + ": EOF exception found" ) |
| 66 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 67 | main.cleanup() |
| 68 | main.exit() |
| 69 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 70 | main.log.info( self.name + ":::::::::::::::::::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 71 | main.log.error( traceback.print_exc() ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 72 | main.log.info( ":::::::::::::::::::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 73 | main.cleanup() |
| 74 | main.exit() |
| 75 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 76 | def disconnect( self ): |
| 77 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 78 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 79 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 80 | response = '' |
| 81 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 82 | self.handle.sendline( "" ) |
| 83 | i = self.handle.expect( [ "onos>", "\$" ] ) |
Jon Hall | 7e5b917 | 2014-10-22 12:32:47 -0400 | [diff] [blame] | 84 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 85 | self.handle.sendline( "system:shutdown" ) |
| 86 | self.handle.expect( "Confirm" ) |
| 87 | self.handle.sendline( "yes" ) |
| 88 | self.handle.expect( "\$" ) |
| 89 | self.handle.sendline( "" ) |
| 90 | self.handle.expect( "\$" ) |
| 91 | self.handle.sendline( "exit" ) |
| 92 | self.handle.expect( "closed" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 93 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 94 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 95 | main.log.error( self.name + ": EOF exception found" ) |
| 96 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 97 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 98 | main.log.error( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 99 | response = main.FALSE |
| 100 | return response |
| 101 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 102 | def logout( self ): |
| 103 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 104 | Sends 'logout' command to ONOS cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 105 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 106 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 107 | self.handle.sendline( "" ) |
| 108 | i = self.handle.expect( [ |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 109 | "onos>", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 110 | "\$" ], timeout=10 ) |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 111 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 112 | self.handle.sendline( "logout" ) |
| 113 | self.handle.expect( "\$" ) |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 114 | elif i == 1: |
| 115 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 116 | |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 117 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 118 | main.log.error( self.name + ": eof exception found" ) |
| 119 | main.log.error( self.name + ": " + |
| 120 | self.handle.before ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 121 | main.cleanup() |
| 122 | main.exit() |
| 123 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 124 | main.log.info( self.name + " ::::::" ) |
| 125 | main.log.error( traceback.print_exc() ) |
| 126 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 127 | main.cleanup() |
| 128 | main.exit() |
| 129 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 130 | def set_cell( self, cellname ): |
| 131 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 132 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 133 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 134 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 135 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 136 | try: |
| 137 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 138 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 139 | main.cleanup() |
| 140 | main.exit() |
| 141 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 142 | self.handle.sendline( "cell " + str( cellname ) ) |
| 143 | # Expect the cellname in the ONOS_CELL variable. |
| 144 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 145 | # and that this driver will have to change accordingly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 146 | self.handle.expect( "ONOS_CELL=" + str( cellname ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 147 | handle_before = self.handle.before |
| 148 | handle_after = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 149 | # Get the rest of the handle |
| 150 | self.handle.sendline( "" ) |
| 151 | self.handle.expect( "\$" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 152 | handle_more = self.handle.before |
| 153 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 154 | main.log.info( "Cell call returned: " + handle_before + |
| 155 | handle_after + handle_more ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 156 | |
| 157 | return main.TRUE |
| 158 | |
| 159 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 160 | main.log.error( self.name + ": eof exception found" ) |
| 161 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 162 | main.cleanup() |
| 163 | main.exit() |
| 164 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 165 | main.log.info( self.name + " ::::::" ) |
| 166 | main.log.error( traceback.print_exc() ) |
| 167 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 168 | main.cleanup() |
| 169 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 170 | |
| 171 | def start_onos_cli( self, ONOS_ip, karafTimeout="" ): |
| 172 | """ |
| 173 | karafTimeout is an optional arugument. karafTimeout value passed by user would be used to set the |
Hari Krishna | d7b9c20 | 2015-01-05 10:38:14 -0800 | [diff] [blame] | 174 | current karaf shell idle timeout. Note that when ever this property is modified the shell will exit and |
| 175 | the subsequent login would reflect new idle timeout. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 176 | Below is an example to start a session with 60 seconds idle timeout ( input value is in milliseconds ): |
| 177 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 178 | tValue = "60000" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 179 | main.ONOScli1.start_onos_cli( ONOS_ip, karafTimeout=tValue ) |
| 180 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 181 | Note: karafTimeout is left as str so that this could be read and passed to start_onos_cli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 182 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 183 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 184 | self.handle.sendline( "" ) |
| 185 | x = self.handle.expect( [ |
| 186 | "\$", "onos>" ], timeout=10 ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 187 | |
| 188 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 189 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 190 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 191 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 192 | # Wait for onos start ( -w ) and enter onos cli |
| 193 | self.handle.sendline( "onos -w " + str( ONOS_ip ) ) |
| 194 | i = self.handle.expect( [ |
| 195 | "onos>", |
| 196 | pexpect.TIMEOUT ], timeout=60 ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 197 | |
| 198 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 199 | main.log.info( str( ONOS_ip ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 200 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 201 | self.handle.sendline( |
| 202 | "config:property-set -p org.apache.karaf.shell sshIdleTimeout " + |
| 203 | karafTimeout ) |
| 204 | self.handle.expect( "\$" ) |
| 205 | self.handle.sendline( "onos -w " + str( ONOS_ip ) ) |
| 206 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 207 | return main.TRUE |
| 208 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 209 | # If failed, send ctrl+c to process and try again |
| 210 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 211 | self.handle.send( "\x03" ) |
| 212 | self.handle.sendline( "onos -w " + str( ONOS_ip ) ) |
| 213 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 214 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 215 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 216 | main.log.info( str( ONOS_ip ) + " CLI Started " + |
| 217 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 218 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 219 | self.handle.sendline( |
| 220 | "config:property-set -p org.apache.karaf.shell sshIdleTimeout " + |
| 221 | karafTimeout ) |
| 222 | self.handle.expect( "\$" ) |
| 223 | self.handle.sendline( "onos -w " + str( ONOS_ip ) ) |
| 224 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 225 | return main.TRUE |
| 226 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 227 | main.log.error( "Connection to CLI " + |
| 228 | str( ONOS_ip ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 229 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 230 | |
| 231 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 232 | main.log.error( self.name + ": EOF exception found" ) |
| 233 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 234 | main.cleanup() |
| 235 | main.exit() |
| 236 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 237 | main.log.info( self.name + " ::::::" ) |
| 238 | main.log.error( traceback.print_exc() ) |
| 239 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 240 | main.cleanup() |
| 241 | main.exit() |
| 242 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 243 | <<<<<<< HEAD |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 244 | def sendline(self, cmd_str): |
| 245 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 246 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 247 | def sendline( self, cmd_str ): |
| 248 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 249 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 250 | Send a completely user specified string to |
| 251 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 252 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 253 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 254 | Warning: There are no sanity checking to commands |
| 255 | sent using this method. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 256 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 257 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 258 | self.handle.sendline( "" ) |
| 259 | self.handle.expect( "onos>" ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 260 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 261 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 262 | self.handle.sendline("log:log \"Sending CLI command: '" |
| 263 | + cmd_str + "'\"") |
| 264 | self.handle.expect("onos>") |
| 265 | self.handle.sendline( cmd_str ) |
| 266 | self.handle.expect( cmd_str ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 267 | self.handle.expect("onos>") |
| 268 | |
| 269 | handle = self.handle.before |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 270 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 271 | self.handle.sendline("") |
| 272 | self.handle.expect("onos>") |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 273 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 274 | #handle += self.handle.before |
| 275 | #handle += self.handle.after |
| 276 | |
| 277 | main.log.info("Command '" + str( cmd_str ) + "' sent to " |
| 278 | + self.name + ".") |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 279 | ansi_escape = re.compile(r'\x1b[^m]*m') |
| 280 | handle = ansi_escape.sub('', handle) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 281 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 282 | self.handle.sendline( cmd_str ) |
| 283 | self.handle.expect( "onos>" ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 284 | |
| 285 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 286 | |
| 287 | self.handle.sendline( "" ) |
| 288 | self.handle.expect( "onos>" ) |
| 289 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 290 | handle += self.handle.before |
| 291 | handle += self.handle.after |
| 292 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 293 | main.log.info( "Command sent." ) |
| 294 | ansi_escape = re.compile( r'\x1b[^m]*m' ) |
| 295 | handle = ansi_escape.sub( '', handle ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 296 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 297 | |
| 298 | return handle |
| 299 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 300 | main.log.error( self.name + ": EOF exception found" ) |
| 301 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 302 | main.cleanup() |
| 303 | main.exit() |
| 304 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 305 | main.log.info( self.name + " ::::::" ) |
| 306 | main.log.error( traceback.print_exc() ) |
| 307 | main.log.info( self.name + " ::::::" ) |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 308 | main.cleanup() |
| 309 | main.exit() |
| 310 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 311 | # IMPORTANT NOTE: |
| 312 | # For all cli commands, naming convention should match |
| 313 | # the cli command replacing ':' with '_'. |
| 314 | # Ex ) onos:topology > onos_topology |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 315 | # onos:links > onos_links |
| 316 | # feature:list > feature_list |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 317 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 318 | <<<<<<< HEAD |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 319 | def add_node(self, node_id, ONOS_ip, tcp_port=""): |
| 320 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 321 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 322 | def add_node( self, node_id, ONOS_ip, tcp_port="" ): |
| 323 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 324 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 325 | Adds a new cluster node by ID and address information. |
| 326 | Required: |
| 327 | * node_id |
| 328 | * ONOS_ip |
| 329 | Optional: |
| 330 | * tcp_port |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 331 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 332 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 333 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 334 | cmd_str = "add-node " + str(node_id) + " " +\ |
| 335 | str(ONOS_ip) + " " + str(tcp_port) |
| 336 | handle = self.sendline( cmd_str ) |
| 337 | if re.search("Error", handle): |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 338 | main.log.error("Error in adding node") |
| 339 | main.log.error(handle) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 340 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 341 | self.handle.sendline( "" ) |
| 342 | self.handle.expect( "onos>" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 343 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 344 | self.handle.sendline( "add-node " + |
| 345 | str( node_id ) + " " + |
| 346 | str( ONOS_ip ) + " " + |
| 347 | str( tcp_port ) ) |
| 348 | |
| 349 | i = self.handle.expect( [ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 350 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 351 | "onos>" ] ) |
| 352 | |
| 353 | # Clear handle to get previous output |
| 354 | self.handle.sendline( "" ) |
| 355 | self.handle.expect( "onos>" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 356 | |
| 357 | handle = self.handle.before |
| 358 | |
| 359 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 360 | main.log.error( "Error in adding node" ) |
| 361 | main.log.error( handle ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 362 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 363 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 364 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 365 | main.log.info( "Node " + str( ONOS_ip ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 366 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 367 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 368 | main.log.error( self.name + ": EOF exception found" ) |
| 369 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 370 | main.cleanup() |
| 371 | main.exit() |
| 372 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 373 | main.log.info( self.name + " ::::::" ) |
| 374 | main.log.error( traceback.print_exc() ) |
| 375 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 376 | main.cleanup() |
| 377 | main.exit() |
| 378 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 379 | def remove_node( self, node_id ): |
| 380 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 381 | Removes a cluster by ID |
| 382 | Issues command: 'remove-node [<node-id>]' |
| 383 | Required: |
| 384 | * node_id |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 385 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 386 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 387 | <<<<<<< HEAD |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 388 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 389 | cmd_str = "remove-node " + str(node_id) |
| 390 | self.sendline( cmd_str ) |
| 391 | # TODO: add error checking. Does ONOS give any errors? |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 392 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 393 | self.handle.sendline( "" ) |
| 394 | self.handle.expect( "onos>" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 395 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 396 | self.handle.sendline( "remove-node " + str( node_id ) ) |
| 397 | self.handle.expect( "onos>" ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 398 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 399 | |
| 400 | return main.TRUE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 401 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 402 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 403 | main.log.error( self.name + ": EOF exception found" ) |
| 404 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 405 | main.cleanup() |
| 406 | main.exit() |
| 407 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 408 | main.log.info( self.name + " ::::::" ) |
| 409 | main.log.error( traceback.print_exc() ) |
| 410 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 411 | main.cleanup() |
| 412 | main.exit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 413 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 414 | def nodes( self ): |
| 415 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 416 | List the nodes currently visible |
| 417 | Issues command: 'nodes' |
| 418 | Returns: entire handle of list of nodes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 419 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 420 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 421 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 422 | cmd_str = "nodes" |
| 423 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 424 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 425 | self.handle.sendline( "" ) |
| 426 | self.handle.expect( "onos>" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 427 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 428 | self.handle.sendline( "nodes" ) |
| 429 | self.handle.expect( "onos>" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 430 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 431 | self.handle.sendline( "" ) |
| 432 | self.handle.expect( "onos>" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 433 | |
| 434 | handle = self.handle.before |
| 435 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 436 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 437 | return handle |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 438 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 439 | main.log.error( self.name + ": EOF exception found" ) |
| 440 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 441 | main.cleanup() |
| 442 | main.exit() |
| 443 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 444 | main.log.info( self.name + " ::::::" ) |
| 445 | main.log.error( traceback.print_exc() ) |
| 446 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 447 | main.cleanup() |
| 448 | main.exit() |
| 449 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 450 | def topology( self ): |
| 451 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 452 | Shows the current state of the topology |
| 453 | by issusing command: 'onos> onos:topology' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 454 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 455 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 456 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 457 | # either onos:topology or 'topology' will work in CLI |
| 458 | cmd_str = "onos:topology" |
| 459 | handle = self.sendline( cmd_str ) |
| 460 | main.log.info( "onos:topology returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 461 | return handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 462 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 463 | self.handle.sendline( "" ) |
| 464 | self.handle.expect( "onos>" ) |
| 465 | # either onos:topology or 'topology' will work in CLI |
| 466 | self.handle.sendline( "onos:topology" ) |
| 467 | self.handle.expect( "onos>" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 468 | |
| 469 | handle = self.handle.before |
| 470 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 471 | main.log.info( "onos:topology returned: " + |
| 472 | str( handle ) ) |
| 473 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 474 | return handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 475 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 476 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 477 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 478 | main.log.error( self.name + ": EOF exception found" ) |
| 479 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 480 | main.cleanup() |
| 481 | main.exit() |
| 482 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 483 | main.log.info( self.name + " ::::::" ) |
| 484 | main.log.error( traceback.print_exc() ) |
| 485 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 486 | main.cleanup() |
| 487 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 488 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 489 | <<<<<<< HEAD |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 490 | def feature_install(self, feature_str): |
| 491 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 492 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 493 | def feature_install( self, feature_str ): |
| 494 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 495 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 496 | Installs a specified feature |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 497 | by issuing command: 'onos> feature:install <feature_str>' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 498 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 499 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 500 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 501 | cmd_str = "feature:install " + str( feature_str ) |
| 502 | self.sendline( cmd_str ) |
| 503 | # TODO: Check for possible error responses from karaf |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 504 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 505 | self.handle.sendline( "" ) |
| 506 | self.handle.expect( "onos>" ) |
| 507 | |
| 508 | self.handle.sendline( "feature:install " + str( feature_str ) ) |
| 509 | self.handle.expect( "onos>" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 510 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 511 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 512 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 513 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 514 | main.log.error( self.name + ": EOF exception found" ) |
| 515 | main.log.error( self.name + ": " + self.handle.before ) |
| 516 | main.log.report( "Failed to install feature" ) |
| 517 | main.log.report( "Exiting test" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 518 | main.cleanup() |
| 519 | main.exit() |
| 520 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 521 | main.log.info( self.name + " ::::::" ) |
| 522 | main.log.error( traceback.print_exc() ) |
| 523 | main.log.report( "Failed to install feature" ) |
| 524 | main.log.report( "Exiting test" ) |
| 525 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 526 | main.cleanup() |
| 527 | main.exit() |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 528 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 529 | <<<<<<< HEAD |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 530 | def feature_uninstall(self, feature_str): |
| 531 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 532 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 533 | def feature_uninstall( self, feature_str ): |
| 534 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 535 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 536 | Uninstalls a specified feature |
| 537 | by issuing command: 'onos> feature:uninstall <feature_str>' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 538 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 539 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 540 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 541 | cmd_str = "feature:uninstall " + str( feature_str ) |
| 542 | self.sendline( cmd_str ) |
| 543 | # TODO: Check for possible error responses from karaf |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 544 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 545 | self.handle.sendline( "" ) |
| 546 | self.handle.expect( "onos>" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 547 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 548 | self.handle.sendline( "feature:uninstall " + str( feature_str ) ) |
| 549 | self.handle.expect( "onos>" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 550 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 551 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 552 | return main.TRUE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 553 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 554 | main.log.error( self.name + ": EOF exception found" ) |
| 555 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 556 | main.cleanup() |
| 557 | main.exit() |
| 558 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 559 | main.log.info( self.name + " ::::::" ) |
| 560 | main.log.error( traceback.print_exc() ) |
| 561 | main.log.info( self.name + " ::::::" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 562 | main.cleanup() |
| 563 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 564 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 565 | def devices( self, json_format=True ): |
| 566 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 567 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 568 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 569 | * json_format - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 570 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 571 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 572 | <<<<<<< HEAD |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 573 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 574 | cmd_str = "devices -j" |
| 575 | handle = self.sendline( cmd_str ) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 576 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 577 | handle variable here contains some ANSI escape color code |
| 578 | sequences at the end which are invisible in the print command |
| 579 | output. To make that escape sequence visible, use repr() |
| 580 | function. The repr(handle) output when printed shows the |
| 581 | ANSI escape sequences. In json.loads(somestring), this |
| 582 | somestring variable is actually repr(somestring) and |
| 583 | json.loads would fail with the escape sequence. So we take off |
| 584 | that escape sequence using: |
| 585 | |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 586 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 587 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 588 | ''' |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 589 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 590 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 591 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 592 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 593 | cmd_str = "devices" |
| 594 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 595 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 596 | self.handle.sendline( "" ) |
| 597 | self.handle.expect( "onos>" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 598 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 599 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 600 | self.handle.sendline( "devices -j" ) |
| 601 | self.handle.expect( "devices -j" ) |
| 602 | self.handle.expect( "onos>" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 603 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 604 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 605 | handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 606 | To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences. |
| 607 | In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence. |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 608 | So we take off that escape sequence using |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 609 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 610 | handle1 = ansi_escape.sub( '', handle ) |
| 611 | """ |
| 612 | # print "repr(handle) =", repr( handle ) |
| 613 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 614 | handle1 = ansi_escape.sub( '', handle ) |
| 615 | # print "repr(handle1) = ", repr( handle1 ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 616 | return handle1 |
| 617 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 618 | self.handle.sendline( "devices" ) |
| 619 | self.handle.expect( "onos>" ) |
Jon Hall | cd70729 | 2014-10-17 19:06:17 -0400 | [diff] [blame] | 620 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 621 | # print "handle =",handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 622 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | cd70729 | 2014-10-17 19:06:17 -0400 | [diff] [blame] | 623 | return handle |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 624 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 625 | main.log.error( self.name + ": EOF exception found" ) |
| 626 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 627 | main.cleanup() |
| 628 | main.exit() |
| 629 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 630 | main.log.info( self.name + " ::::::" ) |
| 631 | main.log.error( traceback.print_exc() ) |
| 632 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 633 | main.cleanup() |
| 634 | main.exit() |
| 635 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 636 | <<<<<<< HEAD |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 637 | def balance_masters(self): |
| 638 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 639 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 640 | def balance_masters( self ): |
| 641 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 642 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 643 | This balances the devices across all controllers |
| 644 | by issuing command: 'onos> onos:balance-masters' |
| 645 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 646 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 647 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 648 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 649 | cmd_str = "onos:balance-masters" |
| 650 | self.sendline( cmd_str ) |
| 651 | # TODO: Check for error responses from ONOS |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 652 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 653 | self.handle.sendline( "" ) |
| 654 | self.handle.expect( "onos>" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 655 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 656 | self.handle.sendline( "onos:balance-masters" ) |
| 657 | self.handle.expect( "onos>" ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 658 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 659 | return main.TRUE |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 660 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 661 | main.log.error( self.name + ": EOF exception found" ) |
| 662 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 663 | main.cleanup() |
| 664 | main.exit() |
| 665 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 666 | main.log.info( self.name + " ::::::" ) |
| 667 | main.log.error( traceback.print_exc() ) |
| 668 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 669 | main.cleanup() |
| 670 | main.exit() |
| 671 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 672 | def links( self, json_format=True ): |
| 673 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 674 | Lists all core links |
| 675 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 676 | * json_format - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 677 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 678 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 679 | <<<<<<< HEAD |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 680 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 681 | cmd_str = "links -j" |
| 682 | handle = self.sendline( cmd_str ) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 683 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 684 | handle variable here contains some ANSI escape color code |
| 685 | sequences at the end which are invisible in the print command |
| 686 | output. To make that escape sequence visible, use repr() |
| 687 | function. The repr(handle) output when printed shows the ANSI |
| 688 | escape sequences. In json.loads(somestring), this somestring |
| 689 | variable is actually repr(somestring) and json.loads would |
| 690 | fail with the escape sequence. So we take off that escape |
| 691 | sequence using: |
| 692 | |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 693 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 694 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 695 | ''' |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 696 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 697 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 698 | return handle1 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 699 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 700 | cmd_str = "links" |
| 701 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 702 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 703 | self.handle.sendline( "" ) |
| 704 | self.handle.expect( "onos>" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 705 | |
| 706 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 707 | self.handle.sendline( "links -j" ) |
| 708 | self.handle.expect( "links -j" ) |
| 709 | self.handle.expect( "onos>" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 710 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 711 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 712 | handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 713 | To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences. |
| 714 | In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence. |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 715 | So we take off that escape sequence using |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 716 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 717 | handle1 = ansi_escape.sub( '', handle ) |
| 718 | """ |
| 719 | # print "repr(handle) =", repr( handle ) |
| 720 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 721 | handle1 = ansi_escape.sub( '', handle ) |
| 722 | # print "repr(handle1) = ", repr( handle1 ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 723 | return handle1 |
| 724 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 725 | self.handle.sendline( "links" ) |
| 726 | self.handle.expect( "onos>" ) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 727 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 728 | # print "handle =",handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 729 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 730 | return handle |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 731 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 732 | main.log.error( self.name + ": EOF exception found" ) |
| 733 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 734 | main.cleanup() |
| 735 | main.exit() |
| 736 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 737 | main.log.info( self.name + " ::::::" ) |
| 738 | main.log.error( traceback.print_exc() ) |
| 739 | main.log.info( self.name + " ::::::" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 740 | main.cleanup() |
| 741 | main.exit() |
| 742 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 743 | <<<<<<< HEAD |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 744 | def ports(self, json_format=True): |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 745 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 746 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 747 | def ports( self, json_format=True ): |
| 748 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 749 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 750 | Lists all ports |
| 751 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 752 | * json_format - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 753 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 754 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 755 | <<<<<<< HEAD |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 756 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 757 | cmd_str = "ports -j" |
| 758 | handle = self.sendline( cmd_str ) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 759 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 760 | handle variable here contains some ANSI escape color code |
| 761 | sequences at the end which are invisible in the print command |
| 762 | output. To make that escape sequence visible, use repr() |
| 763 | function. The repr(handle) output when printed shows the ANSI |
| 764 | escape sequences. In json.loads(somestring), this somestring |
| 765 | variable is actually repr(somestring) and json.loads would |
| 766 | fail with the escape sequence. So we take off that escape |
| 767 | sequence using the following commads: |
| 768 | |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 769 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 770 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | d815ce4 | 2014-10-17 19:52:30 -0400 | [diff] [blame] | 771 | ''' |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 772 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 773 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | a001c39 | 2014-10-17 18:50:59 -0400 | [diff] [blame] | 774 | return handle1 |
| 775 | |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 776 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 777 | cmd_str = "ports" |
| 778 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 779 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 780 | self.handle.sendline( "" ) |
| 781 | self.handle.expect( "onos>" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 782 | |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 783 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 784 | self.handle.sendline( "ports -j" ) |
| 785 | self.handle.expect( "ports -j" ) |
| 786 | self.handle.expect( "onos>" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 787 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 788 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 789 | handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 790 | To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences. |
| 791 | In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence. |
Jon Hall | cd70729 | 2014-10-17 19:06:17 -0400 | [diff] [blame] | 792 | So we take off that escape sequence using the following commads: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 793 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 794 | handle1 = ansi_escape.sub( '', handle ) |
| 795 | """ |
| 796 | # print "repr(handle) =", repr( handle ) |
| 797 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 798 | handle1 = ansi_escape.sub( '', handle ) |
| 799 | # print "repr(handle1) = ", repr( handle1 ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 800 | return handle1 |
| 801 | |
| 802 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 803 | self.handle.sendline( "ports" ) |
| 804 | self.handle.expect( "onos>" ) |
| 805 | self.handle.sendline( "" ) |
| 806 | self.handle.expect( "onos>" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 807 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 808 | # print "handle =",handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 809 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 810 | return handle |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 811 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 812 | main.log.error( self.name + ": EOF exception found" ) |
| 813 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 814 | main.cleanup() |
| 815 | main.exit() |
| 816 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 817 | main.log.info( self.name + " ::::::" ) |
| 818 | main.log.error( traceback.print_exc() ) |
| 819 | main.log.info( self.name + " ::::::" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 820 | main.cleanup() |
| 821 | main.exit() |
| 822 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 823 | def roles( self, json_format=True ): |
| 824 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 825 | Lists all devices and the controllers with roles assigned to them |
| 826 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 827 | * json_format - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 828 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 829 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 830 | <<<<<<< HEAD |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 831 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 832 | cmd_str = "roles -j" |
| 833 | handle = self.sendline( cmd_str ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 834 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 835 | handle variable here contains some ANSI escape color code |
| 836 | sequences at the end which are invisible in the print command |
| 837 | output. To make that escape sequence visible, use repr() |
| 838 | function. The repr(handle) output when printed shows the ANSI |
| 839 | escape sequences. In json.loads(somestring), this somestring |
| 840 | variable is actually repr(somestring) and json.loads would |
| 841 | fail with the escape sequence. |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 842 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 843 | So we take off that escape sequence using the following |
| 844 | commads: |
| 845 | |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 846 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 847 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 848 | ''' |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 849 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 850 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 851 | return handle1 |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 852 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 853 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 854 | cmd_str = "roles" |
| 855 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 856 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 857 | self.handle.sendline( "" ) |
| 858 | self.handle.expect( "onos>" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 859 | |
| 860 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 861 | self.handle.sendline( "roles -j" ) |
| 862 | self.handle.expect( "roles -j" ) |
| 863 | self.handle.expect( "onos>" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 864 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 865 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 866 | handle variable here contains some ANSI escape color code sequences at the |
| 867 | end which are invisible in the print command output. To make that escape |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 868 | sequence visible, use repr() function. The repr( handle ) output when printed |
| 869 | shows the ANSI escape sequences. In json.loads( somestring ), this somestring |
| 870 | variable is actually repr( somestring ) and json.loads would fail with the escape |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 871 | sequence. |
| 872 | |
| 873 | So we take off that escape sequence using the following commads: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 874 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 875 | handle1 = ansi_escape.sub( '', handle ) |
| 876 | """ |
| 877 | # print "repr(handle) =", repr( handle ) |
| 878 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 879 | handle1 = ansi_escape.sub( '', handle ) |
| 880 | # print "repr(handle1) = ", repr( handle1 ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 881 | return handle1 |
| 882 | |
| 883 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 884 | self.handle.sendline( "roles" ) |
| 885 | self.handle.expect( "onos>" ) |
| 886 | self.handle.sendline( "" ) |
| 887 | self.handle.expect( "onos>" ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 888 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 889 | # print "handle =",handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 890 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 891 | return handle |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 892 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 893 | main.log.error( self.name + ": EOF exception found" ) |
| 894 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 895 | main.cleanup() |
| 896 | main.exit() |
| 897 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 898 | main.log.info( self.name + " ::::::" ) |
| 899 | main.log.error( traceback.print_exc() ) |
| 900 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 901 | main.cleanup() |
| 902 | main.exit() |
| 903 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 904 | <<<<<<< HEAD |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 905 | def get_role(self, device_id): |
| 906 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 907 | Given the a string containing the json representation of the "roles" |
| 908 | cli command and a partial or whole device id, returns a json object |
| 909 | containing the roles output for the first device whose id contains |
| 910 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 911 | |
| 912 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 913 | A dict of the role assignments for the given device or |
| 914 | None if no match |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 915 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 916 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 917 | def get_role( self, device_id ): |
| 918 | """ |
| 919 | Given the a string containing the json representation of the "roles" cli command and a |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 920 | partial or whole device id, returns a json object containing the |
| 921 | roles output for the first device whose id contains "device_id" |
| 922 | |
| 923 | Returns: |
| 924 | Dict of the role assignments for the given device or |
| 925 | None if not match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 926 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 927 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 928 | try: |
| 929 | import json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 930 | if device_id is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 931 | return None |
| 932 | else: |
| 933 | raw_roles = self.roles() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 934 | roles_json = json.loads( raw_roles ) |
| 935 | # search json for the device with id then return the device |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 936 | for device in roles_json: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 937 | # print device |
| 938 | if str( device_id ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 939 | return device |
| 940 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 941 | |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 942 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 943 | main.log.error( self.name + ": EOF exception found" ) |
| 944 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 945 | main.cleanup() |
| 946 | main.exit() |
| 947 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 948 | main.log.info( self.name + " ::::::" ) |
| 949 | main.log.error( traceback.print_exc() ) |
| 950 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 951 | main.cleanup() |
| 952 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 953 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 954 | def roles_not_null( self ): |
| 955 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 956 | Iterates through each device and checks if there is a master assigned |
| 957 | Returns: main.TRUE if each device has a master |
| 958 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 959 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 960 | try: |
| 961 | import json |
| 962 | raw_roles = self.roles() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 963 | roles_json = json.loads( raw_roles ) |
| 964 | # search json for the device with id then return the device |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 965 | for device in roles_json: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 966 | # print device |
| 967 | if device[ 'master' ] == "none": |
| 968 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 969 | return main.FALSE |
| 970 | return main.TRUE |
| 971 | |
| 972 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 973 | main.log.error( self.name + ": EOF exception found" ) |
| 974 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 975 | main.cleanup() |
| 976 | main.exit() |
| 977 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 978 | main.log.info( self.name + " ::::::" ) |
| 979 | main.log.error( traceback.print_exc() ) |
| 980 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 981 | main.cleanup() |
| 982 | main.exit() |
| 983 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 984 | def paths( self, src_id, dst_id ): |
| 985 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 986 | Returns string of paths, and the cost. |
| 987 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 988 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 989 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 990 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 991 | cmd_str = "onos:paths " + str(src_id) + " " + str(dst_id) |
| 992 | handle = self.sendline( cmd_str ) |
| 993 | if re.search( "Error", handle ): |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 994 | main.log.error("Error in getting paths") |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 995 | return (handle, "Error") |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 996 | else: |
| 997 | path = handle.split(";")[0] |
| 998 | cost = handle.split(";")[1] |
| 999 | return (path, cost) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1000 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1001 | self.handle.sendline( "" ) |
| 1002 | self.handle.expect( "onos>" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1003 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1004 | self.handle.sendline( "onos:paths " + |
| 1005 | str( src_id ) + " " + str( dst_id ) ) |
| 1006 | i = self.handle.expect( [ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1007 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1008 | "onos>" ] ) |
| 1009 | |
| 1010 | self.handle.sendline( "" ) |
| 1011 | self.handle.expect( "onos>" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1012 | |
| 1013 | handle = self.handle.before |
| 1014 | |
| 1015 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1016 | main.log.error( "Error in getting paths" ) |
| 1017 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1018 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1019 | path = handle.split( ";" )[ 0 ] |
| 1020 | cost = handle.split( ";" )[ 1 ] |
| 1021 | return ( path, cost ) |
| 1022 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1023 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1024 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1025 | main.log.error( self.name + ": EOF exception found" ) |
| 1026 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1027 | main.cleanup() |
| 1028 | main.exit() |
| 1029 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1030 | main.log.info( self.name + " ::::::" ) |
| 1031 | main.log.error( traceback.print_exc() ) |
| 1032 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1033 | main.cleanup() |
| 1034 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1035 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1036 | def hosts( self, json_format=True ): |
| 1037 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1038 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1039 | Optional argument: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1040 | * json_format - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1041 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1042 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1043 | <<<<<<< HEAD |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1044 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1045 | cmd_str = "hosts -j" |
| 1046 | handle = self.sendline( cmd_str ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1047 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1048 | handle variable here contains some ANSI escape color code |
| 1049 | sequences at the end which are invisible in the print command |
| 1050 | output. To make that escape sequence visible, use repr() |
| 1051 | function. The repr(handle) output when printed shows the ANSI |
| 1052 | escape sequences. In json.loads(somestring), this somestring |
| 1053 | variable is actually repr(somestring) and json.loads would |
| 1054 | fail with the escape sequence. So we take off that escape |
| 1055 | sequence using: |
| 1056 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1057 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1058 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1059 | ''' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1060 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1061 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1062 | return handle1 |
| 1063 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1064 | cmd_str = "hosts" |
| 1065 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1066 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1067 | self.handle.sendline( "" ) |
| 1068 | self.handle.expect( "onos>" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1069 | |
| 1070 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1071 | self.handle.sendline( "hosts -j" ) |
| 1072 | self.handle.expect( "hosts -j" ) |
| 1073 | self.handle.expect( "onos>" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1074 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1075 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1076 | handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1077 | To make that escape sequence visible, use repr() function. The repr( handle ) output when printed shows the ANSI escape sequences. |
| 1078 | In json.loads( somestring ), this somestring variable is actually repr( somestring ) and json.loads would fail with the escape sequence. |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1079 | So we take off that escape sequence using |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1080 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1081 | handle1 = ansi_escape.sub( '', handle ) |
| 1082 | """ |
| 1083 | # print "repr(handle) =", repr( handle ) |
| 1084 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1085 | handle1 = ansi_escape.sub( '', handle ) |
| 1086 | # print "repr(handle1) = ", repr( handle1 ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1087 | return handle1 |
| 1088 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1089 | self.handle.sendline( "hosts" ) |
| 1090 | self.handle.expect( "onos>" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1091 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1092 | # print "handle =",handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1093 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1094 | return handle |
| 1095 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1096 | main.log.error( self.name + ": EOF exception found" ) |
| 1097 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1098 | main.cleanup() |
| 1099 | main.exit() |
| 1100 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1101 | main.log.info( self.name + " ::::::" ) |
| 1102 | main.log.error( traceback.print_exc() ) |
| 1103 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1104 | main.cleanup() |
| 1105 | main.exit() |
| 1106 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1107 | def get_host( self, mac ): |
| 1108 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1109 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1110 | |
| 1111 | Note: mac must be a colon seperated mac address, but could be a |
| 1112 | partial mac address |
| 1113 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1114 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1115 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1116 | import json |
| 1117 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1118 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1119 | return None |
| 1120 | else: |
| 1121 | mac = mac |
| 1122 | raw_hosts = self.hosts() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1123 | hosts_json = json.loads( raw_hosts ) |
| 1124 | # search json for the host with mac then return the device |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1125 | for host in hosts_json: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1126 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
| 1127 | if mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1128 | return host |
| 1129 | return None |
| 1130 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1131 | main.log.error( self.name + ": EOF exception found" ) |
| 1132 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1133 | main.cleanup() |
| 1134 | main.exit() |
| 1135 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1136 | main.log.info( self.name + " ::::::" ) |
| 1137 | main.log.error( traceback.print_exc() ) |
| 1138 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1139 | main.cleanup() |
| 1140 | main.exit() |
| 1141 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1142 | def get_hosts_id( self, host_list ): |
| 1143 | """ |
| 1144 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1145 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1146 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1147 | Required: |
| 1148 | * host_list: List of hosts obtained by Mininet |
| 1149 | IMPORTANT: |
| 1150 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1151 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1152 | Furthermore, it assumes that value of VLAN is '-1' |
| 1153 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1154 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1155 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1156 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1157 | try: |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1158 | onos_host_list = [] |
| 1159 | |
| 1160 | for host in host_list: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1161 | host = host.replace( "h", "" ) |
| 1162 | host_hex = hex( int( host ) ).zfill( 12 ) |
| 1163 | host_hex = str( host_hex ).replace( 'x', '0' ) |
| 1164 | i = iter( str( host_hex ) ) |
| 1165 | host_hex = ":".join( a + b for a, b in zip( i, i ) ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1166 | host_hex = host_hex + "/-1" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1167 | onos_host_list.append( host_hex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1168 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1169 | return onos_host_list |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1170 | |
| 1171 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1172 | main.log.error( self.name + ": EOF exception found" ) |
| 1173 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1174 | main.cleanup() |
| 1175 | main.exit() |
| 1176 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1177 | main.log.info( self.name + " ::::::" ) |
| 1178 | main.log.error( traceback.print_exc() ) |
| 1179 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1180 | main.cleanup() |
| 1181 | main.exit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1182 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1183 | def add_host_intent( self, host_id_one, host_id_two ): |
| 1184 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1185 | Required: |
| 1186 | * host_id_one: ONOS host id for host1 |
| 1187 | * host_id_two: ONOS host id for host2 |
| 1188 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1189 | Adds a host-to-host intent ( bidrectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1190 | specifying the two hosts. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1191 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1192 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1193 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1194 | cmd_str = "add-host-intent " + str(host_id_one) +\ |
| 1195 | " " + str(host_id_two) |
| 1196 | handle = self.sendline( cmd_str ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 1197 | main.log.info("Host intent installed between "+ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1198 | str(host_id_one) + " and " + str(host_id_two)) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1199 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1200 | self.handle.sendline( "" ) |
| 1201 | self.handle.expect( "onos>" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1202 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1203 | self.handle.sendline( "add-host-intent " + |
| 1204 | str( host_id_one ) + " " + str( host_id_two ) ) |
| 1205 | self.handle.expect( "onos>" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1206 | |
| 1207 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1208 | # print "handle =", handle |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1209 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1210 | main.log.info( "Host intent installed between " + |
| 1211 | str( host_id_one ) + " and " + str( host_id_two ) ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1212 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1213 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1214 | return handle |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1215 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1216 | main.log.error( self.name + ": EOF exception found" ) |
| 1217 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1218 | main.cleanup() |
| 1219 | main.exit() |
| 1220 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1221 | main.log.info( self.name + " ::::::" ) |
| 1222 | main.log.error( traceback.print_exc() ) |
| 1223 | main.log.info( self.name + " ::::::" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1224 | main.cleanup() |
| 1225 | main.exit() |
| 1226 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1227 | def add_optical_intent( self, ingress_device, egress_device ): |
| 1228 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1229 | Required: |
| 1230 | * ingress_device: device id of ingress device |
| 1231 | * egress_device: device id of egress device |
| 1232 | Optional: |
| 1233 | TODO: Still needs to be implemented via dev side |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1234 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1235 | ''' |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1236 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1237 | cmd_str = "add-optical-intent " + str( ingress_device ) +\ |
| 1238 | " " + str( egress_device ) |
| 1239 | handle = self.sendline( cmd_str ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1240 | #If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1241 | if re.search( "Error", handle ): |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1242 | return handle |
| 1243 | else: |
| 1244 | return main.TRUE |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1245 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1246 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1247 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1248 | self.handle.sendline( "add-optical-intent " + |
| 1249 | str( ingress_device ) + " " + str( egress_device ) ) |
| 1250 | self.handle.expect( "add-optical-intent" ) |
| 1251 | i = self.handle.expect( [ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1252 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1253 | "onos>" ] ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1254 | |
| 1255 | handle = self.handle.before |
| 1256 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1257 | # If error, return error message |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1258 | if i == 0: |
| 1259 | return handle |
| 1260 | else: |
| 1261 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1262 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1263 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1264 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1265 | main.log.error( self.name + ": EOF exception found" ) |
| 1266 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1267 | main.cleanup() |
| 1268 | main.exit() |
| 1269 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1270 | main.log.info( self.name + " ::::::" ) |
| 1271 | main.log.error( traceback.print_exc() ) |
| 1272 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1273 | main.cleanup() |
| 1274 | main.exit() |
| 1275 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1276 | <<<<<<< HEAD |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1277 | def add_point_intent(self, ingress_device, egress_device, |
| 1278 | port_ingress="", port_egress="", ethType="", ethSrc="", |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1279 | ethDst="", bandwidth="", lambda_alloc=False, |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1280 | ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst=""): |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1281 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1282 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1283 | def add_point_intent( self, ingress_device, egress_device, |
| 1284 | port_ingress="", port_egress="", ethType="", ethSrc="", |
| 1285 | ethDst="", bandwidth="", lambda_alloc=False, |
| 1286 | ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst="" ): |
| 1287 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1288 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1289 | Required: |
| 1290 | * ingress_device: device id of ingress device |
| 1291 | * egress_device: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1292 | Optional: |
| 1293 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1294 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1295 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1296 | * bandwidth: specify bandwidth capacity of link |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1297 | * lambda_alloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1298 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1299 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1300 | * ipSrc: specify ip source address |
| 1301 | * ipDst: specify ip destination address |
| 1302 | * tcpSrc: specify tcp source port |
| 1303 | * tcpDst: specify tcp destination port |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1304 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1305 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1306 | specifying device id's and optional fields |
| 1307 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1308 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1309 | options developers provide for point-to-point |
| 1310 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1311 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1312 | try: |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1313 | cmd = "" |
| 1314 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1315 | # If there are no optional arguments |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1316 | if not ethType and not ethSrc and not ethDst\ |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1317 | and not bandwidth and not lambda_alloc \ |
| 1318 | and not ipProto and not ipSrc and not ipDst \ |
| 1319 | and not tcpSrc and not tcpDst: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1320 | cmd = "add-point-intent" |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1321 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1322 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1323 | ======= |
| 1324 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1325 | |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1326 | else: |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1327 | cmd = "add-point-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1328 | |
andrewonlab | 0c0a677 | 2014-10-22 12:31:18 -0400 | [diff] [blame] | 1329 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1330 | cmd += " --ethType " + str( ethType ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1331 | if ethSrc: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1332 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1333 | cmd += " --ethSrc " + str(ethSrc) |
| 1334 | if ethDst: |
| 1335 | cmd += " --ethDst " + str(ethDst) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1336 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1337 | cmd += " --ethSrc " + str( ethSrc ) |
| 1338 | if ethDst: |
| 1339 | cmd += " --ethDst " + str( ethDst ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1340 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1341 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1342 | cmd += " --bandwidth " + str( bandwidth ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1343 | if lambda_alloc: |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1344 | cmd += " --lambda " |
| 1345 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1346 | cmd += " --ipProto " + str( ipProto ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1347 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1348 | cmd += " --ipSrc " + str( ipSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1349 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1350 | cmd += " --ipDst " + str( ipDst ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1351 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1352 | cmd += " --tcpSrc " + str( tcpSrc ) |
andrewonlab | fa4ff50 | 2014-11-11 16:41:30 -0500 | [diff] [blame] | 1353 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1354 | cmd += " --tcpDst " + str( tcpDst ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1355 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1356 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1357 | #Check whether the user appended the port |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1358 | #or provided it as an input |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1359 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1360 | # Check whether the user appended the port |
| 1361 | # or provided it as an input |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1362 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1363 | if "/" in ingress_device: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1364 | cmd += " " + str( ingress_device ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1365 | else: |
| 1366 | if not port_ingress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1367 | main.log.error( "You must specify " + |
| 1368 | "the ingress port" ) |
| 1369 | # TODO: perhaps more meaningful return |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1370 | return main.FALSE |
| 1371 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1372 | <<<<<<< HEAD |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1373 | cmd += " "+ \ |
| 1374 | str(ingress_device) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1375 | str(port_ingress) + " " |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1376 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1377 | cmd += " " + \ |
| 1378 | str( ingress_device ) + "/" +\ |
| 1379 | str( port_ingress ) + " " |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1380 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1381 | |
| 1382 | if "/" in egress_device: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1383 | cmd += " " + str( egress_device ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1384 | else: |
| 1385 | if not port_egress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1386 | main.log.error( "You must specify " + |
| 1387 | "the egress port" ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1388 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1389 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1390 | <<<<<<< HEAD |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1391 | cmd += " "+\ |
| 1392 | str(egress_device) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1393 | str(port_egress) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1394 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1395 | handle = self.sendline(cmd) |
| 1396 | if re.search( "Error", handle ): |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1397 | main.log.error("Error in adding point-to-point intent") |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1398 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1399 | cmd += " " +\ |
| 1400 | str( egress_device ) + "/" +\ |
| 1401 | str( port_egress ) |
| 1402 | |
| 1403 | self.handle.sendline( cmd ) |
| 1404 | |
| 1405 | main.log.info( cmd + " sent" ) |
| 1406 | i = self.handle.expect( [ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1407 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1408 | "onos>" ] ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1409 | |
| 1410 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1411 | main.log.error( "Error in adding point-to-point intent" ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1412 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | 47a93fb | 2015-01-06 16:46:06 -0800 | [diff] [blame] | 1413 | return main.FALSE |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1414 | else: |
| 1415 | return main.TRUE |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1416 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1417 | main.log.error( self.name + ": EOF exception found" ) |
| 1418 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1419 | main.cleanup() |
| 1420 | main.exit() |
| 1421 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1422 | main.log.info( self.name + " ::::::" ) |
| 1423 | main.log.error( traceback.print_exc() ) |
| 1424 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1425 | main.cleanup() |
| 1426 | main.exit() |
| 1427 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1428 | <<<<<<< HEAD |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1429 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1430 | def add_multipoint_to_singlepoint_intent(self, ingress_device1, |
| 1431 | ingress_device2, egress_device, port_ingress="", port_egress="", |
| 1432 | ethType="", ethSrc="", ethDst="", bandwidth="", lambda_alloc=False, |
| 1433 | ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst="", setEthSrc="", |
| 1434 | setEthDst=""): |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1435 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1436 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1437 | def add_multipoint_to_singlepoint_intent( |
| 1438 | self, ingress_device1, ingress_device2, egress_device, |
| 1439 | port_ingress="", port_egress="", ethType="", ethSrc="", |
| 1440 | ethDst="", bandwidth="", lambda_alloc=False, |
| 1441 | ipProto="", ipSrc="", ipDst="", tcpSrc="", tcpDst="", setEthSrc="", setEthDst="" ): |
| 1442 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1443 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1444 | Note: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1445 | This function assumes that there would be 2 ingress devices and |
| 1446 | one egress device. For more number of ingress devices, this |
| 1447 | function needs to be modified |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1448 | Required: |
| 1449 | * ingress_device1: device id of ingress device1 |
| 1450 | * ingress_device2: device id of ingress device2 |
| 1451 | * egress_device: device id of egress device |
| 1452 | Optional: |
| 1453 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1454 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1455 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1456 | * bandwidth: specify bandwidth capacity of link |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1457 | * lambda_alloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1458 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1459 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1460 | * ipSrc: specify ip source address |
| 1461 | * ipDst: specify ip destination address |
| 1462 | * tcpSrc: specify tcp source port |
| 1463 | * tcpDst: specify tcp destination port |
| 1464 | * setEthSrc: action to Rewrite Source MAC Address |
| 1465 | * setEthDst: action to Rewrite Destination MAC Address |
| 1466 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1467 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1468 | specifying device id's and optional fields |
| 1469 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1470 | NOTE: This function may change depending on the |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1471 | options developers provide for multipointpoint-to-singlepoint |
| 1472 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1473 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1474 | try: |
| 1475 | cmd = "" |
| 1476 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1477 | # If there are no optional arguments |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1478 | if not ethType and not ethSrc and not ethDst\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1479 | and not bandwidth and not lambda_alloc\ |
| 1480 | and not ipProto and not ipSrc and not ipDst\ |
| 1481 | and not tcpSrc and not tcpDst and not setEthSrc\ |
| 1482 | and not setEthDst: |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1483 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1484 | |
| 1485 | else: |
| 1486 | cmd = "add-multi-to-single-intent" |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1487 | |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1488 | if ethType: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1489 | cmd += " --ethType " + str( ethType ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1490 | if ethSrc: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1491 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1492 | cmd += " --ethSrc " + str(ethSrc) |
| 1493 | if ethDst: |
| 1494 | cmd += " --ethDst " + str(ethDst) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1495 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1496 | cmd += " --ethSrc " + str( ethSrc ) |
| 1497 | if ethDst: |
| 1498 | cmd += " --ethDst " + str( ethDst ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1499 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1500 | if bandwidth: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1501 | cmd += " --bandwidth " + str( bandwidth ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1502 | if lambda_alloc: |
| 1503 | cmd += " --lambda " |
| 1504 | if ipProto: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1505 | cmd += " --ipProto " + str( ipProto ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1506 | if ipSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1507 | cmd += " --ipSrc " + str( ipSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1508 | if ipDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1509 | cmd += " --ipDst " + str( ipDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1510 | if tcpSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1511 | cmd += " --tcpSrc " + str( tcpSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1512 | if tcpDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1513 | cmd += " --tcpDst " + str( tcpDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1514 | if setEthSrc: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1515 | cmd += " --setEthSrc " + str( setEthSrc ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1516 | if setEthDst: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1517 | cmd += " --setEthDst " + str( setEthDst ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1518 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1519 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1520 | #Check whether the user appended the port |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1521 | #or provided it as an input |
| 1522 | if "/" in ingress_device1: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1523 | cmd += " "+str(ingress_device1) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1524 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1525 | # Check whether the user appended the port |
| 1526 | # or provided it as an input |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1527 | if "/" in ingress_device1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1528 | cmd += " " + str( ingress_device1 ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1529 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1530 | else: |
| 1531 | if not port_ingress1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1532 | main.log.error( "You must specify " + |
| 1533 | "the ingress port1" ) |
| 1534 | # TODO: perhaps more meaningful return |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1535 | return main.FALSE |
| 1536 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1537 | <<<<<<< HEAD |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1538 | cmd += " "+ \ |
| 1539 | str(ingress_device1) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1540 | str(port_ingress1) + " " |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1541 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1542 | cmd += " " + \ |
| 1543 | str( ingress_device1 ) + "/" +\ |
| 1544 | str( port_ingress1 ) + " " |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1545 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1546 | |
| 1547 | if "/" in ingress_device2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1548 | cmd += " " + str( ingress_device2 ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1549 | else: |
| 1550 | if not port_ingress2: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1551 | main.log.error( "You must specify " + |
| 1552 | "the ingress port2" ) |
| 1553 | # TODO: perhaps more meaningful return |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1554 | return main.FALSE |
| 1555 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1556 | cmd += " " + \ |
| 1557 | str( ingress_device2 ) + "/" +\ |
| 1558 | str( port_ingress2 ) + " " |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1559 | |
| 1560 | if "/" in egress_device: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1561 | cmd += " " + str( egress_device ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1562 | else: |
| 1563 | if not port_egress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1564 | main.log.error( "You must specify " + |
| 1565 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1566 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1567 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1568 | <<<<<<< HEAD |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1569 | cmd += " "+\ |
| 1570 | str(egress_device) + "/" +\ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1571 | str(port_egress) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1572 | print "cmd= ",cmd |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1573 | handle = self.sendline(cmd) |
| 1574 | if re.search( "Error", handle ): |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1575 | main.log.error("Error in adding point-to-point intent") |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1576 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1577 | cmd += " " +\ |
| 1578 | str( egress_device ) + "/" +\ |
| 1579 | str( port_egress ) |
| 1580 | print "cmd= ", cmd |
| 1581 | self.handle.sendline( cmd ) |
| 1582 | |
| 1583 | main.log.info( cmd + " sent" ) |
| 1584 | i = self.handle.expect( [ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1585 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1586 | "onos>" ] ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1587 | |
| 1588 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1589 | main.log.error( "Error in adding point-to-point intent" ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1590 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1591 | return self.handle |
| 1592 | else: |
| 1593 | return main.TRUE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1594 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1595 | main.log.error( self.name + ": EOF exception found" ) |
| 1596 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1597 | main.cleanup() |
| 1598 | main.exit() |
| 1599 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1600 | main.log.info( self.name + " ::::::" ) |
| 1601 | main.log.error( traceback.print_exc() ) |
| 1602 | main.log.info( self.name + " ::::::" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1603 | main.cleanup() |
| 1604 | main.exit() |
| 1605 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1606 | <<<<<<< HEAD |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1607 | def remove_intent(self, intent_id): |
| 1608 | ''' |
| 1609 | Remove intent for specified intent id |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1610 | |
| 1611 | Returns: |
| 1612 | main.False on error and |
| 1613 | cli output otherwise |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1614 | ''' |
| 1615 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1616 | cmd_str = "remove-intent " + str( intent_id ) |
| 1617 | handle = self.sendline( cmd_str ) |
| 1618 | if re.search( "Error", handle ): |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1619 | main.log.error("Error in removing intent") |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1620 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1621 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1622 | # TODO: Should this be main.TRUE |
| 1623 | return handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1624 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1625 | def remove_intent( self, intent_id ): |
| 1626 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1627 | Remove intent for specified intent id |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1628 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1629 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1630 | self.handle.sendline( "" ) |
| 1631 | self.handle.expect( "onos>" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1632 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1633 | self.handle.sendline( "remove-intent " + str( intent_id ) ) |
| 1634 | i = self.handle.expect( [ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1635 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1636 | "onos>" ] ) |
| 1637 | |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1638 | handle = self.handle.before |
| 1639 | |
| 1640 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1641 | main.log.error( "Error in removing intent" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1642 | return handle |
| 1643 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1644 | return handle |
| 1645 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1646 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1647 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1648 | main.log.error( self.name + ": EOF exception found" ) |
| 1649 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1650 | main.cleanup() |
| 1651 | main.exit() |
| 1652 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1653 | main.log.info( self.name + " ::::::" ) |
| 1654 | main.log.error( traceback.print_exc() ) |
| 1655 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1656 | main.cleanup() |
| 1657 | main.exit() |
| 1658 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1659 | <<<<<<< HEAD |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1660 | def routes(self, json_format=False): |
| 1661 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1662 | NOTE: This method should be used after installing application: |
| 1663 | onos-app-sdnip |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1664 | ======= |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1665 | # This method should be used after installing application: onos-app-sdnip |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1666 | def routes( self, json_format=False ): |
| 1667 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1668 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1669 | Optional: |
| 1670 | * json_format: enable output formatting in json |
| 1671 | Description: |
| 1672 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1673 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1674 | try: |
| 1675 | if json_format: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1676 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1677 | cmd_str = "routes -j" |
| 1678 | handle_tmp = self.sendline( cmd_str ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1679 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1680 | handle = ansi_escape.sub('', handle_tmp) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1681 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1682 | cmd_str = "routes" |
| 1683 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1684 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1685 | self.handle.sendline( "routes -j" ) |
| 1686 | self.handle.expect( "routes -j" ) |
| 1687 | self.handle.expect( "onos>" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1688 | handle_tmp = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1689 | |
| 1690 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1691 | handle = ansi_escape.sub( '', handle_tmp ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1692 | |
| 1693 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1694 | self.handle.sendline( "" ) |
| 1695 | self.handle.expect( "onos>" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1696 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1697 | self.handle.sendline( "routes" ) |
| 1698 | self.handle.expect( "onos>" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1699 | handle = self.handle.before |
| 1700 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1701 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1702 | return handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1703 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1704 | main.log.error( self.name + ": EOF exception found" ) |
| 1705 | main.log.error( self.name + ": " + self.handle.before ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1706 | main.cleanup() |
| 1707 | main.exit() |
| 1708 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1709 | main.log.info( self.name + " ::::::" ) |
| 1710 | main.log.error( traceback.print_exc() ) |
| 1711 | main.log.info( self.name + " ::::::" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1712 | main.cleanup() |
| 1713 | main.exit() |
| 1714 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1715 | def intents( self, json_format=True ): |
| 1716 | """ |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1717 | Optional: |
| 1718 | * json_format: enable output formatting in json |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1719 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1720 | Obtain intents currently installed |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1721 | <<<<<<< HEAD |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1722 | ''' |
| 1723 | try: |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1724 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1725 | cmd_str = "intents -j" |
| 1726 | handle = self.sendline( cmd_str ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1727 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1728 | handle = ansi_escape.sub('', handle) |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1729 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1730 | cmd_str = "intents" |
| 1731 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1732 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1733 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1734 | try: |
| 1735 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1736 | self.handle.sendline( "intents -j" ) |
| 1737 | self.handle.expect( "intents -j" ) |
| 1738 | self.handle.expect( "onos>" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1739 | handle = self.handle.before |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1740 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1741 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1742 | handle = ansi_escape.sub( '', handle ) |
| 1743 | else: |
| 1744 | self.handle.sendline( "" ) |
| 1745 | self.handle.expect( "onos>" ) |
| 1746 | |
| 1747 | self.handle.sendline( "intents" ) |
| 1748 | self.handle.expect( "onos>" ) |
andrewonlab | 377693f | 2014-10-21 16:00:30 -0400 | [diff] [blame] | 1749 | handle = self.handle.before |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1750 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1751 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1752 | return handle |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1753 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1754 | main.log.error( self.name + ": EOF exception found" ) |
| 1755 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1756 | main.cleanup() |
| 1757 | main.exit() |
| 1758 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1759 | main.log.info( self.name + " ::::::" ) |
| 1760 | main.log.error( traceback.print_exc() ) |
| 1761 | main.log.info( self.name + " ::::::" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1762 | main.cleanup() |
| 1763 | main.exit() |
| 1764 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1765 | def flows( self, json_format=True ): |
| 1766 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1767 | Optional: |
| 1768 | * json_format: enable output formatting in json |
| 1769 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1770 | Obtain flows currently installed |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1771 | <<<<<<< HEAD |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1772 | ''' |
| 1773 | try: |
| 1774 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1775 | cmd_str = "flows -j" |
| 1776 | handle = self.sendline( cmd_str ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1777 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1778 | handle = ansi_escape.sub('', handle) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1779 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1780 | cmd_str = "flows" |
| 1781 | handle = self.sendline( cmd_str ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1782 | if re.search("Error\sexecuting\scommand:", handle): |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1783 | main.log.error( self.name + ".flows() response: " + |
| 1784 | str( handle ) ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1785 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1786 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1787 | try: |
| 1788 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1789 | self.handle.sendline( "flows -j" ) |
| 1790 | self.handle.expect( "flows -j" ) |
| 1791 | self.handle.expect( "onos>" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1792 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1793 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1794 | handle = ansi_escape.sub( '', handle ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1795 | |
| 1796 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1797 | self.handle.sendline( "" ) |
| 1798 | self.handle.expect( "onos>" ) |
| 1799 | self.handle.sendline( "flows" ) |
| 1800 | self.handle.expect( "onos>" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1801 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1802 | if re.search( "Error\sexecuting\scommand:", handle ): |
| 1803 | main.log.error( |
| 1804 | self.name + ".flows() response: " + str( handle ) ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1805 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1806 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1807 | return handle |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1808 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1809 | main.log.error( self.name + ": EOF exception found" ) |
| 1810 | main.log.error( self.name + ": " + self.handle.before ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1811 | main.cleanup() |
| 1812 | main.exit() |
| 1813 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1814 | main.log.info( self.name + " ::::::" ) |
| 1815 | main.log.error( traceback.print_exc() ) |
| 1816 | main.log.info( self.name + " ::::::" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1817 | main.cleanup() |
| 1818 | main.exit() |
| 1819 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1820 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1821 | def push_test_intents(self, dpid_src, dpid_dst, num_intents, |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1822 | num_mult="", app_id="", report=True): |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1823 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1824 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1825 | def push_test_intents( self, dpid_src, dpid_dst, num_intents, |
| 1826 | num_mult="", app_id="", report=True ): |
| 1827 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1828 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1829 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1830 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1831 | a specific point-to-point intent definition |
| 1832 | Required: |
| 1833 | * dpid_src: specify source dpid |
| 1834 | * dpid_dst: specify destination dpid |
| 1835 | * num_intents: specify number of intents to push |
| 1836 | Optional: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1837 | * num_mult: number multiplier for multiplying |
| 1838 | the number of intents specified |
| 1839 | * app_id: specify the application id init to further |
| 1840 | modularize the intents |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1841 | * report: default True, returns latency information |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1842 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1843 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1844 | <<<<<<< HEAD |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1845 | cmd = "push-test-intents "+\ |
| 1846 | str(dpid_src)+" "+str(dpid_dst)+" "+\ |
| 1847 | str(num_intents) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1848 | if num_mult: |
| 1849 | cmd += " " + str(num_mult) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1850 | #If app id is specified, then num_mult |
andrewonlab | 042b391 | 2014-12-10 16:40:50 -0500 | [diff] [blame] | 1851 | #must exist because of the way this command |
| 1852 | #takes in arguments |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1853 | if app_id: |
| 1854 | cmd += " " + str(app_id) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1855 | handle = self.sendline( cmd ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1856 | #Some color thing that we want to escape |
| 1857 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1858 | handle = ansi_escape.sub('', handle) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1859 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1860 | cmd = "push-test-intents " +\ |
| 1861 | str( dpid_src ) + " " + str( dpid_dst ) + " " +\ |
| 1862 | str( num_intents ) |
| 1863 | |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1864 | if num_mult: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1865 | cmd += " " + str( num_mult ) |
| 1866 | # If app id is specified, then num_mult |
| 1867 | # must exist because of the way this command |
| 1868 | # takes in arguments |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1869 | if app_id: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1870 | cmd += " " + str( app_id ) |
| 1871 | |
| 1872 | self.handle.sendline( cmd ) |
| 1873 | self.handle.expect( cmd ) |
| 1874 | self.handle.expect( "onos>" ) |
| 1875 | |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1876 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1877 | |
| 1878 | # Some color thing that we want to escape |
| 1879 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1880 | handle = ansi_escape.sub( '', handle ) |
| 1881 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1882 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1883 | if report: |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1884 | lat_result = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1885 | main.log.info( handle ) |
| 1886 | # Split result by newline |
| 1887 | newline = handle.split( "\r\r\n" ) |
| 1888 | # Ignore the first object of list, which is empty |
| 1889 | newline = newline[ 1: ] |
| 1890 | # Some sloppy parsing method to get the latency |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1891 | for result in newline: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1892 | <<<<<<< HEAD |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1893 | result = result.split(": ") |
| 1894 | #Append the first result of second parse |
| 1895 | lat_result.append(result[1].split(" ")[0]) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1896 | main.log.info(lat_result) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1897 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1898 | result = result.split( ": " ) |
| 1899 | # Append the first result of second parse |
| 1900 | lat_result.append( result[ 1 ].split( " " )[ 0 ] ) |
andrewonlab | b66dfa1 | 2014-12-02 15:51:10 -0500 | [diff] [blame] | 1901 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1902 | main.log.info( lat_result ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1903 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1904 | return lat_result |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1905 | else: |
| 1906 | return main.TRUE |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1907 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1908 | main.log.error( self.name + ": EOF exception found" ) |
| 1909 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1910 | main.cleanup() |
| 1911 | main.exit() |
| 1912 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1913 | main.log.info( self.name + " ::::::" ) |
| 1914 | main.log.error( traceback.print_exc() ) |
| 1915 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 1916 | main.cleanup() |
| 1917 | main.exit() |
| 1918 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1919 | <<<<<<< HEAD |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1920 | def intents_events_metrics(self, json_format=True): |
| 1921 | ''' |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1922 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1923 | def intents_events_metrics( self, json_format=True ): |
| 1924 | """ |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1925 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1926 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1927 | Optional: |
| 1928 | * json_format: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1929 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1930 | try: |
| 1931 | if json_format: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1932 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1933 | cmd_str = "intents-events-metrics -j" |
| 1934 | handle = self.sendline( cmd_str ) |
| 1935 | # Some color thing that we want to escape |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1936 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1937 | handle = ansi_escape.sub('', handle) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1938 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1939 | cmd_str = "intents-events-metrics" |
| 1940 | handle = self.sendline( cmd_str ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1941 | return handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1942 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1943 | self.handle.sendline( "intents-events-metrics -j" ) |
| 1944 | self.handle.expect( "intents-events-metrics -j" ) |
| 1945 | self.handle.expect( "onos>" ) |
| 1946 | |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1947 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1948 | |
| 1949 | # Some color thing that we want to escape |
| 1950 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 1951 | handle = ansi_escape.sub( '', handle ) |
| 1952 | |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1953 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1954 | self.handle.sendline( "intents-events-metrics" ) |
| 1955 | self.handle.expect( "intents-events-metrics" ) |
| 1956 | self.handle.expect( "onos>" ) |
| 1957 | |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1958 | handle = self.handle.before |
| 1959 | |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1960 | return handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1961 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1962 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1963 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1964 | main.log.error( self.name + ": EOF exception found" ) |
| 1965 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1966 | main.cleanup() |
| 1967 | main.exit() |
| 1968 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1969 | main.log.info( self.name + " ::::::" ) |
| 1970 | main.log.error( traceback.print_exc() ) |
| 1971 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1972 | main.cleanup() |
| 1973 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 1974 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1975 | def topology_events_metrics( self, json_format=True ): |
| 1976 | """ |
| 1977 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1978 | Optional: |
| 1979 | * json_format: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1980 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1981 | try: |
| 1982 | if json_format: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1983 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1984 | cmd_str = "topology-events-metrics -j" |
| 1985 | handle = self.sendline( cmd_str ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1986 | #Some color thing that we want to escape |
| 1987 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 1988 | handle = ansi_escape.sub('', handle) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1989 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1990 | cmd_str = "topology-events-metrics" |
| 1991 | handle = self.sendline( cmd_str ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1992 | return handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 1993 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1994 | self.handle.sendline( "topology-events-metrics -j" ) |
| 1995 | self.handle.expect( "topology-events-metrics -j" ) |
| 1996 | self.handle.expect( "onos>" ) |
| 1997 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 1998 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1999 | |
| 2000 | # Some color thing that we want to escape |
| 2001 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 2002 | handle = ansi_escape.sub( '', handle ) |
| 2003 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2004 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2005 | self.handle.sendline( "topology-events-metrics" ) |
| 2006 | self.handle.expect( "topology-events-metrics" ) |
| 2007 | self.handle.expect( "onos>" ) |
| 2008 | |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2009 | handle = self.handle.before |
| 2010 | |
| 2011 | return handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2012 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2013 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2014 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2015 | main.log.error( self.name + ": EOF exception found" ) |
| 2016 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2017 | main.cleanup() |
| 2018 | main.exit() |
| 2019 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2020 | main.log.info( self.name + " ::::::" ) |
| 2021 | main.log.error( traceback.print_exc() ) |
| 2022 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2023 | main.cleanup() |
| 2024 | main.exit() |
| 2025 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2026 | # Wrapper functions **************** |
| 2027 | # Wrapper functions use existing driver |
| 2028 | # functions and extends their use case. |
| 2029 | # For example, we may use the output of |
| 2030 | # a normal driver function, and parse it |
| 2031 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2032 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2033 | def get_all_intents_id( self ): |
| 2034 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2035 | Description: |
| 2036 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2037 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2038 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2039 | # Obtain output of intents function |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2040 | intents_str = self.intents() |
| 2041 | all_intent_list = [] |
| 2042 | intent_id_list = [] |
| 2043 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2044 | # Parse the intents output for ID's |
| 2045 | intents_list = [ s.strip() for s in intents_str.splitlines() ] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2046 | for intents in intents_list: |
| 2047 | if "onos>" in intents: |
| 2048 | continue |
| 2049 | elif "intents" in intents: |
| 2050 | continue |
| 2051 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2052 | line_list = intents.split( " " ) |
| 2053 | all_intent_list.append( line_list[ 0 ] ) |
| 2054 | |
| 2055 | all_intent_list = all_intent_list[ 1:-2 ] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2056 | |
| 2057 | for intents in all_intent_list: |
| 2058 | if not intents: |
| 2059 | continue |
| 2060 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2061 | intent_id_list.append( intents ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2062 | |
| 2063 | return intent_id_list |
| 2064 | |
| 2065 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2066 | main.log.error( self.name + ": EOF exception found" ) |
| 2067 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2068 | main.cleanup() |
| 2069 | main.exit() |
| 2070 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2071 | main.log.info( self.name + " ::::::" ) |
| 2072 | main.log.error( traceback.print_exc() ) |
| 2073 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2074 | main.cleanup() |
| 2075 | main.exit() |
| 2076 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2077 | def get_all_devices_id( self ): |
| 2078 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2079 | Use 'devices' function to obtain list of all devices |
| 2080 | and parse the result to obtain a list of all device |
| 2081 | id's. Returns this list. Returns empty list if no |
| 2082 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2083 | List is ordered sequentially |
| 2084 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2085 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2086 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2087 | the ids. By obtaining the list of device ids on the fly, |
| 2088 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2089 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2090 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2091 | # Call devices and store result string |
| 2092 | devices_str = self.devices( json_format=False ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2093 | id_list = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2094 | |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2095 | if not devices_str: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2096 | main.log.info( "There are no devices to get id from" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2097 | return id_list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2098 | |
| 2099 | # Split the string into list by comma |
| 2100 | device_list = devices_str.split( "," ) |
| 2101 | # Get temporary list of all arguments with string 'id=' |
| 2102 | temp_list = [ dev for dev in device_list if "id=" in dev ] |
| 2103 | # Split list further into arguments before and after string |
| 2104 | # 'id='. Get the latter portion ( the actual device id ) and |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2105 | # append to id_list |
| 2106 | for arg in temp_list: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2107 | id_list.append( arg.split( "id=" )[ 1 ] ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2108 | return id_list |
| 2109 | |
| 2110 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2111 | main.log.error( self.name + ": EOF exception found" ) |
| 2112 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2113 | main.cleanup() |
| 2114 | main.exit() |
| 2115 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2116 | main.log.info( self.name + " ::::::" ) |
| 2117 | main.log.error( traceback.print_exc() ) |
| 2118 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2119 | main.cleanup() |
| 2120 | main.exit() |
| 2121 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2122 | def get_all_nodes_id( self ): |
| 2123 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2124 | Uses 'nodes' function to obtain list of all nodes |
| 2125 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2126 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2127 | Returns: |
| 2128 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2129 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2130 | try: |
| 2131 | nodes_str = self.nodes() |
| 2132 | id_list = [] |
| 2133 | |
| 2134 | if not nodes_str: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2135 | main.log.info( "There are no nodes to get id from" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2136 | return id_list |
| 2137 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2138 | # Sample nodes_str output |
| 2139 | # id=local, address=127.0.0.1:9876, state=ACTIVE * |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2140 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2141 | # Split the string into list by comma |
| 2142 | nodes_list = nodes_str.split( "," ) |
| 2143 | temp_list = [ node for node in nodes_list if "id=" in node ] |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2144 | for arg in temp_list: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2145 | id_list.append( arg.split( "id=" )[ 1 ] ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2146 | |
| 2147 | return id_list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2148 | |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2149 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2150 | main.log.error( self.name + ": EOF exception found" ) |
| 2151 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2152 | main.cleanup() |
| 2153 | main.exit() |
| 2154 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2155 | main.log.info( self.name + " ::::::" ) |
| 2156 | main.log.error( traceback.print_exc() ) |
| 2157 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2158 | main.cleanup() |
| 2159 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2160 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2161 | def get_device( self, dpid=None ): |
| 2162 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2163 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 2164 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2165 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2166 | import json |
| 2167 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2168 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2169 | return None |
| 2170 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2171 | dpid = dpid.replace( ':', '' ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2172 | raw_devices = self.devices() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2173 | devices_json = json.loads( raw_devices ) |
| 2174 | # search json for the device with dpid then return the device |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2175 | for device in devices_json: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2176 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 2177 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2178 | return device |
| 2179 | return None |
| 2180 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2181 | main.log.error( self.name + ": EOF exception found" ) |
| 2182 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2183 | main.cleanup() |
| 2184 | main.exit() |
| 2185 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2186 | main.log.info( self.name + " ::::::" ) |
| 2187 | main.log.error( traceback.print_exc() ) |
| 2188 | main.log.info( self.name + " ::::::" ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2189 | main.cleanup() |
| 2190 | main.exit() |
| 2191 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2192 | def check_status( self, ip, numoswitch, numolink, log_level="info" ): |
| 2193 | """ |
| 2194 | Checks the number of swithes & links that ONOS sees against the |
| 2195 | supplied values. By default this will report to main.log, but the |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2196 | log level can be specifid. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2197 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2198 | Params: ip = ip used for the onos cli |
| 2199 | numoswitch = expected number of switches |
| 2200 | numlink = expected number of links |
| 2201 | log_level = level to log to. Currently accepts 'info', 'warn' and 'report' |
| 2202 | |
| 2203 | |
| 2204 | log_level can |
| 2205 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2206 | Returns: main.TRUE if the number of switchs and links are correct, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2207 | main.FALSE if the numer of switches and links is incorrect, |
| 2208 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2209 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2210 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2211 | topology = self.get_topology( ip ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2212 | if topology == {}: |
| 2213 | return main.ERROR |
| 2214 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2215 | # Is the number of switches is what we expected |
| 2216 | devices = topology.get( 'devices', False ) |
| 2217 | links = topology.get( 'links', False ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2218 | if devices == False or links == False: |
| 2219 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2220 | switch_check = ( int( devices ) == int( numoswitch ) ) |
| 2221 | # Is the number of links is what we expected |
| 2222 | link_check = ( int( links ) == int( numolink ) ) |
| 2223 | if ( switch_check and link_check ): |
| 2224 | # We expected the correct numbers |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2225 | output = output + "The number of links and switches match "\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2226 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2227 | result = main.TRUE |
| 2228 | else: |
| 2229 | output = output + \ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2230 | "The number of links and switches does not match what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2231 | result = main.FALSE |
| 2232 | output = output + "\n ONOS sees %i devices (%i expected) and %i links (%i expected)"\ |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2233 | % ( int( devices ), int( numoswitch ), int( links ), int( numolink ) ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2234 | if log_level == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2235 | main.log.report( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2236 | elif log_level == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2237 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2238 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2239 | main.log.info( output ) |
| 2240 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2241 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2242 | main.log.error( self.name + ": EOF exception found" ) |
| 2243 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2244 | main.cleanup() |
| 2245 | main.exit() |
| 2246 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2247 | main.log.info( self.name + " ::::::" ) |
| 2248 | main.log.error( traceback.print_exc() ) |
| 2249 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2250 | main.cleanup() |
| 2251 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2252 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2253 | def device_role( self, device_id, onos_node, role="master" ): |
| 2254 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2255 | Calls the device-role cli command. |
| 2256 | device_id must be the id of a device as seen in the onos devices command |
| 2257 | onos_node is the ip of one of the onos nodes in the cluster |
| 2258 | role must be either master, standby, or none |
| 2259 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2260 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2261 | Returns: |
| 2262 | main.TRUE or main.FALSE based on argument verification and |
| 2263 | main.ERROR if command returns and error |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2264 | ''' |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2265 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2266 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2267 | role.lower() == "none": |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2268 | cmd_str = "device-role " +\ |
| 2269 | str(device_id) + " " +\ |
| 2270 | str(onos_node) + " " +\ |
| 2271 | str(role) |
| 2272 | handle = self.sendline( cmd_str ) |
| 2273 | if re.search( "Error", handle ): |
| 2274 | # end color output to escape any colours |
| 2275 | # from the cli |
| 2276 | main.log.error( self.name + ": " +\ |
| 2277 | handle + '\033[0m' ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 2278 | return main.ERROR |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2279 | return main.TRUE |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2280 | ======= |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2281 | Returns main.TRUE or main.FALSE based on argument verification. |
| 2282 | When device-role supports errors this should be extended to |
| 2283 | support that output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2284 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2285 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2286 | # print "beginning device_role... \n\tdevice_id:" + device_id |
| 2287 | # print "\tonos_node: " + onos_node |
| 2288 | # print "\trole: "+ role |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2289 | if role.lower() == "master" or \ |
| 2290 | role.lower() == "standby" or \ |
| 2291 | role.lower() == "none": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2292 | self.handle.sendline( "" ) |
| 2293 | self.handle.expect( "onos>" ) |
| 2294 | self.handle.sendline( "device-role " + |
| 2295 | str( device_id ) + " " + |
| 2296 | str( onos_node ) + " " + |
| 2297 | str( role ) ) |
| 2298 | i = self.handle.expect( [ "Error", "onos>" ] ) |
| 2299 | if i == 0: |
| 2300 | output = str( self.handle.before ) |
| 2301 | self.handle.expect( "onos>" ) |
| 2302 | output = output + str( self.handle.before ) |
| 2303 | main.log.error( self.name + ": " + |
| 2304 | output + '\033[0m' ) # end color output to escape any colours from the cli |
| 2305 | return main.ERROR |
| 2306 | self.handle.sendline( "" ) |
| 2307 | self.handle.expect( "onos>" ) |
| 2308 | return main.TRUE |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2309 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2310 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2311 | main.log.error("Invalid 'role' given to device_role(). " + |
| 2312 | "Value was '" + str( role ) + "'.") |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2313 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2314 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2315 | main.log.error( self.name + ": EOF exception found" ) |
| 2316 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2317 | main.cleanup() |
| 2318 | main.exit() |
| 2319 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2320 | main.log.info( self.name + " ::::::" ) |
| 2321 | main.log.error( traceback.print_exc() ) |
| 2322 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2323 | main.cleanup() |
| 2324 | main.exit() |
| 2325 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2326 | def clusters( self, json_format=True ): |
| 2327 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2328 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 2329 | Optional argument: |
| 2330 | * json_format - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2331 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2332 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2333 | <<<<<<< HEAD |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2334 | if json_format: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2335 | cmd_str = "clusters -j" |
| 2336 | handle = self.sendline( cmd_str ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2337 | ''' |
| 2338 | handle variable here contains some ANSI escape color code |
| 2339 | sequences at the end which are invisible in the print command |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2340 | output. To make that escape sequence visible, use repr() |
| 2341 | function. The repr(handle) output when printed shows the ANSI |
| 2342 | escape sequences. In json.loads(somestring), this somestring |
| 2343 | variable is actually repr(somestring) and json.loads would fail |
| 2344 | with the escape sequence. So we take off that escape sequence |
| 2345 | using: |
| 2346 | |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2347 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 2348 | handle1 = ansi_escape.sub('', handle) |
| 2349 | ''' |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2350 | ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m') |
| 2351 | handle1 = ansi_escape.sub('', handle) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2352 | return handle1 |
| 2353 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2354 | cmd_str = "clusters" |
| 2355 | handle = self.sendline( cmd_str ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2356 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2357 | self.handle.sendline( "" ) |
| 2358 | self.handle.expect( "onos>" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2359 | |
| 2360 | if json_format: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2361 | self.handle.sendline( "clusters -j" ) |
| 2362 | self.handle.expect( "clusters -j" ) |
| 2363 | self.handle.expect( "onos>" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2364 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2365 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2366 | handle variable here contains some ANSI escape color code |
| 2367 | sequences at the end which are invisible in the print command |
| 2368 | output. To make that escape sequence visible, use repr() function. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2369 | The repr( handle ) output when printed shows the ANSI escape sequences. |
| 2370 | In json.loads( somestring ), this somestring variable is actually |
| 2371 | repr( somestring ) and json.loads would fail with the escape sequence. |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2372 | So we take off that escape sequence using |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2373 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 2374 | handle1 = ansi_escape.sub( '', handle ) |
| 2375 | """ |
| 2376 | # print "repr(handle) =", repr( handle ) |
| 2377 | ansi_escape = re.compile( r'\r\r\n\x1b[^m]*m' ) |
| 2378 | handle1 = ansi_escape.sub( '', handle ) |
| 2379 | # print "repr(handle1) = ", repr( handle1 ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2380 | return handle1 |
| 2381 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2382 | self.handle.sendline( "clusters" ) |
| 2383 | self.handle.expect( "onos>" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2384 | handle = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2385 | # print "handle =",handle |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2386 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2387 | return handle |
| 2388 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2389 | main.log.error( self.name + ": EOF exception found" ) |
| 2390 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2391 | main.cleanup() |
| 2392 | main.exit() |
| 2393 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2394 | main.log.info( self.name + " ::::::" ) |
| 2395 | main.log.error( traceback.print_exc() ) |
| 2396 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2397 | main.cleanup() |
| 2398 | main.exit() |
| 2399 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2400 | <<<<<<< HEAD |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2401 | def election_test_leader(self): |
| 2402 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2403 | CLI command to get the current leader for the Election test application |
| 2404 | NOTE: Requires installation of the onos-app-election feature |
| 2405 | Returns: Node IP of the leader if one exists |
| 2406 | None if none exists |
| 2407 | Main.FALSE on error |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2408 | ''' |
| 2409 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2410 | cmd_str = "election-test-leader" |
| 2411 | response = self.sendline( cmd_str ) |
| 2412 | # Leader |
| 2413 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
| 2414 | "app\sis\s(?P<node>.+)\." |
| 2415 | node_search = re.search(leaderPattern, response) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2416 | if node_search: |
| 2417 | node = node_search.group('node') |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2418 | main.log.info( "Election-test-leader on " + str( self.name ) + |
| 2419 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2420 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2421 | # no leader |
| 2422 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
| 2423 | "the\sElection\sapp" |
| 2424 | null_search = re.search(nullPattern, response) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2425 | if null_search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2426 | main.log.info( "Election-test-leader found no leader on " + |
| 2427 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2428 | return None |
| 2429 | #error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2430 | errorPattern = "Command\snot\sfound" |
| 2431 | if re.search(errorPattern, response): |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2432 | main.log.error("Election app is not loaded on " + self.name) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2433 | # TODO: Should this be main.ERROR? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2434 | return main.FALSE |
| 2435 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2436 | main.log.error("Error in election_test_leader: " + |
| 2437 | "unexpected response") |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2438 | main.log.error( repr(response) ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2439 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2440 | def election_test_leader( self ): |
| 2441 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2442 | * CLI command to get the current leader for the Election test application. |
| 2443 | #NOTE: Requires installation of the onos-app-election feature |
| 2444 | Returns: Node IP of the leader if one exists |
| 2445 | None if none exists |
| 2446 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2447 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2448 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2449 | self.handle.sendline( "election-test-leader" ) |
| 2450 | self.handle.expect( "election-test-leader" ) |
| 2451 | self.handle.expect( "onos>" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2452 | response = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2453 | # Leader |
| 2454 | node_search = re.search( |
| 2455 | "The\scurrent\sleader\sfor\sthe\sElection\sapp\sis\s(?P<node>.+)\.", |
| 2456 | response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2457 | if node_search: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2458 | node = node_search.group( 'node' ) |
| 2459 | main.log.info( "Election-test-leader on " + str( |
| 2460 | self.name ) + " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2461 | return node |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2462 | # no leader |
| 2463 | null_search = re.search( |
| 2464 | "There\sis\scurrently\sno\sleader\selected\sfor\sthe\sElection\sapp", |
| 2465 | response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2466 | if null_search: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2467 | main.log.info( |
| 2468 | "Election-test-leader found no leader on " + |
| 2469 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2470 | return None |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2471 | # error |
| 2472 | if re.search( "Command\snot\sfound", response ): |
| 2473 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2474 | return main.FALSE |
| 2475 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2476 | main.log.error( |
| 2477 | "Error in election_test_leader: unexpected response" ) |
| 2478 | main.log.error( repr( response ) ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2479 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2480 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2481 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2482 | main.log.error( self.name + ": EOF exception found" ) |
| 2483 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2484 | main.cleanup() |
| 2485 | main.exit() |
| 2486 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2487 | main.log.info( self.name + " ::::::" ) |
| 2488 | main.log.error( traceback.print_exc() ) |
| 2489 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2490 | main.cleanup() |
| 2491 | main.exit() |
| 2492 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2493 | <<<<<<< HEAD |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2494 | def election_test_run(self): |
| 2495 | ''' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2496 | CLI command to run for leadership of the Election test application. |
| 2497 | NOTE: Requires installation of the onos-app-election feature |
| 2498 | Returns: Main.TRUE on success |
| 2499 | Main.FALSE on error |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2500 | ''' |
| 2501 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2502 | cmd_str = "election-test-run" |
| 2503 | response = self.sendline( cmd_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2504 | #success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2505 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
| 2506 | "Election\sapp." |
| 2507 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2508 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2509 | main.log.info( self.name + " entering leadership elections " + |
| 2510 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2511 | return main.TRUE |
| 2512 | #error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2513 | errorPattern = "Command\snot\sfound" |
| 2514 | if re.search( errorPattern, response ): |
| 2515 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2516 | return main.FALSE |
| 2517 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2518 | main.log.error( "Error in election_test_run: " + |
| 2519 | "unexpected response" ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2520 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2521 | def election_test_run( self ): |
| 2522 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2523 | * CLI command to run for leadership of the Election test application. |
| 2524 | #NOTE: Requires installation of the onos-app-election feature |
| 2525 | Returns: Main.TRUE on success |
| 2526 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2527 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2528 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2529 | self.handle.sendline( "election-test-run" ) |
| 2530 | self.handle.expect( "election-test-run" ) |
| 2531 | self.handle.expect( "onos>" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2532 | response = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2533 | # success |
| 2534 | search = re.search( |
| 2535 | "Entering\sleadership\selections\sfor\sthe\sElection\sapp.", |
| 2536 | response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2537 | if search: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2538 | main.log.info( |
| 2539 | self.name + |
| 2540 | " entering leadership elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2541 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2542 | # error |
| 2543 | if re.search( "Command\snot\sfound", response ): |
| 2544 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2545 | return main.FALSE |
| 2546 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2547 | main.log.error( |
| 2548 | "Error in election_test_run: unexpected response" ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2549 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2550 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2551 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2552 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2553 | main.log.error( self.name + ": EOF exception found" ) |
| 2554 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2555 | main.cleanup() |
| 2556 | main.exit() |
| 2557 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2558 | main.log.info( self.name + " ::::::" ) |
| 2559 | main.log.error( traceback.print_exc() ) |
| 2560 | main.log.info( self.name + " ::::::" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2561 | main.cleanup() |
| 2562 | main.exit() |
| 2563 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2564 | def election_test_withdraw( self ): |
| 2565 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2566 | * CLI command to withdraw the local node from leadership election for |
| 2567 | * the Election test application. |
| 2568 | #NOTE: Requires installation of the onos-app-election feature |
| 2569 | Returns: Main.TRUE on success |
| 2570 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2571 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2572 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2573 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2574 | cmd_str = "election-test-withdraw" |
| 2575 | response = self.sendline( cmd_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2576 | #success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2577 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
| 2578 | "\sthe\sElection\sapp." |
| 2579 | if re.search( successPattern, response ): |
| 2580 | main.log.info( self.name + " withdrawing from leadership " + |
| 2581 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2582 | return main.TRUE |
| 2583 | #error |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2584 | errorPattern = "Command\snot\sfound" |
| 2585 | if re.search( errorPattern, response ): |
| 2586 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2587 | return main.FALSE |
| 2588 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2589 | main.log.error( "Error in election_test_withdraw: " + |
| 2590 | "unexpected response" ) |
| 2591 | main.log.error( repr( response ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2592 | return main.FALSE |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2593 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2594 | self.handle.sendline( "election-test-withdraw" ) |
| 2595 | self.handle.expect( "election-test-withdraw" ) |
| 2596 | self.handle.expect( "onos>" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2597 | response = self.handle.before |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2598 | # success |
| 2599 | search = re.search( |
| 2600 | "Withdrawing\sfrom\sleadership\selections\sfor\sthe\sElection\sapp.", |
| 2601 | response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2602 | if search: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2603 | main.log.info( |
| 2604 | self.name + |
| 2605 | " withdrawing from leadership elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2606 | return main.TRUE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2607 | # error |
| 2608 | if re.search( "Command\snot\sfound", response ): |
| 2609 | main.log.error( "Election app is not loaded on " + self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2610 | return main.FALSE |
| 2611 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2612 | main.log.error( |
| 2613 | "Error in election_test_withdraw: unexpected response" ) |
| 2614 | main.log.error( repr( response ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2615 | return main.FALSE |
| 2616 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2617 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2618 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2619 | main.log.error( self.name + ": EOF exception found" ) |
| 2620 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2621 | main.cleanup() |
| 2622 | main.exit() |
| 2623 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2624 | main.log.info( self.name + " ::::::" ) |
| 2625 | main.log.error( traceback.print_exc() ) |
| 2626 | main.log.info( self.name + " ::::::" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2627 | main.cleanup() |
| 2628 | main.exit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2629 | |
| 2630 | #*********************************** |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2631 | def getDevicePortsEnabledCount( self, dpid ): |
| 2632 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2633 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2634 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2635 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2636 | dpid = str( dpid ) |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2637 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2638 | cmd_str = "onos:ports -e " + dpid + " | wc -l" |
| 2639 | output = self.sendline( cmd_str ) |
| 2640 | if re.search( "No such device", output ): |
| 2641 | main.log.error( "Error in getting ports" ) |
| 2642 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2643 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2644 | return output |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2645 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2646 | self.handle.sendline( "" ) |
| 2647 | self.handle.expect( "onos>" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2648 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2649 | self.handle.sendline( "onos:ports -e " + dpid + " | wc -l" ) |
| 2650 | i = self.handle.expect( [ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2651 | "No such device", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2652 | "onos>" ] ) |
| 2653 | |
| 2654 | # self.handle.sendline( "" ) |
| 2655 | # self.handle.expect( "onos>" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2656 | |
| 2657 | output = self.handle.before |
| 2658 | |
| 2659 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2660 | main.log.error( "Error in getting ports" ) |
| 2661 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2662 | else: |
| 2663 | result = output |
| 2664 | return result |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2665 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2666 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2667 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2668 | main.log.error( self.name + ": EOF exception found" ) |
| 2669 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2670 | main.cleanup() |
| 2671 | main.exit() |
| 2672 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2673 | main.log.info( self.name + " ::::::" ) |
| 2674 | main.log.error( traceback.print_exc() ) |
| 2675 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2676 | main.cleanup() |
| 2677 | main.exit() |
| 2678 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2679 | def getDeviceLinksActiveCount( self, dpid ): |
| 2680 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2681 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2682 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2683 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2684 | <<<<<<< HEAD |
Hari Krishna | 2bbaa70 | 2014-12-19 14:46:12 -0800 | [diff] [blame] | 2685 | dpid = str(dpid) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2686 | cmd_str = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 2687 | output = self.sendline( cmd_str ) |
| 2688 | if re.search( "No such device", output ): |
| 2689 | main.log.error( "Error in getting ports ") |
| 2690 | return ( output, "Error ") |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2691 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2692 | return output |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2693 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2694 | dpid = str( dpid ) |
| 2695 | self.handle.sendline( "" ) |
| 2696 | self.handle.expect( "onos>" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2697 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2698 | self.handle.sendline( |
| 2699 | "onos:links " + |
| 2700 | dpid + |
| 2701 | " | grep ACTIVE | wc -l" ) |
| 2702 | i = self.handle.expect( [ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2703 | "No such device", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2704 | "onos>" ] ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2705 | |
| 2706 | output = self.handle.before |
| 2707 | |
| 2708 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2709 | main.log.error( "Error in getting ports" ) |
| 2710 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2711 | else: |
| 2712 | result = output |
| 2713 | return result |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2714 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2715 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2716 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2717 | main.log.error( self.name + ": EOF exception found" ) |
| 2718 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2719 | main.cleanup() |
| 2720 | main.exit() |
| 2721 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2722 | main.log.info( self.name + " ::::::" ) |
| 2723 | main.log.error( traceback.print_exc() ) |
| 2724 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2725 | main.cleanup() |
| 2726 | main.exit() |
| 2727 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2728 | def getAllIntentIds( self ): |
| 2729 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2730 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2731 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2732 | try: |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2733 | <<<<<<< HEAD |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2734 | cmd_str = "onos:intents | grep id=" |
| 2735 | output = self.sendline( cmd_str ) |
| 2736 | if re.search( "Error", output ): |
| 2737 | main.log.error( "Error in getting ports" ) |
| 2738 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2739 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2740 | return output |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2741 | ======= |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2742 | self.handle.sendline( "" ) |
| 2743 | self.handle.expect( "onos>" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2744 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2745 | self.handle.sendline( "onos:intents | grep id=" ) |
| 2746 | i = self.handle.expect( [ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2747 | "Error", |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2748 | "onos>" ] ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2749 | |
| 2750 | output = self.handle.before |
| 2751 | |
| 2752 | if i == 0: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2753 | main.log.error( "Error in getting ports" ) |
| 2754 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2755 | else: |
| 2756 | result = output |
| 2757 | return result |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2758 | |
kelvin | 9c3d491 | 2015-01-15 17:36:47 -0800 | [diff] [blame] | 2759 | >>>>>>> 8ec71447cf6f890345b6b3c29368d5bd3c29dd54 |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2760 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2761 | main.log.error( self.name + ": EOF exception found" ) |
| 2762 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2763 | main.cleanup() |
| 2764 | main.exit() |
| 2765 | except: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2766 | main.log.info( self.name + " ::::::" ) |
| 2767 | main.log.error( traceback.print_exc() ) |
| 2768 | main.log.info( self.name + " ::::::" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 2769 | main.cleanup() |
| 2770 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2771 | |