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 |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 17 | Modified 2016 by ON.Lab |
| 18 | |
| 19 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 20 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 21 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 22 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 23 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 24 | import pexpect |
| 25 | import re |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 26 | import json |
| 27 | import types |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 28 | import time |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 29 | import os |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 30 | from drivers.common.clidriver import CLI |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 31 | from core.graph import Graph |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 32 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 33 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 34 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 35 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 36 | def __init__( self ): |
| 37 | """ |
| 38 | Initialize client |
| 39 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 40 | self.name = None |
| 41 | self.home = None |
| 42 | self.handle = None |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 43 | self.graph = Graph() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 44 | super( CLI, self ).__init__() |
| 45 | |
| 46 | def connect( self, **connectargs ): |
| 47 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 48 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 49 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 50 | try: |
| 51 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 52 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 658ec01 | 2015-03-11 15:13:09 -0700 | [diff] [blame] | 53 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 54 | for key in self.options: |
| 55 | if key == "home": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 56 | self.home = self.options[ 'home' ] |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 57 | break |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 58 | if self.home is None or self.home == "": |
Jon Hall | e94919c | 2015-03-23 11:42:57 -0700 | [diff] [blame] | 59 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 60 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 61 | for key in self.options: |
| 62 | if key == 'onosIp': |
| 63 | self.onosIp = self.options[ 'onosIp' ] |
| 64 | break |
| 65 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 66 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 67 | |
| 68 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 69 | if os.getenv( str( self.ip_address ) ) is not None: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 70 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 71 | else: |
| 72 | main.log.info( self.name + |
| 73 | ": Trying to connect to " + |
| 74 | self.ip_address ) |
| 75 | |
| 76 | except KeyError: |
| 77 | main.log.info( "Invalid host name," + |
| 78 | " connecting to local host instead" ) |
| 79 | self.ip_address = 'localhost' |
| 80 | except Exception as inst: |
| 81 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 82 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 83 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 84 | user_name=self.user_name, |
| 85 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 86 | port=self.port, |
| 87 | pwd=self.pwd, |
| 88 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 89 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 90 | self.handle.sendline( "cd " + self.home ) |
| 91 | self.handle.expect( "\$" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 92 | if self.handle: |
| 93 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 94 | else: |
| 95 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 96 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 97 | except TypeError: |
| 98 | main.log.exception( self.name + ": Object not as expected" ) |
| 99 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 100 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 101 | main.log.error( self.name + ": EOF exception found" ) |
| 102 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 103 | main.cleanup() |
| 104 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 105 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 106 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 107 | main.cleanup() |
| 108 | main.exit() |
| 109 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 110 | def disconnect( self ): |
| 111 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 112 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 113 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 114 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 115 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 116 | if self.handle: |
| 117 | i = self.logout() |
| 118 | if i == main.TRUE: |
| 119 | self.handle.sendline( "" ) |
| 120 | self.handle.expect( "\$" ) |
| 121 | self.handle.sendline( "exit" ) |
| 122 | self.handle.expect( "closed" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 123 | except TypeError: |
| 124 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 125 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 126 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 127 | main.log.error( self.name + ": EOF exception found" ) |
| 128 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 129 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 130 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 131 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 132 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 133 | main.log.exception( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 134 | response = main.FALSE |
| 135 | return response |
| 136 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 137 | def logout( self ): |
| 138 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 139 | Sends 'logout' command to ONOS cli |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 140 | Returns main.TRUE if exited CLI and |
| 141 | main.FALSE on timeout (not guranteed you are disconnected) |
| 142 | None on TypeError |
| 143 | Exits test on unknown error or pexpect exits unexpectedly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 144 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 145 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 146 | if self.handle: |
| 147 | self.handle.sendline( "" ) |
| 148 | i = self.handle.expect( [ "onos>", "\$", pexpect.TIMEOUT ], |
| 149 | timeout=10 ) |
| 150 | if i == 0: # In ONOS CLI |
| 151 | self.handle.sendline( "logout" ) |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 152 | j = self.handle.expect( [ "\$", |
| 153 | "Command not found:", |
| 154 | pexpect.TIMEOUT ] ) |
| 155 | if j == 0: # Successfully logged out |
| 156 | return main.TRUE |
| 157 | elif j == 1 or j == 2: |
| 158 | # ONOS didn't fully load, and logout command isn't working |
| 159 | # or the command timed out |
| 160 | self.handle.send( "\x04" ) # send ctrl-d |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 161 | try: |
| 162 | self.handle.expect( "\$" ) |
| 163 | except pexpect.TIMEOUT: |
| 164 | main.log.error( "ONOS did not respond to 'logout' or CTRL-d" ) |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 165 | return main.TRUE |
| 166 | else: # some other output |
| 167 | main.log.warn( "Unknown repsonse to logout command: '{}'", |
| 168 | repr( self.handle.before ) ) |
| 169 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 170 | elif i == 1: # not in CLI |
| 171 | return main.TRUE |
| 172 | elif i == 3: # Timeout |
| 173 | return main.FALSE |
| 174 | else: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 175 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 176 | except TypeError: |
| 177 | main.log.exception( self.name + ": Object not as expected" ) |
| 178 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 179 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 180 | main.log.error( self.name + ": eof exception found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 181 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 182 | main.cleanup() |
| 183 | main.exit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 184 | except ValueError: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 185 | main.log.error( self.name + |
| 186 | "ValueError exception in logout method" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 187 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 188 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 189 | main.cleanup() |
| 190 | main.exit() |
| 191 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 192 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 193 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 194 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 195 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 196 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 197 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 198 | try: |
| 199 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 200 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 201 | main.cleanup() |
| 202 | main.exit() |
| 203 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 204 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 205 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 206 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 207 | # and that this driver will have to change accordingly |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 208 | self.handle.expect(str(cellname)) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 209 | handleBefore = self.handle.before |
| 210 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 211 | # Get the rest of the handle |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 212 | self.handle.sendline("") |
| 213 | self.handle.expect("\$") |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 214 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 215 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 216 | main.log.info( "Cell call returned: " + handleBefore + |
| 217 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 218 | |
| 219 | return main.TRUE |
| 220 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 221 | except TypeError: |
| 222 | main.log.exception( self.name + ": Object not as expected" ) |
| 223 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 224 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 225 | main.log.error( self.name + ": eof exception found" ) |
| 226 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 227 | main.cleanup() |
| 228 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 229 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 230 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 231 | main.cleanup() |
| 232 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 233 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 234 | def startOnosCli( self, ONOSIp, karafTimeout="", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 235 | commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 236 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 237 | karafTimeout is an optional argument. karafTimeout value passed |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 238 | by user would be used to set the current karaf shell idle timeout. |
| 239 | Note that when ever this property is modified the shell will exit and |
Hari Krishna | d7b9c20 | 2015-01-05 10:38:14 -0800 | [diff] [blame] | 240 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 241 | Below is an example to start a session with 60 seconds idle timeout |
| 242 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 243 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 244 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 245 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 246 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 247 | Note: karafTimeout is left as str so that this could be read |
| 248 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 249 | """ |
You Wang | f69ab39 | 2016-01-26 16:34:38 -0800 | [diff] [blame] | 250 | self.onosIp = ONOSIp |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 251 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 252 | self.handle.sendline( "" ) |
| 253 | x = self.handle.expect( [ |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 254 | "\$", "onos>" ], commandlineTimeout) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 255 | |
| 256 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 257 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 258 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 259 | |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 260 | if waitForStart: |
| 261 | # Wait for onos start ( -w ) and enter onos cli |
| 262 | startCliCommand = "onos -w " |
| 263 | else: |
| 264 | startCliCommand = "onos " |
| 265 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 266 | i = self.handle.expect( [ |
| 267 | "onos>", |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 268 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 269 | |
| 270 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 271 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 272 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 273 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 274 | "config:property-set -p org.apache.karaf.shell\ |
| 275 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 276 | karafTimeout ) |
| 277 | self.handle.expect( "\$" ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 278 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 279 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 280 | return main.TRUE |
| 281 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 282 | # If failed, send ctrl+c to process and try again |
| 283 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 284 | self.handle.send( "\x03" ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 285 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 286 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 287 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 288 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 289 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 290 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 291 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 292 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 293 | "config:property-set -p org.apache.karaf.shell\ |
| 294 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 295 | karafTimeout ) |
| 296 | self.handle.expect( "\$" ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 297 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 298 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 299 | return main.TRUE |
| 300 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 301 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 302 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 303 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 304 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 305 | except TypeError: |
| 306 | main.log.exception( self.name + ": Object not as expected" ) |
| 307 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 308 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 309 | main.log.error( self.name + ": EOF exception found" ) |
| 310 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 311 | main.cleanup() |
| 312 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 313 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 314 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 315 | main.cleanup() |
| 316 | main.exit() |
| 317 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 318 | def startCellCli( self, karafTimeout="", |
| 319 | commandlineTimeout=10, onosStartTimeout=60 ): |
| 320 | """ |
| 321 | Start CLI on onos ecll handle. |
| 322 | |
| 323 | karafTimeout is an optional argument. karafTimeout value passed |
| 324 | by user would be used to set the current karaf shell idle timeout. |
| 325 | Note that when ever this property is modified the shell will exit and |
| 326 | the subsequent login would reflect new idle timeout. |
| 327 | Below is an example to start a session with 60 seconds idle timeout |
| 328 | ( input value is in milliseconds ): |
| 329 | |
| 330 | tValue = "60000" |
| 331 | |
| 332 | Note: karafTimeout is left as str so that this could be read |
| 333 | and passed to startOnosCli from PARAMS file as str. |
| 334 | """ |
| 335 | |
| 336 | try: |
| 337 | self.handle.sendline( "" ) |
| 338 | x = self.handle.expect( [ |
| 339 | "\$", "onos>" ], commandlineTimeout) |
| 340 | |
| 341 | if x == 1: |
| 342 | main.log.info( "ONOS cli is already running" ) |
| 343 | return main.TRUE |
| 344 | |
| 345 | # Wait for onos start ( -w ) and enter onos cli |
| 346 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 347 | i = self.handle.expect( [ |
| 348 | "onos>", |
| 349 | pexpect.TIMEOUT ], onosStartTimeout ) |
| 350 | |
| 351 | if i == 0: |
| 352 | main.log.info( self.name + " CLI Started successfully" ) |
| 353 | if karafTimeout: |
| 354 | self.handle.sendline( |
| 355 | "config:property-set -p org.apache.karaf.shell\ |
| 356 | sshIdleTimeout " + |
| 357 | karafTimeout ) |
| 358 | self.handle.expect( "\$" ) |
| 359 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 360 | self.handle.expect( "onos>" ) |
| 361 | return main.TRUE |
| 362 | else: |
| 363 | # If failed, send ctrl+c to process and try again |
| 364 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 365 | self.handle.send( "\x03" ) |
| 366 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 367 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 368 | timeout=30 ) |
| 369 | if i == 0: |
| 370 | main.log.info( self.name + " CLI Started " + |
| 371 | "successfully after retry attempt" ) |
| 372 | if karafTimeout: |
| 373 | self.handle.sendline( |
| 374 | "config:property-set -p org.apache.karaf.shell\ |
| 375 | sshIdleTimeout " + |
| 376 | karafTimeout ) |
| 377 | self.handle.expect( "\$" ) |
| 378 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 379 | self.handle.expect( "onos>" ) |
| 380 | return main.TRUE |
| 381 | else: |
| 382 | main.log.error( "Connection to CLI " + |
| 383 | self.name + " timeout" ) |
| 384 | return main.FALSE |
| 385 | |
| 386 | except TypeError: |
| 387 | main.log.exception( self.name + ": Object not as expected" ) |
| 388 | return None |
| 389 | except pexpect.EOF: |
| 390 | main.log.error( self.name + ": EOF exception found" ) |
| 391 | main.log.error( self.name + ": " + self.handle.before ) |
| 392 | main.cleanup() |
| 393 | main.exit() |
| 394 | except Exception: |
| 395 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 396 | main.cleanup() |
| 397 | main.exit() |
| 398 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 399 | def log( self, cmdStr, level="",noExit=False): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 400 | """ |
| 401 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 402 | returns main.TRUE on success |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 403 | returns main.FALSE if Error occurred |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 404 | if noExit is True, TestON will not exit, but clean up |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 405 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 406 | Level defaults to INFO |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 407 | """ |
| 408 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 409 | lvlStr = "" |
| 410 | if level: |
| 411 | lvlStr = "--level=" + level |
| 412 | |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 413 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 414 | self.handle.expect( "log:log" ) |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 415 | self.handle.expect( "onos>" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 416 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 417 | response = self.handle.before |
| 418 | if re.search( "Error", response ): |
| 419 | return main.FALSE |
| 420 | return main.TRUE |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 421 | except pexpect.TIMEOUT: |
| 422 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 423 | if noExit: |
| 424 | main.cleanup() |
| 425 | return None |
| 426 | else: |
| 427 | main.cleanup() |
| 428 | main.exit() |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 429 | except pexpect.EOF: |
| 430 | main.log.error( self.name + ": EOF exception found" ) |
| 431 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 432 | if noExit: |
| 433 | main.cleanup() |
| 434 | return None |
| 435 | else: |
| 436 | main.cleanup() |
| 437 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 438 | except Exception: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 439 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 440 | if noExit: |
| 441 | main.cleanup() |
| 442 | return None |
| 443 | else: |
| 444 | main.cleanup() |
| 445 | main.exit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 446 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 447 | def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 448 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 449 | Send a completely user specified string to |
| 450 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 451 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 452 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 453 | if noExit is True, TestON will not exit, and return None |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 454 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 455 | Warning: There are no sanity checking to commands |
| 456 | sent using this method. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 457 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 458 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 459 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 460 | # Try to reconnect if disconnected from cli |
| 461 | self.handle.sendline( "" ) |
| 462 | i = self.handle.expect( [ "onos>", "\$", pexpect.TIMEOUT ] ) |
| 463 | if i == 1: |
| 464 | main.log.error( self.name + ": onos cli session closed. ") |
| 465 | if self.onosIp: |
| 466 | main.log.warn( "Trying to reconnect " + self.onosIp ) |
| 467 | reconnectResult = self.startOnosCli( self.onosIp ) |
| 468 | if reconnectResult: |
| 469 | main.log.info( self.name + ": onos cli session reconnected." ) |
| 470 | else: |
| 471 | main.log.error( self.name + ": reconnection failed." ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 472 | if noExit: |
| 473 | return None |
| 474 | else: |
| 475 | main.cleanup() |
| 476 | main.exit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 477 | else: |
| 478 | main.cleanup() |
| 479 | main.exit() |
| 480 | if i == 2: |
| 481 | self.handle.sendline( "" ) |
| 482 | self.handle.expect( "onos>" ) |
| 483 | |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 484 | if debug: |
| 485 | # NOTE: This adds and average of .4 seconds per call |
| 486 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 487 | self.log( logStr,noExit=noExit ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 488 | self.handle.sendline( cmdStr ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 489 | i = self.handle.expect( ["onos>", "\$"], timeout ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 490 | response = self.handle.before |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 491 | # TODO: do something with i |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 492 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
| 493 | + self.name + "." ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 494 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 495 | main.log.debug( self.name + ": Raw output" ) |
| 496 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 497 | |
| 498 | # Remove ANSI color control strings from output |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 499 | ansiEscape = re.compile( r'\x1b[^m]*m' ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 500 | response = ansiEscape.sub( '', response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 501 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 502 | main.log.debug( self.name + ": ansiEscape output" ) |
| 503 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 504 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 505 | # Remove extra return chars that get added |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 506 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 507 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 508 | main.log.debug( self.name + ": Removed extra returns " + |
| 509 | "from output" ) |
| 510 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 511 | |
| 512 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 513 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 514 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 515 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 516 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 517 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 518 | # parse for just the output, remove the cmd from response |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 519 | output = response.split( cmdStr.strip(), 1 ) |
| 520 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 521 | main.log.debug( self.name + ": split output" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 522 | for r in output: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 523 | main.log.debug( self.name + ": " + repr( r ) ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 524 | output = output[1].strip() |
| 525 | if showResponse: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 526 | main.log.info( "Response from ONOS: {}".format( output ) ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 527 | return output |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 528 | except pexpect.TIMEOUT: |
| 529 | main.log.error( self.name + ":ONOS timeout" ) |
| 530 | if debug: |
| 531 | main.log.debug( self.handle.before ) |
| 532 | return None |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 533 | except IndexError: |
| 534 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 535 | main.log.debug( "response: {}".format( repr( response ) ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 536 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 537 | except TypeError: |
| 538 | main.log.exception( self.name + ": Object not as expected" ) |
| 539 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 540 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 541 | main.log.error( self.name + ": EOF exception found" ) |
| 542 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 543 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 544 | return None |
| 545 | else: |
| 546 | main.cleanup() |
| 547 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 548 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 549 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 550 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 551 | return None |
| 552 | else: |
| 553 | main.cleanup() |
| 554 | main.exit() |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 555 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 556 | # IMPORTANT NOTE: |
| 557 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 558 | # the cli command changing 'a:b' with 'aB'. |
| 559 | # Ex ) onos:topology > onosTopology |
| 560 | # onos:links > onosLinks |
| 561 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 562 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 563 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 564 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 565 | Adds a new cluster node by ID and address information. |
| 566 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 567 | * nodeId |
| 568 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 569 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 570 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 571 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 572 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 573 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 574 | str( ONOSIp ) + " " + str( tcpPort ) |
| 575 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 576 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 577 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 578 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 579 | main.log.error( "Error in adding node" ) |
| 580 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 581 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 582 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 583 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 584 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 585 | except AssertionError: |
| 586 | main.log.exception( "" ) |
| 587 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 588 | except TypeError: |
| 589 | main.log.exception( self.name + ": Object not as expected" ) |
| 590 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 591 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 592 | main.log.error( self.name + ": EOF exception found" ) |
| 593 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 594 | main.cleanup() |
| 595 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 596 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 597 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 598 | main.cleanup() |
| 599 | main.exit() |
| 600 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 601 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 602 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 603 | Removes a cluster by ID |
| 604 | Issues command: 'remove-node [<node-id>]' |
| 605 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 606 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 607 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 608 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 609 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 610 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 611 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 612 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 613 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 614 | if re.search( "Error", handle ): |
| 615 | main.log.error( "Error in removing node" ) |
| 616 | main.log.error( handle ) |
| 617 | return main.FALSE |
| 618 | else: |
| 619 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 620 | except AssertionError: |
| 621 | main.log.exception( "" ) |
| 622 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 623 | except TypeError: |
| 624 | main.log.exception( self.name + ": Object not as expected" ) |
| 625 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 626 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 627 | main.log.error( self.name + ": EOF exception found" ) |
| 628 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 629 | main.cleanup() |
| 630 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 631 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 632 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 633 | main.cleanup() |
| 634 | main.exit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 635 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 636 | def nodes( self, jsonFormat=True): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 637 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 638 | List the nodes currently visible |
| 639 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 640 | Optional argument: |
| 641 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 642 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 643 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 644 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 645 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 646 | cmdStr += " -j" |
| 647 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 648 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 649 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 650 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 651 | except AssertionError: |
| 652 | main.log.exception( "" ) |
| 653 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 654 | except TypeError: |
| 655 | main.log.exception( self.name + ": Object not as expected" ) |
| 656 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 657 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 658 | main.log.error( self.name + ": EOF exception found" ) |
| 659 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 660 | main.cleanup() |
| 661 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 662 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 663 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 664 | main.cleanup() |
| 665 | main.exit() |
| 666 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 667 | def topology( self ): |
| 668 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 669 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 670 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 671 | Return: |
| 672 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 673 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 674 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 675 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 676 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 677 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 678 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 679 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 680 | except AssertionError: |
| 681 | main.log.exception( "" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 682 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 683 | except TypeError: |
| 684 | main.log.exception( self.name + ": Object not as expected" ) |
| 685 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 686 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 687 | main.log.error( self.name + ": EOF exception found" ) |
| 688 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 689 | main.cleanup() |
| 690 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 691 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 692 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 693 | main.cleanup() |
| 694 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 695 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 696 | def deviceRemove( self, deviceId ): |
| 697 | """ |
| 698 | Removes particular device from storage |
| 699 | |
| 700 | TODO: refactor this function |
| 701 | """ |
| 702 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 703 | cmdStr = "device-remove " + str( deviceId ) |
| 704 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 705 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 706 | if re.search( "Error", handle ): |
| 707 | main.log.error( "Error in removing device" ) |
| 708 | main.log.error( handle ) |
| 709 | return main.FALSE |
| 710 | else: |
| 711 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 712 | except AssertionError: |
| 713 | main.log.exception( "" ) |
| 714 | return None |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 715 | except TypeError: |
| 716 | main.log.exception( self.name + ": Object not as expected" ) |
| 717 | return None |
| 718 | except pexpect.EOF: |
| 719 | main.log.error( self.name + ": EOF exception found" ) |
| 720 | main.log.error( self.name + ": " + self.handle.before ) |
| 721 | main.cleanup() |
| 722 | main.exit() |
| 723 | except Exception: |
| 724 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 725 | main.cleanup() |
| 726 | main.exit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 727 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 728 | def devices( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 729 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 730 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 731 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 732 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 733 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 734 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 735 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 736 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 737 | cmdStr += " -j" |
| 738 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 739 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 740 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 741 | except AssertionError: |
| 742 | main.log.exception( "" ) |
| 743 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 744 | except TypeError: |
| 745 | main.log.exception( self.name + ": Object not as expected" ) |
| 746 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 747 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 748 | main.log.error( self.name + ": EOF exception found" ) |
| 749 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 750 | main.cleanup() |
| 751 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 752 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 753 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 754 | main.cleanup() |
| 755 | main.exit() |
| 756 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 757 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 758 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 759 | This balances the devices across all controllers |
| 760 | by issuing command: 'onos> onos:balance-masters' |
| 761 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 762 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 763 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 764 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 765 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 766 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 767 | if re.search( "Error", handle ): |
| 768 | main.log.error( "Error in balancing masters" ) |
| 769 | main.log.error( handle ) |
| 770 | return main.FALSE |
| 771 | else: |
| 772 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 773 | except AssertionError: |
| 774 | main.log.exception( "" ) |
| 775 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 776 | except TypeError: |
| 777 | main.log.exception( self.name + ": Object not as expected" ) |
| 778 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 779 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 780 | main.log.error( self.name + ": EOF exception found" ) |
| 781 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 782 | main.cleanup() |
| 783 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 784 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 785 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 786 | main.cleanup() |
| 787 | main.exit() |
| 788 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 789 | def checkMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 790 | """ |
| 791 | Returns the output of the masters command. |
| 792 | Optional argument: |
| 793 | * jsonFormat - boolean indicating if you want output in json |
| 794 | """ |
| 795 | try: |
| 796 | cmdStr = "onos:masters" |
| 797 | if jsonFormat: |
| 798 | cmdStr += " -j" |
| 799 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 800 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 801 | assert "Command not found:" not in output, output |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 802 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 803 | except AssertionError: |
| 804 | main.log.exception( "" ) |
| 805 | return None |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 806 | except TypeError: |
| 807 | main.log.exception( self.name + ": Object not as expected" ) |
| 808 | return None |
| 809 | except pexpect.EOF: |
| 810 | main.log.error( self.name + ": EOF exception found" ) |
| 811 | main.log.error( self.name + ": " + self.handle.before ) |
| 812 | main.cleanup() |
| 813 | main.exit() |
| 814 | except Exception: |
| 815 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 816 | main.cleanup() |
| 817 | main.exit() |
| 818 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 819 | def checkBalanceMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 820 | """ |
| 821 | Uses the master command to check that the devices' leadership |
| 822 | is evenly divided |
| 823 | |
| 824 | Dependencies: checkMasters() and summary() |
| 825 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 826 | Returns main.TRUE if the devices are balanced |
| 827 | Returns main.FALSE if the devices are unbalanced |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 828 | Exits on Exception |
| 829 | Returns None on TypeError |
| 830 | """ |
| 831 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 832 | summaryOutput = self.summary() |
| 833 | totalDevices = json.loads( summaryOutput )[ "devices" ] |
| 834 | except ( TypeError, ValueError ): |
| 835 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) ) |
| 836 | return None |
| 837 | try: |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 838 | totalOwnedDevices = 0 |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 839 | mastersOutput = self.checkMasters() |
| 840 | masters = json.loads( mastersOutput ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 841 | first = masters[ 0 ][ "size" ] |
| 842 | for master in masters: |
| 843 | totalOwnedDevices += master[ "size" ] |
| 844 | if master[ "size" ] > first + 1 or master[ "size" ] < first - 1: |
| 845 | main.log.error( "Mastership not balanced" ) |
| 846 | main.log.info( "\n" + self.checkMasters( False ) ) |
| 847 | return main.FALSE |
| 848 | main.log.info( "Mastership balanced between " \ |
| 849 | + str( len(masters) ) + " masters" ) |
| 850 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 851 | except ( TypeError, ValueError ): |
| 852 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 853 | return None |
| 854 | except pexpect.EOF: |
| 855 | main.log.error( self.name + ": EOF exception found" ) |
| 856 | main.log.error( self.name + ": " + self.handle.before ) |
| 857 | main.cleanup() |
| 858 | main.exit() |
| 859 | except Exception: |
| 860 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 861 | main.cleanup() |
| 862 | main.exit() |
| 863 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 864 | def links( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 865 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 866 | Lists all core links |
| 867 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 868 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 869 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 870 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 871 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 872 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 873 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 874 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 875 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 876 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 877 | except AssertionError: |
| 878 | main.log.exception( "" ) |
| 879 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 880 | except TypeError: |
| 881 | main.log.exception( self.name + ": Object not as expected" ) |
| 882 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 883 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 884 | main.log.error( self.name + ": EOF exception found" ) |
| 885 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 886 | main.cleanup() |
| 887 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 888 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 889 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 890 | main.cleanup() |
| 891 | main.exit() |
| 892 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 893 | def ports( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 894 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 895 | Lists all ports |
| 896 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 897 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 898 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 899 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 900 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 901 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 902 | cmdStr += " -j" |
| 903 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 904 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 905 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 906 | except AssertionError: |
| 907 | main.log.exception( "" ) |
| 908 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 909 | except TypeError: |
| 910 | main.log.exception( self.name + ": Object not as expected" ) |
| 911 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 912 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 913 | main.log.error( self.name + ": EOF exception found" ) |
| 914 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 915 | main.cleanup() |
| 916 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 917 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 918 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 919 | main.cleanup() |
| 920 | main.exit() |
| 921 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 922 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 923 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 924 | Lists all devices and the controllers with roles assigned to them |
| 925 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 926 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 927 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 928 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 929 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 930 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 931 | cmdStr += " -j" |
| 932 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 933 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 934 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 935 | except AssertionError: |
| 936 | main.log.exception( "" ) |
| 937 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 938 | except TypeError: |
| 939 | main.log.exception( self.name + ": Object not as expected" ) |
| 940 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 941 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 942 | main.log.error( self.name + ": EOF exception found" ) |
| 943 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 944 | main.cleanup() |
| 945 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 946 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 947 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 948 | main.cleanup() |
| 949 | main.exit() |
| 950 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 951 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 952 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 953 | Given the a string containing the json representation of the "roles" |
| 954 | cli command and a partial or whole device id, returns a json object |
| 955 | containing the roles output for the first device whose id contains |
| 956 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 957 | |
| 958 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 959 | A dict of the role assignments for the given device or |
| 960 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 961 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 962 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 963 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 964 | return None |
| 965 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 966 | rawRoles = self.roles() |
| 967 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 968 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 969 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 970 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 971 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 972 | return device |
| 973 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 974 | except ( TypeError, ValueError ): |
| 975 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 976 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 977 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 978 | main.log.error( self.name + ": EOF exception found" ) |
| 979 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 980 | main.cleanup() |
| 981 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 982 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 983 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 984 | main.cleanup() |
| 985 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 986 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 987 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 988 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 989 | Iterates through each device and checks if there is a master assigned |
| 990 | Returns: main.TRUE if each device has a master |
| 991 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 992 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 993 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 994 | rawRoles = self.roles() |
| 995 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 996 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 997 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 998 | # print device |
| 999 | if device[ 'master' ] == "none": |
| 1000 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1001 | return main.FALSE |
| 1002 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1003 | except ( TypeError, ValueError ): |
| 1004 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1005 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1006 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1007 | main.log.error( self.name + ": EOF exception found" ) |
| 1008 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1009 | main.cleanup() |
| 1010 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1011 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1012 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1013 | main.cleanup() |
| 1014 | main.exit() |
| 1015 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1016 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1017 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1018 | Returns string of paths, and the cost. |
| 1019 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1020 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1021 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1022 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 1023 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1024 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1025 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1026 | main.log.error( "Error in getting paths" ) |
| 1027 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1028 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1029 | path = handle.split( ";" )[ 0 ] |
| 1030 | cost = handle.split( ";" )[ 1 ] |
| 1031 | return ( path, cost ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1032 | except AssertionError: |
| 1033 | main.log.exception( "" ) |
| 1034 | return ( handle, "Error" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1035 | except TypeError: |
| 1036 | main.log.exception( self.name + ": Object not as expected" ) |
| 1037 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1038 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1039 | main.log.error( self.name + ": EOF exception found" ) |
| 1040 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1041 | main.cleanup() |
| 1042 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1043 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1044 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1045 | main.cleanup() |
| 1046 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1047 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1048 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1049 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1050 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1051 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1052 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1053 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1054 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1055 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1056 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1057 | cmdStr += " -j" |
| 1058 | handle = self.sendline( cmdStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1059 | if handle: |
| 1060 | assert "Command not found:" not in handle, handle |
Jon Hall | baf5316 | 2015-12-17 17:04:34 -0800 | [diff] [blame] | 1061 | # TODO: Maybe make this less hardcoded |
| 1062 | # ConsistentMap Exceptions |
| 1063 | assert "org.onosproject.store.service" not in handle |
| 1064 | # Node not leader |
| 1065 | assert "java.lang.IllegalStateException" not in handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1066 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1067 | except AssertionError: |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1068 | main.log.exception( "Error in processing '" + cmdStr + "' " + |
Jeremy Songster | 6949cea | 2016-04-19 18:13:18 -0700 | [diff] [blame] | 1069 | "command: " + str( handle ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1070 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1071 | except TypeError: |
| 1072 | main.log.exception( self.name + ": Object not as expected" ) |
| 1073 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1074 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1075 | main.log.error( self.name + ": EOF exception found" ) |
| 1076 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1077 | main.cleanup() |
| 1078 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1079 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1080 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1081 | main.cleanup() |
| 1082 | main.exit() |
| 1083 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1084 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1085 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1086 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1087 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1088 | Note: mac must be a colon separated mac address, but could be a |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1089 | partial mac address |
| 1090 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1091 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1092 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1093 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1094 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1095 | return None |
| 1096 | else: |
| 1097 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1098 | rawHosts = self.hosts() |
| 1099 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1100 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1101 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1102 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1103 | if not host: |
| 1104 | pass |
| 1105 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1106 | return host |
| 1107 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1108 | except ( TypeError, ValueError ): |
| 1109 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1110 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1111 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1112 | main.log.error( self.name + ": EOF exception found" ) |
| 1113 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1114 | main.cleanup() |
| 1115 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1116 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1117 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1118 | main.cleanup() |
| 1119 | main.exit() |
| 1120 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1121 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1122 | """ |
| 1123 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1124 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1125 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1126 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1127 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1128 | IMPORTANT: |
| 1129 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1130 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1131 | Furthermore, it assumes that value of VLAN is '-1' |
| 1132 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1133 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1134 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1135 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1136 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1137 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1138 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1139 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1140 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1141 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 1142 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 1143 | i = iter( str( hostHex ) ) |
| 1144 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 1145 | hostHex = hostHex + "/-1" |
| 1146 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1147 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1148 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1149 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1150 | except TypeError: |
| 1151 | main.log.exception( self.name + ": Object not as expected" ) |
| 1152 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1153 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1154 | main.log.error( self.name + ": EOF exception found" ) |
| 1155 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1156 | main.cleanup() |
| 1157 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1158 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1159 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1160 | main.cleanup() |
| 1161 | main.exit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1162 | |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1163 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1164 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1165 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1166 | * hostIdOne: ONOS host id for host1 |
| 1167 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1168 | Optional: |
| 1169 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1170 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1171 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1172 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1173 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1174 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1175 | Returns: |
| 1176 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1177 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1178 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1179 | cmdStr = "add-host-intent " |
| 1180 | if vlanId: |
| 1181 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1182 | if setVlan: |
| 1183 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1184 | if encap: |
| 1185 | cmdStr += "--encapsulation " + str( encap ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1186 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1187 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1188 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1189 | if re.search( "Error", handle ): |
| 1190 | main.log.error( "Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1191 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1192 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1193 | else: |
| 1194 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1195 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
| 1196 | match = re.search('id=0x([\da-f]+),', handle) |
| 1197 | if match: |
| 1198 | return match.group()[3:-1] |
| 1199 | else: |
| 1200 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1201 | main.log.debug( "Response from ONOS was: " + |
| 1202 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1203 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1204 | except AssertionError: |
| 1205 | main.log.exception( "" ) |
| 1206 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1207 | except TypeError: |
| 1208 | main.log.exception( self.name + ": Object not as expected" ) |
| 1209 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1210 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1211 | main.log.error( self.name + ": EOF exception found" ) |
| 1212 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1213 | main.cleanup() |
| 1214 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1215 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1216 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1217 | main.cleanup() |
| 1218 | main.exit() |
| 1219 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1220 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1221 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1222 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1223 | * ingressDevice: device id of ingress device |
| 1224 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1225 | Optional: |
| 1226 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1227 | Description: |
| 1228 | Adds an optical intent by specifying an ingress and egress device |
| 1229 | Returns: |
| 1230 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1231 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1232 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1233 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1234 | " " + str( egressDevice ) |
| 1235 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1236 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1237 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1238 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1239 | main.log.error( "Error in adding Optical intent" ) |
| 1240 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1241 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1242 | main.log.info( "Optical intent installed between " + |
| 1243 | str( ingressDevice ) + " and " + |
| 1244 | str( egressDevice ) ) |
| 1245 | match = re.search('id=0x([\da-f]+),', handle) |
| 1246 | if match: |
| 1247 | return match.group()[3:-1] |
| 1248 | else: |
| 1249 | main.log.error( "Error, intent ID not found" ) |
| 1250 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1251 | except AssertionError: |
| 1252 | main.log.exception( "" ) |
| 1253 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1254 | except TypeError: |
| 1255 | main.log.exception( self.name + ": Object not as expected" ) |
| 1256 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1257 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1258 | main.log.error( self.name + ": EOF exception found" ) |
| 1259 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1260 | main.cleanup() |
| 1261 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1262 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1263 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1264 | main.cleanup() |
| 1265 | main.exit() |
| 1266 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1267 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1268 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1269 | ingressDevice, |
| 1270 | egressDevice, |
| 1271 | portIngress="", |
| 1272 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1273 | ethType="", |
| 1274 | ethSrc="", |
| 1275 | ethDst="", |
| 1276 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1277 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1278 | ipProto="", |
| 1279 | ipSrc="", |
| 1280 | ipDst="", |
| 1281 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1282 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1283 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1284 | setVlan="", |
| 1285 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1286 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1287 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1288 | * ingressDevice: device id of ingress device |
| 1289 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1290 | Optional: |
| 1291 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1292 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1293 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1294 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1295 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1296 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1297 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1298 | * ipSrc: specify ip source address |
| 1299 | * ipDst: specify ip destination address |
| 1300 | * tcpSrc: specify tcp source port |
| 1301 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1302 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1303 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1304 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1305 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1306 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1307 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1308 | Returns: |
| 1309 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1310 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1311 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1312 | options developers provide for point-to-point |
| 1313 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1314 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1315 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1316 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1317 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1318 | if ethType: |
| 1319 | cmd += " --ethType " + str( ethType ) |
| 1320 | if ethSrc: |
| 1321 | cmd += " --ethSrc " + str( ethSrc ) |
| 1322 | if ethDst: |
| 1323 | cmd += " --ethDst " + str( ethDst ) |
| 1324 | if bandwidth: |
| 1325 | cmd += " --bandwidth " + str( bandwidth ) |
| 1326 | if lambdaAlloc: |
| 1327 | cmd += " --lambda " |
| 1328 | if ipProto: |
| 1329 | cmd += " --ipProto " + str( ipProto ) |
| 1330 | if ipSrc: |
| 1331 | cmd += " --ipSrc " + str( ipSrc ) |
| 1332 | if ipDst: |
| 1333 | cmd += " --ipDst " + str( ipDst ) |
| 1334 | if tcpSrc: |
| 1335 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1336 | if tcpDst: |
| 1337 | cmd += " --tcpDst " + str( tcpDst ) |
| 1338 | if vlanId: |
| 1339 | cmd += " -v " + str( vlanId ) |
| 1340 | if setVlan: |
| 1341 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1342 | if encap: |
| 1343 | cmd += " --encapsulation " + str( encap ) |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1344 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1345 | # Check whether the user appended the port |
| 1346 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1347 | if "/" in ingressDevice: |
| 1348 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1349 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1350 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1351 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1352 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1353 | # Would it make sense to throw an exception and exit |
| 1354 | # the test? |
| 1355 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1356 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1357 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1358 | str( ingressDevice ) + "/" +\ |
| 1359 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1360 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1361 | if "/" in egressDevice: |
| 1362 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1363 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1364 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1365 | main.log.error( "You must specify the egress port" ) |
| 1366 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1367 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1368 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1369 | str( egressDevice ) + "/" +\ |
| 1370 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1371 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1372 | handle = self.sendline( cmd ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1373 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1374 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1375 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1376 | main.log.error( "Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1377 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1378 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1379 | # TODO: print out all the options in this message? |
| 1380 | main.log.info( "Point-to-point intent installed between " + |
| 1381 | str( ingressDevice ) + " and " + |
| 1382 | str( egressDevice ) ) |
| 1383 | match = re.search('id=0x([\da-f]+),', handle) |
| 1384 | if match: |
| 1385 | return match.group()[3:-1] |
| 1386 | else: |
| 1387 | main.log.error( "Error, intent ID not found" ) |
| 1388 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1389 | except AssertionError: |
| 1390 | main.log.exception( "" ) |
| 1391 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1392 | except TypeError: |
| 1393 | main.log.exception( self.name + ": Object not as expected" ) |
| 1394 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1395 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1396 | main.log.error( self.name + ": EOF exception found" ) |
| 1397 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1398 | main.cleanup() |
| 1399 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1400 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1401 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1402 | main.cleanup() |
| 1403 | main.exit() |
| 1404 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1405 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1406 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1407 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1408 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1409 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1410 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1411 | ethType="", |
| 1412 | ethSrc="", |
| 1413 | ethDst="", |
| 1414 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1415 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1416 | ipProto="", |
| 1417 | ipSrc="", |
| 1418 | ipDst="", |
| 1419 | tcpSrc="", |
| 1420 | tcpDst="", |
| 1421 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1422 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1423 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1424 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1425 | partial=False, |
| 1426 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1427 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1428 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1429 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1430 | is same. That is, all ingress devices include port numbers |
| 1431 | with a "/" or all ingress devices could specify device |
| 1432 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1433 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1434 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1435 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1436 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1437 | Optional: |
| 1438 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1439 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1440 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1441 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1442 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1443 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1444 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1445 | * ipSrc: specify ip source address |
| 1446 | * ipDst: specify ip destination address |
| 1447 | * tcpSrc: specify tcp source port |
| 1448 | * tcpDst: specify tcp destination port |
| 1449 | * setEthSrc: action to Rewrite Source MAC Address |
| 1450 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1451 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1452 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1453 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1454 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1455 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1456 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1457 | Returns: |
| 1458 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1459 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1460 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1461 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1462 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1463 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1464 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1465 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1466 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1467 | if ethType: |
| 1468 | cmd += " --ethType " + str( ethType ) |
| 1469 | if ethSrc: |
| 1470 | cmd += " --ethSrc " + str( ethSrc ) |
| 1471 | if ethDst: |
| 1472 | cmd += " --ethDst " + str( ethDst ) |
| 1473 | if bandwidth: |
| 1474 | cmd += " --bandwidth " + str( bandwidth ) |
| 1475 | if lambdaAlloc: |
| 1476 | cmd += " --lambda " |
| 1477 | if ipProto: |
| 1478 | cmd += " --ipProto " + str( ipProto ) |
| 1479 | if ipSrc: |
| 1480 | cmd += " --ipSrc " + str( ipSrc ) |
| 1481 | if ipDst: |
| 1482 | cmd += " --ipDst " + str( ipDst ) |
| 1483 | if tcpSrc: |
| 1484 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1485 | if tcpDst: |
| 1486 | cmd += " --tcpDst " + str( tcpDst ) |
| 1487 | if setEthSrc: |
| 1488 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1489 | if setEthDst: |
| 1490 | cmd += " --setEthDst " + str( setEthDst ) |
| 1491 | if vlanId: |
| 1492 | cmd += " -v " + str( vlanId ) |
| 1493 | if setVlan: |
| 1494 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1495 | if partial: |
| 1496 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1497 | if encap: |
| 1498 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1499 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1500 | # Check whether the user appended the port |
| 1501 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1502 | |
| 1503 | if portIngressList is None: |
| 1504 | for ingressDevice in ingressDeviceList: |
| 1505 | if "/" in ingressDevice: |
| 1506 | cmd += " " + str( ingressDevice ) |
| 1507 | else: |
| 1508 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1509 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1510 | # TODO: perhaps more meaningful return |
| 1511 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1512 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1513 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1514 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1515 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1516 | cmd += " " + \ |
| 1517 | str( ingressDevice ) + "/" +\ |
| 1518 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1519 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1520 | main.log.error( "Device list and port list does not " + |
| 1521 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1522 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1523 | if "/" in egressDevice: |
| 1524 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1525 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1526 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1527 | main.log.error( "You must specify " + |
| 1528 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1529 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1530 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1531 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1532 | str( egressDevice ) + "/" +\ |
| 1533 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1534 | handle = self.sendline( cmd ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1535 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1536 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1537 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1538 | main.log.error( "Error in adding multipoint-to-singlepoint " + |
| 1539 | "intent" ) |
| 1540 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1541 | else: |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1542 | match = re.search('id=0x([\da-f]+),', handle) |
| 1543 | if match: |
| 1544 | return match.group()[3:-1] |
| 1545 | else: |
| 1546 | main.log.error( "Error, intent ID not found" ) |
| 1547 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1548 | except AssertionError: |
| 1549 | main.log.exception( "" ) |
| 1550 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1551 | except TypeError: |
| 1552 | main.log.exception( self.name + ": Object not as expected" ) |
| 1553 | return None |
| 1554 | except pexpect.EOF: |
| 1555 | main.log.error( self.name + ": EOF exception found" ) |
| 1556 | main.log.error( self.name + ": " + self.handle.before ) |
| 1557 | main.cleanup() |
| 1558 | main.exit() |
| 1559 | except Exception: |
| 1560 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1561 | main.cleanup() |
| 1562 | main.exit() |
| 1563 | |
| 1564 | def addSinglepointToMultipointIntent( |
| 1565 | self, |
| 1566 | ingressDevice, |
| 1567 | egressDeviceList, |
| 1568 | portIngress="", |
| 1569 | portEgressList=None, |
| 1570 | ethType="", |
| 1571 | ethSrc="", |
| 1572 | ethDst="", |
| 1573 | bandwidth="", |
| 1574 | lambdaAlloc=False, |
| 1575 | ipProto="", |
| 1576 | ipSrc="", |
| 1577 | ipDst="", |
| 1578 | tcpSrc="", |
| 1579 | tcpDst="", |
| 1580 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1581 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1582 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1583 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1584 | partial=False, |
| 1585 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1586 | """ |
| 1587 | Note: |
| 1588 | This function assumes the format of all egress devices |
| 1589 | is same. That is, all egress devices include port numbers |
| 1590 | with a "/" or all egress devices could specify device |
| 1591 | ids and port numbers seperately. |
| 1592 | Required: |
| 1593 | * EgressDeviceList: List of device ids of egress device |
| 1594 | ( Atleast 2 eress devices required in the list ) |
| 1595 | * ingressDevice: device id of ingress device |
| 1596 | Optional: |
| 1597 | * ethType: specify ethType |
| 1598 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1599 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1600 | * bandwidth: specify bandwidth capacity of link |
| 1601 | * lambdaAlloc: if True, intent will allocate lambda |
| 1602 | for the specified intent |
| 1603 | * ipProto: specify ip protocol |
| 1604 | * ipSrc: specify ip source address |
| 1605 | * ipDst: specify ip destination address |
| 1606 | * tcpSrc: specify tcp source port |
| 1607 | * tcpDst: specify tcp destination port |
| 1608 | * setEthSrc: action to Rewrite Source MAC Address |
| 1609 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1610 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1611 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1612 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1613 | Description: |
| 1614 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1615 | specifying device id's and optional fields |
| 1616 | Returns: |
| 1617 | A string of the intent id or None on error |
| 1618 | |
| 1619 | NOTE: This function may change depending on the |
| 1620 | options developers provide for singlepoint-to-multipoint |
| 1621 | intent via cli |
| 1622 | """ |
| 1623 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1624 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1625 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1626 | if ethType: |
| 1627 | cmd += " --ethType " + str( ethType ) |
| 1628 | if ethSrc: |
| 1629 | cmd += " --ethSrc " + str( ethSrc ) |
| 1630 | if ethDst: |
| 1631 | cmd += " --ethDst " + str( ethDst ) |
| 1632 | if bandwidth: |
| 1633 | cmd += " --bandwidth " + str( bandwidth ) |
| 1634 | if lambdaAlloc: |
| 1635 | cmd += " --lambda " |
| 1636 | if ipProto: |
| 1637 | cmd += " --ipProto " + str( ipProto ) |
| 1638 | if ipSrc: |
| 1639 | cmd += " --ipSrc " + str( ipSrc ) |
| 1640 | if ipDst: |
| 1641 | cmd += " --ipDst " + str( ipDst ) |
| 1642 | if tcpSrc: |
| 1643 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1644 | if tcpDst: |
| 1645 | cmd += " --tcpDst " + str( tcpDst ) |
| 1646 | if setEthSrc: |
| 1647 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1648 | if setEthDst: |
| 1649 | cmd += " --setEthDst " + str( setEthDst ) |
| 1650 | if vlanId: |
| 1651 | cmd += " -v " + str( vlanId ) |
| 1652 | if setVlan: |
| 1653 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1654 | if partial: |
| 1655 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1656 | if encap: |
| 1657 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1658 | |
| 1659 | # Check whether the user appended the port |
| 1660 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1661 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1662 | if "/" in ingressDevice: |
| 1663 | cmd += " " + str( ingressDevice ) |
| 1664 | else: |
| 1665 | if not portIngress: |
| 1666 | main.log.error( "You must specify " + |
| 1667 | "the Ingress port" ) |
| 1668 | return main.FALSE |
| 1669 | |
| 1670 | cmd += " " +\ |
| 1671 | str( ingressDevice ) + "/" +\ |
| 1672 | str( portIngress ) |
| 1673 | |
| 1674 | if portEgressList is None: |
| 1675 | for egressDevice in egressDeviceList: |
| 1676 | if "/" in egressDevice: |
| 1677 | cmd += " " + str( egressDevice ) |
| 1678 | else: |
| 1679 | main.log.error( "You must specify " + |
| 1680 | "the egress port" ) |
| 1681 | # TODO: perhaps more meaningful return |
| 1682 | return main.FALSE |
| 1683 | else: |
| 1684 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1685 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1686 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1687 | cmd += " " + \ |
| 1688 | str( egressDevice ) + "/" +\ |
| 1689 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1690 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1691 | main.log.error( "Device list and port list does not " + |
| 1692 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1693 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1694 | handle = self.sendline( cmd ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1695 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1696 | # If error, return error message |
| 1697 | if re.search( "Error", handle ): |
| 1698 | main.log.error( "Error in adding singlepoint-to-multipoint " + |
| 1699 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1700 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1701 | else: |
| 1702 | match = re.search('id=0x([\da-f]+),', handle) |
| 1703 | if match: |
| 1704 | return match.group()[3:-1] |
| 1705 | else: |
| 1706 | main.log.error( "Error, intent ID not found" ) |
| 1707 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1708 | except AssertionError: |
| 1709 | main.log.exception( "" ) |
| 1710 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1711 | except TypeError: |
| 1712 | main.log.exception( self.name + ": Object not as expected" ) |
| 1713 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1714 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1715 | main.log.error( self.name + ": EOF exception found" ) |
| 1716 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1717 | main.cleanup() |
| 1718 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1719 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1720 | main.log.exception( self.name + ": Uncaught exception!" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1721 | main.cleanup() |
| 1722 | main.exit() |
| 1723 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1724 | def addMplsIntent( |
| 1725 | self, |
| 1726 | ingressDevice, |
| 1727 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1728 | ingressPort="", |
| 1729 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1730 | ethType="", |
| 1731 | ethSrc="", |
| 1732 | ethDst="", |
| 1733 | bandwidth="", |
| 1734 | lambdaAlloc=False, |
| 1735 | ipProto="", |
| 1736 | ipSrc="", |
| 1737 | ipDst="", |
| 1738 | tcpSrc="", |
| 1739 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1740 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1741 | egressLabel="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1742 | priority=""): |
| 1743 | """ |
| 1744 | Required: |
| 1745 | * ingressDevice: device id of ingress device |
| 1746 | * egressDevice: device id of egress device |
| 1747 | Optional: |
| 1748 | * ethType: specify ethType |
| 1749 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1750 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1751 | * bandwidth: specify bandwidth capacity of link |
| 1752 | * lambdaAlloc: if True, intent will allocate lambda |
| 1753 | for the specified intent |
| 1754 | * ipProto: specify ip protocol |
| 1755 | * ipSrc: specify ip source address |
| 1756 | * ipDst: specify ip destination address |
| 1757 | * tcpSrc: specify tcp source port |
| 1758 | * tcpDst: specify tcp destination port |
| 1759 | * ingressLabel: Ingress MPLS label |
| 1760 | * egressLabel: Egress MPLS label |
| 1761 | Description: |
| 1762 | Adds MPLS intent by |
| 1763 | specifying device id's and optional fields |
| 1764 | Returns: |
| 1765 | A string of the intent id or None on error |
| 1766 | |
| 1767 | NOTE: This function may change depending on the |
| 1768 | options developers provide for MPLS |
| 1769 | intent via cli |
| 1770 | """ |
| 1771 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1772 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1773 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1774 | if ethType: |
| 1775 | cmd += " --ethType " + str( ethType ) |
| 1776 | if ethSrc: |
| 1777 | cmd += " --ethSrc " + str( ethSrc ) |
| 1778 | if ethDst: |
| 1779 | cmd += " --ethDst " + str( ethDst ) |
| 1780 | if bandwidth: |
| 1781 | cmd += " --bandwidth " + str( bandwidth ) |
| 1782 | if lambdaAlloc: |
| 1783 | cmd += " --lambda " |
| 1784 | if ipProto: |
| 1785 | cmd += " --ipProto " + str( ipProto ) |
| 1786 | if ipSrc: |
| 1787 | cmd += " --ipSrc " + str( ipSrc ) |
| 1788 | if ipDst: |
| 1789 | cmd += " --ipDst " + str( ipDst ) |
| 1790 | if tcpSrc: |
| 1791 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1792 | if tcpDst: |
| 1793 | cmd += " --tcpDst " + str( tcpDst ) |
| 1794 | if ingressLabel: |
| 1795 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 1796 | if egressLabel: |
| 1797 | cmd += " --egressLabel " + str( egressLabel ) |
| 1798 | if priority: |
| 1799 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1800 | |
| 1801 | # Check whether the user appended the port |
| 1802 | # or provided it as an input |
| 1803 | if "/" in ingressDevice: |
| 1804 | cmd += " " + str( ingressDevice ) |
| 1805 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1806 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1807 | main.log.error( "You must specify the ingress port" ) |
| 1808 | return None |
| 1809 | |
| 1810 | cmd += " " + \ |
| 1811 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1812 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1813 | |
| 1814 | if "/" in egressDevice: |
| 1815 | cmd += " " + str( egressDevice ) |
| 1816 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1817 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1818 | main.log.error( "You must specify the egress port" ) |
| 1819 | return None |
| 1820 | |
| 1821 | cmd += " " +\ |
| 1822 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1823 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1824 | |
| 1825 | handle = self.sendline( cmd ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1826 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1827 | # If error, return error message |
| 1828 | if re.search( "Error", handle ): |
| 1829 | main.log.error( "Error in adding mpls intent" ) |
| 1830 | return None |
| 1831 | else: |
| 1832 | # TODO: print out all the options in this message? |
| 1833 | main.log.info( "MPLS intent installed between " + |
| 1834 | str( ingressDevice ) + " and " + |
| 1835 | str( egressDevice ) ) |
| 1836 | match = re.search('id=0x([\da-f]+),', handle) |
| 1837 | if match: |
| 1838 | return match.group()[3:-1] |
| 1839 | else: |
| 1840 | main.log.error( "Error, intent ID not found" ) |
| 1841 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1842 | except AssertionError: |
| 1843 | main.log.exception( "" ) |
| 1844 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1845 | except TypeError: |
| 1846 | main.log.exception( self.name + ": Object not as expected" ) |
| 1847 | return None |
| 1848 | except pexpect.EOF: |
| 1849 | main.log.error( self.name + ": EOF exception found" ) |
| 1850 | main.log.error( self.name + ": " + self.handle.before ) |
| 1851 | main.cleanup() |
| 1852 | main.exit() |
| 1853 | except Exception: |
| 1854 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1855 | main.cleanup() |
| 1856 | main.exit() |
| 1857 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1858 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 1859 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1860 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1861 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1862 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1863 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1864 | -p or --purge: Purge the intent from the store after removal |
| 1865 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1866 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 1867 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1868 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1869 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1870 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1871 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1872 | if purge: |
| 1873 | cmdStr += " -p" |
| 1874 | if sync: |
| 1875 | cmdStr += " -s" |
| 1876 | |
| 1877 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1878 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1879 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1880 | if re.search( "Error", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1881 | main.log.error( "Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1882 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1883 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1884 | # TODO: Should this be main.TRUE |
| 1885 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1886 | except AssertionError: |
| 1887 | main.log.exception( "" ) |
| 1888 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1889 | except TypeError: |
| 1890 | main.log.exception( self.name + ": Object not as expected" ) |
| 1891 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1892 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1893 | main.log.error( self.name + ": EOF exception found" ) |
| 1894 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1895 | main.cleanup() |
| 1896 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1897 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1898 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1899 | main.cleanup() |
| 1900 | main.exit() |
| 1901 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1902 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1903 | """ |
| 1904 | Description: |
| 1905 | Remove all the intents |
| 1906 | Optional args:- |
| 1907 | -s or --sync: Waits for the removal before returning |
| 1908 | -p or --purge: Purge the intent from the store after removal |
| 1909 | Returns: |
| 1910 | Returns main.TRUE if all intents are removed, otherwise returns |
| 1911 | main.FALSE; Returns None for exception |
| 1912 | """ |
| 1913 | try: |
| 1914 | cmdStr = "remove-intent" |
| 1915 | if purge: |
| 1916 | cmdStr += " -p" |
| 1917 | if sync: |
| 1918 | cmdStr += " -s" |
| 1919 | |
| 1920 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1921 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1922 | assert "Command not found:" not in handle, handle |
| 1923 | if re.search( "Error", handle ): |
| 1924 | main.log.error( "Error in removing intent" ) |
| 1925 | return main.FALSE |
| 1926 | else: |
| 1927 | return main.TRUE |
| 1928 | except AssertionError: |
| 1929 | main.log.exception( "" ) |
| 1930 | return None |
| 1931 | except TypeError: |
| 1932 | main.log.exception( self.name + ": Object not as expected" ) |
| 1933 | return None |
| 1934 | except pexpect.EOF: |
| 1935 | main.log.error( self.name + ": EOF exception found" ) |
| 1936 | main.log.error( self.name + ": " + self.handle.before ) |
| 1937 | main.cleanup() |
| 1938 | main.exit() |
| 1939 | except Exception: |
| 1940 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1941 | main.cleanup() |
| 1942 | main.exit() |
| 1943 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 1944 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1945 | """ |
| 1946 | Purges all WITHDRAWN Intents |
| 1947 | """ |
| 1948 | try: |
| 1949 | cmdStr = "purge-intents" |
| 1950 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1951 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1952 | if re.search( "Error", handle ): |
| 1953 | main.log.error( "Error in purging intents" ) |
| 1954 | return main.FALSE |
| 1955 | else: |
| 1956 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1957 | except AssertionError: |
| 1958 | main.log.exception( "" ) |
| 1959 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1960 | except TypeError: |
| 1961 | main.log.exception( self.name + ": Object not as expected" ) |
| 1962 | return None |
| 1963 | except pexpect.EOF: |
| 1964 | main.log.error( self.name + ": EOF exception found" ) |
| 1965 | main.log.error( self.name + ": " + self.handle.before ) |
| 1966 | main.cleanup() |
| 1967 | main.exit() |
| 1968 | except Exception: |
| 1969 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1970 | main.cleanup() |
| 1971 | main.exit() |
| 1972 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1973 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1974 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1975 | NOTE: This method should be used after installing application: |
| 1976 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1977 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1978 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1979 | Description: |
| 1980 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1981 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1982 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1983 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1984 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1985 | cmdStr += " -j" |
| 1986 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1987 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1988 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1989 | except AssertionError: |
| 1990 | main.log.exception( "" ) |
| 1991 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1992 | except TypeError: |
| 1993 | main.log.exception( self.name + ": Object not as expected" ) |
| 1994 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1995 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1996 | main.log.error( self.name + ": EOF exception found" ) |
| 1997 | main.log.error( self.name + ": " + self.handle.before ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1998 | main.cleanup() |
| 1999 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2000 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2001 | main.log.exception( self.name + ": Uncaught exception!" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2002 | main.cleanup() |
| 2003 | main.exit() |
| 2004 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2005 | def ipv4RouteNumber( self ): |
| 2006 | """ |
| 2007 | NOTE: This method should be used after installing application: |
| 2008 | onos-app-sdnip |
| 2009 | Description: |
| 2010 | Obtain the total IPv4 routes number in the system |
| 2011 | """ |
| 2012 | try: |
| 2013 | cmdStr = "routes -s -j" |
| 2014 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2015 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2016 | jsonResult = json.loads( handle ) |
| 2017 | return jsonResult['totalRoutes4'] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2018 | except AssertionError: |
| 2019 | main.log.exception( "" ) |
| 2020 | return None |
| 2021 | except ( TypeError, ValueError ): |
| 2022 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2023 | return None |
| 2024 | except pexpect.EOF: |
| 2025 | main.log.error( self.name + ": EOF exception found" ) |
| 2026 | main.log.error( self.name + ": " + self.handle.before ) |
| 2027 | main.cleanup() |
| 2028 | main.exit() |
| 2029 | except Exception: |
| 2030 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2031 | main.cleanup() |
| 2032 | main.exit() |
| 2033 | |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2034 | def intents( self, jsonFormat = True, summary = False, **intentargs): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2035 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2036 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2037 | Obtain intents from the ONOS cli. |
| 2038 | Optional: |
| 2039 | * jsonFormat: Enable output formatting in json, default to True |
| 2040 | * summary: Whether only output the intent summary, defaults to False |
| 2041 | * type: Only output a certain type of intent. This options is valid |
| 2042 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2043 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2044 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2045 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2046 | if summary: |
| 2047 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2048 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2049 | cmdStr += " -j" |
| 2050 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2051 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2052 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2053 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2054 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2055 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2056 | intentType = "" |
| 2057 | # IF we want the summary of a specific intent type |
| 2058 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2059 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2060 | if intentType in jsonResult.keys(): |
| 2061 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2062 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2063 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2064 | return handle |
| 2065 | else: |
| 2066 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2067 | except AssertionError: |
| 2068 | main.log.exception( "" ) |
| 2069 | return None |
| 2070 | except ( TypeError, ValueError ): |
| 2071 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2072 | return None |
| 2073 | except pexpect.EOF: |
| 2074 | main.log.error( self.name + ": EOF exception found" ) |
| 2075 | main.log.error( self.name + ": " + self.handle.before ) |
| 2076 | main.cleanup() |
| 2077 | main.exit() |
| 2078 | except Exception: |
| 2079 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2080 | main.cleanup() |
| 2081 | main.exit() |
| 2082 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2083 | def getIntentState(self, intentsId, intentsJson=None): |
| 2084 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2085 | Description: |
| 2086 | Gets intent state. Accepts a single intent ID (string type) or a |
| 2087 | list of intent IDs. |
| 2088 | Parameters: |
| 2089 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2090 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2091 | Returns: |
| 2092 | Returns the state (string type) of the ID if a single intent ID is |
| 2093 | accepted. |
| 2094 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2095 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2096 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2097 | """ |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2098 | try: |
| 2099 | state = "State is Undefined" |
| 2100 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2101 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2102 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2103 | rawJson = intentsJson |
| 2104 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2105 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2106 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2107 | if intentsId == intent[ 'id' ]: |
| 2108 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2109 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2110 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
| 2111 | " on the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2112 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2113 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2114 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2115 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2116 | stateDict = {} |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2117 | for intents in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2118 | if intentsId[ i ] == intents[ 'id' ]: |
| 2119 | stateDict[ 'state' ] = intents[ 'state' ] |
| 2120 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2121 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2122 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2123 | if len( intentsId ) != len( dictList ): |
| 2124 | main.log.info( "Cannot find some of the intent ID state" ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2125 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2126 | else: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2127 | main.log.info( "Invalid intents ID entry" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2128 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2129 | except ( TypeError, ValueError ): |
| 2130 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2131 | return None |
| 2132 | except pexpect.EOF: |
| 2133 | main.log.error( self.name + ": EOF exception found" ) |
| 2134 | main.log.error( self.name + ": " + self.handle.before ) |
| 2135 | main.cleanup() |
| 2136 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2137 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2138 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2139 | main.cleanup() |
| 2140 | main.exit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2141 | |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2142 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2143 | """ |
| 2144 | Description: |
| 2145 | Check intents state |
| 2146 | Required: |
| 2147 | intentsId - List of intents ID to be checked |
| 2148 | Optional: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2149 | expectedState - Check the expected state(s) of each intents |
| 2150 | state in the list. |
| 2151 | *NOTE: You can pass in a list of expected state, |
| 2152 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2153 | Return: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2154 | Returns main.TRUE only if all intent are the same as expected states |
| 2155 | , otherwise, returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2156 | """ |
| 2157 | try: |
| 2158 | # Generating a dictionary: intent id as a key and state as value |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2159 | returnValue = main.TRUE |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2160 | intentsDict = self.getIntentState( intentsId ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2161 | if len( intentsId ) != len( intentsDict ): |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2162 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2163 | "getting intents state" ) |
| 2164 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2165 | |
| 2166 | if isinstance( expectedState, types.StringType ): |
| 2167 | for intents in intentsDict: |
| 2168 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2169 | main.log.debug( self.name + " : Intent ID - " + |
| 2170 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2171 | " actual state = " + |
| 2172 | intents.get( 'state' ) |
| 2173 | + " does not equal expected state = " |
| 2174 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2175 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2176 | |
| 2177 | elif isinstance( expectedState, types.ListType ): |
| 2178 | for intents in intentsDict: |
| 2179 | if not any( state == intents.get( 'state' ) for state in |
| 2180 | expectedState ): |
| 2181 | main.log.debug( self.name + " : Intent ID - " + |
| 2182 | intents.get( 'id' ) + |
| 2183 | " actual state = " + |
| 2184 | intents.get( 'state' ) + |
| 2185 | " does not equal expected states = " |
| 2186 | + str( expectedState ) ) |
| 2187 | returnValue = main.FALSE |
| 2188 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2189 | if returnValue == main.TRUE: |
| 2190 | main.log.info( self.name + ": All " + |
| 2191 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2192 | " intents are in " + str( expectedState ) + |
| 2193 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2194 | return returnValue |
| 2195 | except TypeError: |
| 2196 | main.log.exception( self.name + ": Object not as expected" ) |
| 2197 | return None |
| 2198 | except pexpect.EOF: |
| 2199 | main.log.error( self.name + ": EOF exception found" ) |
| 2200 | main.log.error( self.name + ": " + self.handle.before ) |
| 2201 | main.cleanup() |
| 2202 | main.exit() |
| 2203 | except Exception: |
| 2204 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2205 | main.cleanup() |
| 2206 | main.exit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2207 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2208 | def compareIntent( self, intentDict ): |
| 2209 | """ |
| 2210 | Description: |
| 2211 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2212 | Return: |
| 2213 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2214 | Arguments: |
| 2215 | intentDict: a dictionary which maps intent ids to intent states |
| 2216 | """ |
| 2217 | try: |
| 2218 | intentsRaw = self.intents() |
| 2219 | intentsJson = json.loads( intentsRaw ) |
| 2220 | intentDictONOS = {} |
| 2221 | for intent in intentsJson: |
| 2222 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2223 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2224 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2225 | main.log.warn( self.name + ": expected intent count does not match that in ONOS, " + |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2226 | str( len( intentDict ) ) + " expected and " + |
| 2227 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2228 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2229 | for intentID in intentDict.keys(): |
| 2230 | if not intentID in intentDictONOS.keys(): |
| 2231 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2232 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2233 | else: |
| 2234 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2235 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2236 | " expected state is " + intentDict[ intentID ] + |
| 2237 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2238 | returnValue = main.FALSE |
| 2239 | intentDictONOS.pop( intentID ) |
| 2240 | if len( intentDictONOS ) > 0: |
| 2241 | returnValue = main.FALSE |
| 2242 | for intentID in intentDictONOS.keys(): |
| 2243 | main.log.debug( self.name + ": find extra intent in ONOS: intent ID " + intentID ) |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2244 | if returnValue == main.TRUE: |
| 2245 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2246 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2247 | except KeyError: |
| 2248 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2249 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2250 | except ( TypeError, ValueError ): |
| 2251 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2252 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2253 | except pexpect.EOF: |
| 2254 | main.log.error( self.name + ": EOF exception found" ) |
| 2255 | main.log.error( self.name + ": " + self.handle.before ) |
| 2256 | main.cleanup() |
| 2257 | main.exit() |
| 2258 | except Exception: |
| 2259 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2260 | main.cleanup() |
| 2261 | main.exit() |
| 2262 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2263 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2264 | """ |
| 2265 | Description: |
| 2266 | Check the number of installed intents. |
| 2267 | Optional: |
| 2268 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2269 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2270 | Return: |
| 2271 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2272 | , otherwise, returns main.FALSE. |
| 2273 | """ |
| 2274 | |
| 2275 | try: |
| 2276 | cmd = "intents -s -j" |
| 2277 | |
| 2278 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2279 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2280 | if response == None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2281 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2282 | response = json.loads( response ) |
| 2283 | |
| 2284 | # get total and installed number, see if they are match |
| 2285 | allState = response.get( 'all' ) |
| 2286 | if allState.get('total') == allState.get('installed'): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2287 | main.log.info( 'Total Intents: {} Installed Intents: {}'.format( allState.get('total'), allState.get('installed') ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2288 | return main.TRUE |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2289 | main.log.info( 'Verified Intents failed Excepte intetnes: {} installed intents: {}'.format( allState.get('total'), allState.get('installed') ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2290 | return main.FALSE |
| 2291 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2292 | except ( TypeError, ValueError ): |
| 2293 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2294 | return None |
| 2295 | except pexpect.EOF: |
| 2296 | main.log.error( self.name + ": EOF exception found" ) |
| 2297 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2298 | if noExit: |
| 2299 | return main.FALSE |
| 2300 | else: |
| 2301 | main.cleanup() |
| 2302 | main.exit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2303 | except Exception: |
| 2304 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2305 | if noExit: |
| 2306 | return main.FALSE |
| 2307 | else: |
| 2308 | main.cleanup() |
| 2309 | main.exit() |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2310 | except pexpect.TIMEOUT: |
| 2311 | main.log.error( self.name + ": ONOS timeout" ) |
| 2312 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2313 | |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2314 | def flows( self, state="", jsonFormat=True, timeout=60, noExit=False, noCore=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2315 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2316 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2317 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2318 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2319 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2320 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2321 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2322 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2323 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2324 | if jsonFormat: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2325 | cmdStr += " -j " |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2326 | if noCore: |
| 2327 | cmdStr += " -n " |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2328 | cmdStr += state |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2329 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2330 | assert "Command not found:" not in handle, handle |
| 2331 | if re.search( "Error:", handle ): |
| 2332 | main.log.error( self.name + ": flows() response: " + |
| 2333 | str( handle ) ) |
| 2334 | return handle |
| 2335 | except AssertionError: |
| 2336 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2337 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2338 | except TypeError: |
| 2339 | main.log.exception( self.name + ": Object not as expected" ) |
| 2340 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2341 | except pexpect.TIMEOUT: |
| 2342 | main.log.error( self.name + ": ONOS timeout" ) |
| 2343 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2344 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2345 | main.log.error( self.name + ": EOF exception found" ) |
| 2346 | main.log.error( self.name + ": " + self.handle.before ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2347 | main.cleanup() |
| 2348 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2349 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2350 | main.log.exception( self.name + ": Uncaught exception!" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2351 | main.cleanup() |
| 2352 | main.exit() |
| 2353 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 2354 | def checkFlowCount(self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2355 | count = self.getTotalFlowsNum( timeout=timeout ) |
| 2356 | count = int (count) if count else 0 |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 2357 | return count if (count > min) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2358 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2359 | def checkFlowsState( self, isPENDING=True, timeout=60,noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2360 | """ |
| 2361 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2362 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2363 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2364 | if the count of those states is 0, which means all current flows |
| 2365 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2366 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2367 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2368 | Return: |
| 2369 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2370 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2371 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2372 | """ |
| 2373 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2374 | states = ["PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED"] |
| 2375 | checkedStates = [] |
| 2376 | statesCount = [0, 0, 0, 0] |
| 2377 | for s in states: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2378 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2379 | if rawFlows: |
| 2380 | # if we didn't get flows or flows function return None, we should return |
| 2381 | # main.Flase |
| 2382 | checkedStates.append( json.loads( rawFlows ) ) |
| 2383 | else: |
| 2384 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2385 | for i in range( len( states ) ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2386 | for c in checkedStates[i]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2387 | try: |
| 2388 | statesCount[i] += int( c.get( "flowCount" ) ) |
| 2389 | except TypeError: |
| 2390 | main.log.exception( "Json object not as expected" ) |
| 2391 | main.log.info( states[i] + " flows: " + str( statesCount[i] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2392 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2393 | # We want to count PENDING_ADD if isPENDING is true |
| 2394 | if isPENDING: |
| 2395 | if statesCount[1] + statesCount[2] + statesCount[3] > 0: |
| 2396 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2397 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2398 | if statesCount[0] + statesCount[1] + statesCount[2] + statesCount[3] > 0: |
| 2399 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2400 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2401 | except ( TypeError, ValueError ): |
| 2402 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2403 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2404 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2405 | except AssertionError: |
| 2406 | main.log.exception( "" ) |
| 2407 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2408 | except pexpect.EOF: |
| 2409 | main.log.error( self.name + ": EOF exception found" ) |
| 2410 | main.log.error( self.name + ": " + self.handle.before ) |
| 2411 | main.cleanup() |
| 2412 | main.exit() |
| 2413 | except Exception: |
| 2414 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2415 | main.cleanup() |
| 2416 | main.exit() |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2417 | except pexpect.TIMEOUT: |
| 2418 | main.log.error( self.name + ": ONOS timeout" ) |
| 2419 | return None |
| 2420 | |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2421 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2422 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2423 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2424 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2425 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2426 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2427 | a specific point-to-point intent definition |
| 2428 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2429 | * ingress: specify source dpid |
| 2430 | * egress: specify destination dpid |
| 2431 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2432 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2433 | * offset: the keyOffset is where the next batch of intents |
| 2434 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2435 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2436 | * getResponse: If set to True, function will return ONOS response. |
| 2437 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2438 | Returns: If failed to push test intents, it will returen None, |
| 2439 | if successful, return true. |
| 2440 | Timeout expection will return None, |
| 2441 | TypeError will return false |
| 2442 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2443 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2444 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2445 | if background: |
| 2446 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2447 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2448 | back = "" |
| 2449 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2450 | ingress, |
| 2451 | egress, |
| 2452 | batchSize, |
| 2453 | offset, |
| 2454 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2455 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2456 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2457 | main.log.info( response ) |
| 2458 | if response == None: |
| 2459 | return None |
| 2460 | |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2461 | if getResponse: |
| 2462 | return response |
| 2463 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2464 | # TODO: We should handle if there is failure in installation |
| 2465 | return main.TRUE |
| 2466 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2467 | except AssertionError: |
| 2468 | main.log.exception( "" ) |
| 2469 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2470 | except pexpect.TIMEOUT: |
| 2471 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2472 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2473 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2474 | main.log.error( self.name + ": EOF exception found" ) |
| 2475 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2476 | main.cleanup() |
| 2477 | main.exit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2478 | except TypeError: |
| 2479 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2480 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2481 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2482 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2483 | main.cleanup() |
| 2484 | main.exit() |
| 2485 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2486 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2487 | """ |
| 2488 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2489 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2490 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2491 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2492 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2493 | """ |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2494 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2495 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2496 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2497 | cmd = "flows -c added" |
| 2498 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2499 | if rawFlows: |
| 2500 | rawFlows = rawFlows.split("\n") |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2501 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2502 | for l in rawFlows: |
| 2503 | totalFlows += int(l.split("Count=")[1]) |
| 2504 | else: |
| 2505 | main.log.error("Response not as expected!") |
| 2506 | return None |
| 2507 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2508 | |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2509 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2510 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2511 | return None |
| 2512 | except pexpect.EOF: |
| 2513 | main.log.error( self.name + ": EOF exception found" ) |
| 2514 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2515 | if not noExit: |
| 2516 | main.cleanup() |
| 2517 | main.exit() |
| 2518 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2519 | except Exception: |
| 2520 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2521 | if not noExit: |
| 2522 | main.cleanup() |
| 2523 | main.exit() |
| 2524 | return None |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2525 | except pexpect.TIMEOUT: |
| 2526 | main.log.error( self.name + ": ONOS timeout" ) |
| 2527 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2528 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2529 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2530 | """ |
| 2531 | Description: |
| 2532 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2533 | Optional: |
| 2534 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2535 | Return: |
| 2536 | The number of intents |
| 2537 | """ |
| 2538 | try: |
| 2539 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2540 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2541 | if response == None: |
| 2542 | return -1 |
| 2543 | response = json.loads( response ) |
| 2544 | return int( response.get("intents") ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2545 | except ( TypeError, ValueError ): |
| 2546 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2547 | return None |
| 2548 | except pexpect.EOF: |
| 2549 | main.log.error( self.name + ": EOF exception found" ) |
| 2550 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2551 | if noExit: |
| 2552 | return -1 |
| 2553 | else: |
| 2554 | main.cleanup() |
| 2555 | main.exit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2556 | except Exception: |
| 2557 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2558 | if noExit: |
| 2559 | return -1 |
| 2560 | else: |
| 2561 | main.cleanup() |
| 2562 | main.exit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2563 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2564 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2565 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2566 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2567 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2568 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2569 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2570 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2571 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2572 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2573 | cmdStr += " -j" |
| 2574 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2575 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2576 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2577 | except AssertionError: |
| 2578 | main.log.exception( "" ) |
| 2579 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2580 | except TypeError: |
| 2581 | main.log.exception( self.name + ": Object not as expected" ) |
| 2582 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2583 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2584 | main.log.error( self.name + ": EOF exception found" ) |
| 2585 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2586 | main.cleanup() |
| 2587 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2588 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2589 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2590 | main.cleanup() |
| 2591 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2592 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2593 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2594 | """ |
| 2595 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2596 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2597 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2598 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2599 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2600 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2601 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2602 | cmdStr += " -j" |
| 2603 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2604 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2605 | if handle: |
| 2606 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2607 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2608 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2609 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2610 | else: |
| 2611 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2612 | except AssertionError: |
| 2613 | main.log.exception( "" ) |
| 2614 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2615 | except TypeError: |
| 2616 | main.log.exception( self.name + ": Object not as expected" ) |
| 2617 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -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 | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2621 | main.cleanup() |
| 2622 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2623 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2624 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2625 | main.cleanup() |
| 2626 | main.exit() |
| 2627 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2628 | # Wrapper functions **************** |
| 2629 | # Wrapper functions use existing driver |
| 2630 | # functions and extends their use case. |
| 2631 | # For example, we may use the output of |
| 2632 | # a normal driver function, and parse it |
| 2633 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2634 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2635 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2636 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2637 | Description: |
| 2638 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2639 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2640 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2641 | # Obtain output of intents function |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 2642 | intentsStr = self.intents(jsonFormat=False) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2643 | intentIdList = [] |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2644 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2645 | # Parse the intents output for ID's |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2646 | intentsList = [ s.strip() for s in intentsStr.splitlines() ] |
| 2647 | for intents in intentsList: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 2648 | match = re.search('id=0x([\da-f]+),', intents) |
| 2649 | if match: |
| 2650 | tmpId = match.group()[3:-1] |
| 2651 | intentIdList.append( tmpId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2652 | return intentIdList |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2653 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2654 | except TypeError: |
| 2655 | main.log.exception( self.name + ": Object not as expected" ) |
| 2656 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2657 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2658 | main.log.error( self.name + ": EOF exception found" ) |
| 2659 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2660 | main.cleanup() |
| 2661 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2662 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2663 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2664 | main.cleanup() |
| 2665 | main.exit() |
| 2666 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2667 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2668 | """ |
| 2669 | Determine the number of flow rules for the given device id that are |
| 2670 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2671 | Params: |
| 2672 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2673 | """ |
| 2674 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2675 | if core: |
| 2676 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2677 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2678 | else: |
| 2679 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2680 | "grep 'state=ADDED' | wc -l" |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2681 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2682 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2683 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2684 | except AssertionError: |
| 2685 | main.log.exception( "" ) |
| 2686 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2687 | except pexpect.EOF: |
| 2688 | main.log.error( self.name + ": EOF exception found" ) |
| 2689 | main.log.error( self.name + ": " + self.handle.before ) |
| 2690 | main.cleanup() |
| 2691 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2692 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2693 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2694 | main.cleanup() |
| 2695 | main.exit() |
| 2696 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2697 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2698 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2699 | Use 'devices' function to obtain list of all devices |
| 2700 | and parse the result to obtain a list of all device |
| 2701 | id's. Returns this list. Returns empty list if no |
| 2702 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2703 | List is ordered sequentially |
| 2704 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2705 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2706 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2707 | the ids. By obtaining the list of device ids on the fly, |
| 2708 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2709 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2710 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2711 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2712 | devicesStr = self.devices( jsonFormat=False ) |
| 2713 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2714 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2715 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2716 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2717 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2718 | |
| 2719 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2720 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2721 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2722 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2723 | # Split list further into arguments before and after string |
| 2724 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2725 | # append to idList |
| 2726 | for arg in tempList: |
| 2727 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 2728 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2729 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2730 | except TypeError: |
| 2731 | main.log.exception( self.name + ": Object not as expected" ) |
| 2732 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2733 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2734 | main.log.error( self.name + ": EOF exception found" ) |
| 2735 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2736 | main.cleanup() |
| 2737 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2738 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2739 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2740 | main.cleanup() |
| 2741 | main.exit() |
| 2742 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2743 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2744 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2745 | Uses 'nodes' function to obtain list of all nodes |
| 2746 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2747 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2748 | Returns: |
| 2749 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2750 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2751 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2752 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2753 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2754 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 2755 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2756 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2757 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2758 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2759 | nodesJson = json.loads( nodesStr ) |
| 2760 | idList = [ node.get('id') for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2761 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2762 | except ( TypeError, ValueError ): |
| 2763 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2764 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2765 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2766 | main.log.error( self.name + ": EOF exception found" ) |
| 2767 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2768 | main.cleanup() |
| 2769 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2770 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2771 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2772 | main.cleanup() |
| 2773 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2774 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2775 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2776 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2777 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 2778 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2779 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2780 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2781 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2782 | return None |
| 2783 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2784 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2785 | rawDevices = self.devices() |
| 2786 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2787 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2788 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2789 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 2790 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2791 | return device |
| 2792 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2793 | except ( TypeError, ValueError ): |
| 2794 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2795 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2796 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2797 | main.log.error( self.name + ": EOF exception found" ) |
| 2798 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2799 | main.cleanup() |
| 2800 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2801 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2802 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2803 | main.cleanup() |
| 2804 | main.exit() |
| 2805 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2806 | def getTopology( self, topologyOutput ): |
| 2807 | """ |
| 2808 | Definition: |
| 2809 | Loads a json topology output |
| 2810 | Return: |
| 2811 | topology = current ONOS topology |
| 2812 | """ |
| 2813 | import json |
| 2814 | try: |
| 2815 | # either onos:topology or 'topology' will work in CLI |
| 2816 | topology = json.loads(topologyOutput) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 2817 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2818 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2819 | except ( TypeError, ValueError ): |
| 2820 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 2821 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2822 | except pexpect.EOF: |
| 2823 | main.log.error( self.name + ": EOF exception found" ) |
| 2824 | main.log.error( self.name + ": " + self.handle.before ) |
| 2825 | main.cleanup() |
| 2826 | main.exit() |
| 2827 | except Exception: |
| 2828 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2829 | main.cleanup() |
| 2830 | main.exit() |
| 2831 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2832 | def checkStatus(self, numoswitch, numolink, numoctrl = -1, logLevel="info"): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2833 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2834 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2835 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2836 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2837 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2838 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2839 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2840 | numoctrl = expected number of controllers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2841 | logLevel = level to log to. |
| 2842 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2843 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2844 | Returns: main.TRUE if the number of switches and links are correct, |
| 2845 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2846 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2847 | """ |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2848 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2849 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 2850 | summary = self.summary() |
| 2851 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 2852 | except ( TypeError, ValueError ): |
| 2853 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 2854 | return main.ERROR |
| 2855 | try: |
| 2856 | topology = self.getTopology( self.topology() ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2857 | if topology == {} or topology == None or summary == {} or summary == None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2858 | return main.ERROR |
| 2859 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2860 | # Is the number of switches is what we expected |
| 2861 | devices = topology.get( 'devices', False ) |
| 2862 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2863 | nodes = summary.get( 'nodes', False ) |
| 2864 | if devices is False or links is False or nodes is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2865 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2866 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2867 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2868 | linkCheck = ( int( links ) == int( numolink ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2869 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
| 2870 | if switchCheck and linkCheck and nodeCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2871 | # We expected the correct numbers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2872 | output = output + "The number of links and switches match "\ |
| 2873 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2874 | result = main.TRUE |
| 2875 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2876 | output = output + \ |
| 2877 | "The number of links and switches does not match " + \ |
| 2878 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2879 | result = main.FALSE |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2880 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 2881 | output = output + " (%i expected) " % int( numoswitch ) |
| 2882 | output = output + "and %i links " % int( links ) |
| 2883 | output = output + "(%i expected)" % int( numolink ) |
YPZhang | d7e4b6e | 2016-06-17 16:07:55 -0700 | [diff] [blame] | 2884 | if int( numoctrl ) > 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2885 | output = output + "and %i controllers " % int( nodes ) |
| 2886 | output = output + "(%i expected)" % int( numoctrl ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2887 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2888 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2889 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2890 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2891 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2892 | main.log.info( output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2893 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2894 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2895 | main.log.error( self.name + ": EOF exception found" ) |
| 2896 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2897 | main.cleanup() |
| 2898 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2899 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2900 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2901 | main.cleanup() |
| 2902 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2903 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2904 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2905 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2906 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2907 | deviceId must be the id of a device as seen in the onos devices command |
| 2908 | onosNode is the ip of one of the onos nodes in the cluster |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2909 | role must be either master, standby, or none |
| 2910 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2911 | Returns: |
| 2912 | main.TRUE or main.FALSE based on argument verification and |
| 2913 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2914 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2915 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2916 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2917 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2918 | cmdStr = "device-role " +\ |
| 2919 | str( deviceId ) + " " +\ |
| 2920 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2921 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2922 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2923 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2924 | if re.search( "Error", handle ): |
| 2925 | # end color output to escape any colours |
| 2926 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2927 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2928 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2929 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2930 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2931 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2932 | main.log.error( "Invalid 'role' given to device_role(). " + |
| 2933 | "Value was '" + str(role) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2934 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2935 | except AssertionError: |
| 2936 | main.log.exception( "" ) |
| 2937 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2938 | except TypeError: |
| 2939 | main.log.exception( self.name + ": Object not as expected" ) |
| 2940 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2941 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2942 | main.log.error( self.name + ": EOF exception found" ) |
| 2943 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2944 | main.cleanup() |
| 2945 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2946 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2947 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2948 | main.cleanup() |
| 2949 | main.exit() |
| 2950 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2951 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2952 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2953 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 2954 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2955 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2956 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2957 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2958 | cmdStr = "clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2959 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2960 | cmdStr += " -j" |
| 2961 | handle = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2962 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2963 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2964 | except AssertionError: |
| 2965 | main.log.exception( "" ) |
| 2966 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2967 | except TypeError: |
| 2968 | main.log.exception( self.name + ": Object not as expected" ) |
| 2969 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2970 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2971 | main.log.error( self.name + ": EOF exception found" ) |
| 2972 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2973 | main.cleanup() |
| 2974 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2975 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2976 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 2977 | main.cleanup() |
| 2978 | main.exit() |
| 2979 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2980 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2981 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2982 | CLI command to get the current leader for the Election test application |
| 2983 | NOTE: Requires installation of the onos-app-election feature |
| 2984 | Returns: Node IP of the leader if one exists |
| 2985 | None if none exists |
| 2986 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2987 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 2988 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2989 | cmdStr = "election-test-leader" |
| 2990 | response = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2991 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2992 | # Leader |
| 2993 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2994 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2995 | nodeSearch = re.search( leaderPattern, response ) |
| 2996 | if nodeSearch: |
| 2997 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2998 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2999 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3000 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3001 | # no leader |
| 3002 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3003 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3004 | nullSearch = re.search( nullPattern, response ) |
| 3005 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3006 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3007 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3008 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3009 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3010 | main.log.error( "Error in electionTestLeader on " + self.name + |
| 3011 | ": " + "unexpected response" ) |
| 3012 | main.log.error( repr( response ) ) |
| 3013 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3014 | except AssertionError: |
| 3015 | main.log.exception( "" ) |
| 3016 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3017 | except TypeError: |
| 3018 | main.log.exception( self.name + ": Object not as expected" ) |
| 3019 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3020 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3021 | main.log.error( self.name + ": EOF exception found" ) |
| 3022 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3023 | main.cleanup() |
| 3024 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3025 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3026 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3027 | main.cleanup() |
| 3028 | main.exit() |
| 3029 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3030 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3031 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3032 | CLI command to run for leadership of the Election test application. |
| 3033 | NOTE: Requires installation of the onos-app-election feature |
| 3034 | Returns: Main.TRUE on success |
| 3035 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3036 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3037 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3038 | cmdStr = "election-test-run" |
| 3039 | response = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3040 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3041 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3042 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3043 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3044 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3045 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3046 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3047 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3048 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3049 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3050 | main.log.error( "Error in electionTestRun on " + self.name + |
| 3051 | ": " + "unexpected response" ) |
| 3052 | main.log.error( repr( response ) ) |
| 3053 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3054 | except AssertionError: |
| 3055 | main.log.exception( "" ) |
| 3056 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3057 | except TypeError: |
| 3058 | main.log.exception( self.name + ": Object not as expected" ) |
| 3059 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3060 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3061 | main.log.error( self.name + ": EOF exception found" ) |
| 3062 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3063 | main.cleanup() |
| 3064 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3065 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3066 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3067 | main.cleanup() |
| 3068 | main.exit() |
| 3069 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3070 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3071 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3072 | * CLI command to withdraw the local node from leadership election for |
| 3073 | * the Election test application. |
| 3074 | #NOTE: Requires installation of the onos-app-election feature |
| 3075 | Returns: Main.TRUE on success |
| 3076 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3077 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3078 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3079 | cmdStr = "election-test-withdraw" |
| 3080 | response = self.sendline( cmdStr ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3081 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3082 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3083 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3084 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3085 | if re.search( successPattern, response ): |
| 3086 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3087 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3088 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3089 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3090 | main.log.error( "Error in electionTestWithdraw on " + |
| 3091 | self.name + ": " + "unexpected response" ) |
| 3092 | main.log.error( repr( response ) ) |
| 3093 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3094 | except AssertionError: |
| 3095 | main.log.exception( "" ) |
| 3096 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3097 | except TypeError: |
| 3098 | main.log.exception( self.name + ": Object not as expected" ) |
| 3099 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3100 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3101 | main.log.error( self.name + ": EOF exception found" ) |
| 3102 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3103 | main.cleanup() |
| 3104 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3105 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3106 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3107 | main.cleanup() |
| 3108 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3109 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3110 | def getDevicePortsEnabledCount( self, dpid ): |
| 3111 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3112 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3113 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3114 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3115 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3116 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 3117 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3118 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3119 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3120 | if re.search( "No such device", output ): |
| 3121 | main.log.error( "Error in getting ports" ) |
| 3122 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3123 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3124 | except AssertionError: |
| 3125 | main.log.exception( "" ) |
| 3126 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3127 | except TypeError: |
| 3128 | main.log.exception( self.name + ": Object not as expected" ) |
| 3129 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3130 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3131 | main.log.error( self.name + ": EOF exception found" ) |
| 3132 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3133 | main.cleanup() |
| 3134 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3135 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3136 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3137 | main.cleanup() |
| 3138 | main.exit() |
| 3139 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3140 | def getDeviceLinksActiveCount( self, dpid ): |
| 3141 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3142 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3143 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3144 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3145 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3146 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 3147 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3148 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3149 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3150 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3151 | main.log.error( "Error in getting ports " ) |
| 3152 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3153 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3154 | except AssertionError: |
| 3155 | main.log.exception( "" ) |
| 3156 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3157 | except TypeError: |
| 3158 | main.log.exception( self.name + ": Object not as expected" ) |
| 3159 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3160 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3161 | main.log.error( self.name + ": EOF exception found" ) |
| 3162 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3163 | main.cleanup() |
| 3164 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3165 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3166 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3167 | main.cleanup() |
| 3168 | main.exit() |
| 3169 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3170 | def getAllIntentIds( self ): |
| 3171 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3172 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3173 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3174 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3175 | cmdStr = "onos:intents | grep id=" |
| 3176 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3177 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3178 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3179 | if re.search( "Error", output ): |
| 3180 | main.log.error( "Error in getting ports" ) |
| 3181 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3182 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3183 | except AssertionError: |
| 3184 | main.log.exception( "" ) |
| 3185 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3186 | except TypeError: |
| 3187 | main.log.exception( self.name + ": Object not as expected" ) |
| 3188 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3189 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3190 | main.log.error( self.name + ": EOF exception found" ) |
| 3191 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3192 | main.cleanup() |
| 3193 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3194 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3195 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3196 | main.cleanup() |
| 3197 | main.exit() |
| 3198 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3199 | def intentSummary( self ): |
| 3200 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3201 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3202 | """ |
| 3203 | try: |
| 3204 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3205 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3206 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3207 | states.append( intent.get( 'state', None ) ) |
| 3208 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3209 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3210 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3211 | except ( TypeError, ValueError ): |
| 3212 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3213 | return None |
| 3214 | except pexpect.EOF: |
| 3215 | main.log.error( self.name + ": EOF exception found" ) |
| 3216 | main.log.error( self.name + ": " + self.handle.before ) |
| 3217 | main.cleanup() |
| 3218 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3219 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3220 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3221 | main.cleanup() |
| 3222 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3223 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3224 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3225 | """ |
| 3226 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3227 | Optional argument: |
| 3228 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3229 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3230 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3231 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3232 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3233 | cmdStr += " -j" |
| 3234 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3235 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3236 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3237 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3238 | except AssertionError: |
| 3239 | main.log.exception( "" ) |
| 3240 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3241 | except TypeError: |
| 3242 | main.log.exception( self.name + ": Object not as expected" ) |
| 3243 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3244 | except pexpect.EOF: |
| 3245 | main.log.error( self.name + ": EOF exception found" ) |
| 3246 | main.log.error( self.name + ": " + self.handle.before ) |
| 3247 | main.cleanup() |
| 3248 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3249 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3250 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3251 | main.cleanup() |
| 3252 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3253 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3254 | def leaderCandidates( self, jsonFormat=True ): |
| 3255 | """ |
| 3256 | Returns the output of the leaders -c command. |
| 3257 | Optional argument: |
| 3258 | * jsonFormat - boolean indicating if you want output in json |
| 3259 | """ |
| 3260 | try: |
| 3261 | cmdStr = "onos:leaders -c" |
| 3262 | if jsonFormat: |
| 3263 | cmdStr += " -j" |
| 3264 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3265 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3266 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3267 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3268 | except AssertionError: |
| 3269 | main.log.exception( "" ) |
| 3270 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3271 | except TypeError: |
| 3272 | main.log.exception( self.name + ": Object not as expected" ) |
| 3273 | return None |
| 3274 | except pexpect.EOF: |
| 3275 | main.log.error( self.name + ": EOF exception found" ) |
| 3276 | main.log.error( self.name + ": " + self.handle.before ) |
| 3277 | main.cleanup() |
| 3278 | main.exit() |
| 3279 | except Exception: |
| 3280 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3281 | main.cleanup() |
| 3282 | main.exit() |
| 3283 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3284 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3285 | """ |
| 3286 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
| 3287 | topic parameter and an empty list if the topic doesn't exist |
| 3288 | If no leader is elected leader in the returned list will be "none" |
| 3289 | Returns None if there is a type error processing the json object |
| 3290 | """ |
| 3291 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3292 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3293 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3294 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3295 | assert "Command not found:" not in rawOutput, rawOutput |
| 3296 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3297 | results = [] |
| 3298 | for dict in output: |
| 3299 | if dict["topic"] == topic: |
| 3300 | leader = dict["leader"] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3301 | candidates = re.split( ", ", dict["candidates"][1:-1] ) |
| 3302 | results.append( leader ) |
| 3303 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3304 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3305 | except AssertionError: |
| 3306 | main.log.exception( "" ) |
| 3307 | return None |
| 3308 | except ( TypeError, ValueError ): |
| 3309 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3310 | return None |
| 3311 | except pexpect.EOF: |
| 3312 | main.log.error( self.name + ": EOF exception found" ) |
| 3313 | main.log.error( self.name + ": " + self.handle.before ) |
| 3314 | main.cleanup() |
| 3315 | main.exit() |
| 3316 | except Exception: |
| 3317 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3318 | main.cleanup() |
| 3319 | main.exit() |
| 3320 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3321 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3322 | """ |
| 3323 | Returns the output of the intent Pending map. |
| 3324 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3325 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3326 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3327 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3328 | cmdStr += " -j" |
| 3329 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3330 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3331 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3332 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3333 | except AssertionError: |
| 3334 | main.log.exception( "" ) |
| 3335 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3336 | except TypeError: |
| 3337 | main.log.exception( self.name + ": Object not as expected" ) |
| 3338 | return None |
| 3339 | except pexpect.EOF: |
| 3340 | main.log.error( self.name + ": EOF exception found" ) |
| 3341 | main.log.error( self.name + ": " + self.handle.before ) |
| 3342 | main.cleanup() |
| 3343 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3344 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3345 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3346 | main.cleanup() |
| 3347 | main.exit() |
| 3348 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3349 | def partitions( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3350 | """ |
| 3351 | Returns the output of the raft partitions command for ONOS. |
| 3352 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3353 | # Sample JSON |
| 3354 | # { |
| 3355 | # "leader": "tcp://10.128.30.11:7238", |
| 3356 | # "members": [ |
| 3357 | # "tcp://10.128.30.11:7238", |
| 3358 | # "tcp://10.128.30.17:7238", |
| 3359 | # "tcp://10.128.30.13:7238", |
| 3360 | # ], |
| 3361 | # "name": "p1", |
| 3362 | # "term": 3 |
| 3363 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3364 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3365 | cmdStr = "onos:partitions" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3366 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3367 | cmdStr += " -j" |
| 3368 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3369 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3370 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3371 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3372 | except AssertionError: |
| 3373 | main.log.exception( "" ) |
| 3374 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3375 | except TypeError: |
| 3376 | main.log.exception( self.name + ": Object not as expected" ) |
| 3377 | return None |
| 3378 | except pexpect.EOF: |
| 3379 | main.log.error( self.name + ": EOF exception found" ) |
| 3380 | main.log.error( self.name + ": " + self.handle.before ) |
| 3381 | main.cleanup() |
| 3382 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3383 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3384 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3385 | main.cleanup() |
| 3386 | main.exit() |
| 3387 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3388 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3389 | """ |
| 3390 | Returns the output of the apps command for ONOS. This command lists |
| 3391 | information about installed ONOS applications |
| 3392 | """ |
| 3393 | # Sample JSON object |
| 3394 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
| 3395 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3396 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
| 3397 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
| 3398 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3399 | cmdStr = "onos:apps" |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3400 | if summary: |
| 3401 | cmdStr += " -s" |
| 3402 | if active: |
| 3403 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3404 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3405 | cmdStr += " -j" |
| 3406 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3407 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3408 | assert "Command not found:" not in output, output |
| 3409 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3410 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3411 | # FIXME: look at specific exceptions/Errors |
| 3412 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3413 | main.log.exception( "Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3414 | return None |
| 3415 | except TypeError: |
| 3416 | main.log.exception( self.name + ": Object not as expected" ) |
| 3417 | return None |
| 3418 | except pexpect.EOF: |
| 3419 | main.log.error( self.name + ": EOF exception found" ) |
| 3420 | main.log.error( self.name + ": " + self.handle.before ) |
| 3421 | main.cleanup() |
| 3422 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3423 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3424 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3425 | main.cleanup() |
| 3426 | main.exit() |
| 3427 | |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3428 | def appStatus( self, appName ): |
| 3429 | """ |
| 3430 | Uses the onos:apps cli command to return the status of an application. |
| 3431 | Returns: |
| 3432 | "ACTIVE" - If app is installed and activated |
| 3433 | "INSTALLED" - If app is installed and deactivated |
| 3434 | "UNINSTALLED" - If app is not installed |
| 3435 | None - on error |
| 3436 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3437 | try: |
| 3438 | if not isinstance( appName, types.StringType ): |
| 3439 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3440 | " a string" ) |
| 3441 | return None |
| 3442 | output = self.apps( jsonFormat=True ) |
| 3443 | appsJson = json.loads( output ) |
| 3444 | state = None |
| 3445 | for app in appsJson: |
| 3446 | if appName == app.get('name'): |
| 3447 | state = app.get('state') |
| 3448 | break |
| 3449 | if state == "ACTIVE" or state == "INSTALLED": |
| 3450 | return state |
| 3451 | elif state is None: |
| 3452 | return "UNINSTALLED" |
| 3453 | elif state: |
| 3454 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3455 | str( state ) ) |
| 3456 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3457 | except ( TypeError, ValueError ): |
| 3458 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3459 | return None |
| 3460 | except pexpect.EOF: |
| 3461 | main.log.error( self.name + ": EOF exception found" ) |
| 3462 | main.log.error( self.name + ": " + self.handle.before ) |
| 3463 | main.cleanup() |
| 3464 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3465 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3466 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3467 | main.cleanup() |
| 3468 | main.exit() |
| 3469 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3470 | def app( self, appName, option ): |
| 3471 | """ |
| 3472 | Interacts with the app command for ONOS. This command manages |
| 3473 | application inventory. |
| 3474 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3475 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3476 | # Validate argument types |
| 3477 | valid = True |
| 3478 | if not isinstance( appName, types.StringType ): |
| 3479 | main.log.error( self.name + ".app(): appName must be a " + |
| 3480 | "string" ) |
| 3481 | valid = False |
| 3482 | if not isinstance( option, types.StringType ): |
| 3483 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3484 | valid = False |
| 3485 | if not valid: |
| 3486 | return main.FALSE |
| 3487 | # Validate Option |
| 3488 | option = option.lower() |
| 3489 | # NOTE: Install may become a valid option |
| 3490 | if option == "activate": |
| 3491 | pass |
| 3492 | elif option == "deactivate": |
| 3493 | pass |
| 3494 | elif option == "uninstall": |
| 3495 | pass |
| 3496 | else: |
| 3497 | # Invalid option |
| 3498 | main.log.error( "The ONOS app command argument only takes " + |
| 3499 | "the values: (activate|deactivate|uninstall)" + |
| 3500 | "; was given '" + option + "'") |
| 3501 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3502 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3503 | output = self.sendline( cmdStr ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3504 | if "Error executing command" in output: |
| 3505 | main.log.error( "Error in processing onos:app command: " + |
| 3506 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3507 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3508 | elif "No such application" in output: |
| 3509 | main.log.error( "The application '" + appName + |
| 3510 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3511 | return main.FALSE |
| 3512 | elif "Command not found:" in output: |
| 3513 | main.log.error( "Error in processing onos:app command: " + |
| 3514 | str( output ) ) |
| 3515 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3516 | elif "Unsupported command:" in output: |
| 3517 | main.log.error( "Incorrect command given to 'app': " + |
| 3518 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3519 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3520 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3521 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3522 | return main.TRUE |
| 3523 | except TypeError: |
| 3524 | main.log.exception( self.name + ": Object not as expected" ) |
| 3525 | return main.ERROR |
| 3526 | except pexpect.EOF: |
| 3527 | main.log.error( self.name + ": EOF exception found" ) |
| 3528 | main.log.error( self.name + ": " + self.handle.before ) |
| 3529 | main.cleanup() |
| 3530 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3531 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3532 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3533 | main.cleanup() |
| 3534 | main.exit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3535 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3536 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3537 | """ |
| 3538 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3539 | appName is the hierarchical app name, not the feature name |
| 3540 | If check is True, method will check the status of the app after the |
| 3541 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3542 | Returns main.TRUE if the command was successfully sent |
| 3543 | main.FALSE if the cli responded with an error or given |
| 3544 | incorrect input |
| 3545 | """ |
| 3546 | try: |
| 3547 | if not isinstance( appName, types.StringType ): |
| 3548 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3549 | " a string" ) |
| 3550 | return main.FALSE |
| 3551 | status = self.appStatus( appName ) |
| 3552 | if status == "INSTALLED": |
| 3553 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3554 | if check and response == main.TRUE: |
| 3555 | for i in range(10): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3556 | status = self.appStatus( appName ) |
| 3557 | if status == "ACTIVE": |
| 3558 | return main.TRUE |
| 3559 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3560 | main.log.debug( "The state of application " + |
| 3561 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3562 | time.sleep( 1 ) |
| 3563 | return main.FALSE |
| 3564 | else: # not 'check' or command didn't succeed |
| 3565 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3566 | elif status == "ACTIVE": |
| 3567 | return main.TRUE |
| 3568 | elif status == "UNINSTALLED": |
| 3569 | main.log.error( self.name + ": Tried to activate the " + |
| 3570 | "application '" + appName + "' which is not " + |
| 3571 | "installed." ) |
| 3572 | else: |
| 3573 | main.log.error( "Unexpected return value from appStatus: " + |
| 3574 | str( status ) ) |
| 3575 | return main.ERROR |
| 3576 | except TypeError: |
| 3577 | main.log.exception( self.name + ": Object not as expected" ) |
| 3578 | return main.ERROR |
| 3579 | except pexpect.EOF: |
| 3580 | main.log.error( self.name + ": EOF exception found" ) |
| 3581 | main.log.error( self.name + ": " + self.handle.before ) |
| 3582 | main.cleanup() |
| 3583 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3584 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3585 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3586 | main.cleanup() |
| 3587 | main.exit() |
| 3588 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3589 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3590 | """ |
| 3591 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3592 | appName is the hierarchical app name, not the feature name |
| 3593 | If check is True, method will check the status of the app after the |
| 3594 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3595 | Returns main.TRUE if the command was successfully sent |
| 3596 | main.FALSE if the cli responded with an error or given |
| 3597 | incorrect input |
| 3598 | """ |
| 3599 | try: |
| 3600 | if not isinstance( appName, types.StringType ): |
| 3601 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 3602 | "be a string" ) |
| 3603 | return main.FALSE |
| 3604 | status = self.appStatus( appName ) |
| 3605 | if status == "INSTALLED": |
| 3606 | return main.TRUE |
| 3607 | elif status == "ACTIVE": |
| 3608 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3609 | if check and response == main.TRUE: |
| 3610 | for i in range(10): # try 10 times then give up |
| 3611 | status = self.appStatus( appName ) |
| 3612 | if status == "INSTALLED": |
| 3613 | return main.TRUE |
| 3614 | else: |
| 3615 | time.sleep( 1 ) |
| 3616 | return main.FALSE |
| 3617 | else: # not check or command didn't succeed |
| 3618 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3619 | elif status == "UNINSTALLED": |
| 3620 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 3621 | "application '" + appName + "' which is not " + |
| 3622 | "installed." ) |
| 3623 | return main.TRUE |
| 3624 | else: |
| 3625 | main.log.error( "Unexpected return value from appStatus: " + |
| 3626 | str( status ) ) |
| 3627 | return main.ERROR |
| 3628 | except TypeError: |
| 3629 | main.log.exception( self.name + ": Object not as expected" ) |
| 3630 | return main.ERROR |
| 3631 | except pexpect.EOF: |
| 3632 | main.log.error( self.name + ": EOF exception found" ) |
| 3633 | main.log.error( self.name + ": " + self.handle.before ) |
| 3634 | main.cleanup() |
| 3635 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3636 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3637 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3638 | main.cleanup() |
| 3639 | main.exit() |
| 3640 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3641 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3642 | """ |
| 3643 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3644 | appName is the hierarchical app name, not the feature name |
| 3645 | If check is True, method will check the status of the app after the |
| 3646 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3647 | Returns main.TRUE if the command was successfully sent |
| 3648 | main.FALSE if the cli responded with an error or given |
| 3649 | incorrect input |
| 3650 | """ |
| 3651 | # TODO: check with Thomas about the state machine for apps |
| 3652 | try: |
| 3653 | if not isinstance( appName, types.StringType ): |
| 3654 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 3655 | "be a string" ) |
| 3656 | return main.FALSE |
| 3657 | status = self.appStatus( appName ) |
| 3658 | if status == "INSTALLED": |
| 3659 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3660 | if check and response == main.TRUE: |
| 3661 | for i in range(10): # try 10 times then give up |
| 3662 | status = self.appStatus( appName ) |
| 3663 | if status == "UNINSTALLED": |
| 3664 | return main.TRUE |
| 3665 | else: |
| 3666 | time.sleep( 1 ) |
| 3667 | return main.FALSE |
| 3668 | else: # not check or command didn't succeed |
| 3669 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3670 | elif status == "ACTIVE": |
| 3671 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 3672 | "application '" + appName + "' which is " + |
| 3673 | "currently active." ) |
| 3674 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3675 | if check and response == main.TRUE: |
| 3676 | for i in range(10): # try 10 times then give up |
| 3677 | status = self.appStatus( appName ) |
| 3678 | if status == "UNINSTALLED": |
| 3679 | return main.TRUE |
| 3680 | else: |
| 3681 | time.sleep( 1 ) |
| 3682 | return main.FALSE |
| 3683 | else: # not check or command didn't succeed |
| 3684 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3685 | elif status == "UNINSTALLED": |
| 3686 | return main.TRUE |
| 3687 | else: |
| 3688 | main.log.error( "Unexpected return value from appStatus: " + |
| 3689 | str( status ) ) |
| 3690 | return main.ERROR |
| 3691 | except TypeError: |
| 3692 | main.log.exception( self.name + ": Object not as expected" ) |
| 3693 | return main.ERROR |
| 3694 | except pexpect.EOF: |
| 3695 | main.log.error( self.name + ": EOF exception found" ) |
| 3696 | main.log.error( self.name + ": " + self.handle.before ) |
| 3697 | main.cleanup() |
| 3698 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3699 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3700 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3701 | main.cleanup() |
| 3702 | main.exit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3703 | |
| 3704 | def appIDs( self, jsonFormat=True ): |
| 3705 | """ |
| 3706 | Show the mappings between app id and app names given by the 'app-ids' |
| 3707 | cli command |
| 3708 | """ |
| 3709 | try: |
| 3710 | cmdStr = "app-ids" |
| 3711 | if jsonFormat: |
| 3712 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3713 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3714 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3715 | assert "Command not found:" not in output, output |
| 3716 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3717 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3718 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3719 | main.log.exception( "Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3720 | return None |
| 3721 | except TypeError: |
| 3722 | main.log.exception( self.name + ": Object not as expected" ) |
| 3723 | return None |
| 3724 | except pexpect.EOF: |
| 3725 | main.log.error( self.name + ": EOF exception found" ) |
| 3726 | main.log.error( self.name + ": " + self.handle.before ) |
| 3727 | main.cleanup() |
| 3728 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3729 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3730 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3731 | main.cleanup() |
| 3732 | main.exit() |
| 3733 | |
| 3734 | def appToIDCheck( self ): |
| 3735 | """ |
| 3736 | This method will check that each application's ID listed in 'apps' is |
| 3737 | the same as the ID listed in 'app-ids'. The check will also check that |
| 3738 | there are no duplicate IDs issued. Note that an app ID should be |
| 3739 | a globaly unique numerical identifier for app/app-like features. Once |
| 3740 | an ID is registered, the ID is never freed up so that if an app is |
| 3741 | reinstalled it will have the same ID. |
| 3742 | |
| 3743 | Returns: main.TRUE if the check passes and |
| 3744 | main.FALSE if the check fails or |
| 3745 | main.ERROR if there is some error in processing the test |
| 3746 | """ |
| 3747 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3748 | bail = False |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3749 | rawJson = self.appIDs( jsonFormat=True ) |
| 3750 | if rawJson: |
| 3751 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3752 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3753 | main.log.error( "app-ids returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3754 | bail = True |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3755 | rawJson = self.apps( jsonFormat=True ) |
| 3756 | if rawJson: |
| 3757 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3758 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3759 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3760 | bail = True |
| 3761 | if bail: |
| 3762 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3763 | result = main.TRUE |
| 3764 | for app in apps: |
| 3765 | appID = app.get( 'id' ) |
| 3766 | if appID is None: |
| 3767 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3768 | result = main.FALSE |
| 3769 | appName = app.get( 'name' ) |
| 3770 | if appName is None: |
| 3771 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3772 | result = main.FALSE |
| 3773 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3774 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3775 | # main.log.debug( "Comparing " + str( app ) + " to " + |
| 3776 | # str( current ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3777 | if not current: # if ids doesn't have this id |
| 3778 | result = main.FALSE |
| 3779 | main.log.error( "'app-ids' does not have the ID for " + |
| 3780 | str( appName ) + " that apps does." ) |
| 3781 | elif len( current ) > 1: |
| 3782 | # there is more than one app with this ID |
| 3783 | result = main.FALSE |
| 3784 | # We will log this later in the method |
| 3785 | elif not current[0][ 'name' ] == appName: |
| 3786 | currentName = current[0][ 'name' ] |
| 3787 | result = main.FALSE |
| 3788 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 3789 | " registered under id:" + str( appID ) + |
| 3790 | " but 'apps' has " + str( appName ) ) |
| 3791 | else: |
| 3792 | pass # id and name match! |
| 3793 | # now make sure that app-ids has no duplicates |
| 3794 | idsList = [] |
| 3795 | namesList = [] |
| 3796 | for item in ids: |
| 3797 | idsList.append( item[ 'id' ] ) |
| 3798 | namesList.append( item[ 'name' ] ) |
| 3799 | if len( idsList ) != len( set( idsList ) ) or\ |
| 3800 | len( namesList ) != len( set( namesList ) ): |
| 3801 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 3802 | + json.dumps( ids, |
| 3803 | sort_keys=True, |
| 3804 | indent=4, |
| 3805 | separators=( ',', ': ' ) ) ) |
| 3806 | result = main.FALSE |
| 3807 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3808 | except ( TypeError, ValueError ): |
| 3809 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3810 | return main.ERROR |
| 3811 | except pexpect.EOF: |
| 3812 | main.log.error( self.name + ": EOF exception found" ) |
| 3813 | main.log.error( self.name + ": " + self.handle.before ) |
| 3814 | main.cleanup() |
| 3815 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3816 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3817 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3818 | main.cleanup() |
| 3819 | main.exit() |
| 3820 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3821 | def getCfg( self, component=None, propName=None, short=False, |
| 3822 | jsonFormat=True ): |
| 3823 | """ |
| 3824 | Get configuration settings from onos cli |
| 3825 | Optional arguments: |
| 3826 | component - Optionally only list configurations for a specific |
| 3827 | component. If None, all components with configurations |
| 3828 | are displayed. Case Sensitive string. |
| 3829 | propName - If component is specified, propName option will show |
| 3830 | only this specific configuration from that component. |
| 3831 | Case Sensitive string. |
| 3832 | jsonFormat - Returns output as json. Note that this will override |
| 3833 | the short option |
| 3834 | short - Short, less verbose, version of configurations. |
| 3835 | This is overridden by the json option |
| 3836 | returns: |
| 3837 | Output from cli as a string or None on error |
| 3838 | """ |
| 3839 | try: |
| 3840 | baseStr = "cfg" |
| 3841 | cmdStr = " get" |
| 3842 | componentStr = "" |
| 3843 | if component: |
| 3844 | componentStr += " " + component |
| 3845 | if propName: |
| 3846 | componentStr += " " + propName |
| 3847 | if jsonFormat: |
| 3848 | baseStr += " -j" |
| 3849 | elif short: |
| 3850 | baseStr += " -s" |
| 3851 | output = self.sendline( baseStr + cmdStr + componentStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3852 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3853 | assert "Command not found:" not in output, output |
| 3854 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3855 | return output |
| 3856 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3857 | main.log.exception( "Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3858 | return None |
| 3859 | except TypeError: |
| 3860 | main.log.exception( self.name + ": Object not as expected" ) |
| 3861 | return None |
| 3862 | except pexpect.EOF: |
| 3863 | main.log.error( self.name + ": EOF exception found" ) |
| 3864 | main.log.error( self.name + ": " + self.handle.before ) |
| 3865 | main.cleanup() |
| 3866 | main.exit() |
| 3867 | except Exception: |
| 3868 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3869 | main.cleanup() |
| 3870 | main.exit() |
| 3871 | |
| 3872 | def setCfg( self, component, propName, value=None, check=True ): |
| 3873 | """ |
| 3874 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3875 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3876 | component - The case sensitive name of the component whose |
| 3877 | property is to be set |
| 3878 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3879 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3880 | value - The value to set the property to. If None, will unset the |
| 3881 | property and revert it to it's default value(if applicable) |
| 3882 | check - Boolean, Check whether the option was successfully set this |
| 3883 | only applies when a value is given. |
| 3884 | returns: |
| 3885 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 3886 | will return main.TRUE unless there is an error |
| 3887 | """ |
| 3888 | try: |
| 3889 | baseStr = "cfg" |
| 3890 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 3891 | if value is not None: |
| 3892 | cmdStr += " " + str( value ) |
| 3893 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3894 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3895 | assert "Command not found:" not in output, output |
| 3896 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3897 | if value and check: |
| 3898 | results = self.getCfg( component=str( component ), |
| 3899 | propName=str( propName ), |
| 3900 | jsonFormat=True ) |
| 3901 | # Check if current value is what we just set |
| 3902 | try: |
| 3903 | jsonOutput = json.loads( results ) |
| 3904 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3905 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3906 | main.log.exception( "Error parsing cfg output" ) |
| 3907 | main.log.error( "output:" + repr( results ) ) |
| 3908 | return main.FALSE |
| 3909 | if current == str( value ): |
| 3910 | return main.TRUE |
| 3911 | return main.FALSE |
| 3912 | return main.TRUE |
| 3913 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3914 | main.log.exception( "Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3915 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3916 | except ( TypeError, ValueError ): |
| 3917 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3918 | return main.FALSE |
| 3919 | except pexpect.EOF: |
| 3920 | main.log.error( self.name + ": EOF exception found" ) |
| 3921 | main.log.error( self.name + ": " + self.handle.before ) |
| 3922 | main.cleanup() |
| 3923 | main.exit() |
| 3924 | except Exception: |
| 3925 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3926 | main.cleanup() |
| 3927 | main.exit() |
| 3928 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3929 | def setTestAdd( self, setName, values ): |
| 3930 | """ |
| 3931 | CLI command to add elements to a distributed set. |
| 3932 | Arguments: |
| 3933 | setName - The name of the set to add to. |
| 3934 | values - The value(s) to add to the set, space seperated. |
| 3935 | Example usages: |
| 3936 | setTestAdd( "set1", "a b c" ) |
| 3937 | setTestAdd( "set2", "1" ) |
| 3938 | returns: |
| 3939 | main.TRUE on success OR |
| 3940 | main.FALSE if elements were already in the set OR |
| 3941 | main.ERROR on error |
| 3942 | """ |
| 3943 | try: |
| 3944 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
| 3945 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3946 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3947 | assert "Command not found:" not in output, output |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3948 | try: |
| 3949 | # TODO: Maybe make this less hardcoded |
| 3950 | # ConsistentMap Exceptions |
| 3951 | assert "org.onosproject.store.service" not in output |
| 3952 | # Node not leader |
| 3953 | assert "java.lang.IllegalStateException" not in output |
| 3954 | except AssertionError: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 3955 | main.log.error( "Error in processing '" + cmdStr + "' " + |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 3956 | "command: " + str( output ) ) |
| 3957 | retryTime = 30 # Conservative time, given by Madan |
| 3958 | main.log.info( "Waiting " + str( retryTime ) + |
| 3959 | "seconds before retrying." ) |
| 3960 | time.sleep( retryTime ) # Due to change in mastership |
| 3961 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3962 | assert output is not None, "Error in sendline" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3963 | assert "Error executing command" not in output |
| 3964 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 3965 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
| 3966 | main.log.info( self.name + ": " + output ) |
| 3967 | if re.search( positiveMatch, output): |
| 3968 | return main.TRUE |
| 3969 | elif re.search( negativeMatch, output): |
| 3970 | return main.FALSE |
| 3971 | else: |
| 3972 | main.log.error( self.name + ": setTestAdd did not" + |
| 3973 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3974 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 3975 | return main.ERROR |
| 3976 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3977 | main.log.exception( "Error in processing '" + cmdStr + "' command. " ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3978 | return main.ERROR |
| 3979 | except TypeError: |
| 3980 | main.log.exception( self.name + ": Object not as expected" ) |
| 3981 | return main.ERROR |
| 3982 | except pexpect.EOF: |
| 3983 | main.log.error( self.name + ": EOF exception found" ) |
| 3984 | main.log.error( self.name + ": " + self.handle.before ) |
| 3985 | main.cleanup() |
| 3986 | main.exit() |
| 3987 | except Exception: |
| 3988 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3989 | main.cleanup() |
| 3990 | main.exit() |
| 3991 | |
| 3992 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 3993 | """ |
| 3994 | CLI command to remove elements from a distributed set. |
| 3995 | Required arguments: |
| 3996 | setName - The name of the set to remove from. |
| 3997 | values - The value(s) to remove from the set, space seperated. |
| 3998 | Optional arguments: |
| 3999 | clear - Clear all elements from the set |
| 4000 | retain - Retain only the given values. (intersection of the |
| 4001 | original set and the given set) |
| 4002 | returns: |
| 4003 | main.TRUE on success OR |
| 4004 | main.FALSE if the set was not changed OR |
| 4005 | main.ERROR on error |
| 4006 | """ |
| 4007 | try: |
| 4008 | cmdStr = "set-test-remove " |
| 4009 | if clear: |
| 4010 | cmdStr += "-c " + str( setName ) |
| 4011 | elif retain: |
| 4012 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4013 | else: |
| 4014 | cmdStr += str( setName ) + " " + str( values ) |
| 4015 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4016 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4017 | assert output is not None, "Error in sendline" |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4018 | # TODO: Maybe make this less hardcoded |
| 4019 | # ConsistentMap Exceptions |
| 4020 | assert "org.onosproject.store.service" not in output |
| 4021 | # Node not leader |
| 4022 | assert "java.lang.IllegalStateException" not in output |
| 4023 | except AssertionError: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4024 | main.log.error( "Error in processing '" + cmdStr + "' " + |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4025 | "command: " + str( output ) ) |
| 4026 | retryTime = 30 # Conservative time, given by Madan |
| 4027 | main.log.info( "Waiting " + str( retryTime ) + |
| 4028 | "seconds before retrying." ) |
| 4029 | time.sleep( retryTime ) # Due to change in mastership |
| 4030 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4031 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4032 | assert "Command not found:" not in output, output |
| 4033 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4034 | main.log.info( self.name + ": " + output ) |
| 4035 | if clear: |
| 4036 | pattern = "Set " + str( setName ) + " cleared" |
| 4037 | if re.search( pattern, output ): |
| 4038 | return main.TRUE |
| 4039 | elif retain: |
| 4040 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4041 | "only elements of set \[(.*)\]" |
| 4042 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4043 | "retaining only elements of the set " +\ |
| 4044 | "\[(.*)\]" |
| 4045 | if re.search( positivePattern, output ): |
| 4046 | return main.TRUE |
| 4047 | elif re.search( negativePattern, output ): |
| 4048 | return main.FALSE |
| 4049 | else: |
| 4050 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4051 | str( setName ) |
| 4052 | if ( len( values.split() ) == 1 ): |
| 4053 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4054 | str( setName ) |
| 4055 | else: |
| 4056 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4057 | str( setName ) |
| 4058 | if re.search( positivePattern, output ): |
| 4059 | return main.TRUE |
| 4060 | elif re.search( negativePattern, output ): |
| 4061 | return main.FALSE |
| 4062 | main.log.error( self.name + ": setTestRemove did not" + |
| 4063 | " match expected output" ) |
| 4064 | main.log.debug( self.name + " expected: " + pattern ) |
| 4065 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4066 | return main.ERROR |
| 4067 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4068 | main.log.exception( "Error in processing '" + cmdStr + "' commandr. " ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4069 | return main.ERROR |
| 4070 | except TypeError: |
| 4071 | main.log.exception( self.name + ": Object not as expected" ) |
| 4072 | return main.ERROR |
| 4073 | except pexpect.EOF: |
| 4074 | main.log.error( self.name + ": EOF exception found" ) |
| 4075 | main.log.error( self.name + ": " + self.handle.before ) |
| 4076 | main.cleanup() |
| 4077 | main.exit() |
| 4078 | except Exception: |
| 4079 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4080 | main.cleanup() |
| 4081 | main.exit() |
| 4082 | |
| 4083 | def setTestGet( self, setName, values="" ): |
| 4084 | """ |
| 4085 | CLI command to get the elements in a distributed set. |
| 4086 | Required arguments: |
| 4087 | setName - The name of the set to remove from. |
| 4088 | Optional arguments: |
| 4089 | values - The value(s) to check if in the set, space seperated. |
| 4090 | returns: |
| 4091 | main.ERROR on error OR |
| 4092 | A list of elements in the set if no optional arguments are |
| 4093 | supplied OR |
| 4094 | A tuple containing the list then: |
| 4095 | main.FALSE if the given values are not in the set OR |
| 4096 | main.TRUE if the given values are in the set OR |
| 4097 | """ |
| 4098 | try: |
| 4099 | values = str( values ).strip() |
| 4100 | setName = str( setName ).strip() |
| 4101 | length = len( values.split() ) |
| 4102 | containsCheck = None |
| 4103 | # Patterns to match |
| 4104 | setPattern = "\[(.*)\]" |
| 4105 | pattern = "Items in set " + setName + ":\n" + setPattern |
| 4106 | containsTrue = "Set " + setName + " contains the value " + values |
| 4107 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4108 | values |
| 4109 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4110 | setPattern |
| 4111 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4112 | " subset " + setPattern |
| 4113 | |
| 4114 | cmdStr = "set-test-get " |
| 4115 | cmdStr += setName + " " + values |
| 4116 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4117 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4118 | assert output is not None, "Error in sendline" |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4119 | # TODO: Maybe make this less hardcoded |
| 4120 | # ConsistentMap Exceptions |
| 4121 | assert "org.onosproject.store.service" not in output |
| 4122 | # Node not leader |
| 4123 | assert "java.lang.IllegalStateException" not in output |
| 4124 | except AssertionError: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4125 | main.log.error( "Error in processing '" + cmdStr + "' " + |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4126 | "command: " + str( output ) ) |
| 4127 | retryTime = 30 # Conservative time, given by Madan |
| 4128 | main.log.info( "Waiting " + str( retryTime ) + |
| 4129 | "seconds before retrying." ) |
| 4130 | time.sleep( retryTime ) # Due to change in mastership |
| 4131 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4132 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4133 | assert "Command not found:" not in output, output |
| 4134 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4135 | main.log.info( self.name + ": " + output ) |
| 4136 | |
| 4137 | if length == 0: |
| 4138 | match = re.search( pattern, output ) |
| 4139 | else: # if given values |
| 4140 | if length == 1: # Contains output |
| 4141 | patternTrue = pattern + "\n" + containsTrue |
| 4142 | patternFalse = pattern + "\n" + containsFalse |
| 4143 | else: # ContainsAll output |
| 4144 | patternTrue = pattern + "\n" + containsAllTrue |
| 4145 | patternFalse = pattern + "\n" + containsAllFalse |
| 4146 | matchTrue = re.search( patternTrue, output ) |
| 4147 | matchFalse = re.search( patternFalse, output ) |
| 4148 | if matchTrue: |
| 4149 | containsCheck = main.TRUE |
| 4150 | match = matchTrue |
| 4151 | elif matchFalse: |
| 4152 | containsCheck = main.FALSE |
| 4153 | match = matchFalse |
| 4154 | else: |
| 4155 | main.log.error( self.name + " setTestGet did not match " +\ |
| 4156 | "expected output" ) |
| 4157 | main.log.debug( self.name + " expected: " + pattern ) |
| 4158 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4159 | match = None |
| 4160 | if match: |
| 4161 | setMatch = match.group( 1 ) |
| 4162 | if setMatch == '': |
| 4163 | setList = [] |
| 4164 | else: |
| 4165 | setList = setMatch.split( ", " ) |
| 4166 | if length > 0: |
| 4167 | return ( setList, containsCheck ) |
| 4168 | else: |
| 4169 | return setList |
| 4170 | else: # no match |
| 4171 | main.log.error( self.name + ": setTestGet did not" + |
| 4172 | " match expected output" ) |
| 4173 | main.log.debug( self.name + " expected: " + pattern ) |
| 4174 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4175 | return main.ERROR |
| 4176 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4177 | main.log.exception( "Error in processing '" + cmdStr + "' command." ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4178 | return main.ERROR |
| 4179 | except TypeError: |
| 4180 | main.log.exception( self.name + ": Object not as expected" ) |
| 4181 | return main.ERROR |
| 4182 | except pexpect.EOF: |
| 4183 | main.log.error( self.name + ": EOF exception found" ) |
| 4184 | main.log.error( self.name + ": " + self.handle.before ) |
| 4185 | main.cleanup() |
| 4186 | main.exit() |
| 4187 | except Exception: |
| 4188 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4189 | main.cleanup() |
| 4190 | main.exit() |
| 4191 | |
| 4192 | def setTestSize( self, setName ): |
| 4193 | """ |
| 4194 | CLI command to get the elements in a distributed set. |
| 4195 | Required arguments: |
| 4196 | setName - The name of the set to remove from. |
| 4197 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4198 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4199 | None on error |
| 4200 | """ |
| 4201 | try: |
| 4202 | # TODO: Should this check against the number of elements returned |
| 4203 | # and then return true/false based on that? |
| 4204 | setName = str( setName ).strip() |
| 4205 | # Patterns to match |
| 4206 | setPattern = "\[(.*)\]" |
| 4207 | pattern = "There are (\d+) items in set " + setName + ":\n" +\ |
| 4208 | setPattern |
| 4209 | cmdStr = "set-test-get -s " |
| 4210 | cmdStr += setName |
| 4211 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4212 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4213 | assert output is not None, "Error in sendline" |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4214 | # TODO: Maybe make this less hardcoded |
| 4215 | # ConsistentMap Exceptions |
| 4216 | assert "org.onosproject.store.service" not in output |
| 4217 | # Node not leader |
| 4218 | assert "java.lang.IllegalStateException" not in output |
| 4219 | except AssertionError: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4220 | main.log.error( "Error in processing '" + cmdStr + "' " + |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4221 | "command: " + str( output ) ) |
| 4222 | retryTime = 30 # Conservative time, given by Madan |
| 4223 | main.log.info( "Waiting " + str( retryTime ) + |
| 4224 | "seconds before retrying." ) |
| 4225 | time.sleep( retryTime ) # Due to change in mastership |
| 4226 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4227 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4228 | assert "Command not found:" not in output, output |
| 4229 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4230 | main.log.info( self.name + ": " + output ) |
| 4231 | match = re.search( pattern, output ) |
| 4232 | if match: |
| 4233 | setSize = int( match.group( 1 ) ) |
| 4234 | setMatch = match.group( 2 ) |
| 4235 | if len( setMatch.split() ) == setSize: |
| 4236 | main.log.info( "The size returned by " + self.name + |
| 4237 | " matches the number of elements in " + |
| 4238 | "the returned set" ) |
| 4239 | else: |
| 4240 | main.log.error( "The size returned by " + self.name + |
| 4241 | " does not match the number of " + |
| 4242 | "elements in the returned set." ) |
| 4243 | return setSize |
| 4244 | else: # no match |
| 4245 | main.log.error( self.name + ": setTestGet did not" + |
| 4246 | " match expected output" ) |
| 4247 | main.log.debug( self.name + " expected: " + pattern ) |
| 4248 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4249 | return None |
| 4250 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4251 | main.log.exception( "Error in processing '" + cmdStr + "' command." ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 4252 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4253 | except TypeError: |
| 4254 | main.log.exception( self.name + ": Object not as expected" ) |
| 4255 | return None |
| 4256 | except pexpect.EOF: |
| 4257 | main.log.error( self.name + ": EOF exception found" ) |
| 4258 | main.log.error( self.name + ": " + self.handle.before ) |
| 4259 | main.cleanup() |
| 4260 | main.exit() |
| 4261 | except Exception: |
| 4262 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4263 | main.cleanup() |
| 4264 | main.exit() |
| 4265 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4266 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4267 | """ |
| 4268 | Command to list the various counters in the system. |
| 4269 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4270 | if jsonFormat, a string of the json object returned by the cli |
| 4271 | command |
| 4272 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4273 | None on error |
| 4274 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4275 | try: |
| 4276 | counters = {} |
| 4277 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4278 | if jsonFormat: |
| 4279 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4280 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4281 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4282 | assert "Command not found:" not in output, output |
| 4283 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4284 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4285 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4286 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4287 | main.log.exception( "Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4288 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4289 | except TypeError: |
| 4290 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4291 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4292 | except pexpect.EOF: |
| 4293 | main.log.error( self.name + ": EOF exception found" ) |
| 4294 | main.log.error( self.name + ": " + self.handle.before ) |
| 4295 | main.cleanup() |
| 4296 | main.exit() |
| 4297 | except Exception: |
| 4298 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4299 | main.cleanup() |
| 4300 | main.exit() |
| 4301 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4302 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4303 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4304 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4305 | Required arguments: |
| 4306 | counter - The name of the counter to increment. |
| 4307 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4308 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4309 | returns: |
| 4310 | integer value of the counter or |
| 4311 | None on Error |
| 4312 | """ |
| 4313 | try: |
| 4314 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4315 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4316 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4317 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4318 | if delta != 1: |
| 4319 | cmdStr += " " + str( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4320 | output = self.sendline( cmdStr ) |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4321 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4322 | assert output is not None, "Error in sendline" |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4323 | # TODO: Maybe make this less hardcoded |
| 4324 | # ConsistentMap Exceptions |
| 4325 | assert "org.onosproject.store.service" not in output |
| 4326 | # Node not leader |
| 4327 | assert "java.lang.IllegalStateException" not in output |
| 4328 | except AssertionError: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4329 | main.log.error( "Error in processing '" + cmdStr + "' " + |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4330 | "command: " + str( output ) ) |
| 4331 | retryTime = 30 # Conservative time, given by Madan |
| 4332 | main.log.info( "Waiting " + str( retryTime ) + |
| 4333 | "seconds before retrying." ) |
| 4334 | time.sleep( retryTime ) # Due to change in mastership |
| 4335 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4336 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4337 | assert "Command not found:" not in output, output |
| 4338 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4339 | main.log.info( self.name + ": " + output ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4340 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4341 | match = re.search( pattern, output ) |
| 4342 | if match: |
| 4343 | return int( match.group( 1 ) ) |
| 4344 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4345 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4346 | " match expected output." ) |
| 4347 | main.log.debug( self.name + " expected: " + pattern ) |
| 4348 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4349 | return None |
| 4350 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4351 | main.log.exception( "Error in processing '" + cmdStr + "' command." ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4352 | return None |
| 4353 | except TypeError: |
| 4354 | main.log.exception( self.name + ": Object not as expected" ) |
| 4355 | return None |
| 4356 | except pexpect.EOF: |
| 4357 | main.log.error( self.name + ": EOF exception found" ) |
| 4358 | main.log.error( self.name + ": " + self.handle.before ) |
| 4359 | main.cleanup() |
| 4360 | main.exit() |
| 4361 | except Exception: |
| 4362 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4363 | main.cleanup() |
| 4364 | main.exit() |
| 4365 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4366 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4367 | """ |
| 4368 | CLI command to get a distributed counter then add a delta to it. |
| 4369 | Required arguments: |
| 4370 | counter - The name of the counter to increment. |
| 4371 | Optional arguments: |
| 4372 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4373 | returns: |
| 4374 | integer value of the counter or |
| 4375 | None on Error |
| 4376 | """ |
| 4377 | try: |
| 4378 | counter = str( counter ) |
| 4379 | delta = int( delta ) |
| 4380 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4381 | cmdStr += counter |
| 4382 | if delta != 1: |
| 4383 | cmdStr += " " + str( delta ) |
| 4384 | output = self.sendline( cmdStr ) |
| 4385 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4386 | assert output is not None, "Error in sendline" |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4387 | # TODO: Maybe make this less hardcoded |
| 4388 | # ConsistentMap Exceptions |
| 4389 | assert "org.onosproject.store.service" not in output |
| 4390 | # Node not leader |
| 4391 | assert "java.lang.IllegalStateException" not in output |
| 4392 | except AssertionError: |
| 4393 | main.log.error( "Error in processing '" + cmdStr + "' " + |
| 4394 | "command: " + str( output ) ) |
| 4395 | retryTime = 30 # Conservative time, given by Madan |
| 4396 | main.log.info( "Waiting " + str( retryTime ) + |
| 4397 | "seconds before retrying." ) |
| 4398 | time.sleep( retryTime ) # Due to change in mastership |
| 4399 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4400 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4401 | assert "Command not found:" not in output, output |
| 4402 | assert "Error executing command" not in output, output |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4403 | main.log.info( self.name + ": " + output ) |
| 4404 | pattern = counter + " was updated to (-?\d+)" |
| 4405 | match = re.search( pattern, output ) |
| 4406 | if match: |
| 4407 | return int( match.group( 1 ) ) |
| 4408 | else: |
| 4409 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4410 | " match expected output." ) |
| 4411 | main.log.debug( self.name + " expected: " + pattern ) |
| 4412 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4413 | return None |
| 4414 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4415 | main.log.exception( "Error in processing '" + cmdStr + "' command." ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4416 | return None |
| 4417 | except TypeError: |
| 4418 | main.log.exception( self.name + ": Object not as expected" ) |
| 4419 | return None |
| 4420 | except pexpect.EOF: |
| 4421 | main.log.error( self.name + ": EOF exception found" ) |
| 4422 | main.log.error( self.name + ": " + self.handle.before ) |
| 4423 | main.cleanup() |
| 4424 | main.exit() |
| 4425 | except Exception: |
| 4426 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4427 | main.cleanup() |
| 4428 | main.exit() |
| 4429 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4430 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4431 | """ |
| 4432 | Description: Execute summary command in onos |
| 4433 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4434 | no output |
| 4435 | |
| 4436 | """ |
| 4437 | try: |
| 4438 | cmdStr = "summary" |
| 4439 | if jsonFormat: |
| 4440 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4441 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4442 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4443 | assert "Command not found:" not in handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4444 | assert "Error:" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4445 | if not handle: |
| 4446 | main.log.error( self.name + ": There is no output in " + |
| 4447 | "summary command" ) |
| 4448 | return main.FALSE |
| 4449 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4450 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4451 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4452 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4453 | except TypeError: |
| 4454 | main.log.exception( self.name + ": Object not as expected" ) |
| 4455 | return None |
| 4456 | except pexpect.EOF: |
| 4457 | main.log.error( self.name + ": EOF exception found" ) |
| 4458 | main.log.error( self.name + ": " + self.handle.before ) |
| 4459 | main.cleanup() |
| 4460 | main.exit() |
| 4461 | except Exception: |
| 4462 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4463 | main.cleanup() |
| 4464 | main.exit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4465 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4466 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4467 | """ |
| 4468 | CLI command to get the value of a key in a consistent map using |
| 4469 | transactions. This a test function and can only get keys from the |
| 4470 | test map hard coded into the cli command |
| 4471 | Required arguments: |
| 4472 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4473 | returns: |
| 4474 | The string value of the key or |
| 4475 | None on Error |
| 4476 | """ |
| 4477 | try: |
| 4478 | keyName = str( keyName ) |
| 4479 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4480 | cmdStr += keyName |
| 4481 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4482 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4483 | assert "Command not found:" not in output, output |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4484 | try: |
| 4485 | # TODO: Maybe make this less hardcoded |
| 4486 | # ConsistentMap Exceptions |
| 4487 | assert "org.onosproject.store.service" not in output |
| 4488 | # Node not leader |
| 4489 | assert "java.lang.IllegalStateException" not in output |
| 4490 | except AssertionError: |
| 4491 | main.log.error( "Error in processing '" + cmdStr + "' " + |
| 4492 | "command: " + str( output ) ) |
| 4493 | return None |
| 4494 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4495 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4496 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4497 | return None |
| 4498 | else: |
| 4499 | match = re.search( pattern, output ) |
| 4500 | if match: |
| 4501 | return match.groupdict()[ 'value' ] |
| 4502 | else: |
| 4503 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4504 | " match expected output." ) |
| 4505 | main.log.debug( self.name + " expected: " + pattern ) |
| 4506 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4507 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4508 | except AssertionError: |
| 4509 | main.log.exception( "" ) |
| 4510 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4511 | except TypeError: |
| 4512 | main.log.exception( self.name + ": Object not as expected" ) |
| 4513 | return None |
| 4514 | except pexpect.EOF: |
| 4515 | main.log.error( self.name + ": EOF exception found" ) |
| 4516 | main.log.error( self.name + ": " + self.handle.before ) |
| 4517 | main.cleanup() |
| 4518 | main.exit() |
| 4519 | except Exception: |
| 4520 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4521 | main.cleanup() |
| 4522 | main.exit() |
| 4523 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4524 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4525 | """ |
| 4526 | CLI command to put a value into 'numKeys' number of keys in a |
| 4527 | consistent map using transactions. This a test function and can only |
| 4528 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4529 | Required arguments: |
| 4530 | numKeys - Number of keys to add the value to |
| 4531 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4532 | returns: |
| 4533 | A dictionary whose keys are the name of the keys put into the map |
| 4534 | and the values of the keys are dictionaries whose key-values are |
| 4535 | 'value': value put into map and optionaly |
| 4536 | 'oldValue': Previous value in the key or |
| 4537 | None on Error |
| 4538 | |
| 4539 | Example output |
| 4540 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4541 | 'Key2': {'value': 'Testing'} } |
| 4542 | """ |
| 4543 | try: |
| 4544 | numKeys = str( numKeys ) |
| 4545 | value = str( value ) |
| 4546 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4547 | cmdStr += numKeys + " " + value |
| 4548 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4549 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4550 | assert "Command not found:" not in output, output |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4551 | try: |
| 4552 | # TODO: Maybe make this less hardcoded |
| 4553 | # ConsistentMap Exceptions |
| 4554 | assert "org.onosproject.store.service" not in output |
| 4555 | # Node not leader |
| 4556 | assert "java.lang.IllegalStateException" not in output |
| 4557 | except AssertionError: |
| 4558 | main.log.error( "Error in processing '" + cmdStr + "' " + |
| 4559 | "command: " + str( output ) ) |
| 4560 | return None |
| 4561 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4562 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4563 | results = {} |
| 4564 | for line in output.splitlines(): |
| 4565 | new = re.search( newPattern, line ) |
| 4566 | updated = re.search( updatedPattern, line ) |
| 4567 | if new: |
| 4568 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 4569 | elif updated: |
| 4570 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4571 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4572 | else: |
| 4573 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4574 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4575 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 4576 | newPattern, |
| 4577 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4578 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4579 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4580 | except AssertionError: |
| 4581 | main.log.exception( "" ) |
| 4582 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4583 | except TypeError: |
| 4584 | main.log.exception( self.name + ": Object not as expected" ) |
| 4585 | return None |
| 4586 | except pexpect.EOF: |
| 4587 | main.log.error( self.name + ": EOF exception found" ) |
| 4588 | main.log.error( self.name + ": " + self.handle.before ) |
| 4589 | main.cleanup() |
| 4590 | main.exit() |
| 4591 | except Exception: |
| 4592 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4593 | main.cleanup() |
| 4594 | main.exit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4595 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4596 | def maps( self, jsonFormat=True ): |
| 4597 | """ |
| 4598 | Description: Returns result of onos:maps |
| 4599 | Optional: |
| 4600 | * jsonFormat: enable json formatting of output |
| 4601 | """ |
| 4602 | try: |
| 4603 | cmdStr = "maps" |
| 4604 | if jsonFormat: |
| 4605 | cmdStr += " -j" |
| 4606 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4607 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4608 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4609 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4610 | except AssertionError: |
| 4611 | main.log.exception( "" ) |
| 4612 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4613 | except TypeError: |
| 4614 | main.log.exception( self.name + ": Object not as expected" ) |
| 4615 | return None |
| 4616 | except pexpect.EOF: |
| 4617 | main.log.error( self.name + ": EOF exception found" ) |
| 4618 | main.log.error( self.name + ": " + self.handle.before ) |
| 4619 | main.cleanup() |
| 4620 | main.exit() |
| 4621 | except Exception: |
| 4622 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4623 | main.cleanup() |
| 4624 | main.exit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4625 | |
| 4626 | def getSwController( self, uri, jsonFormat=True ): |
| 4627 | """ |
| 4628 | Descrition: Gets the controller information from the device |
| 4629 | """ |
| 4630 | try: |
| 4631 | cmd = "device-controllers " |
| 4632 | if jsonFormat: |
| 4633 | cmd += "-j " |
| 4634 | response = self.sendline( cmd + uri ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4635 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4636 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4637 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4638 | except AssertionError: |
| 4639 | main.log.exception( "" ) |
| 4640 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4641 | except TypeError: |
| 4642 | main.log.exception( self.name + ": Object not as expected" ) |
| 4643 | return None |
| 4644 | except pexpect.EOF: |
| 4645 | main.log.error( self.name + ": EOF exception found" ) |
| 4646 | main.log.error( self.name + ": " + self.handle.before ) |
| 4647 | main.cleanup() |
| 4648 | main.exit() |
| 4649 | except Exception: |
| 4650 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4651 | main.cleanup() |
| 4652 | main.exit() |
| 4653 | |
| 4654 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 4655 | """ |
| 4656 | Descrition: sets the controller(s) for the specified device |
| 4657 | |
| 4658 | Parameters: |
| 4659 | Required: uri - String: The uri of the device(switch). |
| 4660 | ip - String or List: The ip address of the controller. |
| 4661 | This parameter can be formed in a couple of different ways. |
| 4662 | VALID: |
| 4663 | 10.0.0.1 - just the ip address |
| 4664 | tcp:10.0.0.1 - the protocol and the ip address |
| 4665 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 4666 | so that you can add controllers with different |
| 4667 | protocols and ports |
| 4668 | INVALID: |
| 4669 | 10.0.0.1:6653 - this is not supported by ONOS |
| 4670 | |
| 4671 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 4672 | port - The port number. |
| 4673 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 4674 | |
| 4675 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 4676 | """ |
| 4677 | try: |
| 4678 | cmd = "device-setcontrollers" |
| 4679 | |
| 4680 | if jsonFormat: |
| 4681 | cmd += " -j" |
| 4682 | cmd += " " + uri |
| 4683 | if isinstance( ip, str ): |
| 4684 | ip = [ip] |
| 4685 | for item in ip: |
| 4686 | if ":" in item: |
| 4687 | sitem = item.split( ":" ) |
| 4688 | if len(sitem) == 3: |
| 4689 | cmd += " " + item |
| 4690 | elif "." in sitem[1]: |
| 4691 | cmd += " {}:{}".format(item, port) |
| 4692 | else: |
| 4693 | main.log.error( "Malformed entry: " + item ) |
| 4694 | raise TypeError |
| 4695 | else: |
| 4696 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4697 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4698 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4699 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4700 | if "Error" in response: |
| 4701 | main.log.error( response ) |
| 4702 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4703 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4704 | except AssertionError: |
| 4705 | main.log.exception( "" ) |
| 4706 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4707 | except TypeError: |
| 4708 | main.log.exception( self.name + ": Object not as expected" ) |
| 4709 | return main.FALSE |
| 4710 | except pexpect.EOF: |
| 4711 | main.log.error( self.name + ": EOF exception found" ) |
| 4712 | main.log.error( self.name + ": " + self.handle.before ) |
| 4713 | main.cleanup() |
| 4714 | main.exit() |
| 4715 | except Exception: |
| 4716 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4717 | main.cleanup() |
| 4718 | main.exit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4719 | |
| 4720 | def removeDevice( self, device ): |
| 4721 | ''' |
| 4722 | Description: |
| 4723 | Remove a device from ONOS by passing the uri of the device(s). |
| 4724 | Parameters: |
| 4725 | device - (str or list) the id or uri of the device ex. "of:0000000000000001" |
| 4726 | Returns: |
| 4727 | Returns main.FALSE if an exception is thrown or an error is present |
| 4728 | in the response. Otherwise, returns main.TRUE. |
| 4729 | NOTE: |
| 4730 | If a host cannot be removed, then this function will return main.FALSE |
| 4731 | ''' |
| 4732 | try: |
| 4733 | if type( device ) is str: |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 4734 | deviceStr = device |
| 4735 | device = [] |
| 4736 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4737 | |
| 4738 | for d in device: |
| 4739 | time.sleep( 1 ) |
| 4740 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4741 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4742 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4743 | if "Error" in response: |
| 4744 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 4745 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4746 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4747 | except AssertionError: |
| 4748 | main.log.exception( "" ) |
| 4749 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4750 | except TypeError: |
| 4751 | main.log.exception( self.name + ": Object not as expected" ) |
| 4752 | return main.FALSE |
| 4753 | except pexpect.EOF: |
| 4754 | main.log.error( self.name + ": EOF exception found" ) |
| 4755 | main.log.error( self.name + ": " + self.handle.before ) |
| 4756 | main.cleanup() |
| 4757 | main.exit() |
| 4758 | except Exception: |
| 4759 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4760 | main.cleanup() |
| 4761 | main.exit() |
| 4762 | |
| 4763 | def removeHost( self, host ): |
| 4764 | ''' |
| 4765 | Description: |
| 4766 | Remove a host from ONOS by passing the id of the host(s) |
| 4767 | Parameters: |
| 4768 | hostId - (str or list) the id or mac of the host ex. "00:00:00:00:00:01" |
| 4769 | Returns: |
| 4770 | Returns main.FALSE if an exception is thrown or an error is present |
| 4771 | in the response. Otherwise, returns main.TRUE. |
| 4772 | NOTE: |
| 4773 | If a host cannot be removed, then this function will return main.FALSE |
| 4774 | ''' |
| 4775 | try: |
| 4776 | if type( host ) is str: |
| 4777 | host = list( host ) |
| 4778 | |
| 4779 | for h in host: |
| 4780 | time.sleep( 1 ) |
| 4781 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4782 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4783 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4784 | if "Error" in response: |
| 4785 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 4786 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4787 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4788 | except AssertionError: |
| 4789 | main.log.exception( "" ) |
| 4790 | return None |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4791 | except TypeError: |
| 4792 | main.log.exception( self.name + ": Object not as expected" ) |
| 4793 | return main.FALSE |
| 4794 | except pexpect.EOF: |
| 4795 | main.log.error( self.name + ": EOF exception found" ) |
| 4796 | main.log.error( self.name + ": " + self.handle.before ) |
| 4797 | main.cleanup() |
| 4798 | main.exit() |
| 4799 | except Exception: |
| 4800 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4801 | main.cleanup() |
| 4802 | main.exit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4803 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4804 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4805 | ''' |
| 4806 | Description: |
| 4807 | Bring link down or up in the null-provider. |
| 4808 | params: |
| 4809 | begin - (string) One end of a device or switch. |
| 4810 | end - (string) the other end of the device or switch |
| 4811 | returns: |
| 4812 | main.TRUE if no exceptions were thrown and no Errors are |
| 4813 | present in the resoponse. Otherwise, returns main.FALSE |
| 4814 | ''' |
| 4815 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4816 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4817 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4818 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4819 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4820 | if "Error" in response or "Failure" in response: |
| 4821 | main.log.error( response ) |
| 4822 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4823 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4824 | except AssertionError: |
| 4825 | main.log.exception( "" ) |
| 4826 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4827 | except TypeError: |
| 4828 | main.log.exception( self.name + ": Object not as expected" ) |
| 4829 | return main.FALSE |
| 4830 | except pexpect.EOF: |
| 4831 | main.log.error( self.name + ": EOF exception found" ) |
| 4832 | main.log.error( self.name + ": " + self.handle.before ) |
| 4833 | main.cleanup() |
| 4834 | main.exit() |
| 4835 | except Exception: |
| 4836 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4837 | main.cleanup() |
| 4838 | main.exit() |
| 4839 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4840 | def portstate(self, dpid='of:0000000000000102', port='2', state='enable'): |
| 4841 | ''' |
| 4842 | Description: |
| 4843 | Changes the state of port in an OF switch by means of the |
| 4844 | PORTSTATUS OF messages. |
| 4845 | params: |
| 4846 | dpid - (string) Datapath ID of the device |
| 4847 | port - (string) target port in the device |
| 4848 | state - (string) target state (enable or disabled) |
| 4849 | returns: |
| 4850 | main.TRUE if no exceptions were thrown and no Errors are |
| 4851 | present in the resoponse. Otherwise, returns main.FALSE |
| 4852 | ''' |
| 4853 | try: |
| 4854 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
| 4855 | response = self.sendline( cmd, showResponse=True ) |
| 4856 | assert response is not None, "Error in sendline" |
| 4857 | assert "Command not found:" not in response, response |
| 4858 | if "Error" in response or "Failure" in response: |
| 4859 | main.log.error( response ) |
| 4860 | return main.FALSE |
| 4861 | return main.TRUE |
| 4862 | except AssertionError: |
| 4863 | main.log.exception( "" ) |
| 4864 | return None |
| 4865 | except TypeError: |
| 4866 | main.log.exception( self.name + ": Object not as expected" ) |
| 4867 | return main.FALSE |
| 4868 | except pexpect.EOF: |
| 4869 | main.log.error( self.name + ": EOF exception found" ) |
| 4870 | main.log.error( self.name + ": " + self.handle.before ) |
| 4871 | main.cleanup() |
| 4872 | main.exit() |
| 4873 | except Exception: |
| 4874 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4875 | main.cleanup() |
| 4876 | main.exit() |
| 4877 | |
| 4878 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 4879 | """ |
| 4880 | Set the logging level to lvl for a specific app |
| 4881 | returns main.TRUE on success |
| 4882 | returns main.FALSE if Error occurred |
| 4883 | if noExit is True, TestON will not exit, but clean up |
| 4884 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 4885 | Level defaults to INFO |
| 4886 | """ |
| 4887 | try: |
| 4888 | self.handle.sendline( "log:set %s %s" %( level, app ) ) |
| 4889 | self.handle.expect( "onos>" ) |
| 4890 | |
| 4891 | response = self.handle.before |
| 4892 | if re.search( "Error", response ): |
| 4893 | return main.FALSE |
| 4894 | return main.TRUE |
| 4895 | except pexpect.TIMEOUT: |
| 4896 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
| 4897 | main.cleanup() |
| 4898 | main.exit() |
| 4899 | except pexpect.EOF: |
| 4900 | main.log.error( self.name + ": EOF exception found" ) |
| 4901 | main.log.error( self.name + ": " + self.handle.before ) |
| 4902 | main.cleanup() |
| 4903 | main.exit() |
| 4904 | except Exception: |
| 4905 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4906 | main.cleanup() |
| 4907 | main.exit() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 4908 | |
| 4909 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 4910 | """ |
| 4911 | Return a dictionary which describes the latest network topology data as a |
| 4912 | graph. |
| 4913 | An example of the dictionary: |
| 4914 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 4915 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 4916 | Each vertex should at least have an 'edges' attribute which describes the |
| 4917 | adjacency information. The value of 'edges' attribute is also represented by |
| 4918 | a dictionary, which maps each edge (identified by the neighbor vertex) to a |
| 4919 | list of attributes. |
| 4920 | An example of the edges dictionary: |
| 4921 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 4922 | vertex3: { 'port': ..., 'weight': ... } } |
| 4923 | If includeHost == True, all hosts (and host-switch links) will be included |
| 4924 | in topology data. |
| 4925 | """ |
| 4926 | graphDict = {} |
| 4927 | try: |
| 4928 | links = self.links() |
| 4929 | links = json.loads( links ) |
| 4930 | devices = self.devices() |
| 4931 | devices = json.loads( devices ) |
| 4932 | idToDevice = {} |
| 4933 | for device in devices: |
| 4934 | idToDevice[ device[ 'id' ] ] = device |
| 4935 | if includeHost: |
| 4936 | hosts = self.hosts() |
| 4937 | # FIXME: support 'includeHost' argument |
| 4938 | for link in links: |
| 4939 | nodeA = link[ 'src' ][ 'device' ] |
| 4940 | nodeB = link[ 'dst' ][ 'device' ] |
| 4941 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
| 4942 | if not nodeA in graphDict.keys(): |
| 4943 | graphDict[ nodeA ] = { 'edges':{}, |
| 4944 | 'dpid':idToDevice[ nodeA ][ 'id' ][3:], |
| 4945 | 'type':idToDevice[ nodeA ][ 'type' ], |
| 4946 | 'available':idToDevice[ nodeA ][ 'available' ], |
| 4947 | 'role':idToDevice[ nodeA ][ 'role' ], |
| 4948 | 'mfr':idToDevice[ nodeA ][ 'mfr' ], |
| 4949 | 'hw':idToDevice[ nodeA ][ 'hw' ], |
| 4950 | 'sw':idToDevice[ nodeA ][ 'sw' ], |
| 4951 | 'serial':idToDevice[ nodeA ][ 'serial' ], |
| 4952 | 'chassisId':idToDevice[ nodeA ][ 'chassisId' ], |
| 4953 | 'annotations':idToDevice[ nodeA ][ 'annotations' ]} |
| 4954 | else: |
| 4955 | # Assert nodeB is not connected to any current links of nodeA |
| 4956 | assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
| 4957 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port':link[ 'src' ][ 'port' ], |
| 4958 | 'type':link[ 'type' ], |
| 4959 | 'state':link[ 'state' ] } |
| 4960 | return graphDict |
| 4961 | except ( TypeError, ValueError ): |
| 4962 | main.log.exception( self.name + ": Object not as expected" ) |
| 4963 | return None |
| 4964 | except KeyError: |
| 4965 | main.log.exception( self.name + ": KeyError exception found" ) |
| 4966 | return None |
| 4967 | except AssertionError: |
| 4968 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 4969 | return None |
| 4970 | except pexpect.EOF: |
| 4971 | main.log.error( self.name + ": EOF exception found" ) |
| 4972 | main.log.error( self.name + ": " + self.handle.before ) |
| 4973 | return None |
| 4974 | except Exception: |
| 4975 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4976 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 4977 | |
| 4978 | def getIntentPerfSummary( self ): |
| 4979 | ''' |
| 4980 | Send command to check intent-perf summary |
| 4981 | Returns: dictionary for intent-perf summary |
| 4982 | if something wrong, function will return None |
| 4983 | ''' |
| 4984 | cmd = "intent-perf -s" |
| 4985 | respDic = {} |
| 4986 | resp = self.sendline( cmd ) |
| 4987 | try: |
| 4988 | # Generate the dictionary to return |
| 4989 | for l in resp.split( "\n" ): |
| 4990 | # Delete any white space in line |
| 4991 | temp = re.sub( r'\s+', '', l ) |
| 4992 | temp = temp.split( ":" ) |
| 4993 | respDic[ temp[0] ] = temp[ 1 ] |
| 4994 | |
| 4995 | except (TypeError, ValueError): |
| 4996 | main.log.exception( self.name + ": Object not as expected" ) |
| 4997 | return None |
| 4998 | except KeyError: |
| 4999 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5000 | return None |
| 5001 | except AssertionError: |
| 5002 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5003 | return None |
| 5004 | except pexpect.EOF: |
| 5005 | main.log.error( self.name + ": EOF exception found" ) |
| 5006 | main.log.error( self.name + ": " + self.handle.before ) |
| 5007 | return None |
| 5008 | except Exception: |
| 5009 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5010 | return None |
| 5011 | return respDic |
| 5012 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5013 | def logSearch( self, searchTerm, mode='all' ): |
| 5014 | """ |
| 5015 | Searches the latest ONOS log file for the given search term and |
| 5016 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5017 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5018 | Arguments: |
| 5019 | searchTerm - A string to grep for in the ONOS log. |
| 5020 | mode: |
| 5021 | all: return all the strings that contain the search term |
| 5022 | last: return the last string that contains the search term |
| 5023 | first: return the first string that contains the search term |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5024 | num: return the number that the searchTerm appears in the log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5025 | """ |
| 5026 | try: |
| 5027 | assert type( searchTerm ) is str |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5028 | cmd = "cat /opt/onos/log/karaf.log | grep \'" + searchTerm + "\'" |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5029 | if mode == 'last': |
| 5030 | cmd = cmd + " | tail -n 1" |
| 5031 | if mode == 'first': |
| 5032 | cmd = cmd + " | head -n 1" |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5033 | if mode == 'num': |
| 5034 | cmd = "cat /opt/onos/log/karaf.log | grep -c \'" + searchTerm + "\'" |
| 5035 | num = self.sendline( cmd ) |
| 5036 | return num |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5037 | before = self.sendline( cmd ) |
| 5038 | before = before.splitlines() |
| 5039 | # make sure the returned list only contains the search term |
| 5040 | returnLines = [line for line in before if searchTerm in line] |
| 5041 | return returnLines |
| 5042 | except AssertionError: |
| 5043 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5044 | return None |
| 5045 | except pexpect.EOF: |
| 5046 | main.log.error( self.name + ": EOF exception found" ) |
| 5047 | main.log.error( self.name + ": " + self.handle.before ) |
| 5048 | main.cleanup() |
| 5049 | main.exit() |
| 5050 | except pexpect.TIMEOUT: |
| 5051 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5052 | main.log.error( self.name + ": " + self.handle.before ) |
| 5053 | main.cleanup() |
| 5054 | main.exit() |
| 5055 | except Exception: |
| 5056 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5057 | main.cleanup() |
| 5058 | main.exit() |