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 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 4 | OCT 13 2014 |
| 5 | Copyright 2014 Open Networking Foundation (ONF) |
| 6 | |
| 7 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 8 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 9 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 10 | |
| 11 | TestON is free software: you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation, either version 2 of the License, or |
| 14 | (at your option) any later version. |
| 15 | |
| 16 | TestON is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 23 | """ |
| 24 | |
| 25 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 26 | This driver enters the onos> prompt to issue commands. |
| 27 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 28 | Please follow the coding style demonstrated by existing |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 29 | functions and document properly. |
| 30 | |
| 31 | If you are a contributor to the driver, please |
| 32 | list your email here for future contact: |
| 33 | |
| 34 | jhall@onlab.us |
| 35 | andrew@onlab.us |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 36 | shreya@onlab.us |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 37 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 38 | import pexpect |
| 39 | import re |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 40 | import json |
| 41 | import types |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 42 | import time |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 43 | import os |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 44 | from drivers.common.clidriver import CLI |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 45 | from core.graph import Graph |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 46 | from cStringIO import StringIO |
| 47 | from itertools import izip |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 48 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 49 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 50 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 51 | def __init__( self ): |
| 52 | """ |
| 53 | Initialize client |
| 54 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 55 | self.name = None |
| 56 | self.home = None |
| 57 | self.handle = None |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 58 | self.karafUser = None |
| 59 | self.karafPass = None |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 60 | self.graph = Graph() |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 61 | super( OnosCliDriver, self ).__init__() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 62 | |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 63 | def checkOptions(self, var, defaultVar): |
| 64 | if var is None or var == "": |
| 65 | return defaultVar |
| 66 | return var |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 67 | def connect( self, **connectargs ): |
| 68 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 69 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 70 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 71 | try: |
| 72 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 73 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 658ec01 | 2015-03-11 15:13:09 -0700 | [diff] [blame] | 74 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 75 | for key in self.options: |
| 76 | if key == "home": |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 77 | self.home = self.options[ key ] |
| 78 | elif key == "karaf_username": |
| 79 | self.karafUser = self.options[ key ] |
| 80 | elif key == "karaf_password": |
| 81 | self.karafPass = self.options[ key ] |
| 82 | |
| 83 | self.home = self.checkOptions(self.home, "~/onos") |
| 84 | self.karafUser = self.checkOptions(self.karafUser, self.user_name) |
| 85 | self.karafPass = self.checkOptions(self.karafPass, self.pwd ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 86 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 87 | for key in self.options: |
| 88 | if key == 'onosIp': |
| 89 | self.onosIp = self.options[ 'onosIp' ] |
| 90 | break |
| 91 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 92 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 93 | |
| 94 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 95 | if os.getenv( str( self.ip_address ) ) is not None: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 96 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 97 | else: |
| 98 | main.log.info( self.name + |
| 99 | ": Trying to connect to " + |
| 100 | self.ip_address ) |
| 101 | |
| 102 | except KeyError: |
| 103 | main.log.info( "Invalid host name," + |
| 104 | " connecting to local host instead" ) |
| 105 | self.ip_address = 'localhost' |
| 106 | except Exception as inst: |
| 107 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 108 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 109 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 110 | user_name=self.user_name, |
| 111 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 112 | port=self.port, |
| 113 | pwd=self.pwd, |
| 114 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 115 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 116 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 117 | self.handle.expect( self.prompt ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 118 | if self.handle: |
| 119 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 120 | else: |
| 121 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 122 | return main.FALSE |
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" ) |
| 125 | return None |
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 ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 129 | main.cleanup() |
| 130 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 131 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 132 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 133 | main.cleanup() |
| 134 | main.exit() |
| 135 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 136 | def disconnect( self ): |
| 137 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 138 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 139 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 140 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 141 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 142 | if self.handle: |
| 143 | i = self.logout() |
| 144 | if i == main.TRUE: |
| 145 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 146 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 147 | self.handle.sendline( "exit" ) |
| 148 | self.handle.expect( "closed" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 149 | except TypeError: |
| 150 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 151 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 152 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 153 | main.log.error( self.name + ": EOF exception found" ) |
| 154 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 155 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 156 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 157 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 158 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 159 | main.log.exception( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 160 | response = main.FALSE |
| 161 | return response |
| 162 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 163 | def logout( self ): |
| 164 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 165 | Sends 'logout' command to ONOS cli |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 166 | Returns main.TRUE if exited CLI and |
| 167 | main.FALSE on timeout (not guranteed you are disconnected) |
| 168 | None on TypeError |
| 169 | Exits test on unknown error or pexpect exits unexpectedly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 170 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 171 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 172 | if self.handle: |
| 173 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 174 | i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ], |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 175 | timeout=10 ) |
| 176 | if i == 0: # In ONOS CLI |
| 177 | self.handle.sendline( "logout" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 178 | j = self.handle.expect( [ self.prompt, |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 179 | "Command not found:", |
| 180 | pexpect.TIMEOUT ] ) |
| 181 | if j == 0: # Successfully logged out |
| 182 | return main.TRUE |
| 183 | elif j == 1 or j == 2: |
| 184 | # ONOS didn't fully load, and logout command isn't working |
| 185 | # or the command timed out |
| 186 | self.handle.send( "\x04" ) # send ctrl-d |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 187 | try: |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 188 | self.handle.expect( self.prompt ) |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 189 | except pexpect.TIMEOUT: |
| 190 | main.log.error( "ONOS did not respond to 'logout' or CTRL-d" ) |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 191 | return main.TRUE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 192 | else: # some other output |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 193 | main.log.warn( "Unknown repsonse to logout command: '{}'", |
| 194 | repr( self.handle.before ) ) |
| 195 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 196 | elif i == 1: # not in CLI |
| 197 | return main.TRUE |
| 198 | elif i == 3: # Timeout |
| 199 | return main.FALSE |
| 200 | else: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 201 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 202 | except TypeError: |
| 203 | main.log.exception( self.name + ": Object not as expected" ) |
| 204 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 205 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 206 | main.log.error( self.name + ": eof exception found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 207 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 208 | main.cleanup() |
| 209 | main.exit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 210 | except ValueError: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 211 | main.log.error( self.name + |
| 212 | "ValueError exception in logout method" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 213 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 214 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 215 | main.cleanup() |
| 216 | main.exit() |
| 217 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 218 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 219 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 220 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 221 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 222 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 223 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 224 | try: |
| 225 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 226 | main.log.error( "Must define cellname" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 227 | main.cleanup() |
| 228 | main.exit() |
| 229 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 230 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 231 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 232 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 233 | # and that this driver will have to change accordingly |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 234 | self.handle.expect(str(cellname)) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 235 | handleBefore = self.handle.before |
| 236 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 237 | # Get the rest of the handle |
Cameron Franke | 9c94fb0 | 2015-01-21 10:20:20 -0800 | [diff] [blame] | 238 | self.handle.sendline("") |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 239 | self.handle.expect(self.prompt) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 240 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 241 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 242 | main.log.info( "Cell call returned: " + handleBefore + |
| 243 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 244 | |
| 245 | return main.TRUE |
| 246 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 247 | except TypeError: |
| 248 | main.log.exception( self.name + ": Object not as expected" ) |
| 249 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 250 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 251 | main.log.error( self.name + ": eof exception found" ) |
| 252 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 253 | main.cleanup() |
| 254 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 255 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 256 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 257 | main.cleanup() |
| 258 | main.exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 259 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 260 | def startOnosCli( self, ONOSIp, karafTimeout="", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 261 | commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 262 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 263 | karafTimeout is an optional argument. karafTimeout value passed |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 264 | by user would be used to set the current karaf shell idle timeout. |
| 265 | 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] | 266 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 267 | Below is an example to start a session with 60 seconds idle timeout |
| 268 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 269 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 270 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 271 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 272 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 273 | Note: karafTimeout is left as str so that this could be read |
| 274 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 275 | """ |
You Wang | f69ab39 | 2016-01-26 16:34:38 -0800 | [diff] [blame] | 276 | self.onosIp = ONOSIp |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 277 | try: |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 278 | # Check if we are already in the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 279 | self.handle.sendline( "" ) |
| 280 | x = self.handle.expect( [ |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 281 | self.prompt, "onos>" ], commandlineTimeout) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 282 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 283 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 284 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 285 | |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 286 | # Not in CLI so login |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 287 | if waitForStart: |
| 288 | # Wait for onos start ( -w ) and enter onos cli |
| 289 | startCliCommand = "onos -w " |
| 290 | else: |
| 291 | startCliCommand = "onos " |
| 292 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 293 | i = self.handle.expect( [ |
| 294 | "onos>", |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 295 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 296 | |
| 297 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 298 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 299 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 300 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 301 | "config:property-set -p org.apache.karaf.shell\ |
| 302 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 303 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 304 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 305 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 306 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 307 | return main.TRUE |
| 308 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 309 | # If failed, send ctrl+c to process and try again |
| 310 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 311 | self.handle.send( "\x03" ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 312 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 313 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 314 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 315 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 316 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 317 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 318 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 319 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 320 | "config:property-set -p org.apache.karaf.shell\ |
| 321 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 322 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 323 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 324 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 325 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 326 | return main.TRUE |
| 327 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 328 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 329 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 330 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 331 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 332 | except TypeError: |
| 333 | main.log.exception( self.name + ": Object not as expected" ) |
| 334 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 335 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 336 | main.log.error( self.name + ": EOF exception found" ) |
| 337 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 338 | main.cleanup() |
| 339 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 340 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 341 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 342 | main.cleanup() |
| 343 | main.exit() |
| 344 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 345 | def startCellCli( self, karafTimeout="", |
| 346 | commandlineTimeout=10, onosStartTimeout=60 ): |
| 347 | """ |
| 348 | Start CLI on onos ecll handle. |
| 349 | |
| 350 | karafTimeout is an optional argument. karafTimeout value passed |
| 351 | by user would be used to set the current karaf shell idle timeout. |
| 352 | Note that when ever this property is modified the shell will exit and |
| 353 | the subsequent login would reflect new idle timeout. |
| 354 | Below is an example to start a session with 60 seconds idle timeout |
| 355 | ( input value is in milliseconds ): |
| 356 | |
| 357 | tValue = "60000" |
| 358 | |
| 359 | Note: karafTimeout is left as str so that this could be read |
| 360 | and passed to startOnosCli from PARAMS file as str. |
| 361 | """ |
| 362 | |
| 363 | try: |
| 364 | self.handle.sendline( "" ) |
| 365 | x = self.handle.expect( [ |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 366 | self.prompt, "onos>" ], commandlineTimeout) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 367 | |
| 368 | if x == 1: |
| 369 | main.log.info( "ONOS cli is already running" ) |
| 370 | return main.TRUE |
| 371 | |
| 372 | # Wait for onos start ( -w ) and enter onos cli |
| 373 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 374 | i = self.handle.expect( [ |
| 375 | "onos>", |
| 376 | pexpect.TIMEOUT ], onosStartTimeout ) |
| 377 | |
| 378 | if i == 0: |
| 379 | main.log.info( self.name + " CLI Started successfully" ) |
| 380 | if karafTimeout: |
| 381 | self.handle.sendline( |
| 382 | "config:property-set -p org.apache.karaf.shell\ |
| 383 | sshIdleTimeout " + |
| 384 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 385 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 386 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 387 | self.handle.expect( "onos>" ) |
| 388 | return main.TRUE |
| 389 | else: |
| 390 | # If failed, send ctrl+c to process and try again |
| 391 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 392 | self.handle.send( "\x03" ) |
| 393 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 394 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 395 | timeout=30 ) |
| 396 | if i == 0: |
| 397 | main.log.info( self.name + " CLI Started " + |
| 398 | "successfully after retry attempt" ) |
| 399 | if karafTimeout: |
| 400 | self.handle.sendline( |
| 401 | "config:property-set -p org.apache.karaf.shell\ |
| 402 | sshIdleTimeout " + |
| 403 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 404 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 405 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 406 | self.handle.expect( "onos>" ) |
| 407 | return main.TRUE |
| 408 | else: |
| 409 | main.log.error( "Connection to CLI " + |
| 410 | self.name + " timeout" ) |
| 411 | return main.FALSE |
| 412 | |
| 413 | except TypeError: |
| 414 | main.log.exception( self.name + ": Object not as expected" ) |
| 415 | return None |
| 416 | except pexpect.EOF: |
| 417 | main.log.error( self.name + ": EOF exception found" ) |
| 418 | main.log.error( self.name + ": " + self.handle.before ) |
| 419 | main.cleanup() |
| 420 | main.exit() |
| 421 | except Exception: |
| 422 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 423 | main.cleanup() |
| 424 | main.exit() |
| 425 | |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 426 | def log( self, cmdStr, level="", noExit=False ): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 427 | """ |
| 428 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 429 | returns main.TRUE on success |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 430 | returns main.FALSE if Error occurred |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 431 | if noExit is True, TestON will not exit, but clean up |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 432 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 433 | Level defaults to INFO |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 434 | if cmdStr has spaces then put quotes in the passed string |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 435 | """ |
| 436 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 437 | lvlStr = "" |
| 438 | if level: |
| 439 | lvlStr = "--level=" + level |
| 440 | |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 441 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 442 | self.handle.expect( "log:log" ) |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 443 | self.handle.expect( "onos>" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 444 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 445 | response = self.handle.before |
| 446 | if re.search( "Error", response ): |
| 447 | return main.FALSE |
| 448 | return main.TRUE |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 449 | except pexpect.TIMEOUT: |
| 450 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 451 | if noExit: |
| 452 | main.cleanup() |
| 453 | return None |
| 454 | else: |
| 455 | main.cleanup() |
| 456 | main.exit() |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 457 | except pexpect.EOF: |
| 458 | main.log.error( self.name + ": EOF exception found" ) |
| 459 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 460 | if noExit: |
| 461 | main.cleanup() |
| 462 | return None |
| 463 | else: |
| 464 | main.cleanup() |
| 465 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 466 | except Exception: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 467 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 468 | if noExit: |
| 469 | main.cleanup() |
| 470 | return None |
| 471 | else: |
| 472 | main.cleanup() |
| 473 | main.exit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 474 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 475 | def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, dollarSign=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 476 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 477 | Send a completely user specified string to |
| 478 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 479 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 480 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 481 | if noExit is True, TestON will not exit, and return None |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 482 | if dollarSign is True, TestON will not expect for '$' as a new CLI or onos> prompt |
| 483 | since '$' can be in the output. |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 484 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 485 | Warning: There are no sanity checking to commands |
| 486 | sent using this method. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 487 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 488 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 489 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 490 | # Try to reconnect if disconnected from cli |
| 491 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 492 | i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ] ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 493 | if i == 1: |
| 494 | main.log.error( self.name + ": onos cli session closed. ") |
| 495 | if self.onosIp: |
| 496 | main.log.warn( "Trying to reconnect " + self.onosIp ) |
| 497 | reconnectResult = self.startOnosCli( self.onosIp ) |
| 498 | if reconnectResult: |
| 499 | main.log.info( self.name + ": onos cli session reconnected." ) |
| 500 | else: |
| 501 | main.log.error( self.name + ": reconnection failed." ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 502 | if noExit: |
| 503 | return None |
| 504 | else: |
| 505 | main.cleanup() |
| 506 | main.exit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 507 | else: |
| 508 | main.cleanup() |
| 509 | main.exit() |
| 510 | if i == 2: |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 511 | main.log.warn( "Timeout when testing cli responsiveness" ) |
| 512 | main.log.debug( self.handle.before ) |
| 513 | self.handle.send( "\x03" ) # Send ctrl-c to clear previous output |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 514 | self.handle.expect( "onos>" ) |
| 515 | |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 516 | if debug: |
| 517 | # NOTE: This adds and average of .4 seconds per call |
| 518 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 519 | self.log( logStr, noExit=noExit ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 520 | self.handle.sendline( cmdStr ) |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 521 | if dollarSign: |
| 522 | i = self.handle.expect( ["onos>"], timeout ) |
| 523 | else: |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 524 | i = self.handle.expect( ["onos>", self.prompt], timeout ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 525 | response = self.handle.before |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 526 | # TODO: do something with i |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 527 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
| 528 | + self.name + "." ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 529 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 530 | main.log.debug( self.name + ": Raw output" ) |
| 531 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 532 | |
| 533 | # Remove ANSI color control strings from output |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 534 | ansiEscape = re.compile( r'\x1b[^m]*m' ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 535 | response = ansiEscape.sub( '', response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 536 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 537 | main.log.debug( self.name + ": ansiEscape output" ) |
| 538 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 539 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 540 | # Remove extra return chars that get added |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 541 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 542 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 543 | main.log.debug( self.name + ": Removed extra returns " + |
| 544 | "from output" ) |
| 545 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 546 | |
| 547 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 548 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 549 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 550 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 551 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 552 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 553 | # parse for just the output, remove the cmd from response |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 554 | output = response.split( cmdStr.strip(), 1 ) |
| 555 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 556 | main.log.debug( self.name + ": split output" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 557 | for r in output: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 558 | main.log.debug( self.name + ": " + repr( r ) ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 559 | output = output[1].strip() |
| 560 | if showResponse: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 561 | main.log.info( "Response from ONOS: {}".format( output ) ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 562 | return output |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 563 | except pexpect.TIMEOUT: |
| 564 | main.log.error( self.name + ":ONOS timeout" ) |
| 565 | if debug: |
| 566 | main.log.debug( self.handle.before ) |
| 567 | return None |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 568 | except IndexError: |
| 569 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 570 | main.log.debug( "response: {}".format( repr( response ) ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 571 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 572 | except TypeError: |
| 573 | main.log.exception( self.name + ": Object not as expected" ) |
| 574 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 575 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 576 | main.log.error( self.name + ": EOF exception found" ) |
| 577 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 578 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 579 | return None |
| 580 | else: |
| 581 | main.cleanup() |
| 582 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 583 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 584 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 585 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 586 | return None |
| 587 | else: |
| 588 | main.cleanup() |
| 589 | main.exit() |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 590 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 591 | # IMPORTANT NOTE: |
| 592 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 593 | # the cli command changing 'a:b' with 'aB'. |
| 594 | # Ex ) onos:topology > onosTopology |
| 595 | # onos:links > onosLinks |
| 596 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 597 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 598 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 599 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 600 | Adds a new cluster node by ID and address information. |
| 601 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 602 | * nodeId |
| 603 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 604 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 605 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 606 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 607 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 608 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 609 | str( ONOSIp ) + " " + str( tcpPort ) |
| 610 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 611 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 612 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 613 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 614 | main.log.error( "Error in adding node" ) |
| 615 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 616 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 617 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 618 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 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 | c2d05aa | 2014-10-13 16:51:10 -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 | c2d05aa | 2014-10-13 16:51:10 -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 | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 633 | main.cleanup() |
| 634 | main.exit() |
| 635 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 636 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 637 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 638 | Removes a cluster by ID |
| 639 | Issues command: 'remove-node [<node-id>]' |
| 640 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 641 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 642 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 643 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 644 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 645 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 646 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 647 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 648 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 649 | if re.search( "Error", handle ): |
| 650 | main.log.error( "Error in removing node" ) |
| 651 | main.log.error( handle ) |
| 652 | return main.FALSE |
| 653 | else: |
| 654 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 655 | except AssertionError: |
| 656 | main.log.exception( "" ) |
| 657 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 658 | except TypeError: |
| 659 | main.log.exception( self.name + ": Object not as expected" ) |
| 660 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 661 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 662 | main.log.error( self.name + ": EOF exception found" ) |
| 663 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 664 | main.cleanup() |
| 665 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 666 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 667 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 668 | main.cleanup() |
| 669 | main.exit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 670 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 671 | def nodes( self, jsonFormat=True): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 672 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 673 | List the nodes currently visible |
| 674 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 675 | Optional argument: |
| 676 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 677 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 678 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 679 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 680 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 681 | cmdStr += " -j" |
| 682 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 683 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 684 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 685 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 686 | except AssertionError: |
| 687 | main.log.exception( "" ) |
| 688 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 689 | except TypeError: |
| 690 | main.log.exception( self.name + ": Object not as expected" ) |
| 691 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 692 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 693 | main.log.error( self.name + ": EOF exception found" ) |
| 694 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 695 | main.cleanup() |
| 696 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 697 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 698 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 699 | main.cleanup() |
| 700 | main.exit() |
| 701 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 702 | def topology( self ): |
| 703 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 704 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 705 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 706 | Return: |
| 707 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 708 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 709 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 710 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 711 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 712 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 713 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 714 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 715 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 716 | except AssertionError: |
| 717 | main.log.exception( "" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 718 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 719 | except TypeError: |
| 720 | main.log.exception( self.name + ": Object not as expected" ) |
| 721 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 722 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 723 | main.log.error( self.name + ": EOF exception found" ) |
| 724 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 725 | main.cleanup() |
| 726 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 727 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 728 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 729 | main.cleanup() |
| 730 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 731 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 732 | def deviceRemove( self, deviceId ): |
| 733 | """ |
| 734 | Removes particular device from storage |
| 735 | |
| 736 | TODO: refactor this function |
| 737 | """ |
| 738 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 739 | cmdStr = "device-remove " + str( deviceId ) |
| 740 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 741 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 742 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 743 | if re.search( "Error", handle ): |
| 744 | main.log.error( "Error in removing device" ) |
| 745 | main.log.error( handle ) |
| 746 | return main.FALSE |
| 747 | else: |
| 748 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 749 | except AssertionError: |
| 750 | main.log.exception( "" ) |
| 751 | return None |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 752 | except TypeError: |
| 753 | main.log.exception( self.name + ": Object not as expected" ) |
| 754 | return None |
| 755 | except pexpect.EOF: |
| 756 | main.log.error( self.name + ": EOF exception found" ) |
| 757 | main.log.error( self.name + ": " + self.handle.before ) |
| 758 | main.cleanup() |
| 759 | main.exit() |
| 760 | except Exception: |
| 761 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 762 | main.cleanup() |
| 763 | main.exit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 764 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 765 | def devices( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 766 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 767 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 768 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 769 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 770 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 771 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 772 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 773 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 774 | cmdStr += " -j" |
| 775 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 776 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 777 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 778 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 779 | except AssertionError: |
| 780 | main.log.exception( "" ) |
| 781 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 782 | except TypeError: |
| 783 | main.log.exception( self.name + ": Object not as expected" ) |
| 784 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 785 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 786 | main.log.error( self.name + ": EOF exception found" ) |
| 787 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 788 | main.cleanup() |
| 789 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 790 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 791 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 792 | main.cleanup() |
| 793 | main.exit() |
| 794 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 795 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 796 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 797 | This balances the devices across all controllers |
| 798 | by issuing command: 'onos> onos:balance-masters' |
| 799 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 800 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 801 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 802 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 803 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 804 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 805 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 806 | if re.search( "Error", handle ): |
| 807 | main.log.error( "Error in balancing masters" ) |
| 808 | main.log.error( handle ) |
| 809 | return main.FALSE |
| 810 | else: |
| 811 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 812 | except AssertionError: |
| 813 | main.log.exception( "" ) |
| 814 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 815 | except TypeError: |
| 816 | main.log.exception( self.name + ": Object not as expected" ) |
| 817 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 818 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 819 | main.log.error( self.name + ": EOF exception found" ) |
| 820 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 821 | main.cleanup() |
| 822 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 823 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 824 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 825 | main.cleanup() |
| 826 | main.exit() |
| 827 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 828 | def checkMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 829 | """ |
| 830 | Returns the output of the masters command. |
| 831 | Optional argument: |
| 832 | * jsonFormat - boolean indicating if you want output in json |
| 833 | """ |
| 834 | try: |
| 835 | cmdStr = "onos:masters" |
| 836 | if jsonFormat: |
| 837 | cmdStr += " -j" |
| 838 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 839 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 840 | assert "Command not found:" not in output, output |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 841 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 842 | except AssertionError: |
| 843 | main.log.exception( "" ) |
| 844 | return None |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 845 | except TypeError: |
| 846 | main.log.exception( self.name + ": Object not as expected" ) |
| 847 | return None |
| 848 | except pexpect.EOF: |
| 849 | main.log.error( self.name + ": EOF exception found" ) |
| 850 | main.log.error( self.name + ": " + self.handle.before ) |
| 851 | main.cleanup() |
| 852 | main.exit() |
| 853 | except Exception: |
| 854 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 855 | main.cleanup() |
| 856 | main.exit() |
| 857 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 858 | def checkBalanceMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 859 | """ |
| 860 | Uses the master command to check that the devices' leadership |
| 861 | is evenly divided |
| 862 | |
| 863 | Dependencies: checkMasters() and summary() |
| 864 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 865 | Returns main.TRUE if the devices are balanced |
| 866 | Returns main.FALSE if the devices are unbalanced |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 867 | Exits on Exception |
| 868 | Returns None on TypeError |
| 869 | """ |
| 870 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 871 | summaryOutput = self.summary() |
| 872 | totalDevices = json.loads( summaryOutput )[ "devices" ] |
| 873 | except ( TypeError, ValueError ): |
| 874 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) ) |
| 875 | return None |
| 876 | try: |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 877 | totalOwnedDevices = 0 |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 878 | mastersOutput = self.checkMasters() |
| 879 | masters = json.loads( mastersOutput ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 880 | first = masters[ 0 ][ "size" ] |
| 881 | for master in masters: |
| 882 | totalOwnedDevices += master[ "size" ] |
| 883 | if master[ "size" ] > first + 1 or master[ "size" ] < first - 1: |
| 884 | main.log.error( "Mastership not balanced" ) |
| 885 | main.log.info( "\n" + self.checkMasters( False ) ) |
| 886 | return main.FALSE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 887 | main.log.info( "Mastership balanced between " + |
| 888 | str( len(masters) ) + " masters" ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 889 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 890 | except ( TypeError, ValueError ): |
| 891 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 892 | return None |
| 893 | except pexpect.EOF: |
| 894 | main.log.error( self.name + ": EOF exception found" ) |
| 895 | main.log.error( self.name + ": " + self.handle.before ) |
| 896 | main.cleanup() |
| 897 | main.exit() |
| 898 | except Exception: |
| 899 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 900 | main.cleanup() |
| 901 | main.exit() |
| 902 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 903 | def links( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 904 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 905 | Lists all core links |
| 906 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 907 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 908 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 909 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 910 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 911 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 912 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 913 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 914 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 915 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 916 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 917 | except AssertionError: |
| 918 | main.log.exception( "" ) |
| 919 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 920 | except TypeError: |
| 921 | main.log.exception( self.name + ": Object not as expected" ) |
| 922 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 923 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 924 | main.log.error( self.name + ": EOF exception found" ) |
| 925 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 926 | main.cleanup() |
| 927 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 928 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 929 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 930 | main.cleanup() |
| 931 | main.exit() |
| 932 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 933 | def ports( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 934 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 935 | Lists all ports |
| 936 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 937 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 938 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 939 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 940 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 941 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 942 | cmdStr += " -j" |
| 943 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 944 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 945 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 946 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 947 | except AssertionError: |
| 948 | main.log.exception( "" ) |
| 949 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 950 | except TypeError: |
| 951 | main.log.exception( self.name + ": Object not as expected" ) |
| 952 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 953 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 954 | main.log.error( self.name + ": EOF exception found" ) |
| 955 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 956 | main.cleanup() |
| 957 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 958 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 959 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 960 | main.cleanup() |
| 961 | main.exit() |
| 962 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 963 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 964 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 965 | Lists all devices and the controllers with roles assigned to them |
| 966 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 967 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 968 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 969 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 970 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 971 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 972 | cmdStr += " -j" |
| 973 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 974 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 975 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 976 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 977 | except AssertionError: |
| 978 | main.log.exception( "" ) |
| 979 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 980 | except TypeError: |
| 981 | main.log.exception( self.name + ": Object not as expected" ) |
| 982 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 983 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 984 | main.log.error( self.name + ": EOF exception found" ) |
| 985 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 986 | main.cleanup() |
| 987 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 988 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 989 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 990 | main.cleanup() |
| 991 | main.exit() |
| 992 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 993 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 994 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 995 | Given the a string containing the json representation of the "roles" |
| 996 | cli command and a partial or whole device id, returns a json object |
| 997 | containing the roles output for the first device whose id contains |
| 998 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 999 | |
| 1000 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1001 | A dict of the role assignments for the given device or |
| 1002 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1003 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1004 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1005 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1006 | return None |
| 1007 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1008 | rawRoles = self.roles() |
| 1009 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1010 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1011 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1012 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1013 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1014 | return device |
| 1015 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1016 | except ( TypeError, ValueError ): |
| 1017 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1018 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 1019 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1020 | main.log.error( self.name + ": EOF exception found" ) |
| 1021 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 1022 | main.cleanup() |
| 1023 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1024 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1025 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 1026 | main.cleanup() |
| 1027 | main.exit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1028 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1029 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1030 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1031 | Iterates through each device and checks if there is a master assigned |
| 1032 | Returns: main.TRUE if each device has a master |
| 1033 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1034 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1035 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1036 | rawRoles = self.roles() |
| 1037 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1038 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1039 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1040 | # print device |
| 1041 | if device[ 'master' ] == "none": |
| 1042 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1043 | return main.FALSE |
| 1044 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1045 | except ( TypeError, ValueError ): |
| 1046 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1047 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1048 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1049 | main.log.error( self.name + ": EOF exception found" ) |
| 1050 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1051 | main.cleanup() |
| 1052 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1053 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1054 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1055 | main.cleanup() |
| 1056 | main.exit() |
| 1057 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1058 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1059 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1060 | Returns string of paths, and the cost. |
| 1061 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1062 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1063 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1064 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 1065 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1066 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1067 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1068 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1069 | main.log.error( "Error in getting paths" ) |
| 1070 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1071 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1072 | path = handle.split( ";" )[ 0 ] |
| 1073 | cost = handle.split( ";" )[ 1 ] |
| 1074 | return ( path, cost ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1075 | except AssertionError: |
| 1076 | main.log.exception( "" ) |
| 1077 | return ( handle, "Error" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1078 | except TypeError: |
| 1079 | main.log.exception( self.name + ": Object not as expected" ) |
| 1080 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1081 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1082 | main.log.error( self.name + ": EOF exception found" ) |
| 1083 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1084 | main.cleanup() |
| 1085 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1086 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1087 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1088 | main.cleanup() |
| 1089 | main.exit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1090 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1091 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1092 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1093 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1094 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1095 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1096 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1097 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1098 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1099 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1100 | cmdStr += " -j" |
| 1101 | handle = self.sendline( cmdStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1102 | if handle: |
| 1103 | assert "Command not found:" not in handle, handle |
Jon Hall | baf5316 | 2015-12-17 17:04:34 -0800 | [diff] [blame] | 1104 | # TODO: Maybe make this less hardcoded |
| 1105 | # ConsistentMap Exceptions |
| 1106 | assert "org.onosproject.store.service" not in handle |
| 1107 | # Node not leader |
| 1108 | assert "java.lang.IllegalStateException" not in handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1109 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1110 | except AssertionError: |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1111 | main.log.exception( "Error in processing '" + cmdStr + "' " + |
Jeremy Songster | 6949cea | 2016-04-19 18:13:18 -0700 | [diff] [blame] | 1112 | "command: " + str( handle ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1113 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1114 | except TypeError: |
| 1115 | main.log.exception( self.name + ": Object not as expected" ) |
| 1116 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1117 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1118 | main.log.error( self.name + ": EOF exception found" ) |
| 1119 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1120 | main.cleanup() |
| 1121 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1122 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1123 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1124 | main.cleanup() |
| 1125 | main.exit() |
| 1126 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1127 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1128 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1129 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1130 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1131 | 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] | 1132 | partial mac address |
| 1133 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1134 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1135 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1136 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1137 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1138 | return None |
| 1139 | else: |
| 1140 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1141 | rawHosts = self.hosts() |
| 1142 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1143 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1144 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1145 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1146 | if not host: |
| 1147 | pass |
| 1148 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1149 | return host |
| 1150 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1151 | except ( TypeError, ValueError ): |
| 1152 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1153 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1154 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1155 | main.log.error( self.name + ": EOF exception found" ) |
| 1156 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1157 | main.cleanup() |
| 1158 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1159 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1160 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1161 | main.cleanup() |
| 1162 | main.exit() |
| 1163 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1164 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1165 | """ |
| 1166 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1167 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1168 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1169 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1170 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1171 | IMPORTANT: |
| 1172 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1173 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1174 | Furthermore, it assumes that value of VLAN is '-1' |
| 1175 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1176 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1177 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1178 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1179 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1180 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1181 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1182 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1183 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1184 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 1185 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 1186 | i = iter( str( hostHex ) ) |
| 1187 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 1188 | hostHex = hostHex + "/-1" |
| 1189 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1190 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1191 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1192 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1193 | except TypeError: |
| 1194 | main.log.exception( self.name + ": Object not as expected" ) |
| 1195 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1196 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1197 | main.log.error( self.name + ": EOF exception found" ) |
| 1198 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1199 | main.cleanup() |
| 1200 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1201 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1202 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1203 | main.cleanup() |
| 1204 | main.exit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1205 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1206 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1207 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1208 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1209 | * hostIdOne: ONOS host id for host1 |
| 1210 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1211 | Optional: |
| 1212 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1213 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1214 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1215 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1216 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1217 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1218 | Returns: |
| 1219 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1220 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1221 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1222 | cmdStr = "add-host-intent " |
| 1223 | if vlanId: |
| 1224 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1225 | if setVlan: |
| 1226 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1227 | if encap: |
| 1228 | cmdStr += "--encapsulation " + str( encap ) + " " |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1229 | if bandwidth: |
| 1230 | cmdStr += "-b " + str( bandwidth ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1231 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1232 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1233 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1234 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1235 | if re.search( "Error", handle ): |
| 1236 | main.log.error( "Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1237 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1238 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1239 | else: |
| 1240 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1241 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
| 1242 | match = re.search('id=0x([\da-f]+),', handle) |
| 1243 | if match: |
| 1244 | return match.group()[3:-1] |
| 1245 | else: |
| 1246 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1247 | main.log.debug( "Response from ONOS was: " + |
| 1248 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1249 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1250 | except AssertionError: |
| 1251 | main.log.exception( "" ) |
| 1252 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1253 | except TypeError: |
| 1254 | main.log.exception( self.name + ": Object not as expected" ) |
| 1255 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1256 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1257 | main.log.error( self.name + ": EOF exception found" ) |
| 1258 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1259 | main.cleanup() |
| 1260 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1261 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1262 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1263 | main.cleanup() |
| 1264 | main.exit() |
| 1265 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1266 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1267 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1268 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1269 | * ingressDevice: device id of ingress device |
| 1270 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1271 | Optional: |
| 1272 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1273 | Description: |
| 1274 | Adds an optical intent by specifying an ingress and egress device |
| 1275 | Returns: |
| 1276 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1277 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1278 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1279 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1280 | " " + str( egressDevice ) |
| 1281 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1282 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1283 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1284 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1285 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1286 | main.log.error( "Error in adding Optical intent" ) |
| 1287 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1288 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1289 | main.log.info( "Optical intent installed between " + |
| 1290 | str( ingressDevice ) + " and " + |
| 1291 | str( egressDevice ) ) |
| 1292 | match = re.search('id=0x([\da-f]+),', handle) |
| 1293 | if match: |
| 1294 | return match.group()[3:-1] |
| 1295 | else: |
| 1296 | main.log.error( "Error, intent ID not found" ) |
| 1297 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1298 | except AssertionError: |
| 1299 | main.log.exception( "" ) |
| 1300 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1301 | except TypeError: |
| 1302 | main.log.exception( self.name + ": Object not as expected" ) |
| 1303 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1304 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1305 | main.log.error( self.name + ": EOF exception found" ) |
| 1306 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1307 | main.cleanup() |
| 1308 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1309 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1310 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1311 | main.cleanup() |
| 1312 | main.exit() |
| 1313 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1314 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1315 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1316 | ingressDevice, |
| 1317 | egressDevice, |
| 1318 | portIngress="", |
| 1319 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1320 | ethType="", |
| 1321 | ethSrc="", |
| 1322 | ethDst="", |
| 1323 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1324 | lambdaAlloc=False, |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1325 | protected=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1326 | ipProto="", |
| 1327 | ipSrc="", |
| 1328 | ipDst="", |
| 1329 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1330 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1331 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1332 | setVlan="", |
| 1333 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1334 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1335 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1336 | * ingressDevice: device id of ingress device |
| 1337 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1338 | Optional: |
| 1339 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1340 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1341 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1342 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1343 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1344 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1345 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1346 | * ipSrc: specify ip source address |
| 1347 | * ipDst: specify ip destination address |
| 1348 | * tcpSrc: specify tcp source port |
| 1349 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1350 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1351 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1352 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1353 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1354 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1355 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1356 | Returns: |
| 1357 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1358 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1359 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1360 | options developers provide for point-to-point |
| 1361 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1362 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1363 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1364 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1365 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1366 | if ethType: |
| 1367 | cmd += " --ethType " + str( ethType ) |
| 1368 | if ethSrc: |
| 1369 | cmd += " --ethSrc " + str( ethSrc ) |
| 1370 | if ethDst: |
| 1371 | cmd += " --ethDst " + str( ethDst ) |
| 1372 | if bandwidth: |
| 1373 | cmd += " --bandwidth " + str( bandwidth ) |
| 1374 | if lambdaAlloc: |
| 1375 | cmd += " --lambda " |
| 1376 | if ipProto: |
| 1377 | cmd += " --ipProto " + str( ipProto ) |
| 1378 | if ipSrc: |
| 1379 | cmd += " --ipSrc " + str( ipSrc ) |
| 1380 | if ipDst: |
| 1381 | cmd += " --ipDst " + str( ipDst ) |
| 1382 | if tcpSrc: |
| 1383 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1384 | if tcpDst: |
| 1385 | cmd += " --tcpDst " + str( tcpDst ) |
| 1386 | if vlanId: |
| 1387 | cmd += " -v " + str( vlanId ) |
| 1388 | if setVlan: |
| 1389 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1390 | if encap: |
| 1391 | cmd += " --encapsulation " + str( encap ) |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1392 | if protected: |
| 1393 | cmd += " --protect " |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1394 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1395 | # Check whether the user appended the port |
| 1396 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1397 | if "/" in ingressDevice: |
| 1398 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1399 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1400 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1401 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1402 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1403 | # Would it make sense to throw an exception and exit |
| 1404 | # the test? |
| 1405 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1406 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1407 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1408 | str( ingressDevice ) + "/" +\ |
| 1409 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1410 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1411 | if "/" in egressDevice: |
| 1412 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1413 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1414 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1415 | main.log.error( "You must specify the egress port" ) |
| 1416 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1417 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1418 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1419 | str( egressDevice ) + "/" +\ |
| 1420 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1421 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1422 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1423 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1424 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1425 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1426 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1427 | main.log.error( "Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1428 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1429 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1430 | # TODO: print out all the options in this message? |
| 1431 | main.log.info( "Point-to-point intent installed between " + |
| 1432 | str( ingressDevice ) + " and " + |
| 1433 | str( egressDevice ) ) |
| 1434 | match = re.search('id=0x([\da-f]+),', handle) |
| 1435 | if match: |
| 1436 | return match.group()[3:-1] |
| 1437 | else: |
| 1438 | main.log.error( "Error, intent ID not found" ) |
| 1439 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1440 | except AssertionError: |
| 1441 | main.log.exception( "" ) |
| 1442 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1443 | except TypeError: |
| 1444 | main.log.exception( self.name + ": Object not as expected" ) |
| 1445 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1446 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1447 | main.log.error( self.name + ": EOF exception found" ) |
| 1448 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1449 | main.cleanup() |
| 1450 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1451 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1452 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1453 | main.cleanup() |
| 1454 | main.exit() |
| 1455 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1456 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1457 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1458 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1459 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1460 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1461 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1462 | ethType="", |
| 1463 | ethSrc="", |
| 1464 | ethDst="", |
| 1465 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1466 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1467 | ipProto="", |
| 1468 | ipSrc="", |
| 1469 | ipDst="", |
| 1470 | tcpSrc="", |
| 1471 | tcpDst="", |
| 1472 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1473 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1474 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1475 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1476 | partial=False, |
| 1477 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1478 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1479 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1480 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1481 | is same. That is, all ingress devices include port numbers |
| 1482 | with a "/" or all ingress devices could specify device |
| 1483 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1484 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1485 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1486 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1487 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1488 | Optional: |
| 1489 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1490 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1491 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1492 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1493 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1494 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1495 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1496 | * ipSrc: specify ip source address |
| 1497 | * ipDst: specify ip destination address |
| 1498 | * tcpSrc: specify tcp source port |
| 1499 | * tcpDst: specify tcp destination port |
| 1500 | * setEthSrc: action to Rewrite Source MAC Address |
| 1501 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1502 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1503 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1504 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1505 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1506 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1507 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1508 | Returns: |
| 1509 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1510 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1511 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1512 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1513 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1514 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1515 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1516 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1517 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1518 | if ethType: |
| 1519 | cmd += " --ethType " + str( ethType ) |
| 1520 | if ethSrc: |
| 1521 | cmd += " --ethSrc " + str( ethSrc ) |
| 1522 | if ethDst: |
| 1523 | cmd += " --ethDst " + str( ethDst ) |
| 1524 | if bandwidth: |
| 1525 | cmd += " --bandwidth " + str( bandwidth ) |
| 1526 | if lambdaAlloc: |
| 1527 | cmd += " --lambda " |
| 1528 | if ipProto: |
| 1529 | cmd += " --ipProto " + str( ipProto ) |
| 1530 | if ipSrc: |
| 1531 | cmd += " --ipSrc " + str( ipSrc ) |
| 1532 | if ipDst: |
| 1533 | cmd += " --ipDst " + str( ipDst ) |
| 1534 | if tcpSrc: |
| 1535 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1536 | if tcpDst: |
| 1537 | cmd += " --tcpDst " + str( tcpDst ) |
| 1538 | if setEthSrc: |
| 1539 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1540 | if setEthDst: |
| 1541 | cmd += " --setEthDst " + str( setEthDst ) |
| 1542 | if vlanId: |
| 1543 | cmd += " -v " + str( vlanId ) |
| 1544 | if setVlan: |
| 1545 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1546 | if partial: |
| 1547 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1548 | if encap: |
| 1549 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1550 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1551 | # Check whether the user appended the port |
| 1552 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1553 | |
| 1554 | if portIngressList is None: |
| 1555 | for ingressDevice in ingressDeviceList: |
| 1556 | if "/" in ingressDevice: |
| 1557 | cmd += " " + str( ingressDevice ) |
| 1558 | else: |
| 1559 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1560 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1561 | # TODO: perhaps more meaningful return |
| 1562 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1563 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1564 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1565 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1566 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1567 | cmd += " " + \ |
| 1568 | str( ingressDevice ) + "/" +\ |
| 1569 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1570 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1571 | main.log.error( "Device list and port list does not " + |
| 1572 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1573 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1574 | if "/" in egressDevice: |
| 1575 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1576 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1577 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1578 | main.log.error( "You must specify " + |
| 1579 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1580 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1581 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1582 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1583 | str( egressDevice ) + "/" +\ |
| 1584 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1585 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1586 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1587 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1588 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1589 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1590 | main.log.error( "Error in adding multipoint-to-singlepoint " + |
| 1591 | "intent" ) |
| 1592 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1593 | else: |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1594 | match = re.search('id=0x([\da-f]+),', handle) |
| 1595 | if match: |
| 1596 | return match.group()[3:-1] |
| 1597 | else: |
| 1598 | main.log.error( "Error, intent ID not found" ) |
| 1599 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1600 | except AssertionError: |
| 1601 | main.log.exception( "" ) |
| 1602 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1603 | except TypeError: |
| 1604 | main.log.exception( self.name + ": Object not as expected" ) |
| 1605 | return None |
| 1606 | except pexpect.EOF: |
| 1607 | main.log.error( self.name + ": EOF exception found" ) |
| 1608 | main.log.error( self.name + ": " + self.handle.before ) |
| 1609 | main.cleanup() |
| 1610 | main.exit() |
| 1611 | except Exception: |
| 1612 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1613 | main.cleanup() |
| 1614 | main.exit() |
| 1615 | |
| 1616 | def addSinglepointToMultipointIntent( |
| 1617 | self, |
| 1618 | ingressDevice, |
| 1619 | egressDeviceList, |
| 1620 | portIngress="", |
| 1621 | portEgressList=None, |
| 1622 | ethType="", |
| 1623 | ethSrc="", |
| 1624 | ethDst="", |
| 1625 | bandwidth="", |
| 1626 | lambdaAlloc=False, |
| 1627 | ipProto="", |
| 1628 | ipSrc="", |
| 1629 | ipDst="", |
| 1630 | tcpSrc="", |
| 1631 | tcpDst="", |
| 1632 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1633 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1634 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1635 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1636 | partial=False, |
| 1637 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1638 | """ |
| 1639 | Note: |
| 1640 | This function assumes the format of all egress devices |
| 1641 | is same. That is, all egress devices include port numbers |
| 1642 | with a "/" or all egress devices could specify device |
| 1643 | ids and port numbers seperately. |
| 1644 | Required: |
| 1645 | * EgressDeviceList: List of device ids of egress device |
| 1646 | ( Atleast 2 eress devices required in the list ) |
| 1647 | * ingressDevice: device id of ingress device |
| 1648 | Optional: |
| 1649 | * ethType: specify ethType |
| 1650 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1651 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1652 | * bandwidth: specify bandwidth capacity of link |
| 1653 | * lambdaAlloc: if True, intent will allocate lambda |
| 1654 | for the specified intent |
| 1655 | * ipProto: specify ip protocol |
| 1656 | * ipSrc: specify ip source address |
| 1657 | * ipDst: specify ip destination address |
| 1658 | * tcpSrc: specify tcp source port |
| 1659 | * tcpDst: specify tcp destination port |
| 1660 | * setEthSrc: action to Rewrite Source MAC Address |
| 1661 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1662 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1663 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1664 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1665 | Description: |
| 1666 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1667 | specifying device id's and optional fields |
| 1668 | Returns: |
| 1669 | A string of the intent id or None on error |
| 1670 | |
| 1671 | NOTE: This function may change depending on the |
| 1672 | options developers provide for singlepoint-to-multipoint |
| 1673 | intent via cli |
| 1674 | """ |
| 1675 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1676 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1677 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1678 | if ethType: |
| 1679 | cmd += " --ethType " + str( ethType ) |
| 1680 | if ethSrc: |
| 1681 | cmd += " --ethSrc " + str( ethSrc ) |
| 1682 | if ethDst: |
| 1683 | cmd += " --ethDst " + str( ethDst ) |
| 1684 | if bandwidth: |
| 1685 | cmd += " --bandwidth " + str( bandwidth ) |
| 1686 | if lambdaAlloc: |
| 1687 | cmd += " --lambda " |
| 1688 | if ipProto: |
| 1689 | cmd += " --ipProto " + str( ipProto ) |
| 1690 | if ipSrc: |
| 1691 | cmd += " --ipSrc " + str( ipSrc ) |
| 1692 | if ipDst: |
| 1693 | cmd += " --ipDst " + str( ipDst ) |
| 1694 | if tcpSrc: |
| 1695 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1696 | if tcpDst: |
| 1697 | cmd += " --tcpDst " + str( tcpDst ) |
| 1698 | if setEthSrc: |
| 1699 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1700 | if setEthDst: |
| 1701 | cmd += " --setEthDst " + str( setEthDst ) |
| 1702 | if vlanId: |
| 1703 | cmd += " -v " + str( vlanId ) |
| 1704 | if setVlan: |
| 1705 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1706 | if partial: |
| 1707 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1708 | if encap: |
| 1709 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1710 | |
| 1711 | # Check whether the user appended the port |
| 1712 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1713 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1714 | if "/" in ingressDevice: |
| 1715 | cmd += " " + str( ingressDevice ) |
| 1716 | else: |
| 1717 | if not portIngress: |
| 1718 | main.log.error( "You must specify " + |
| 1719 | "the Ingress port" ) |
| 1720 | return main.FALSE |
| 1721 | |
| 1722 | cmd += " " +\ |
| 1723 | str( ingressDevice ) + "/" +\ |
| 1724 | str( portIngress ) |
| 1725 | |
| 1726 | if portEgressList is None: |
| 1727 | for egressDevice in egressDeviceList: |
| 1728 | if "/" in egressDevice: |
| 1729 | cmd += " " + str( egressDevice ) |
| 1730 | else: |
| 1731 | main.log.error( "You must specify " + |
| 1732 | "the egress port" ) |
| 1733 | # TODO: perhaps more meaningful return |
| 1734 | return main.FALSE |
| 1735 | else: |
| 1736 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1737 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1738 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1739 | cmd += " " + \ |
| 1740 | str( egressDevice ) + "/" +\ |
| 1741 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1742 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1743 | main.log.error( "Device list and port list does not " + |
| 1744 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1745 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1746 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1747 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1748 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1749 | # If error, return error message |
| 1750 | if re.search( "Error", handle ): |
| 1751 | main.log.error( "Error in adding singlepoint-to-multipoint " + |
| 1752 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1753 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1754 | else: |
| 1755 | match = re.search('id=0x([\da-f]+),', handle) |
| 1756 | if match: |
| 1757 | return match.group()[3:-1] |
| 1758 | else: |
| 1759 | main.log.error( "Error, intent ID not found" ) |
| 1760 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1761 | except AssertionError: |
| 1762 | main.log.exception( "" ) |
| 1763 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1764 | except TypeError: |
| 1765 | main.log.exception( self.name + ": Object not as expected" ) |
| 1766 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1767 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1768 | main.log.error( self.name + ": EOF exception found" ) |
| 1769 | main.log.error( self.name + ": " + self.handle.before ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1770 | main.cleanup() |
| 1771 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1772 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1773 | main.log.exception( self.name + ": Uncaught exception!" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1774 | main.cleanup() |
| 1775 | main.exit() |
| 1776 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1777 | def addMplsIntent( |
| 1778 | self, |
| 1779 | ingressDevice, |
| 1780 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1781 | ingressPort="", |
| 1782 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1783 | ethType="", |
| 1784 | ethSrc="", |
| 1785 | ethDst="", |
| 1786 | bandwidth="", |
| 1787 | lambdaAlloc=False, |
| 1788 | ipProto="", |
| 1789 | ipSrc="", |
| 1790 | ipDst="", |
| 1791 | tcpSrc="", |
| 1792 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1793 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1794 | egressLabel="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1795 | priority=""): |
| 1796 | """ |
| 1797 | Required: |
| 1798 | * ingressDevice: device id of ingress device |
| 1799 | * egressDevice: device id of egress device |
| 1800 | Optional: |
| 1801 | * ethType: specify ethType |
| 1802 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1803 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1804 | * bandwidth: specify bandwidth capacity of link |
| 1805 | * lambdaAlloc: if True, intent will allocate lambda |
| 1806 | for the specified intent |
| 1807 | * ipProto: specify ip protocol |
| 1808 | * ipSrc: specify ip source address |
| 1809 | * ipDst: specify ip destination address |
| 1810 | * tcpSrc: specify tcp source port |
| 1811 | * tcpDst: specify tcp destination port |
| 1812 | * ingressLabel: Ingress MPLS label |
| 1813 | * egressLabel: Egress MPLS label |
| 1814 | Description: |
| 1815 | Adds MPLS intent by |
| 1816 | specifying device id's and optional fields |
| 1817 | Returns: |
| 1818 | A string of the intent id or None on error |
| 1819 | |
| 1820 | NOTE: This function may change depending on the |
| 1821 | options developers provide for MPLS |
| 1822 | intent via cli |
| 1823 | """ |
| 1824 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1825 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1826 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1827 | if ethType: |
| 1828 | cmd += " --ethType " + str( ethType ) |
| 1829 | if ethSrc: |
| 1830 | cmd += " --ethSrc " + str( ethSrc ) |
| 1831 | if ethDst: |
| 1832 | cmd += " --ethDst " + str( ethDst ) |
| 1833 | if bandwidth: |
| 1834 | cmd += " --bandwidth " + str( bandwidth ) |
| 1835 | if lambdaAlloc: |
| 1836 | cmd += " --lambda " |
| 1837 | if ipProto: |
| 1838 | cmd += " --ipProto " + str( ipProto ) |
| 1839 | if ipSrc: |
| 1840 | cmd += " --ipSrc " + str( ipSrc ) |
| 1841 | if ipDst: |
| 1842 | cmd += " --ipDst " + str( ipDst ) |
| 1843 | if tcpSrc: |
| 1844 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1845 | if tcpDst: |
| 1846 | cmd += " --tcpDst " + str( tcpDst ) |
| 1847 | if ingressLabel: |
| 1848 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 1849 | if egressLabel: |
| 1850 | cmd += " --egressLabel " + str( egressLabel ) |
| 1851 | if priority: |
| 1852 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1853 | |
| 1854 | # Check whether the user appended the port |
| 1855 | # or provided it as an input |
| 1856 | if "/" in ingressDevice: |
| 1857 | cmd += " " + str( ingressDevice ) |
| 1858 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1859 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1860 | main.log.error( "You must specify the ingress port" ) |
| 1861 | return None |
| 1862 | |
| 1863 | cmd += " " + \ |
| 1864 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1865 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1866 | |
| 1867 | if "/" in egressDevice: |
| 1868 | cmd += " " + str( egressDevice ) |
| 1869 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1870 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1871 | main.log.error( "You must specify the egress port" ) |
| 1872 | return None |
| 1873 | |
| 1874 | cmd += " " +\ |
| 1875 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1876 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1877 | |
| 1878 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1879 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1880 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1881 | # If error, return error message |
| 1882 | if re.search( "Error", handle ): |
| 1883 | main.log.error( "Error in adding mpls intent" ) |
| 1884 | return None |
| 1885 | else: |
| 1886 | # TODO: print out all the options in this message? |
| 1887 | main.log.info( "MPLS intent installed between " + |
| 1888 | str( ingressDevice ) + " and " + |
| 1889 | str( egressDevice ) ) |
| 1890 | match = re.search('id=0x([\da-f]+),', handle) |
| 1891 | if match: |
| 1892 | return match.group()[3:-1] |
| 1893 | else: |
| 1894 | main.log.error( "Error, intent ID not found" ) |
| 1895 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1896 | except AssertionError: |
| 1897 | main.log.exception( "" ) |
| 1898 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1899 | except TypeError: |
| 1900 | main.log.exception( self.name + ": Object not as expected" ) |
| 1901 | return None |
| 1902 | except pexpect.EOF: |
| 1903 | main.log.error( self.name + ": EOF exception found" ) |
| 1904 | main.log.error( self.name + ": " + self.handle.before ) |
| 1905 | main.cleanup() |
| 1906 | main.exit() |
| 1907 | except Exception: |
| 1908 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1909 | main.cleanup() |
| 1910 | main.exit() |
| 1911 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1912 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 1913 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1914 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1915 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1916 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1917 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1918 | -p or --purge: Purge the intent from the store after removal |
| 1919 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1920 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 1921 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1922 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1923 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1924 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1925 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1926 | if purge: |
| 1927 | cmdStr += " -p" |
| 1928 | if sync: |
| 1929 | cmdStr += " -s" |
| 1930 | |
| 1931 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1932 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1933 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1934 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1935 | if re.search( "Error", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1936 | main.log.error( "Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1937 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1938 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1939 | # TODO: Should this be main.TRUE |
| 1940 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1941 | except AssertionError: |
| 1942 | main.log.exception( "" ) |
| 1943 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1944 | except TypeError: |
| 1945 | main.log.exception( self.name + ": Object not as expected" ) |
| 1946 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1947 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1948 | main.log.error( self.name + ": EOF exception found" ) |
| 1949 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1950 | main.cleanup() |
| 1951 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1952 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1953 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1954 | main.cleanup() |
| 1955 | main.exit() |
| 1956 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1957 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1958 | """ |
| 1959 | Description: |
| 1960 | Remove all the intents |
| 1961 | Optional args:- |
| 1962 | -s or --sync: Waits for the removal before returning |
| 1963 | -p or --purge: Purge the intent from the store after removal |
| 1964 | Returns: |
| 1965 | Returns main.TRUE if all intents are removed, otherwise returns |
| 1966 | main.FALSE; Returns None for exception |
| 1967 | """ |
| 1968 | try: |
| 1969 | cmdStr = "remove-intent" |
| 1970 | if purge: |
| 1971 | cmdStr += " -p" |
| 1972 | if sync: |
| 1973 | cmdStr += " -s" |
| 1974 | |
| 1975 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1976 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1977 | assert handle is not None, "Error in sendline" |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1978 | assert "Command not found:" not in handle, handle |
| 1979 | if re.search( "Error", handle ): |
| 1980 | main.log.error( "Error in removing intent" ) |
| 1981 | return main.FALSE |
| 1982 | else: |
| 1983 | return main.TRUE |
| 1984 | except AssertionError: |
| 1985 | main.log.exception( "" ) |
| 1986 | return None |
| 1987 | except TypeError: |
| 1988 | main.log.exception( self.name + ": Object not as expected" ) |
| 1989 | return None |
| 1990 | except pexpect.EOF: |
| 1991 | main.log.error( self.name + ": EOF exception found" ) |
| 1992 | main.log.error( self.name + ": " + self.handle.before ) |
| 1993 | main.cleanup() |
| 1994 | main.exit() |
| 1995 | except Exception: |
| 1996 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1997 | main.cleanup() |
| 1998 | main.exit() |
| 1999 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 2000 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2001 | """ |
| 2002 | Purges all WITHDRAWN Intents |
| 2003 | """ |
| 2004 | try: |
| 2005 | cmdStr = "purge-intents" |
| 2006 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2007 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2008 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2009 | if re.search( "Error", handle ): |
| 2010 | main.log.error( "Error in purging intents" ) |
| 2011 | return main.FALSE |
| 2012 | else: |
| 2013 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2014 | except AssertionError: |
| 2015 | main.log.exception( "" ) |
| 2016 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2017 | except TypeError: |
| 2018 | main.log.exception( self.name + ": Object not as expected" ) |
| 2019 | return None |
| 2020 | except pexpect.EOF: |
| 2021 | main.log.error( self.name + ": EOF exception found" ) |
| 2022 | main.log.error( self.name + ": " + self.handle.before ) |
| 2023 | main.cleanup() |
| 2024 | main.exit() |
| 2025 | except Exception: |
| 2026 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2027 | main.cleanup() |
| 2028 | main.exit() |
| 2029 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2030 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2031 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2032 | NOTE: This method should be used after installing application: |
| 2033 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2034 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2035 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2036 | Description: |
| 2037 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2038 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2039 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2040 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2041 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2042 | cmdStr += " -j" |
| 2043 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2044 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2045 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2046 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2047 | except AssertionError: |
| 2048 | main.log.exception( "" ) |
| 2049 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2050 | except TypeError: |
| 2051 | main.log.exception( self.name + ": Object not as expected" ) |
| 2052 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2053 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2054 | main.log.error( self.name + ": EOF exception found" ) |
| 2055 | main.log.error( self.name + ": " + self.handle.before ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2056 | main.cleanup() |
| 2057 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2058 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2059 | main.log.exception( self.name + ": Uncaught exception!" ) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2060 | main.cleanup() |
| 2061 | main.exit() |
| 2062 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2063 | def ipv4RouteNumber( self ): |
| 2064 | """ |
| 2065 | NOTE: This method should be used after installing application: |
| 2066 | onos-app-sdnip |
| 2067 | Description: |
| 2068 | Obtain the total IPv4 routes number in the system |
| 2069 | """ |
| 2070 | try: |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2071 | cmdStr = "routes -j" |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2072 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2073 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2074 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2075 | jsonResult = json.loads( handle ) |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2076 | return len(jsonResult['routes4']) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2077 | except AssertionError: |
| 2078 | main.log.exception( "" ) |
| 2079 | return None |
| 2080 | except ( TypeError, ValueError ): |
| 2081 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2082 | return None |
| 2083 | except pexpect.EOF: |
| 2084 | main.log.error( self.name + ": EOF exception found" ) |
| 2085 | main.log.error( self.name + ": " + self.handle.before ) |
| 2086 | main.cleanup() |
| 2087 | main.exit() |
| 2088 | except Exception: |
| 2089 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2090 | main.cleanup() |
| 2091 | main.exit() |
| 2092 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2093 | #=============Function to check Bandwidth allocation======== |
| 2094 | def allocations( self, jsonFormat = True, dollarSign = True ): |
| 2095 | """ |
| 2096 | Description: |
| 2097 | Obtain Bandwidth Allocation Information from ONOS cli. |
| 2098 | """ |
| 2099 | try: |
| 2100 | cmdStr = "allocations" |
| 2101 | if jsonFormat: |
| 2102 | cmdStr += " -j" |
| 2103 | handle = self.sendline( cmdStr, timeout=300, dollarSign=True ) |
| 2104 | assert handle is not None, "Error in sendline" |
| 2105 | assert "Command not found:" not in handle, handle |
| 2106 | return handle |
| 2107 | except AssertionError: |
| 2108 | main.log.exception( "" ) |
| 2109 | return None |
| 2110 | except ( TypeError, ValueError ): |
| 2111 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
| 2112 | return None |
| 2113 | except pexpect.EOF: |
| 2114 | main.log.error( self.name + ": EOF exception found" ) |
| 2115 | main.log.error( self.name + ": " + self.handle.before ) |
| 2116 | main.cleanup() |
| 2117 | main.exit() |
| 2118 | except Exception: |
| 2119 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2120 | main.cleanup() |
| 2121 | main.exit() |
| 2122 | |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2123 | def intents( self, jsonFormat = True, summary = False, **intentargs): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2124 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2125 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2126 | Obtain intents from the ONOS cli. |
| 2127 | Optional: |
| 2128 | * jsonFormat: Enable output formatting in json, default to True |
| 2129 | * summary: Whether only output the intent summary, defaults to False |
| 2130 | * type: Only output a certain type of intent. This options is valid |
| 2131 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2132 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2133 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2134 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2135 | if summary: |
| 2136 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2137 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2138 | cmdStr += " -j" |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2139 | handle = self.sendline( cmdStr, timeout=300 ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2140 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2141 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2142 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2143 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2144 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2145 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2146 | intentType = "" |
| 2147 | # IF we want the summary of a specific intent type |
| 2148 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2149 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2150 | if intentType in jsonResult.keys(): |
| 2151 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2152 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2153 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2154 | return handle |
| 2155 | else: |
| 2156 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2157 | except AssertionError: |
| 2158 | main.log.exception( "" ) |
| 2159 | return None |
| 2160 | except ( TypeError, ValueError ): |
| 2161 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2162 | return None |
| 2163 | except pexpect.EOF: |
| 2164 | main.log.error( self.name + ": EOF exception found" ) |
| 2165 | main.log.error( self.name + ": " + self.handle.before ) |
| 2166 | main.cleanup() |
| 2167 | main.exit() |
| 2168 | except Exception: |
| 2169 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2170 | main.cleanup() |
| 2171 | main.exit() |
| 2172 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2173 | def getIntentState(self, intentsId, intentsJson=None): |
| 2174 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2175 | Description: |
| 2176 | Gets intent state. Accepts a single intent ID (string type) or a |
| 2177 | list of intent IDs. |
| 2178 | Parameters: |
| 2179 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2180 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2181 | Returns: |
| 2182 | Returns the state (string type) of the ID if a single intent ID is |
| 2183 | accepted. |
| 2184 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2185 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2186 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2187 | """ |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2188 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2189 | try: |
| 2190 | state = "State is Undefined" |
| 2191 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2192 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2193 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2194 | rawJson = intentsJson |
| 2195 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2196 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2197 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2198 | if intentsId == intent[ 'id' ]: |
| 2199 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2200 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2201 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2202 | " in the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2203 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2204 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2205 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2206 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2207 | stateDict = {} |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2208 | for intent in parsedIntentsJson: |
| 2209 | if intentsId[ i ] == intent[ 'id' ]: |
| 2210 | stateDict[ 'state' ] = intent[ 'state' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2211 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2212 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2213 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2214 | if len( intentsId ) != len( dictList ): |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2215 | main.log.warn( "Could not find all intents in ONOS output" ) |
| 2216 | main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2217 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2218 | else: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2219 | main.log.info( "Invalid type for intentsId argument" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2220 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2221 | except ( TypeError, ValueError ): |
| 2222 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2223 | return None |
| 2224 | except pexpect.EOF: |
| 2225 | main.log.error( self.name + ": EOF exception found" ) |
| 2226 | main.log.error( self.name + ": " + self.handle.before ) |
| 2227 | main.cleanup() |
| 2228 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2229 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2230 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2231 | main.cleanup() |
| 2232 | main.exit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2233 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2234 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2235 | """ |
| 2236 | Description: |
| 2237 | Check intents state |
| 2238 | Required: |
| 2239 | intentsId - List of intents ID to be checked |
| 2240 | Optional: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2241 | expectedState - Check the expected state(s) of each intents |
| 2242 | state in the list. |
| 2243 | *NOTE: You can pass in a list of expected state, |
| 2244 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2245 | Return: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2246 | Returns main.TRUE only if all intent are the same as expected states, |
| 2247 | otherwise returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2248 | """ |
| 2249 | try: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2250 | returnValue = main.TRUE |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2251 | # Generating a dictionary: intent id as a key and state as value |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2252 | |
| 2253 | #intentsDict = self.getIntentState( intentsId ) |
| 2254 | intentsDict = [] |
| 2255 | for intent in json.loads( self.intents() ): |
| 2256 | if isinstance ( intentsId, types.StringType) \ |
| 2257 | and intent.get('id') == intentsId: |
| 2258 | intentsDict.append(intent) |
| 2259 | elif isinstance ( intentsId, types.ListType ) \ |
| 2260 | and any( intent.get( 'id' ) == ids for ids in intentsId ): |
| 2261 | intentsDict.append(intent) |
| 2262 | |
| 2263 | if not intentsDict: |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2264 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2265 | "getting intents state" ) |
| 2266 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2267 | |
| 2268 | if isinstance( expectedState, types.StringType ): |
| 2269 | for intents in intentsDict: |
| 2270 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2271 | main.log.debug( self.name + " : Intent ID - " + |
| 2272 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2273 | " actual state = " + |
| 2274 | intents.get( 'state' ) |
| 2275 | + " does not equal expected state = " |
| 2276 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2277 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2278 | elif isinstance( expectedState, types.ListType ): |
| 2279 | for intents in intentsDict: |
| 2280 | if not any( state == intents.get( 'state' ) for state in |
| 2281 | expectedState ): |
| 2282 | main.log.debug( self.name + " : Intent ID - " + |
| 2283 | intents.get( 'id' ) + |
| 2284 | " actual state = " + |
| 2285 | intents.get( 'state' ) + |
| 2286 | " does not equal expected states = " |
| 2287 | + str( expectedState ) ) |
| 2288 | returnValue = main.FALSE |
| 2289 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2290 | if returnValue == main.TRUE: |
| 2291 | main.log.info( self.name + ": All " + |
| 2292 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2293 | " intents are in " + str( expectedState ) + |
| 2294 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2295 | return returnValue |
| 2296 | except TypeError: |
| 2297 | main.log.exception( self.name + ": Object not as expected" ) |
| 2298 | return None |
| 2299 | except pexpect.EOF: |
| 2300 | main.log.error( self.name + ": EOF exception found" ) |
| 2301 | main.log.error( self.name + ": " + self.handle.before ) |
| 2302 | main.cleanup() |
| 2303 | main.exit() |
| 2304 | except Exception: |
| 2305 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2306 | main.cleanup() |
| 2307 | main.exit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2308 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2309 | def compareBandwidthAllocations( self, expectedAllocations ): |
| 2310 | """ |
| 2311 | Description: |
| 2312 | Compare the allocated bandwidth with the given allocations |
| 2313 | Required: |
| 2314 | expectedAllocations - The expected ONOS output of the allocations command |
| 2315 | Return: |
| 2316 | Returns main.TRUE only if all intent are the same as expected states, |
| 2317 | otherwise returns main.FALSE. |
| 2318 | """ |
| 2319 | # FIXME: Convert these string comparisons to object comparisons |
| 2320 | try: |
| 2321 | returnValue = main.TRUE |
| 2322 | bandwidthFailed = False |
| 2323 | rawAlloc = self.allocations() |
| 2324 | expectedFormat = StringIO( expectedAllocations ) |
| 2325 | ONOSOutput = StringIO( rawAlloc ) |
| 2326 | main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ), |
| 2327 | str( expectedFormat ) ) ) |
| 2328 | |
| 2329 | for actual, expected in izip( ONOSOutput, expectedFormat ): |
| 2330 | actual = actual.rstrip() |
| 2331 | expected = expected.rstrip() |
| 2332 | main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) ) |
| 2333 | if actual != expected and 'allocated' in actual and 'allocated' in expected: |
| 2334 | marker1 = actual.find('allocated') |
| 2335 | m1 = actual[:marker1] |
| 2336 | marker2 = expected.find('allocated') |
| 2337 | m2 = expected[:marker2] |
| 2338 | if m1 != m2: |
| 2339 | bandwidthFailed = True |
| 2340 | elif actual != expected and 'allocated' not in actual and 'allocated' not in expected: |
| 2341 | bandwidthFailed = True |
| 2342 | expectedFormat.close() |
| 2343 | ONOSOutput.close() |
| 2344 | |
| 2345 | if bandwidthFailed: |
| 2346 | main.log.error("Bandwidth not allocated correctly using Intents!!") |
| 2347 | returnValue = main.FALSE |
| 2348 | return returnValue |
| 2349 | except TypeError: |
| 2350 | main.log.exception( self.name + ": Object not as expected" ) |
| 2351 | return None |
| 2352 | except pexpect.EOF: |
| 2353 | main.log.error( self.name + ": EOF exception found" ) |
| 2354 | main.log.error( self.name + ": " + self.handle.before ) |
| 2355 | main.cleanup() |
| 2356 | main.exit() |
| 2357 | except Exception: |
| 2358 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2359 | main.cleanup() |
| 2360 | main.exit() |
| 2361 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2362 | def compareIntent( self, intentDict ): |
| 2363 | """ |
| 2364 | Description: |
| 2365 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2366 | Return: |
| 2367 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2368 | Arguments: |
| 2369 | intentDict: a dictionary which maps intent ids to intent states |
| 2370 | """ |
| 2371 | try: |
| 2372 | intentsRaw = self.intents() |
| 2373 | intentsJson = json.loads( intentsRaw ) |
| 2374 | intentDictONOS = {} |
| 2375 | for intent in intentsJson: |
| 2376 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2377 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2378 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2379 | 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] | 2380 | str( len( intentDict ) ) + " expected and " + |
| 2381 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2382 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2383 | for intentID in intentDict.keys(): |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2384 | if intentID not in intentDictONOS.keys(): |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2385 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2386 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2387 | else: |
| 2388 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2389 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2390 | " expected state is " + intentDict[ intentID ] + |
| 2391 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2392 | returnValue = main.FALSE |
| 2393 | intentDictONOS.pop( intentID ) |
| 2394 | if len( intentDictONOS ) > 0: |
| 2395 | returnValue = main.FALSE |
| 2396 | for intentID in intentDictONOS.keys(): |
| 2397 | 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] | 2398 | if returnValue == main.TRUE: |
| 2399 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2400 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2401 | except KeyError: |
| 2402 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2403 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2404 | except ( TypeError, ValueError ): |
| 2405 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2406 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2407 | except pexpect.EOF: |
| 2408 | main.log.error( self.name + ": EOF exception found" ) |
| 2409 | main.log.error( self.name + ": " + self.handle.before ) |
| 2410 | main.cleanup() |
| 2411 | main.exit() |
| 2412 | except Exception: |
| 2413 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2414 | main.cleanup() |
| 2415 | main.exit() |
| 2416 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2417 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2418 | """ |
| 2419 | Description: |
| 2420 | Check the number of installed intents. |
| 2421 | Optional: |
| 2422 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2423 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2424 | Return: |
| 2425 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2426 | , otherwise, returns main.FALSE. |
| 2427 | """ |
| 2428 | |
| 2429 | try: |
| 2430 | cmd = "intents -s -j" |
| 2431 | |
| 2432 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2433 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2434 | if response is None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2435 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2436 | response = json.loads( response ) |
| 2437 | |
| 2438 | # get total and installed number, see if they are match |
| 2439 | allState = response.get( 'all' ) |
| 2440 | if allState.get('total') == allState.get('installed'): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2441 | 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] | 2442 | return main.TRUE |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2443 | 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] | 2444 | return main.FALSE |
| 2445 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2446 | except ( TypeError, ValueError ): |
| 2447 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2448 | return None |
| 2449 | except pexpect.EOF: |
| 2450 | main.log.error( self.name + ": EOF exception found" ) |
| 2451 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2452 | if noExit: |
| 2453 | return main.FALSE |
| 2454 | else: |
| 2455 | main.cleanup() |
| 2456 | main.exit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2457 | except pexpect.TIMEOUT: |
| 2458 | main.log.error( self.name + ": ONOS timeout" ) |
| 2459 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2460 | except Exception: |
| 2461 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2462 | if noExit: |
| 2463 | return main.FALSE |
| 2464 | else: |
| 2465 | main.cleanup() |
| 2466 | main.exit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2467 | |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2468 | def flows( self, state="", jsonFormat=True, timeout=60, noExit=False, noCore=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2469 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2470 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2471 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2472 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2473 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2474 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2475 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2476 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2477 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2478 | if jsonFormat: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2479 | cmdStr += " -j " |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2480 | if noCore: |
| 2481 | cmdStr += " -n " |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2482 | cmdStr += state |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2483 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2484 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2485 | assert "Command not found:" not in handle, handle |
| 2486 | if re.search( "Error:", handle ): |
| 2487 | main.log.error( self.name + ": flows() response: " + |
| 2488 | str( handle ) ) |
| 2489 | return handle |
| 2490 | except AssertionError: |
| 2491 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2492 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2493 | except TypeError: |
| 2494 | main.log.exception( self.name + ": Object not as expected" ) |
| 2495 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2496 | except pexpect.TIMEOUT: |
| 2497 | main.log.error( self.name + ": ONOS timeout" ) |
| 2498 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2499 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2500 | main.log.error( self.name + ": EOF exception found" ) |
| 2501 | main.log.error( self.name + ": " + self.handle.before ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2502 | main.cleanup() |
| 2503 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2504 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2505 | main.log.exception( self.name + ": Uncaught exception!" ) |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2506 | main.cleanup() |
| 2507 | main.exit() |
| 2508 | |
Flavio Castro | d2ffffa | 2016-04-26 15:56:56 -0700 | [diff] [blame] | 2509 | def checkFlowCount(self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2510 | count = self.getTotalFlowsNum( timeout=timeout ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2511 | count = int( count ) if count else 0 |
| 2512 | return count if ( count > min ) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2513 | |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2514 | def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2515 | """ |
| 2516 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2517 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2518 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2519 | if the count of those states is 0, which means all current flows |
| 2520 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2521 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2522 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2523 | Return: |
| 2524 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2525 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2526 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2527 | """ |
| 2528 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2529 | states = ["PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED"] |
| 2530 | checkedStates = [] |
| 2531 | statesCount = [0, 0, 0, 0] |
| 2532 | for s in states: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2533 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2534 | if rawFlows: |
| 2535 | # if we didn't get flows or flows function return None, we should return |
| 2536 | # main.Flase |
| 2537 | checkedStates.append( json.loads( rawFlows ) ) |
| 2538 | else: |
| 2539 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2540 | for i in range( len( states ) ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2541 | for c in checkedStates[i]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2542 | try: |
| 2543 | statesCount[i] += int( c.get( "flowCount" ) ) |
| 2544 | except TypeError: |
| 2545 | main.log.exception( "Json object not as expected" ) |
| 2546 | main.log.info( states[i] + " flows: " + str( statesCount[i] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2547 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2548 | # We want to count PENDING_ADD if isPENDING is true |
| 2549 | if isPENDING: |
| 2550 | if statesCount[1] + statesCount[2] + statesCount[3] > 0: |
| 2551 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2552 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2553 | if statesCount[0] + statesCount[1] + statesCount[2] + statesCount[3] > 0: |
| 2554 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2555 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2556 | except ( TypeError, ValueError ): |
| 2557 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2558 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2559 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2560 | except AssertionError: |
| 2561 | main.log.exception( "" ) |
| 2562 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2563 | except pexpect.TIMEOUT: |
| 2564 | main.log.error( self.name + ": ONOS timeout" ) |
| 2565 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2566 | except pexpect.EOF: |
| 2567 | main.log.error( self.name + ": EOF exception found" ) |
| 2568 | main.log.error( self.name + ": " + self.handle.before ) |
| 2569 | main.cleanup() |
| 2570 | main.exit() |
| 2571 | except Exception: |
| 2572 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2573 | main.cleanup() |
| 2574 | main.exit() |
| 2575 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2576 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2577 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2578 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2579 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2580 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2581 | a specific point-to-point intent definition |
| 2582 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2583 | * ingress: specify source dpid |
| 2584 | * egress: specify destination dpid |
| 2585 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2586 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2587 | * offset: the keyOffset is where the next batch of intents |
| 2588 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2589 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2590 | * getResponse: If set to True, function will return ONOS response. |
| 2591 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2592 | Returns: If failed to push test intents, it will returen None, |
| 2593 | if successful, return true. |
| 2594 | Timeout expection will return None, |
| 2595 | TypeError will return false |
| 2596 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2597 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2598 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2599 | if background: |
| 2600 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2601 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2602 | back = "" |
| 2603 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2604 | ingress, |
| 2605 | egress, |
| 2606 | batchSize, |
| 2607 | offset, |
| 2608 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2609 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2610 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2611 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2612 | main.log.info( response ) |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2613 | if getResponse: |
| 2614 | return response |
| 2615 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2616 | # TODO: We should handle if there is failure in installation |
| 2617 | return main.TRUE |
| 2618 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2619 | except AssertionError: |
| 2620 | main.log.exception( "" ) |
| 2621 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2622 | except pexpect.TIMEOUT: |
| 2623 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2624 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2625 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2626 | main.log.error( self.name + ": EOF exception found" ) |
| 2627 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2628 | main.cleanup() |
| 2629 | main.exit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2630 | except TypeError: |
| 2631 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2632 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2633 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2634 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2635 | main.cleanup() |
| 2636 | main.exit() |
| 2637 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2638 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2639 | """ |
| 2640 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2641 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2642 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2643 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2644 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2645 | """ |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2646 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2647 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2648 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2649 | cmd = "flows -c added" |
| 2650 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2651 | if rawFlows: |
| 2652 | rawFlows = rawFlows.split("\n") |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2653 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2654 | for l in rawFlows: |
| 2655 | totalFlows += int(l.split("Count=")[1]) |
| 2656 | else: |
| 2657 | main.log.error("Response not as expected!") |
| 2658 | return None |
| 2659 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2660 | |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2661 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2662 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2663 | return None |
| 2664 | except pexpect.EOF: |
| 2665 | main.log.error( self.name + ": EOF exception found" ) |
| 2666 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2667 | if not noExit: |
| 2668 | main.cleanup() |
| 2669 | main.exit() |
| 2670 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2671 | except pexpect.TIMEOUT: |
| 2672 | main.log.error( self.name + ": ONOS timeout" ) |
| 2673 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2674 | except Exception: |
| 2675 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2676 | if not noExit: |
| 2677 | main.cleanup() |
| 2678 | main.exit() |
| 2679 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2680 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2681 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2682 | """ |
| 2683 | Description: |
| 2684 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2685 | Optional: |
| 2686 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2687 | Return: |
| 2688 | The number of intents |
| 2689 | """ |
| 2690 | try: |
| 2691 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2692 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2693 | if response is None: |
| 2694 | return -1 |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2695 | response = json.loads( response ) |
| 2696 | return int( response.get("intents") ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2697 | except ( TypeError, ValueError ): |
| 2698 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2699 | return None |
| 2700 | except pexpect.EOF: |
| 2701 | main.log.error( self.name + ": EOF exception found" ) |
| 2702 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2703 | if noExit: |
| 2704 | return -1 |
| 2705 | else: |
| 2706 | main.cleanup() |
| 2707 | main.exit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2708 | except Exception: |
| 2709 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2710 | if noExit: |
| 2711 | return -1 |
| 2712 | else: |
| 2713 | main.cleanup() |
| 2714 | main.exit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2715 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2716 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2717 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2718 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2719 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2720 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2721 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2722 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2723 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2724 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2725 | cmdStr += " -j" |
| 2726 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2727 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2728 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2729 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2730 | except AssertionError: |
| 2731 | main.log.exception( "" ) |
| 2732 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2733 | except TypeError: |
| 2734 | main.log.exception( self.name + ": Object not as expected" ) |
| 2735 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2736 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2737 | main.log.error( self.name + ": EOF exception found" ) |
| 2738 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2739 | main.cleanup() |
| 2740 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2741 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2742 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2743 | main.cleanup() |
| 2744 | main.exit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2745 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2746 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2747 | """ |
| 2748 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2749 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2750 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2751 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2752 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2753 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2754 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2755 | cmdStr += " -j" |
| 2756 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2757 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2758 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2759 | if handle: |
| 2760 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2761 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2762 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2763 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2764 | else: |
| 2765 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2766 | except AssertionError: |
| 2767 | main.log.exception( "" ) |
| 2768 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2769 | except TypeError: |
| 2770 | main.log.exception( self.name + ": Object not as expected" ) |
| 2771 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2772 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2773 | main.log.error( self.name + ": EOF exception found" ) |
| 2774 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2775 | main.cleanup() |
| 2776 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2777 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2778 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2779 | main.cleanup() |
| 2780 | main.exit() |
| 2781 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2782 | # Wrapper functions **************** |
| 2783 | # Wrapper functions use existing driver |
| 2784 | # functions and extends their use case. |
| 2785 | # For example, we may use the output of |
| 2786 | # a normal driver function, and parse it |
| 2787 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2788 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2789 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2790 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2791 | Description: |
| 2792 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2793 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2794 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2795 | # Obtain output of intents function |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2796 | intentsStr = self.intents(jsonFormat=True) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 2797 | if intentsStr is None: |
| 2798 | raise TypeError |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2799 | # Convert to a dictionary |
| 2800 | intents = json.loads( intentsStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2801 | intentIdList = [] |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2802 | for intent in intents: |
| 2803 | intentIdList.append( intent[ 'id' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2804 | return intentIdList |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2805 | except TypeError: |
| 2806 | main.log.exception( self.name + ": Object not as expected" ) |
| 2807 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2808 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2809 | main.log.error( self.name + ": EOF exception found" ) |
| 2810 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2811 | main.cleanup() |
| 2812 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2813 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2814 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2815 | main.cleanup() |
| 2816 | main.exit() |
| 2817 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2818 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2819 | """ |
| 2820 | Determine the number of flow rules for the given device id that are |
| 2821 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2822 | Params: |
| 2823 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2824 | """ |
| 2825 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2826 | if core: |
| 2827 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2828 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2829 | else: |
| 2830 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2831 | "grep 'state=ADDED' | wc -l" |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2832 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2833 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2834 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2835 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2836 | except AssertionError: |
| 2837 | main.log.exception( "" ) |
| 2838 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2839 | except pexpect.EOF: |
| 2840 | main.log.error( self.name + ": EOF exception found" ) |
| 2841 | main.log.error( self.name + ": " + self.handle.before ) |
| 2842 | main.cleanup() |
| 2843 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2844 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2845 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2846 | main.cleanup() |
| 2847 | main.exit() |
| 2848 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2849 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2850 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2851 | Use 'devices' function to obtain list of all devices |
| 2852 | and parse the result to obtain a list of all device |
| 2853 | id's. Returns this list. Returns empty list if no |
| 2854 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2855 | List is ordered sequentially |
| 2856 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2857 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2858 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2859 | the ids. By obtaining the list of device ids on the fly, |
| 2860 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2861 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2862 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2863 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2864 | devicesStr = self.devices( jsonFormat=False ) |
| 2865 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2866 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2867 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2868 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2869 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2870 | |
| 2871 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2872 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2873 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2874 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2875 | # Split list further into arguments before and after string |
| 2876 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2877 | # append to idList |
| 2878 | for arg in tempList: |
| 2879 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 2880 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2881 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2882 | except TypeError: |
| 2883 | main.log.exception( self.name + ": Object not as expected" ) |
| 2884 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2885 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2886 | main.log.error( self.name + ": EOF exception found" ) |
| 2887 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2888 | main.cleanup() |
| 2889 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2890 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2891 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2892 | main.cleanup() |
| 2893 | main.exit() |
| 2894 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2895 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2896 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2897 | Uses 'nodes' function to obtain list of all nodes |
| 2898 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2899 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2900 | Returns: |
| 2901 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2902 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2903 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2904 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2905 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2906 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 2907 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2908 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2909 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2910 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2911 | nodesJson = json.loads( nodesStr ) |
| 2912 | idList = [ node.get('id') for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2913 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2914 | except ( TypeError, ValueError ): |
| 2915 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2916 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2917 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2918 | main.log.error( self.name + ": EOF exception found" ) |
| 2919 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2920 | main.cleanup() |
| 2921 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2922 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2923 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2924 | main.cleanup() |
| 2925 | main.exit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2926 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2927 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2928 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2929 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 2930 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2931 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2932 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2933 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2934 | return None |
| 2935 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2936 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2937 | rawDevices = self.devices() |
| 2938 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2939 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2940 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2941 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 2942 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2943 | return device |
| 2944 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2945 | except ( TypeError, ValueError ): |
| 2946 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2947 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2948 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2949 | main.log.error( self.name + ": EOF exception found" ) |
| 2950 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2951 | main.cleanup() |
| 2952 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2953 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2954 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2955 | main.cleanup() |
| 2956 | main.exit() |
| 2957 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2958 | def getTopology( self, topologyOutput ): |
| 2959 | """ |
| 2960 | Definition: |
| 2961 | Loads a json topology output |
| 2962 | Return: |
| 2963 | topology = current ONOS topology |
| 2964 | """ |
| 2965 | import json |
| 2966 | try: |
| 2967 | # either onos:topology or 'topology' will work in CLI |
| 2968 | topology = json.loads(topologyOutput) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 2969 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2970 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2971 | except ( TypeError, ValueError ): |
| 2972 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 2973 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2974 | except pexpect.EOF: |
| 2975 | main.log.error( self.name + ": EOF exception found" ) |
| 2976 | main.log.error( self.name + ": " + self.handle.before ) |
| 2977 | main.cleanup() |
| 2978 | main.exit() |
| 2979 | except Exception: |
| 2980 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2981 | main.cleanup() |
| 2982 | main.exit() |
| 2983 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2984 | def checkStatus(self, numoswitch, numolink, numoctrl = -1, logLevel="info"): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2985 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2986 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2987 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2988 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2989 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2990 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2991 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2992 | numoctrl = expected number of controllers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2993 | logLevel = level to log to. |
| 2994 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2995 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2996 | Returns: main.TRUE if the number of switches and links are correct, |
| 2997 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2998 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2999 | """ |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3000 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3001 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 3002 | summary = self.summary() |
| 3003 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 3004 | except ( TypeError, ValueError ): |
| 3005 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 3006 | return main.ERROR |
| 3007 | try: |
| 3008 | topology = self.getTopology( self.topology() ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 3009 | if topology == {} or topology is None or summary == {} or summary is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3010 | return main.ERROR |
| 3011 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3012 | # Is the number of switches is what we expected |
| 3013 | devices = topology.get( 'devices', False ) |
| 3014 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3015 | nodes = summary.get( 'nodes', False ) |
| 3016 | if devices is False or links is False or nodes is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3017 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3018 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3019 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3020 | linkCheck = ( int( links ) == int( numolink ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3021 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
| 3022 | if switchCheck and linkCheck and nodeCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3023 | # We expected the correct numbers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3024 | output = output + "The number of links and switches match "\ |
| 3025 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3026 | result = main.TRUE |
| 3027 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3028 | output = output + \ |
| 3029 | "The number of links and switches does not match " + \ |
| 3030 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3031 | result = main.FALSE |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3032 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 3033 | output = output + " (%i expected) " % int( numoswitch ) |
| 3034 | output = output + "and %i links " % int( links ) |
| 3035 | output = output + "(%i expected)" % int( numolink ) |
YPZhang | d7e4b6e | 2016-06-17 16:07:55 -0700 | [diff] [blame] | 3036 | if int( numoctrl ) > 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3037 | output = output + "and %i controllers " % int( nodes ) |
| 3038 | output = output + "(%i expected)" % int( numoctrl ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3039 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3040 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3041 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3042 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3043 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3044 | main.log.info( output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3045 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3046 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3047 | main.log.error( self.name + ": EOF exception found" ) |
| 3048 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3049 | main.cleanup() |
| 3050 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3051 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3052 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3053 | main.cleanup() |
| 3054 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3055 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3056 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3057 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3058 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3059 | deviceId must be the id of a device as seen in the onos devices command |
| 3060 | 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] | 3061 | role must be either master, standby, or none |
| 3062 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3063 | Returns: |
| 3064 | main.TRUE or main.FALSE based on argument verification and |
| 3065 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3066 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3067 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3068 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3069 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3070 | cmdStr = "device-role " +\ |
| 3071 | str( deviceId ) + " " +\ |
| 3072 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3073 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3074 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3075 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3076 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3077 | if re.search( "Error", handle ): |
| 3078 | # end color output to escape any colours |
| 3079 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3080 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3081 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3082 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3083 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3084 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3085 | main.log.error( "Invalid 'role' given to device_role(). " + |
| 3086 | "Value was '" + str(role) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3087 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3088 | except AssertionError: |
| 3089 | main.log.exception( "" ) |
| 3090 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3091 | except TypeError: |
| 3092 | main.log.exception( self.name + ": Object not as expected" ) |
| 3093 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3094 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3095 | main.log.error( self.name + ": EOF exception found" ) |
| 3096 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3097 | main.cleanup() |
| 3098 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3099 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3100 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3101 | main.cleanup() |
| 3102 | main.exit() |
| 3103 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3104 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3105 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3106 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 3107 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3108 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3109 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3110 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3111 | cmdStr = "clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3112 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3113 | cmdStr += " -j" |
| 3114 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3115 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3116 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3117 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3118 | except AssertionError: |
| 3119 | main.log.exception( "" ) |
| 3120 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3121 | except TypeError: |
| 3122 | main.log.exception( self.name + ": Object not as expected" ) |
| 3123 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3124 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3125 | main.log.error( self.name + ": EOF exception found" ) |
| 3126 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3127 | main.cleanup() |
| 3128 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3129 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3130 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3131 | main.cleanup() |
| 3132 | main.exit() |
| 3133 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3134 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3135 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3136 | CLI command to get the current leader for the Election test application |
| 3137 | NOTE: Requires installation of the onos-app-election feature |
| 3138 | Returns: Node IP of the leader if one exists |
| 3139 | None if none exists |
| 3140 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3141 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3142 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3143 | cmdStr = "election-test-leader" |
| 3144 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3145 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3146 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3147 | # Leader |
| 3148 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3149 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3150 | nodeSearch = re.search( leaderPattern, response ) |
| 3151 | if nodeSearch: |
| 3152 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3153 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3154 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3155 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3156 | # no leader |
| 3157 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3158 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3159 | nullSearch = re.search( nullPattern, response ) |
| 3160 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3161 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3162 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3163 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3164 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3165 | main.log.error( "Error in electionTestLeader on " + self.name + |
| 3166 | ": " + "unexpected response" ) |
| 3167 | main.log.error( repr( response ) ) |
| 3168 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3169 | except AssertionError: |
| 3170 | main.log.exception( "" ) |
| 3171 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3172 | except TypeError: |
| 3173 | main.log.exception( self.name + ": Object not as expected" ) |
| 3174 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3175 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3176 | main.log.error( self.name + ": EOF exception found" ) |
| 3177 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3178 | main.cleanup() |
| 3179 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3180 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3181 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3182 | main.cleanup() |
| 3183 | main.exit() |
| 3184 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3185 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3186 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3187 | CLI command to run for leadership of the Election test application. |
| 3188 | NOTE: Requires installation of the onos-app-election feature |
| 3189 | Returns: Main.TRUE on success |
| 3190 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3191 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3192 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3193 | cmdStr = "election-test-run" |
| 3194 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3195 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3196 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3197 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3198 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3199 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3200 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3201 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3202 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3203 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3204 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3205 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3206 | main.log.error( "Error in electionTestRun on " + self.name + |
| 3207 | ": " + "unexpected response" ) |
| 3208 | main.log.error( repr( response ) ) |
| 3209 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3210 | except AssertionError: |
| 3211 | main.log.exception( "" ) |
| 3212 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3213 | except TypeError: |
| 3214 | main.log.exception( self.name + ": Object not as expected" ) |
| 3215 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3216 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3217 | main.log.error( self.name + ": EOF exception found" ) |
| 3218 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3219 | main.cleanup() |
| 3220 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3221 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3222 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3223 | main.cleanup() |
| 3224 | main.exit() |
| 3225 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3226 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3227 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3228 | * CLI command to withdraw the local node from leadership election for |
| 3229 | * the Election test application. |
| 3230 | #NOTE: Requires installation of the onos-app-election feature |
| 3231 | Returns: Main.TRUE on success |
| 3232 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3233 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3234 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3235 | cmdStr = "election-test-withdraw" |
| 3236 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3237 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3238 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3239 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3240 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3241 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3242 | if re.search( successPattern, response ): |
| 3243 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3244 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3245 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3246 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3247 | main.log.error( "Error in electionTestWithdraw on " + |
| 3248 | self.name + ": " + "unexpected response" ) |
| 3249 | main.log.error( repr( response ) ) |
| 3250 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3251 | except AssertionError: |
| 3252 | main.log.exception( "" ) |
| 3253 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3254 | except TypeError: |
| 3255 | main.log.exception( self.name + ": Object not as expected" ) |
| 3256 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3257 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3258 | main.log.error( self.name + ": EOF exception found" ) |
| 3259 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3260 | main.cleanup() |
| 3261 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3262 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3263 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3264 | main.cleanup() |
| 3265 | main.exit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3266 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3267 | def getDevicePortsEnabledCount( self, dpid ): |
| 3268 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3269 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3270 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3271 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3272 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3273 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 3274 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3275 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3276 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3277 | if re.search( "No such device", output ): |
| 3278 | main.log.error( "Error in getting ports" ) |
| 3279 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3280 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3281 | except AssertionError: |
| 3282 | main.log.exception( "" ) |
| 3283 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3284 | except TypeError: |
| 3285 | main.log.exception( self.name + ": Object not as expected" ) |
| 3286 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3287 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3288 | main.log.error( self.name + ": EOF exception found" ) |
| 3289 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3290 | main.cleanup() |
| 3291 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3292 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3293 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3294 | main.cleanup() |
| 3295 | main.exit() |
| 3296 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3297 | def getDeviceLinksActiveCount( self, dpid ): |
| 3298 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3299 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3300 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3301 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3302 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3303 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 3304 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3305 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3306 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3307 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3308 | main.log.error( "Error in getting ports " ) |
| 3309 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3310 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3311 | except AssertionError: |
| 3312 | main.log.exception( "" ) |
| 3313 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3314 | except TypeError: |
| 3315 | main.log.exception( self.name + ": Object not as expected" ) |
| 3316 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3317 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3318 | main.log.error( self.name + ": EOF exception found" ) |
| 3319 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3320 | main.cleanup() |
| 3321 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3322 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3323 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3324 | main.cleanup() |
| 3325 | main.exit() |
| 3326 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3327 | def getAllIntentIds( self ): |
| 3328 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3329 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3330 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3331 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3332 | cmdStr = "onos:intents | grep id=" |
| 3333 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3334 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3335 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3336 | if re.search( "Error", output ): |
| 3337 | main.log.error( "Error in getting ports" ) |
| 3338 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3339 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3340 | except AssertionError: |
| 3341 | main.log.exception( "" ) |
| 3342 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3343 | except TypeError: |
| 3344 | main.log.exception( self.name + ": Object not as expected" ) |
| 3345 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3346 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3347 | main.log.error( self.name + ": EOF exception found" ) |
| 3348 | main.log.error( self.name + ": " + self.handle.before ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3349 | main.cleanup() |
| 3350 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3351 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3352 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3353 | main.cleanup() |
| 3354 | main.exit() |
| 3355 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3356 | def intentSummary( self ): |
| 3357 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3358 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3359 | """ |
| 3360 | try: |
| 3361 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3362 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3363 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3364 | states.append( intent.get( 'state', None ) ) |
| 3365 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3366 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3367 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3368 | except ( TypeError, ValueError ): |
| 3369 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3370 | return None |
| 3371 | except pexpect.EOF: |
| 3372 | main.log.error( self.name + ": EOF exception found" ) |
| 3373 | main.log.error( self.name + ": " + self.handle.before ) |
| 3374 | main.cleanup() |
| 3375 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3376 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3377 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3378 | main.cleanup() |
| 3379 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3380 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3381 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3382 | """ |
| 3383 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3384 | Optional argument: |
| 3385 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3386 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3387 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3388 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3389 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3390 | cmdStr += " -j" |
| 3391 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3392 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3393 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3394 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3395 | except AssertionError: |
| 3396 | main.log.exception( "" ) |
| 3397 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3398 | except TypeError: |
| 3399 | main.log.exception( self.name + ": Object not as expected" ) |
| 3400 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3401 | except pexpect.EOF: |
| 3402 | main.log.error( self.name + ": EOF exception found" ) |
| 3403 | main.log.error( self.name + ": " + self.handle.before ) |
| 3404 | main.cleanup() |
| 3405 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3406 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3407 | main.log.exception( self.name + ": Uncaught exception!" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3408 | main.cleanup() |
| 3409 | main.exit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3410 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3411 | def leaderCandidates( self, jsonFormat=True ): |
| 3412 | """ |
| 3413 | Returns the output of the leaders -c command. |
| 3414 | Optional argument: |
| 3415 | * jsonFormat - boolean indicating if you want output in json |
| 3416 | """ |
| 3417 | try: |
| 3418 | cmdStr = "onos:leaders -c" |
| 3419 | if jsonFormat: |
| 3420 | cmdStr += " -j" |
| 3421 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3422 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3423 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3424 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3425 | except AssertionError: |
| 3426 | main.log.exception( "" ) |
| 3427 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3428 | except TypeError: |
| 3429 | main.log.exception( self.name + ": Object not as expected" ) |
| 3430 | return None |
| 3431 | except pexpect.EOF: |
| 3432 | main.log.error( self.name + ": EOF exception found" ) |
| 3433 | main.log.error( self.name + ": " + self.handle.before ) |
| 3434 | main.cleanup() |
| 3435 | main.exit() |
| 3436 | except Exception: |
| 3437 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3438 | main.cleanup() |
| 3439 | main.exit() |
| 3440 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3441 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3442 | """ |
| 3443 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
| 3444 | topic parameter and an empty list if the topic doesn't exist |
| 3445 | If no leader is elected leader in the returned list will be "none" |
| 3446 | Returns None if there is a type error processing the json object |
| 3447 | """ |
| 3448 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3449 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3450 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3451 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3452 | assert "Command not found:" not in rawOutput, rawOutput |
| 3453 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3454 | results = [] |
| 3455 | for dict in output: |
| 3456 | if dict["topic"] == topic: |
| 3457 | leader = dict["leader"] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3458 | candidates = re.split( ", ", dict["candidates"][1:-1] ) |
| 3459 | results.append( leader ) |
| 3460 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3461 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3462 | except AssertionError: |
| 3463 | main.log.exception( "" ) |
| 3464 | return None |
| 3465 | except ( TypeError, ValueError ): |
| 3466 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3467 | return None |
| 3468 | except pexpect.EOF: |
| 3469 | main.log.error( self.name + ": EOF exception found" ) |
| 3470 | main.log.error( self.name + ": " + self.handle.before ) |
| 3471 | main.cleanup() |
| 3472 | main.exit() |
| 3473 | except Exception: |
| 3474 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3475 | main.cleanup() |
| 3476 | main.exit() |
| 3477 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3478 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3479 | """ |
| 3480 | Returns the output of the intent Pending map. |
| 3481 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3482 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3483 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3484 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3485 | cmdStr += " -j" |
| 3486 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3487 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3488 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3489 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3490 | except AssertionError: |
| 3491 | main.log.exception( "" ) |
| 3492 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3493 | except TypeError: |
| 3494 | main.log.exception( self.name + ": Object not as expected" ) |
| 3495 | return None |
| 3496 | except pexpect.EOF: |
| 3497 | main.log.error( self.name + ": EOF exception found" ) |
| 3498 | main.log.error( self.name + ": " + self.handle.before ) |
| 3499 | main.cleanup() |
| 3500 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3501 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3502 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3503 | main.cleanup() |
| 3504 | main.exit() |
| 3505 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3506 | def partitions( self, candidates=False, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3507 | """ |
| 3508 | Returns the output of the raft partitions command for ONOS. |
| 3509 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3510 | # Sample JSON |
| 3511 | # { |
| 3512 | # "leader": "tcp://10.128.30.11:7238", |
| 3513 | # "members": [ |
| 3514 | # "tcp://10.128.30.11:7238", |
| 3515 | # "tcp://10.128.30.17:7238", |
| 3516 | # "tcp://10.128.30.13:7238", |
| 3517 | # ], |
| 3518 | # "name": "p1", |
| 3519 | # "term": 3 |
| 3520 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3521 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3522 | cmdStr = "onos:partitions" |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3523 | if candidates: |
| 3524 | cmdStr += " -c" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3525 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3526 | cmdStr += " -j" |
| 3527 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3528 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3529 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3530 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3531 | except AssertionError: |
| 3532 | main.log.exception( "" ) |
| 3533 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3534 | except TypeError: |
| 3535 | main.log.exception( self.name + ": Object not as expected" ) |
| 3536 | return None |
| 3537 | except pexpect.EOF: |
| 3538 | main.log.error( self.name + ": EOF exception found" ) |
| 3539 | main.log.error( self.name + ": " + self.handle.before ) |
| 3540 | main.cleanup() |
| 3541 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3542 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3543 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3544 | main.cleanup() |
| 3545 | main.exit() |
| 3546 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3547 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3548 | """ |
| 3549 | Returns the output of the apps command for ONOS. This command lists |
| 3550 | information about installed ONOS applications |
| 3551 | """ |
| 3552 | # Sample JSON object |
| 3553 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
| 3554 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3555 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
| 3556 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
| 3557 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3558 | cmdStr = "onos:apps" |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3559 | if summary: |
| 3560 | cmdStr += " -s" |
| 3561 | if active: |
| 3562 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3563 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3564 | cmdStr += " -j" |
| 3565 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3566 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3567 | assert "Command not found:" not in output, output |
| 3568 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3569 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3570 | # FIXME: look at specific exceptions/Errors |
| 3571 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3572 | main.log.exception( "Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3573 | return None |
| 3574 | except TypeError: |
| 3575 | main.log.exception( self.name + ": Object not as expected" ) |
| 3576 | return None |
| 3577 | except pexpect.EOF: |
| 3578 | main.log.error( self.name + ": EOF exception found" ) |
| 3579 | main.log.error( self.name + ": " + self.handle.before ) |
| 3580 | main.cleanup() |
| 3581 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3582 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3583 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3584 | main.cleanup() |
| 3585 | main.exit() |
| 3586 | |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3587 | def appStatus( self, appName ): |
| 3588 | """ |
| 3589 | Uses the onos:apps cli command to return the status of an application. |
| 3590 | Returns: |
| 3591 | "ACTIVE" - If app is installed and activated |
| 3592 | "INSTALLED" - If app is installed and deactivated |
| 3593 | "UNINSTALLED" - If app is not installed |
| 3594 | None - on error |
| 3595 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3596 | try: |
| 3597 | if not isinstance( appName, types.StringType ): |
| 3598 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3599 | " a string" ) |
| 3600 | return None |
| 3601 | output = self.apps( jsonFormat=True ) |
| 3602 | appsJson = json.loads( output ) |
| 3603 | state = None |
| 3604 | for app in appsJson: |
| 3605 | if appName == app.get('name'): |
| 3606 | state = app.get('state') |
| 3607 | break |
| 3608 | if state == "ACTIVE" or state == "INSTALLED": |
| 3609 | return state |
| 3610 | elif state is None: |
| 3611 | return "UNINSTALLED" |
| 3612 | elif state: |
| 3613 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3614 | str( state ) ) |
| 3615 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3616 | except ( TypeError, ValueError ): |
| 3617 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3618 | return None |
| 3619 | except pexpect.EOF: |
| 3620 | main.log.error( self.name + ": EOF exception found" ) |
| 3621 | main.log.error( self.name + ": " + self.handle.before ) |
| 3622 | main.cleanup() |
| 3623 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3624 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3625 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3626 | main.cleanup() |
| 3627 | main.exit() |
| 3628 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3629 | def app( self, appName, option ): |
| 3630 | """ |
| 3631 | Interacts with the app command for ONOS. This command manages |
| 3632 | application inventory. |
| 3633 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3634 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3635 | # Validate argument types |
| 3636 | valid = True |
| 3637 | if not isinstance( appName, types.StringType ): |
| 3638 | main.log.error( self.name + ".app(): appName must be a " + |
| 3639 | "string" ) |
| 3640 | valid = False |
| 3641 | if not isinstance( option, types.StringType ): |
| 3642 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3643 | valid = False |
| 3644 | if not valid: |
| 3645 | return main.FALSE |
| 3646 | # Validate Option |
| 3647 | option = option.lower() |
| 3648 | # NOTE: Install may become a valid option |
| 3649 | if option == "activate": |
| 3650 | pass |
| 3651 | elif option == "deactivate": |
| 3652 | pass |
| 3653 | elif option == "uninstall": |
| 3654 | pass |
| 3655 | else: |
| 3656 | # Invalid option |
| 3657 | main.log.error( "The ONOS app command argument only takes " + |
| 3658 | "the values: (activate|deactivate|uninstall)" + |
| 3659 | "; was given '" + option + "'") |
| 3660 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3661 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3662 | output = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3663 | assert output is not None, "Error in sendline" |
| 3664 | assert "Command not found:" not in output, output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3665 | if "Error executing command" in output: |
| 3666 | main.log.error( "Error in processing onos:app command: " + |
| 3667 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3668 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3669 | elif "No such application" in output: |
| 3670 | main.log.error( "The application '" + appName + |
| 3671 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3672 | return main.FALSE |
| 3673 | elif "Command not found:" in output: |
| 3674 | main.log.error( "Error in processing onos:app command: " + |
| 3675 | str( output ) ) |
| 3676 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3677 | elif "Unsupported command:" in output: |
| 3678 | main.log.error( "Incorrect command given to 'app': " + |
| 3679 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3680 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3681 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3682 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3683 | return main.TRUE |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3684 | except AssertionError: |
| 3685 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 3686 | return main.ERROR |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3687 | except TypeError: |
| 3688 | main.log.exception( self.name + ": Object not as expected" ) |
| 3689 | return main.ERROR |
| 3690 | except pexpect.EOF: |
| 3691 | main.log.error( self.name + ": EOF exception found" ) |
| 3692 | main.log.error( self.name + ": " + self.handle.before ) |
| 3693 | main.cleanup() |
| 3694 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3695 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3696 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3697 | main.cleanup() |
| 3698 | main.exit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3699 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3700 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3701 | """ |
| 3702 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3703 | appName is the hierarchical app name, not the feature name |
| 3704 | If check is True, method will check the status of the app after the |
| 3705 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3706 | Returns main.TRUE if the command was successfully sent |
| 3707 | main.FALSE if the cli responded with an error or given |
| 3708 | incorrect input |
| 3709 | """ |
| 3710 | try: |
| 3711 | if not isinstance( appName, types.StringType ): |
| 3712 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3713 | " a string" ) |
| 3714 | return main.FALSE |
| 3715 | status = self.appStatus( appName ) |
| 3716 | if status == "INSTALLED": |
| 3717 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3718 | if check and response == main.TRUE: |
| 3719 | for i in range(10): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3720 | status = self.appStatus( appName ) |
| 3721 | if status == "ACTIVE": |
| 3722 | return main.TRUE |
| 3723 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3724 | main.log.debug( "The state of application " + |
| 3725 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3726 | time.sleep( 1 ) |
| 3727 | return main.FALSE |
| 3728 | else: # not 'check' or command didn't succeed |
| 3729 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3730 | elif status == "ACTIVE": |
| 3731 | return main.TRUE |
| 3732 | elif status == "UNINSTALLED": |
| 3733 | main.log.error( self.name + ": Tried to activate the " + |
| 3734 | "application '" + appName + "' which is not " + |
| 3735 | "installed." ) |
| 3736 | else: |
| 3737 | main.log.error( "Unexpected return value from appStatus: " + |
| 3738 | str( status ) ) |
| 3739 | return main.ERROR |
| 3740 | except TypeError: |
| 3741 | main.log.exception( self.name + ": Object not as expected" ) |
| 3742 | return main.ERROR |
| 3743 | except pexpect.EOF: |
| 3744 | main.log.error( self.name + ": EOF exception found" ) |
| 3745 | main.log.error( self.name + ": " + self.handle.before ) |
| 3746 | main.cleanup() |
| 3747 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3748 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3749 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3750 | main.cleanup() |
| 3751 | main.exit() |
| 3752 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3753 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3754 | """ |
| 3755 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3756 | appName is the hierarchical app name, not the feature name |
| 3757 | If check is True, method will check the status of the app after the |
| 3758 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3759 | Returns main.TRUE if the command was successfully sent |
| 3760 | main.FALSE if the cli responded with an error or given |
| 3761 | incorrect input |
| 3762 | """ |
| 3763 | try: |
| 3764 | if not isinstance( appName, types.StringType ): |
| 3765 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 3766 | "be a string" ) |
| 3767 | return main.FALSE |
| 3768 | status = self.appStatus( appName ) |
| 3769 | if status == "INSTALLED": |
| 3770 | return main.TRUE |
| 3771 | elif status == "ACTIVE": |
| 3772 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3773 | if check and response == main.TRUE: |
| 3774 | for i in range(10): # try 10 times then give up |
| 3775 | status = self.appStatus( appName ) |
| 3776 | if status == "INSTALLED": |
| 3777 | return main.TRUE |
| 3778 | else: |
| 3779 | time.sleep( 1 ) |
| 3780 | return main.FALSE |
| 3781 | else: # not check or command didn't succeed |
| 3782 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3783 | elif status == "UNINSTALLED": |
| 3784 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 3785 | "application '" + appName + "' which is not " + |
| 3786 | "installed." ) |
| 3787 | return main.TRUE |
| 3788 | else: |
| 3789 | main.log.error( "Unexpected return value from appStatus: " + |
| 3790 | str( status ) ) |
| 3791 | return main.ERROR |
| 3792 | except TypeError: |
| 3793 | main.log.exception( self.name + ": Object not as expected" ) |
| 3794 | return main.ERROR |
| 3795 | except pexpect.EOF: |
| 3796 | main.log.error( self.name + ": EOF exception found" ) |
| 3797 | main.log.error( self.name + ": " + self.handle.before ) |
| 3798 | main.cleanup() |
| 3799 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3800 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3801 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3802 | main.cleanup() |
| 3803 | main.exit() |
| 3804 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3805 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3806 | """ |
| 3807 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3808 | appName is the hierarchical app name, not the feature name |
| 3809 | If check is True, method will check the status of the app after the |
| 3810 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3811 | Returns main.TRUE if the command was successfully sent |
| 3812 | main.FALSE if the cli responded with an error or given |
| 3813 | incorrect input |
| 3814 | """ |
| 3815 | # TODO: check with Thomas about the state machine for apps |
| 3816 | try: |
| 3817 | if not isinstance( appName, types.StringType ): |
| 3818 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 3819 | "be a string" ) |
| 3820 | return main.FALSE |
| 3821 | status = self.appStatus( appName ) |
| 3822 | if status == "INSTALLED": |
| 3823 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3824 | if check and response == main.TRUE: |
| 3825 | for i in range(10): # try 10 times then give up |
| 3826 | status = self.appStatus( appName ) |
| 3827 | if status == "UNINSTALLED": |
| 3828 | return main.TRUE |
| 3829 | else: |
| 3830 | time.sleep( 1 ) |
| 3831 | return main.FALSE |
| 3832 | else: # not check or command didn't succeed |
| 3833 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3834 | elif status == "ACTIVE": |
| 3835 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 3836 | "application '" + appName + "' which is " + |
| 3837 | "currently active." ) |
| 3838 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3839 | if check and response == main.TRUE: |
| 3840 | for i in range(10): # try 10 times then give up |
| 3841 | status = self.appStatus( appName ) |
| 3842 | if status == "UNINSTALLED": |
| 3843 | return main.TRUE |
| 3844 | else: |
| 3845 | time.sleep( 1 ) |
| 3846 | return main.FALSE |
| 3847 | else: # not check or command didn't succeed |
| 3848 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3849 | elif status == "UNINSTALLED": |
| 3850 | return main.TRUE |
| 3851 | else: |
| 3852 | main.log.error( "Unexpected return value from appStatus: " + |
| 3853 | str( status ) ) |
| 3854 | return main.ERROR |
| 3855 | except TypeError: |
| 3856 | main.log.exception( self.name + ": Object not as expected" ) |
| 3857 | return main.ERROR |
| 3858 | except pexpect.EOF: |
| 3859 | main.log.error( self.name + ": EOF exception found" ) |
| 3860 | main.log.error( self.name + ": " + self.handle.before ) |
| 3861 | main.cleanup() |
| 3862 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3863 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3864 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3865 | main.cleanup() |
| 3866 | main.exit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3867 | |
| 3868 | def appIDs( self, jsonFormat=True ): |
| 3869 | """ |
| 3870 | Show the mappings between app id and app names given by the 'app-ids' |
| 3871 | cli command |
| 3872 | """ |
| 3873 | try: |
| 3874 | cmdStr = "app-ids" |
| 3875 | if jsonFormat: |
| 3876 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3877 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3878 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3879 | assert "Command not found:" not in output, output |
| 3880 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3881 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3882 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3883 | main.log.exception( "Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3884 | return None |
| 3885 | except TypeError: |
| 3886 | main.log.exception( self.name + ": Object not as expected" ) |
| 3887 | return None |
| 3888 | except pexpect.EOF: |
| 3889 | main.log.error( self.name + ": EOF exception found" ) |
| 3890 | main.log.error( self.name + ": " + self.handle.before ) |
| 3891 | main.cleanup() |
| 3892 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3893 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3894 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3895 | main.cleanup() |
| 3896 | main.exit() |
| 3897 | |
| 3898 | def appToIDCheck( self ): |
| 3899 | """ |
| 3900 | This method will check that each application's ID listed in 'apps' is |
| 3901 | the same as the ID listed in 'app-ids'. The check will also check that |
| 3902 | there are no duplicate IDs issued. Note that an app ID should be |
| 3903 | a globaly unique numerical identifier for app/app-like features. Once |
| 3904 | an ID is registered, the ID is never freed up so that if an app is |
| 3905 | reinstalled it will have the same ID. |
| 3906 | |
| 3907 | Returns: main.TRUE if the check passes and |
| 3908 | main.FALSE if the check fails or |
| 3909 | main.ERROR if there is some error in processing the test |
| 3910 | """ |
| 3911 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3912 | bail = False |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3913 | rawJson = self.appIDs( jsonFormat=True ) |
| 3914 | if rawJson: |
| 3915 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3916 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3917 | main.log.error( "app-ids returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3918 | bail = True |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3919 | rawJson = self.apps( jsonFormat=True ) |
| 3920 | if rawJson: |
| 3921 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3922 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3923 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3924 | bail = True |
| 3925 | if bail: |
| 3926 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3927 | result = main.TRUE |
| 3928 | for app in apps: |
| 3929 | appID = app.get( 'id' ) |
| 3930 | if appID is None: |
| 3931 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3932 | result = main.FALSE |
| 3933 | appName = app.get( 'name' ) |
| 3934 | if appName is None: |
| 3935 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3936 | result = main.FALSE |
| 3937 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3938 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3939 | # main.log.debug( "Comparing " + str( app ) + " to " + |
| 3940 | # str( current ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3941 | if not current: # if ids doesn't have this id |
| 3942 | result = main.FALSE |
| 3943 | main.log.error( "'app-ids' does not have the ID for " + |
| 3944 | str( appName ) + " that apps does." ) |
| 3945 | elif len( current ) > 1: |
| 3946 | # there is more than one app with this ID |
| 3947 | result = main.FALSE |
| 3948 | # We will log this later in the method |
| 3949 | elif not current[0][ 'name' ] == appName: |
| 3950 | currentName = current[0][ 'name' ] |
| 3951 | result = main.FALSE |
| 3952 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 3953 | " registered under id:" + str( appID ) + |
| 3954 | " but 'apps' has " + str( appName ) ) |
| 3955 | else: |
| 3956 | pass # id and name match! |
| 3957 | # now make sure that app-ids has no duplicates |
| 3958 | idsList = [] |
| 3959 | namesList = [] |
| 3960 | for item in ids: |
| 3961 | idsList.append( item[ 'id' ] ) |
| 3962 | namesList.append( item[ 'name' ] ) |
| 3963 | if len( idsList ) != len( set( idsList ) ) or\ |
| 3964 | len( namesList ) != len( set( namesList ) ): |
| 3965 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 3966 | + json.dumps( ids, |
| 3967 | sort_keys=True, |
| 3968 | indent=4, |
| 3969 | separators=( ',', ': ' ) ) ) |
| 3970 | result = main.FALSE |
| 3971 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3972 | except ( TypeError, ValueError ): |
| 3973 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3974 | return main.ERROR |
| 3975 | except pexpect.EOF: |
| 3976 | main.log.error( self.name + ": EOF exception found" ) |
| 3977 | main.log.error( self.name + ": " + self.handle.before ) |
| 3978 | main.cleanup() |
| 3979 | main.exit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3980 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3981 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3982 | main.cleanup() |
| 3983 | main.exit() |
| 3984 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3985 | def getCfg( self, component=None, propName=None, short=False, |
| 3986 | jsonFormat=True ): |
| 3987 | """ |
| 3988 | Get configuration settings from onos cli |
| 3989 | Optional arguments: |
| 3990 | component - Optionally only list configurations for a specific |
| 3991 | component. If None, all components with configurations |
| 3992 | are displayed. Case Sensitive string. |
| 3993 | propName - If component is specified, propName option will show |
| 3994 | only this specific configuration from that component. |
| 3995 | Case Sensitive string. |
| 3996 | jsonFormat - Returns output as json. Note that this will override |
| 3997 | the short option |
| 3998 | short - Short, less verbose, version of configurations. |
| 3999 | This is overridden by the json option |
| 4000 | returns: |
| 4001 | Output from cli as a string or None on error |
| 4002 | """ |
| 4003 | try: |
| 4004 | baseStr = "cfg" |
| 4005 | cmdStr = " get" |
| 4006 | componentStr = "" |
| 4007 | if component: |
| 4008 | componentStr += " " + component |
| 4009 | if propName: |
| 4010 | componentStr += " " + propName |
| 4011 | if jsonFormat: |
| 4012 | baseStr += " -j" |
| 4013 | elif short: |
| 4014 | baseStr += " -s" |
| 4015 | output = self.sendline( baseStr + cmdStr + componentStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4016 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4017 | assert "Command not found:" not in output, output |
| 4018 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4019 | return output |
| 4020 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4021 | main.log.exception( "Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4022 | return None |
| 4023 | except TypeError: |
| 4024 | main.log.exception( self.name + ": Object not as expected" ) |
| 4025 | return None |
| 4026 | except pexpect.EOF: |
| 4027 | main.log.error( self.name + ": EOF exception found" ) |
| 4028 | main.log.error( self.name + ": " + self.handle.before ) |
| 4029 | main.cleanup() |
| 4030 | main.exit() |
| 4031 | except Exception: |
| 4032 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4033 | main.cleanup() |
| 4034 | main.exit() |
| 4035 | |
| 4036 | def setCfg( self, component, propName, value=None, check=True ): |
| 4037 | """ |
| 4038 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4039 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4040 | component - The case sensitive name of the component whose |
| 4041 | property is to be set |
| 4042 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4043 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4044 | value - The value to set the property to. If None, will unset the |
| 4045 | property and revert it to it's default value(if applicable) |
| 4046 | check - Boolean, Check whether the option was successfully set this |
| 4047 | only applies when a value is given. |
| 4048 | returns: |
| 4049 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 4050 | will return main.TRUE unless there is an error |
| 4051 | """ |
| 4052 | try: |
| 4053 | baseStr = "cfg" |
| 4054 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 4055 | if value is not None: |
| 4056 | cmdStr += " " + str( value ) |
| 4057 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4058 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4059 | assert "Command not found:" not in output, output |
| 4060 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4061 | if value and check: |
| 4062 | results = self.getCfg( component=str( component ), |
| 4063 | propName=str( propName ), |
| 4064 | jsonFormat=True ) |
| 4065 | # Check if current value is what we just set |
| 4066 | try: |
| 4067 | jsonOutput = json.loads( results ) |
| 4068 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4069 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4070 | main.log.exception( "Error parsing cfg output" ) |
| 4071 | main.log.error( "output:" + repr( results ) ) |
| 4072 | return main.FALSE |
| 4073 | if current == str( value ): |
| 4074 | return main.TRUE |
| 4075 | return main.FALSE |
| 4076 | return main.TRUE |
| 4077 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4078 | main.log.exception( "Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4079 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4080 | except ( TypeError, ValueError ): |
| 4081 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4082 | return main.FALSE |
| 4083 | except pexpect.EOF: |
| 4084 | main.log.error( self.name + ": EOF exception found" ) |
| 4085 | main.log.error( self.name + ": " + self.handle.before ) |
| 4086 | main.cleanup() |
| 4087 | main.exit() |
| 4088 | except Exception: |
| 4089 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4090 | main.cleanup() |
| 4091 | main.exit() |
| 4092 | |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4093 | def distPrimitivesSend( self, cmd ): |
| 4094 | """ |
| 4095 | Function to handle sending cli commands for the distributed primitives test app |
| 4096 | |
| 4097 | This command will catch some exceptions and retry the command on some |
| 4098 | specific store exceptions. |
| 4099 | |
| 4100 | Required arguments: |
| 4101 | cmd - The command to send to the cli |
| 4102 | returns: |
| 4103 | string containing the cli output |
| 4104 | None on Error |
| 4105 | """ |
| 4106 | try: |
| 4107 | output = self.sendline( cmd ) |
| 4108 | try: |
| 4109 | assert output is not None, "Error in sendline" |
| 4110 | # TODO: Maybe make this less hardcoded |
| 4111 | # ConsistentMap Exceptions |
| 4112 | assert "org.onosproject.store.service" not in output |
| 4113 | # Node not leader |
| 4114 | assert "java.lang.IllegalStateException" not in output |
| 4115 | except AssertionError: |
| 4116 | main.log.error( "Error in processing '" + cmd + "' " + |
| 4117 | "command: " + str( output ) ) |
| 4118 | retryTime = 30 # Conservative time, given by Madan |
| 4119 | main.log.info( "Waiting " + str( retryTime ) + |
| 4120 | "seconds before retrying." ) |
| 4121 | time.sleep( retryTime ) # Due to change in mastership |
| 4122 | output = self.sendline( cmd ) |
| 4123 | assert output is not None, "Error in sendline" |
| 4124 | assert "Command not found:" not in output, output |
| 4125 | assert "Error executing command" not in output, output |
| 4126 | main.log.info( self.name + ": " + output ) |
| 4127 | return output |
| 4128 | except AssertionError: |
| 4129 | main.log.exception( "Error in processing '" + cmd + "' command." ) |
| 4130 | return None |
| 4131 | except TypeError: |
| 4132 | main.log.exception( self.name + ": Object not as expected" ) |
| 4133 | return None |
| 4134 | except pexpect.EOF: |
| 4135 | main.log.error( self.name + ": EOF exception found" ) |
| 4136 | main.log.error( self.name + ": " + self.handle.before ) |
| 4137 | main.cleanup() |
| 4138 | main.exit() |
| 4139 | except Exception: |
| 4140 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4141 | main.cleanup() |
| 4142 | main.exit() |
| 4143 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4144 | def setTestAdd( self, setName, values ): |
| 4145 | """ |
| 4146 | CLI command to add elements to a distributed set. |
| 4147 | Arguments: |
| 4148 | setName - The name of the set to add to. |
| 4149 | values - The value(s) to add to the set, space seperated. |
| 4150 | Example usages: |
| 4151 | setTestAdd( "set1", "a b c" ) |
| 4152 | setTestAdd( "set2", "1" ) |
| 4153 | returns: |
| 4154 | main.TRUE on success OR |
| 4155 | main.FALSE if elements were already in the set OR |
| 4156 | main.ERROR on error |
| 4157 | """ |
| 4158 | try: |
| 4159 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4160 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4161 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 4162 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4163 | if re.search( positiveMatch, output): |
| 4164 | return main.TRUE |
| 4165 | elif re.search( negativeMatch, output): |
| 4166 | return main.FALSE |
| 4167 | else: |
| 4168 | main.log.error( self.name + ": setTestAdd did not" + |
| 4169 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4170 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4171 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4172 | except TypeError: |
| 4173 | main.log.exception( self.name + ": Object not as expected" ) |
| 4174 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4175 | except Exception: |
| 4176 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4177 | main.cleanup() |
| 4178 | main.exit() |
| 4179 | |
| 4180 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 4181 | """ |
| 4182 | CLI command to remove elements from a distributed set. |
| 4183 | Required arguments: |
| 4184 | setName - The name of the set to remove from. |
| 4185 | values - The value(s) to remove from the set, space seperated. |
| 4186 | Optional arguments: |
| 4187 | clear - Clear all elements from the set |
| 4188 | retain - Retain only the given values. (intersection of the |
| 4189 | original set and the given set) |
| 4190 | returns: |
| 4191 | main.TRUE on success OR |
| 4192 | main.FALSE if the set was not changed OR |
| 4193 | main.ERROR on error |
| 4194 | """ |
| 4195 | try: |
| 4196 | cmdStr = "set-test-remove " |
| 4197 | if clear: |
| 4198 | cmdStr += "-c " + str( setName ) |
| 4199 | elif retain: |
| 4200 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4201 | else: |
| 4202 | cmdStr += str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4203 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4204 | if clear: |
| 4205 | pattern = "Set " + str( setName ) + " cleared" |
| 4206 | if re.search( pattern, output ): |
| 4207 | return main.TRUE |
| 4208 | elif retain: |
| 4209 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4210 | "only elements of set \[(.*)\]" |
| 4211 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4212 | "retaining only elements of the set " +\ |
| 4213 | "\[(.*)\]" |
| 4214 | if re.search( positivePattern, output ): |
| 4215 | return main.TRUE |
| 4216 | elif re.search( negativePattern, output ): |
| 4217 | return main.FALSE |
| 4218 | else: |
| 4219 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4220 | str( setName ) |
| 4221 | if ( len( values.split() ) == 1 ): |
| 4222 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4223 | str( setName ) |
| 4224 | else: |
| 4225 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4226 | str( setName ) |
| 4227 | if re.search( positivePattern, output ): |
| 4228 | return main.TRUE |
| 4229 | elif re.search( negativePattern, output ): |
| 4230 | return main.FALSE |
| 4231 | main.log.error( self.name + ": setTestRemove did not" + |
| 4232 | " match expected output" ) |
| 4233 | main.log.debug( self.name + " expected: " + pattern ) |
| 4234 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4235 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4236 | except TypeError: |
| 4237 | main.log.exception( self.name + ": Object not as expected" ) |
| 4238 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4239 | except Exception: |
| 4240 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4241 | main.cleanup() |
| 4242 | main.exit() |
| 4243 | |
| 4244 | def setTestGet( self, setName, values="" ): |
| 4245 | """ |
| 4246 | CLI command to get the elements in a distributed set. |
| 4247 | Required arguments: |
| 4248 | setName - The name of the set to remove from. |
| 4249 | Optional arguments: |
| 4250 | values - The value(s) to check if in the set, space seperated. |
| 4251 | returns: |
| 4252 | main.ERROR on error OR |
| 4253 | A list of elements in the set if no optional arguments are |
| 4254 | supplied OR |
| 4255 | A tuple containing the list then: |
| 4256 | main.FALSE if the given values are not in the set OR |
| 4257 | main.TRUE if the given values are in the set OR |
| 4258 | """ |
| 4259 | try: |
| 4260 | values = str( values ).strip() |
| 4261 | setName = str( setName ).strip() |
| 4262 | length = len( values.split() ) |
| 4263 | containsCheck = None |
| 4264 | # Patterns to match |
| 4265 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4266 | pattern = "Items in set " + setName + ":\r\n" + setPattern |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4267 | containsTrue = "Set " + setName + " contains the value " + values |
| 4268 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4269 | values |
| 4270 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4271 | setPattern |
| 4272 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4273 | " subset " + setPattern |
| 4274 | |
| 4275 | cmdStr = "set-test-get " |
| 4276 | cmdStr += setName + " " + values |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4277 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4278 | if length == 0: |
| 4279 | match = re.search( pattern, output ) |
| 4280 | else: # if given values |
| 4281 | if length == 1: # Contains output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4282 | patternTrue = pattern + "\r\n" + containsTrue |
| 4283 | patternFalse = pattern + "\r\n" + containsFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4284 | else: # ContainsAll output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4285 | patternTrue = pattern + "\r\n" + containsAllTrue |
| 4286 | patternFalse = pattern + "\r\n" + containsAllFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4287 | matchTrue = re.search( patternTrue, output ) |
| 4288 | matchFalse = re.search( patternFalse, output ) |
| 4289 | if matchTrue: |
| 4290 | containsCheck = main.TRUE |
| 4291 | match = matchTrue |
| 4292 | elif matchFalse: |
| 4293 | containsCheck = main.FALSE |
| 4294 | match = matchFalse |
| 4295 | else: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4296 | main.log.error( self.name + " setTestGet did not match " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4297 | "expected output" ) |
| 4298 | main.log.debug( self.name + " expected: " + pattern ) |
| 4299 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4300 | match = None |
| 4301 | if match: |
| 4302 | setMatch = match.group( 1 ) |
| 4303 | if setMatch == '': |
| 4304 | setList = [] |
| 4305 | else: |
| 4306 | setList = setMatch.split( ", " ) |
| 4307 | if length > 0: |
| 4308 | return ( setList, containsCheck ) |
| 4309 | else: |
| 4310 | return setList |
| 4311 | else: # no match |
| 4312 | main.log.error( self.name + ": setTestGet did not" + |
| 4313 | " match expected output" ) |
| 4314 | main.log.debug( self.name + " expected: " + pattern ) |
| 4315 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4316 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4317 | except TypeError: |
| 4318 | main.log.exception( self.name + ": Object not as expected" ) |
| 4319 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4320 | except Exception: |
| 4321 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4322 | main.cleanup() |
| 4323 | main.exit() |
| 4324 | |
| 4325 | def setTestSize( self, setName ): |
| 4326 | """ |
| 4327 | CLI command to get the elements in a distributed set. |
| 4328 | Required arguments: |
| 4329 | setName - The name of the set to remove from. |
| 4330 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4331 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4332 | None on error |
| 4333 | """ |
| 4334 | try: |
| 4335 | # TODO: Should this check against the number of elements returned |
| 4336 | # and then return true/false based on that? |
| 4337 | setName = str( setName ).strip() |
| 4338 | # Patterns to match |
| 4339 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4340 | pattern = "There are (\d+) items in set " + setName + ":\r\n" +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4341 | setPattern |
| 4342 | cmdStr = "set-test-get -s " |
| 4343 | cmdStr += setName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4344 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4345 | match = re.search( pattern, output ) |
| 4346 | if match: |
| 4347 | setSize = int( match.group( 1 ) ) |
| 4348 | setMatch = match.group( 2 ) |
| 4349 | if len( setMatch.split() ) == setSize: |
| 4350 | main.log.info( "The size returned by " + self.name + |
| 4351 | " matches the number of elements in " + |
| 4352 | "the returned set" ) |
| 4353 | else: |
| 4354 | main.log.error( "The size returned by " + self.name + |
| 4355 | " does not match the number of " + |
| 4356 | "elements in the returned set." ) |
| 4357 | return setSize |
| 4358 | else: # no match |
| 4359 | main.log.error( self.name + ": setTestGet did not" + |
| 4360 | " match expected output" ) |
| 4361 | main.log.debug( self.name + " expected: " + pattern ) |
| 4362 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4363 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4364 | except TypeError: |
| 4365 | main.log.exception( self.name + ": Object not as expected" ) |
| 4366 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4367 | except Exception: |
| 4368 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4369 | main.cleanup() |
| 4370 | main.exit() |
| 4371 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4372 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4373 | """ |
| 4374 | Command to list the various counters in the system. |
| 4375 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4376 | if jsonFormat, a string of the json object returned by the cli |
| 4377 | command |
| 4378 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4379 | None on error |
| 4380 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4381 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4382 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4383 | if jsonFormat: |
| 4384 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4385 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4386 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4387 | assert "Command not found:" not in output, output |
| 4388 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4389 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4390 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4391 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4392 | main.log.exception( "Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4393 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4394 | except TypeError: |
| 4395 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4396 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4397 | except pexpect.EOF: |
| 4398 | main.log.error( self.name + ": EOF exception found" ) |
| 4399 | main.log.error( self.name + ": " + self.handle.before ) |
| 4400 | main.cleanup() |
| 4401 | main.exit() |
| 4402 | except Exception: |
| 4403 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4404 | main.cleanup() |
| 4405 | main.exit() |
| 4406 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4407 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4408 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4409 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4410 | Required arguments: |
| 4411 | counter - The name of the counter to increment. |
| 4412 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4413 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4414 | returns: |
| 4415 | integer value of the counter or |
| 4416 | None on Error |
| 4417 | """ |
| 4418 | try: |
| 4419 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4420 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4421 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4422 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4423 | if delta != 1: |
| 4424 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4425 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4426 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4427 | match = re.search( pattern, output ) |
| 4428 | if match: |
| 4429 | return int( match.group( 1 ) ) |
| 4430 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4431 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4432 | " match expected output." ) |
| 4433 | main.log.debug( self.name + " expected: " + pattern ) |
| 4434 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4435 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4436 | except TypeError: |
| 4437 | main.log.exception( self.name + ": Object not as expected" ) |
| 4438 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4439 | except Exception: |
| 4440 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4441 | main.cleanup() |
| 4442 | main.exit() |
| 4443 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4444 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4445 | """ |
| 4446 | CLI command to get a distributed counter then add a delta to it. |
| 4447 | Required arguments: |
| 4448 | counter - The name of the counter to increment. |
| 4449 | Optional arguments: |
| 4450 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4451 | returns: |
| 4452 | integer value of the counter or |
| 4453 | None on Error |
| 4454 | """ |
| 4455 | try: |
| 4456 | counter = str( counter ) |
| 4457 | delta = int( delta ) |
| 4458 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4459 | cmdStr += counter |
| 4460 | if delta != 1: |
| 4461 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4462 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4463 | pattern = counter + " was updated to (-?\d+)" |
| 4464 | match = re.search( pattern, output ) |
| 4465 | if match: |
| 4466 | return int( match.group( 1 ) ) |
| 4467 | else: |
| 4468 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4469 | " match expected output." ) |
| 4470 | main.log.debug( self.name + " expected: " + pattern ) |
| 4471 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4472 | return None |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4473 | except TypeError: |
| 4474 | main.log.exception( self.name + ": Object not as expected" ) |
| 4475 | return None |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4476 | except Exception: |
| 4477 | main.log.exception( self.name + ": Uncaught exception!" ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4478 | main.cleanup() |
| 4479 | main.exit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4480 | |
| 4481 | def valueTestGet( self, valueName ): |
| 4482 | """ |
| 4483 | CLI command to get the value of an atomic value. |
| 4484 | Required arguments: |
| 4485 | valueName - The name of the value to get. |
| 4486 | returns: |
| 4487 | string value of the value or |
| 4488 | None on Error |
| 4489 | """ |
| 4490 | try: |
| 4491 | valueName = str( valueName ) |
| 4492 | cmdStr = "value-test " |
| 4493 | operation = "get" |
| 4494 | cmdStr = "value-test {} {}".format( valueName, |
| 4495 | operation ) |
| 4496 | output = self.distPrimitivesSend( cmdStr ) |
| 4497 | pattern = "(\w+)" |
| 4498 | match = re.search( pattern, output ) |
| 4499 | if match: |
| 4500 | return match.group( 1 ) |
| 4501 | else: |
| 4502 | main.log.error( self.name + ": valueTestGet did not" + |
| 4503 | " match expected output." ) |
| 4504 | main.log.debug( self.name + " expected: " + pattern ) |
| 4505 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4506 | return None |
| 4507 | except TypeError: |
| 4508 | main.log.exception( self.name + ": Object not as expected" ) |
| 4509 | return None |
| 4510 | except Exception: |
| 4511 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4512 | main.cleanup() |
| 4513 | main.exit() |
| 4514 | |
| 4515 | def valueTestSet( self, valueName, newValue ): |
| 4516 | """ |
| 4517 | CLI command to set the value of an atomic value. |
| 4518 | Required arguments: |
| 4519 | valueName - The name of the value to set. |
| 4520 | newValue - The value to assign to the given value. |
| 4521 | returns: |
| 4522 | main.TRUE on success or |
| 4523 | main.ERROR on Error |
| 4524 | """ |
| 4525 | try: |
| 4526 | valueName = str( valueName ) |
| 4527 | newValue = str( newValue ) |
| 4528 | operation = "set" |
| 4529 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4530 | operation, |
| 4531 | newValue ) |
| 4532 | output = self.distPrimitivesSend( cmdStr ) |
| 4533 | if output is not None: |
| 4534 | return main.TRUE |
| 4535 | else: |
| 4536 | return main.ERROR |
| 4537 | except TypeError: |
| 4538 | main.log.exception( self.name + ": Object not as expected" ) |
| 4539 | return main.ERROR |
| 4540 | except Exception: |
| 4541 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4542 | main.cleanup() |
| 4543 | main.exit() |
| 4544 | |
| 4545 | def valueTestCompareAndSet( self, valueName, oldValue, newValue ): |
| 4546 | """ |
| 4547 | CLI command to compareAndSet the value of an atomic value. |
| 4548 | Required arguments: |
| 4549 | valueName - The name of the value. |
| 4550 | oldValue - Compare the current value of the atomic value to this |
| 4551 | newValue - If the value equals oldValue, set the value to newValue |
| 4552 | returns: |
| 4553 | main.TRUE on success or |
| 4554 | main.FALSE on failure or |
| 4555 | main.ERROR on Error |
| 4556 | """ |
| 4557 | try: |
| 4558 | valueName = str( valueName ) |
| 4559 | oldValue = str( oldValue ) |
| 4560 | newValue = str( newValue ) |
| 4561 | operation = "compareAndSet" |
| 4562 | cmdStr = "value-test {} {} {} {}".format( valueName, |
| 4563 | operation, |
| 4564 | oldValue, |
| 4565 | newValue ) |
| 4566 | output = self.distPrimitivesSend( cmdStr ) |
| 4567 | pattern = "(\w+)" |
| 4568 | match = re.search( pattern, output ) |
| 4569 | if match: |
| 4570 | result = match.group( 1 ) |
| 4571 | if result == "true": |
| 4572 | return main.TRUE |
| 4573 | elif result == "false": |
| 4574 | return main.FALSE |
| 4575 | else: |
| 4576 | main.log.error( self.name + ": valueTestCompareAndSet did not" + |
| 4577 | " match expected output." ) |
| 4578 | main.log.debug( self.name + " expected: " + pattern ) |
| 4579 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4580 | return main.ERROR |
| 4581 | except TypeError: |
| 4582 | main.log.exception( self.name + ": Object not as expected" ) |
| 4583 | return main.ERROR |
| 4584 | except Exception: |
| 4585 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4586 | main.cleanup() |
| 4587 | main.exit() |
| 4588 | |
| 4589 | def valueTestGetAndSet( self, valueName, newValue ): |
| 4590 | """ |
| 4591 | CLI command to getAndSet the value of an atomic value. |
| 4592 | Required arguments: |
| 4593 | valueName - The name of the value to get. |
| 4594 | newValue - The value to assign to the given value |
| 4595 | returns: |
| 4596 | string value of the value or |
| 4597 | None on Error |
| 4598 | """ |
| 4599 | try: |
| 4600 | valueName = str( valueName ) |
| 4601 | cmdStr = "value-test " |
| 4602 | operation = "getAndSet" |
| 4603 | cmdStr += valueName + " " + operation |
| 4604 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4605 | operation, |
| 4606 | newValue ) |
| 4607 | output = self.distPrimitivesSend( cmdStr ) |
| 4608 | pattern = "(\w+)" |
| 4609 | match = re.search( pattern, output ) |
| 4610 | if match: |
| 4611 | return match.group( 1 ) |
| 4612 | else: |
| 4613 | main.log.error( self.name + ": valueTestGetAndSet did not" + |
| 4614 | " match expected output." ) |
| 4615 | main.log.debug( self.name + " expected: " + pattern ) |
| 4616 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4617 | return None |
| 4618 | except TypeError: |
| 4619 | main.log.exception( self.name + ": Object not as expected" ) |
| 4620 | return None |
| 4621 | except Exception: |
| 4622 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4623 | main.cleanup() |
| 4624 | main.exit() |
| 4625 | |
| 4626 | def valueTestDestroy( self, valueName ): |
| 4627 | """ |
| 4628 | CLI command to destroy an atomic value. |
| 4629 | Required arguments: |
| 4630 | valueName - The name of the value to destroy. |
| 4631 | returns: |
| 4632 | main.TRUE on success or |
| 4633 | main.ERROR on Error |
| 4634 | """ |
| 4635 | try: |
| 4636 | valueName = str( valueName ) |
| 4637 | cmdStr = "value-test " |
| 4638 | operation = "destroy" |
| 4639 | cmdStr += valueName + " " + operation |
| 4640 | output = self.distPrimitivesSend( cmdStr ) |
| 4641 | if output is not None: |
| 4642 | return main.TRUE |
| 4643 | else: |
| 4644 | return main.ERROR |
| 4645 | except TypeError: |
| 4646 | main.log.exception( self.name + ": Object not as expected" ) |
| 4647 | return main.ERROR |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4648 | except Exception: |
| 4649 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4650 | main.cleanup() |
| 4651 | main.exit() |
| 4652 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4653 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4654 | """ |
| 4655 | Description: Execute summary command in onos |
| 4656 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4657 | no output |
| 4658 | |
| 4659 | """ |
| 4660 | try: |
| 4661 | cmdStr = "summary" |
| 4662 | if jsonFormat: |
| 4663 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4664 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4665 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4666 | assert "Command not found:" not in handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4667 | assert "Error:" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4668 | if not handle: |
| 4669 | main.log.error( self.name + ": There is no output in " + |
| 4670 | "summary command" ) |
| 4671 | return main.FALSE |
| 4672 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4673 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4674 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4675 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4676 | except TypeError: |
| 4677 | main.log.exception( self.name + ": Object not as expected" ) |
| 4678 | return None |
| 4679 | except pexpect.EOF: |
| 4680 | main.log.error( self.name + ": EOF exception found" ) |
| 4681 | main.log.error( self.name + ": " + self.handle.before ) |
| 4682 | main.cleanup() |
| 4683 | main.exit() |
| 4684 | except Exception: |
| 4685 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4686 | main.cleanup() |
| 4687 | main.exit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4688 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4689 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4690 | """ |
| 4691 | CLI command to get the value of a key in a consistent map using |
| 4692 | transactions. This a test function and can only get keys from the |
| 4693 | test map hard coded into the cli command |
| 4694 | Required arguments: |
| 4695 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4696 | returns: |
| 4697 | The string value of the key or |
| 4698 | None on Error |
| 4699 | """ |
| 4700 | try: |
| 4701 | keyName = str( keyName ) |
| 4702 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4703 | cmdStr += keyName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4704 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4705 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4706 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4707 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4708 | return None |
| 4709 | else: |
| 4710 | match = re.search( pattern, output ) |
| 4711 | if match: |
| 4712 | return match.groupdict()[ 'value' ] |
| 4713 | else: |
| 4714 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4715 | " match expected output." ) |
| 4716 | main.log.debug( self.name + " expected: " + pattern ) |
| 4717 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4718 | return None |
| 4719 | except TypeError: |
| 4720 | main.log.exception( self.name + ": Object not as expected" ) |
| 4721 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4722 | except Exception: |
| 4723 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4724 | main.cleanup() |
| 4725 | main.exit() |
| 4726 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4727 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4728 | """ |
| 4729 | CLI command to put a value into 'numKeys' number of keys in a |
| 4730 | consistent map using transactions. This a test function and can only |
| 4731 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4732 | Required arguments: |
| 4733 | numKeys - Number of keys to add the value to |
| 4734 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4735 | returns: |
| 4736 | A dictionary whose keys are the name of the keys put into the map |
| 4737 | and the values of the keys are dictionaries whose key-values are |
| 4738 | 'value': value put into map and optionaly |
| 4739 | 'oldValue': Previous value in the key or |
| 4740 | None on Error |
| 4741 | |
| 4742 | Example output |
| 4743 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4744 | 'Key2': {'value': 'Testing'} } |
| 4745 | """ |
| 4746 | try: |
| 4747 | numKeys = str( numKeys ) |
| 4748 | value = str( value ) |
| 4749 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4750 | cmdStr += numKeys + " " + value |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4751 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4752 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4753 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4754 | results = {} |
| 4755 | for line in output.splitlines(): |
| 4756 | new = re.search( newPattern, line ) |
| 4757 | updated = re.search( updatedPattern, line ) |
| 4758 | if new: |
| 4759 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 4760 | elif updated: |
| 4761 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4762 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4763 | else: |
| 4764 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4765 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4766 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 4767 | newPattern, |
| 4768 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4769 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4770 | return results |
| 4771 | except TypeError: |
| 4772 | main.log.exception( self.name + ": Object not as expected" ) |
| 4773 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4774 | except Exception: |
| 4775 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4776 | main.cleanup() |
| 4777 | main.exit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4778 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4779 | def maps( self, jsonFormat=True ): |
| 4780 | """ |
| 4781 | Description: Returns result of onos:maps |
| 4782 | Optional: |
| 4783 | * jsonFormat: enable json formatting of output |
| 4784 | """ |
| 4785 | try: |
| 4786 | cmdStr = "maps" |
| 4787 | if jsonFormat: |
| 4788 | cmdStr += " -j" |
| 4789 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4790 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4791 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4792 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4793 | except AssertionError: |
| 4794 | main.log.exception( "" ) |
| 4795 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4796 | except TypeError: |
| 4797 | main.log.exception( self.name + ": Object not as expected" ) |
| 4798 | return None |
| 4799 | except pexpect.EOF: |
| 4800 | main.log.error( self.name + ": EOF exception found" ) |
| 4801 | main.log.error( self.name + ": " + self.handle.before ) |
| 4802 | main.cleanup() |
| 4803 | main.exit() |
| 4804 | except Exception: |
| 4805 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4806 | main.cleanup() |
| 4807 | main.exit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4808 | |
| 4809 | def getSwController( self, uri, jsonFormat=True ): |
| 4810 | """ |
| 4811 | Descrition: Gets the controller information from the device |
| 4812 | """ |
| 4813 | try: |
| 4814 | cmd = "device-controllers " |
| 4815 | if jsonFormat: |
| 4816 | cmd += "-j " |
| 4817 | response = self.sendline( cmd + uri ) |
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 | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4820 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4821 | except AssertionError: |
| 4822 | main.log.exception( "" ) |
| 4823 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4824 | except TypeError: |
| 4825 | main.log.exception( self.name + ": Object not as expected" ) |
| 4826 | return None |
| 4827 | except pexpect.EOF: |
| 4828 | main.log.error( self.name + ": EOF exception found" ) |
| 4829 | main.log.error( self.name + ": " + self.handle.before ) |
| 4830 | main.cleanup() |
| 4831 | main.exit() |
| 4832 | except Exception: |
| 4833 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4834 | main.cleanup() |
| 4835 | main.exit() |
| 4836 | |
| 4837 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 4838 | """ |
| 4839 | Descrition: sets the controller(s) for the specified device |
| 4840 | |
| 4841 | Parameters: |
| 4842 | Required: uri - String: The uri of the device(switch). |
| 4843 | ip - String or List: The ip address of the controller. |
| 4844 | This parameter can be formed in a couple of different ways. |
| 4845 | VALID: |
| 4846 | 10.0.0.1 - just the ip address |
| 4847 | tcp:10.0.0.1 - the protocol and the ip address |
| 4848 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 4849 | so that you can add controllers with different |
| 4850 | protocols and ports |
| 4851 | INVALID: |
| 4852 | 10.0.0.1:6653 - this is not supported by ONOS |
| 4853 | |
| 4854 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 4855 | port - The port number. |
| 4856 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 4857 | |
| 4858 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 4859 | """ |
| 4860 | try: |
| 4861 | cmd = "device-setcontrollers" |
| 4862 | |
| 4863 | if jsonFormat: |
| 4864 | cmd += " -j" |
| 4865 | cmd += " " + uri |
| 4866 | if isinstance( ip, str ): |
| 4867 | ip = [ip] |
| 4868 | for item in ip: |
| 4869 | if ":" in item: |
| 4870 | sitem = item.split( ":" ) |
| 4871 | if len(sitem) == 3: |
| 4872 | cmd += " " + item |
| 4873 | elif "." in sitem[1]: |
| 4874 | cmd += " {}:{}".format(item, port) |
| 4875 | else: |
| 4876 | main.log.error( "Malformed entry: " + item ) |
| 4877 | raise TypeError |
| 4878 | else: |
| 4879 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4880 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4881 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4882 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4883 | if "Error" in response: |
| 4884 | main.log.error( response ) |
| 4885 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4886 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4887 | except AssertionError: |
| 4888 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4889 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4890 | except TypeError: |
| 4891 | main.log.exception( self.name + ": Object not as expected" ) |
| 4892 | return main.FALSE |
| 4893 | except pexpect.EOF: |
| 4894 | main.log.error( self.name + ": EOF exception found" ) |
| 4895 | main.log.error( self.name + ": " + self.handle.before ) |
| 4896 | main.cleanup() |
| 4897 | main.exit() |
| 4898 | except Exception: |
| 4899 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4900 | main.cleanup() |
| 4901 | main.exit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4902 | |
| 4903 | def removeDevice( self, device ): |
| 4904 | ''' |
| 4905 | Description: |
| 4906 | Remove a device from ONOS by passing the uri of the device(s). |
| 4907 | Parameters: |
| 4908 | device - (str or list) the id or uri of the device ex. "of:0000000000000001" |
| 4909 | Returns: |
| 4910 | Returns main.FALSE if an exception is thrown or an error is present |
| 4911 | in the response. Otherwise, returns main.TRUE. |
| 4912 | NOTE: |
| 4913 | If a host cannot be removed, then this function will return main.FALSE |
| 4914 | ''' |
| 4915 | try: |
| 4916 | if type( device ) is str: |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 4917 | deviceStr = device |
| 4918 | device = [] |
| 4919 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4920 | |
| 4921 | for d in device: |
| 4922 | time.sleep( 1 ) |
| 4923 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4924 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4925 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4926 | if "Error" in response: |
| 4927 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 4928 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4929 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4930 | except AssertionError: |
| 4931 | main.log.exception( "" ) |
| 4932 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4933 | except TypeError: |
| 4934 | main.log.exception( self.name + ": Object not as expected" ) |
| 4935 | return main.FALSE |
| 4936 | except pexpect.EOF: |
| 4937 | main.log.error( self.name + ": EOF exception found" ) |
| 4938 | main.log.error( self.name + ": " + self.handle.before ) |
| 4939 | main.cleanup() |
| 4940 | main.exit() |
| 4941 | except Exception: |
| 4942 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4943 | main.cleanup() |
| 4944 | main.exit() |
| 4945 | |
| 4946 | def removeHost( self, host ): |
| 4947 | ''' |
| 4948 | Description: |
| 4949 | Remove a host from ONOS by passing the id of the host(s) |
| 4950 | Parameters: |
| 4951 | hostId - (str or list) the id or mac of the host ex. "00:00:00:00:00:01" |
| 4952 | Returns: |
| 4953 | Returns main.FALSE if an exception is thrown or an error is present |
| 4954 | in the response. Otherwise, returns main.TRUE. |
| 4955 | NOTE: |
| 4956 | If a host cannot be removed, then this function will return main.FALSE |
| 4957 | ''' |
| 4958 | try: |
| 4959 | if type( host ) is str: |
| 4960 | host = list( host ) |
| 4961 | |
| 4962 | for h in host: |
| 4963 | time.sleep( 1 ) |
| 4964 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4965 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4966 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4967 | if "Error" in response: |
| 4968 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 4969 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4970 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4971 | except AssertionError: |
| 4972 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4973 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4974 | except TypeError: |
| 4975 | main.log.exception( self.name + ": Object not as expected" ) |
| 4976 | return main.FALSE |
| 4977 | except pexpect.EOF: |
| 4978 | main.log.error( self.name + ": EOF exception found" ) |
| 4979 | main.log.error( self.name + ": " + self.handle.before ) |
| 4980 | main.cleanup() |
| 4981 | main.exit() |
| 4982 | except Exception: |
| 4983 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4984 | main.cleanup() |
| 4985 | main.exit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4986 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4987 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4988 | ''' |
| 4989 | Description: |
| 4990 | Bring link down or up in the null-provider. |
| 4991 | params: |
| 4992 | begin - (string) One end of a device or switch. |
| 4993 | end - (string) the other end of the device or switch |
| 4994 | returns: |
| 4995 | main.TRUE if no exceptions were thrown and no Errors are |
| 4996 | present in the resoponse. Otherwise, returns main.FALSE |
| 4997 | ''' |
| 4998 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4999 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5000 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5001 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5002 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5003 | if "Error" in response or "Failure" in response: |
| 5004 | main.log.error( response ) |
| 5005 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5006 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5007 | except AssertionError: |
| 5008 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5009 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5010 | except TypeError: |
| 5011 | main.log.exception( self.name + ": Object not as expected" ) |
| 5012 | return main.FALSE |
| 5013 | except pexpect.EOF: |
| 5014 | main.log.error( self.name + ": EOF exception found" ) |
| 5015 | main.log.error( self.name + ": " + self.handle.before ) |
| 5016 | main.cleanup() |
| 5017 | main.exit() |
| 5018 | except Exception: |
| 5019 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5020 | main.cleanup() |
| 5021 | main.exit() |
| 5022 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5023 | def portstate( self, dpid, port, state ): |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5024 | ''' |
| 5025 | Description: |
| 5026 | Changes the state of port in an OF switch by means of the |
| 5027 | PORTSTATUS OF messages. |
| 5028 | params: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5029 | dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102' |
| 5030 | port - (string) target port in the device. Ex: '2' |
| 5031 | state - (string) target state (enable or disable) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5032 | returns: |
| 5033 | main.TRUE if no exceptions were thrown and no Errors are |
| 5034 | present in the resoponse. Otherwise, returns main.FALSE |
| 5035 | ''' |
| 5036 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5037 | state = state.lower() |
| 5038 | assert state == 'enable' or state == 'disable', "Unknown state" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5039 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5040 | response = self.sendline( cmd, showResponse=True ) |
| 5041 | assert response is not None, "Error in sendline" |
| 5042 | assert "Command not found:" not in response, response |
| 5043 | if "Error" in response or "Failure" in response: |
| 5044 | main.log.error( response ) |
| 5045 | return main.FALSE |
| 5046 | return main.TRUE |
| 5047 | except AssertionError: |
| 5048 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5049 | return main.FALSE |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5050 | except TypeError: |
| 5051 | main.log.exception( self.name + ": Object not as expected" ) |
| 5052 | return main.FALSE |
| 5053 | except pexpect.EOF: |
| 5054 | main.log.error( self.name + ": EOF exception found" ) |
| 5055 | main.log.error( self.name + ": " + self.handle.before ) |
| 5056 | main.cleanup() |
| 5057 | main.exit() |
| 5058 | except Exception: |
| 5059 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5060 | main.cleanup() |
| 5061 | main.exit() |
| 5062 | |
| 5063 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 5064 | """ |
| 5065 | Set the logging level to lvl for a specific app |
| 5066 | returns main.TRUE on success |
| 5067 | returns main.FALSE if Error occurred |
| 5068 | if noExit is True, TestON will not exit, but clean up |
| 5069 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 5070 | Level defaults to INFO |
| 5071 | """ |
| 5072 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5073 | self.handle.sendline( "log:set %s %s" % ( level, app ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5074 | self.handle.expect( "onos>" ) |
| 5075 | |
| 5076 | response = self.handle.before |
| 5077 | if re.search( "Error", response ): |
| 5078 | return main.FALSE |
| 5079 | return main.TRUE |
| 5080 | except pexpect.TIMEOUT: |
| 5081 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
| 5082 | main.cleanup() |
| 5083 | main.exit() |
| 5084 | except pexpect.EOF: |
| 5085 | main.log.error( self.name + ": EOF exception found" ) |
| 5086 | main.log.error( self.name + ": " + self.handle.before ) |
| 5087 | main.cleanup() |
| 5088 | main.exit() |
| 5089 | except Exception: |
| 5090 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5091 | main.cleanup() |
| 5092 | main.exit() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5093 | |
| 5094 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 5095 | """ |
| 5096 | Return a dictionary which describes the latest network topology data as a |
| 5097 | graph. |
| 5098 | An example of the dictionary: |
| 5099 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 5100 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 5101 | Each vertex should at least have an 'edges' attribute which describes the |
| 5102 | adjacency information. The value of 'edges' attribute is also represented by |
| 5103 | a dictionary, which maps each edge (identified by the neighbor vertex) to a |
| 5104 | list of attributes. |
| 5105 | An example of the edges dictionary: |
| 5106 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 5107 | vertex3: { 'port': ..., 'weight': ... } } |
| 5108 | If includeHost == True, all hosts (and host-switch links) will be included |
| 5109 | in topology data. |
| 5110 | """ |
| 5111 | graphDict = {} |
| 5112 | try: |
| 5113 | links = self.links() |
| 5114 | links = json.loads( links ) |
| 5115 | devices = self.devices() |
| 5116 | devices = json.loads( devices ) |
| 5117 | idToDevice = {} |
| 5118 | for device in devices: |
| 5119 | idToDevice[ device[ 'id' ] ] = device |
| 5120 | if includeHost: |
| 5121 | hosts = self.hosts() |
| 5122 | # FIXME: support 'includeHost' argument |
| 5123 | for link in links: |
| 5124 | nodeA = link[ 'src' ][ 'device' ] |
| 5125 | nodeB = link[ 'dst' ][ 'device' ] |
| 5126 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5127 | if nodeA not in graphDict.keys(): |
| 5128 | graphDict[ nodeA ] = { 'edges': {}, |
| 5129 | 'dpid': idToDevice[ nodeA ][ 'id' ][3:], |
| 5130 | 'type': idToDevice[ nodeA ][ 'type' ], |
| 5131 | 'available': idToDevice[ nodeA ][ 'available' ], |
| 5132 | 'role': idToDevice[ nodeA ][ 'role' ], |
| 5133 | 'mfr': idToDevice[ nodeA ][ 'mfr' ], |
| 5134 | 'hw': idToDevice[ nodeA ][ 'hw' ], |
| 5135 | 'sw': idToDevice[ nodeA ][ 'sw' ], |
| 5136 | 'serial': idToDevice[ nodeA ][ 'serial' ], |
| 5137 | 'chassisId': idToDevice[ nodeA ][ 'chassisId' ], |
| 5138 | 'annotations': idToDevice[ nodeA ][ 'annotations' ]} |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5139 | else: |
| 5140 | # Assert nodeB is not connected to any current links of nodeA |
| 5141 | assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5142 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ], |
| 5143 | 'type': link[ 'type' ], |
| 5144 | 'state': link[ 'state' ] } |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5145 | return graphDict |
| 5146 | except ( TypeError, ValueError ): |
| 5147 | main.log.exception( self.name + ": Object not as expected" ) |
| 5148 | return None |
| 5149 | except KeyError: |
| 5150 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5151 | return None |
| 5152 | except AssertionError: |
| 5153 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5154 | return None |
| 5155 | except pexpect.EOF: |
| 5156 | main.log.error( self.name + ": EOF exception found" ) |
| 5157 | main.log.error( self.name + ": " + self.handle.before ) |
| 5158 | return None |
| 5159 | except Exception: |
| 5160 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5161 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5162 | |
| 5163 | def getIntentPerfSummary( self ): |
| 5164 | ''' |
| 5165 | Send command to check intent-perf summary |
| 5166 | Returns: dictionary for intent-perf summary |
| 5167 | if something wrong, function will return None |
| 5168 | ''' |
| 5169 | cmd = "intent-perf -s" |
| 5170 | respDic = {} |
| 5171 | resp = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 5172 | assert resp is not None, "Error in sendline" |
| 5173 | assert "Command not found:" not in resp, resp |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5174 | try: |
| 5175 | # Generate the dictionary to return |
| 5176 | for l in resp.split( "\n" ): |
| 5177 | # Delete any white space in line |
| 5178 | temp = re.sub( r'\s+', '', l ) |
| 5179 | temp = temp.split( ":" ) |
| 5180 | respDic[ temp[0] ] = temp[ 1 ] |
| 5181 | |
| 5182 | except (TypeError, ValueError): |
| 5183 | main.log.exception( self.name + ": Object not as expected" ) |
| 5184 | return None |
| 5185 | except KeyError: |
| 5186 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5187 | return None |
| 5188 | except AssertionError: |
| 5189 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5190 | return None |
| 5191 | except pexpect.EOF: |
| 5192 | main.log.error( self.name + ": EOF exception found" ) |
| 5193 | main.log.error( self.name + ": " + self.handle.before ) |
| 5194 | return None |
| 5195 | except Exception: |
| 5196 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5197 | return None |
| 5198 | return respDic |
| 5199 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5200 | def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ): |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5201 | """ |
| 5202 | Searches the latest ONOS log file for the given search term and |
| 5203 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5204 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5205 | Arguments: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5206 | searchTerm: |
| 5207 | The string to grep from the ONOS log. |
| 5208 | startLine: |
| 5209 | The term that decides which line is the start to search the searchTerm in |
| 5210 | the karaf log. For now, startTerm only works in 'first' mode. |
| 5211 | logNum: |
| 5212 | In some extreme cases, one karaf log is not big enough to contain all the |
| 5213 | information.Because of this, search mutiply logs is necessary to capture |
| 5214 | the right result. logNum is the number of karaf logs that we need to search |
| 5215 | the searchTerm. |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5216 | mode: |
| 5217 | all: return all the strings that contain the search term |
| 5218 | last: return the last string that contains the search term |
| 5219 | first: return the first string that contains the search term |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5220 | num: return the number of times that the searchTerm appears in the log |
| 5221 | total: return how many lines in karaf log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5222 | """ |
| 5223 | try: |
| 5224 | assert type( searchTerm ) is str |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5225 | # Build the log paths string |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5226 | logPath = '/opt/onos/log/karaf.log.' |
| 5227 | logPaths = '/opt/onos/log/karaf.log' |
| 5228 | for i in range( 1, logNum ): |
| 5229 | logPaths = logPath + str( i ) + " " + logPaths |
| 5230 | cmd = "cat " + logPaths |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5231 | if startLine: |
| 5232 | # 100000000 is just a extreme large number to make sure this function can grep all the lines after startLine |
| 5233 | cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'" |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5234 | if mode == 'all': |
| 5235 | cmd = cmd + " | grep \'" + searchTerm + "\'" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5236 | elif mode == 'last': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5237 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5238 | elif mode == 'first': |
| 5239 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1" |
| 5240 | elif mode == 'num': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5241 | cmd = cmd + " | grep -c \'" + searchTerm + "\'" |
You Wang | 118ba58 | 2017-01-02 17:14:43 -0800 | [diff] [blame] | 5242 | num = self.sendline( cmd ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5243 | return num |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5244 | elif mode == 'total': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5245 | totalLines = self.sendline( "cat /opt/onos/log/karaf.log | wc -l" ) |
| 5246 | return int(totalLines) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5247 | else: |
| 5248 | main.log.error( self.name + " unsupported mode" ) |
| 5249 | return main.ERROR |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5250 | before = self.sendline( cmd ) |
| 5251 | before = before.splitlines() |
| 5252 | # make sure the returned list only contains the search term |
| 5253 | returnLines = [line for line in before if searchTerm in line] |
| 5254 | return returnLines |
| 5255 | except AssertionError: |
| 5256 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5257 | return None |
| 5258 | except pexpect.EOF: |
| 5259 | main.log.error( self.name + ": EOF exception found" ) |
| 5260 | main.log.error( self.name + ": " + self.handle.before ) |
| 5261 | main.cleanup() |
| 5262 | main.exit() |
| 5263 | except pexpect.TIMEOUT: |
| 5264 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5265 | main.log.error( self.name + ": " + self.handle.before ) |
| 5266 | main.cleanup() |
| 5267 | main.exit() |
| 5268 | except Exception: |
| 5269 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5270 | main.cleanup() |
| 5271 | main.exit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5272 | |
| 5273 | def vplsShow( self, jsonFormat=True ): |
| 5274 | """ |
| 5275 | Description: Returns result of onos:vpls show, which should list the |
| 5276 | configured VPLS networks and the assigned interfaces. |
| 5277 | Optional: |
| 5278 | * jsonFormat: enable json formatting of output |
| 5279 | Returns: |
| 5280 | The output of the command or None on error. |
| 5281 | """ |
| 5282 | try: |
| 5283 | cmdStr = "vpls show" |
| 5284 | if jsonFormat: |
| 5285 | raise NotImplementedError |
| 5286 | cmdStr += " -j" |
| 5287 | handle = self.sendline( cmdStr ) |
| 5288 | assert handle is not None, "Error in sendline" |
| 5289 | assert "Command not found:" not in handle, handle |
| 5290 | return handle |
| 5291 | except AssertionError: |
| 5292 | main.log.exception( "" ) |
| 5293 | return None |
| 5294 | except TypeError: |
| 5295 | main.log.exception( self.name + ": Object not as expected" ) |
| 5296 | return None |
| 5297 | except pexpect.EOF: |
| 5298 | main.log.error( self.name + ": EOF exception found" ) |
| 5299 | main.log.error( self.name + ": " + self.handle.before ) |
| 5300 | main.cleanup() |
| 5301 | main.exit() |
| 5302 | except NotImplementedError: |
| 5303 | main.log.exception( self.name + ": Json output not supported") |
| 5304 | return None |
| 5305 | except Exception: |
| 5306 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5307 | main.cleanup() |
| 5308 | main.exit() |
| 5309 | |
| 5310 | def parseVplsShow( self ): |
| 5311 | """ |
| 5312 | Parse the cli output of 'vpls show' into json output. This is required |
| 5313 | as there is currently no json output available. |
| 5314 | """ |
| 5315 | try: |
| 5316 | output = [] |
| 5317 | raw = self.vplsShow( jsonFormat=False ) |
| 5318 | namePat = "VPLS name: (?P<name>\w+)" |
| 5319 | interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]" |
| 5320 | encapPat = "Encapsulation: (?P<encap>\w+)" |
| 5321 | pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] ) |
| 5322 | mIter = re.finditer( pattern, raw ) |
| 5323 | for match in mIter: |
| 5324 | item = {} |
| 5325 | item[ 'name' ] = match.group( 'name' ) |
| 5326 | ifaces = match.group( 'interfaces' ).split( ', ') |
| 5327 | if ifaces == [ "" ]: |
| 5328 | ifaces = [] |
| 5329 | item[ 'interfaces' ] = ifaces |
| 5330 | encap = match.group( 'encap' ) |
| 5331 | if encap != 'NONE': |
| 5332 | item[ 'encapsulation' ] = encap.lower() |
| 5333 | output.append( item ) |
| 5334 | return output |
| 5335 | except Exception: |
| 5336 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5337 | main.cleanup() |
| 5338 | main.exit() |
| 5339 | |
| 5340 | def vplsList( self, jsonFormat=True ): |
| 5341 | """ |
| 5342 | Description: Returns result of onos:vpls list, which should list the |
| 5343 | configured VPLS networks. |
| 5344 | Optional: |
| 5345 | * jsonFormat: enable json formatting of output |
| 5346 | """ |
| 5347 | try: |
| 5348 | cmdStr = "vpls list" |
| 5349 | if jsonFormat: |
| 5350 | raise NotImplementedError |
| 5351 | cmdStr += " -j" |
| 5352 | handle = self.sendline( cmdStr ) |
| 5353 | assert handle is not None, "Error in sendline" |
| 5354 | assert "Command not found:" not in handle, handle |
| 5355 | return handle |
| 5356 | except AssertionError: |
| 5357 | main.log.exception( "" ) |
| 5358 | return None |
| 5359 | except TypeError: |
| 5360 | main.log.exception( self.name + ": Object not as expected" ) |
| 5361 | return None |
| 5362 | except pexpect.EOF: |
| 5363 | main.log.error( self.name + ": EOF exception found" ) |
| 5364 | main.log.error( self.name + ": " + self.handle.before ) |
| 5365 | main.cleanup() |
| 5366 | main.exit() |
| 5367 | except NotImplementedError: |
| 5368 | main.log.exception( self.name + ": Json output not supported") |
| 5369 | return None |
| 5370 | except Exception: |
| 5371 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5372 | main.cleanup() |
| 5373 | main.exit() |
| 5374 | |
| 5375 | def vplsCreate( self, network ): |
| 5376 | """ |
| 5377 | CLI command to create a new VPLS network. |
| 5378 | Required arguments: |
| 5379 | network - String name of the network to create. |
| 5380 | returns: |
| 5381 | main.TRUE on success and main.FALSE on failure |
| 5382 | """ |
| 5383 | try: |
| 5384 | network = str( network ) |
| 5385 | cmdStr = "vpls create " |
| 5386 | cmdStr += network |
| 5387 | output = self.sendline( cmdStr ) |
| 5388 | assert output is not None, "Error in sendline" |
| 5389 | assert "Command not found:" not in output, output |
| 5390 | assert "Error executing command" not in output, output |
| 5391 | assert "VPLS already exists:" not in output, output |
| 5392 | return main.TRUE |
| 5393 | except AssertionError: |
| 5394 | main.log.exception( "" ) |
| 5395 | return main.FALSE |
| 5396 | except TypeError: |
| 5397 | main.log.exception( self.name + ": Object not as expected" ) |
| 5398 | return main.FALSE |
| 5399 | except pexpect.EOF: |
| 5400 | main.log.error( self.name + ": EOF exception found" ) |
| 5401 | main.log.error( self.name + ": " + self.handle.before ) |
| 5402 | main.cleanup() |
| 5403 | main.exit() |
| 5404 | except Exception: |
| 5405 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5406 | main.cleanup() |
| 5407 | main.exit() |
| 5408 | |
| 5409 | def vplsDelete( self, network ): |
| 5410 | """ |
| 5411 | CLI command to delete a VPLS network. |
| 5412 | Required arguments: |
| 5413 | network - Name of the network to delete. |
| 5414 | returns: |
| 5415 | main.TRUE on success and main.FALSE on failure |
| 5416 | """ |
| 5417 | try: |
| 5418 | network = str( network ) |
| 5419 | cmdStr = "vpls delete " |
| 5420 | cmdStr += network |
| 5421 | output = self.sendline( cmdStr ) |
| 5422 | assert output is not None, "Error in sendline" |
| 5423 | assert "Command not found:" not in output, output |
| 5424 | assert "Error executing command" not in output, output |
| 5425 | assert " not found" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5426 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5427 | return main.TRUE |
| 5428 | except AssertionError: |
| 5429 | main.log.exception( "" ) |
| 5430 | return main.FALSE |
| 5431 | except TypeError: |
| 5432 | main.log.exception( self.name + ": Object not as expected" ) |
| 5433 | return main.FALSE |
| 5434 | except pexpect.EOF: |
| 5435 | main.log.error( self.name + ": EOF exception found" ) |
| 5436 | main.log.error( self.name + ": " + self.handle.before ) |
| 5437 | main.cleanup() |
| 5438 | main.exit() |
| 5439 | except Exception: |
| 5440 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5441 | main.cleanup() |
| 5442 | main.exit() |
| 5443 | |
| 5444 | def vplsAddIface( self, network, iface ): |
| 5445 | """ |
| 5446 | CLI command to add an interface to a VPLS network. |
| 5447 | Required arguments: |
| 5448 | network - Name of the network to add the interface to. |
| 5449 | iface - The ONOS name for an interface. |
| 5450 | returns: |
| 5451 | main.TRUE on success and main.FALSE on failure |
| 5452 | """ |
| 5453 | try: |
| 5454 | network = str( network ) |
| 5455 | iface = str( iface ) |
| 5456 | cmdStr = "vpls add-if " |
| 5457 | cmdStr += network + " " + iface |
| 5458 | output = self.sendline( cmdStr ) |
| 5459 | assert output is not None, "Error in sendline" |
| 5460 | assert "Command not found:" not in output, output |
| 5461 | assert "Error executing command" not in output, output |
| 5462 | assert "already associated to network" not in output, output |
| 5463 | assert "Interface cannot be added." not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5464 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5465 | return main.TRUE |
| 5466 | except AssertionError: |
| 5467 | main.log.exception( "" ) |
| 5468 | return main.FALSE |
| 5469 | except TypeError: |
| 5470 | main.log.exception( self.name + ": Object not as expected" ) |
| 5471 | return main.FALSE |
| 5472 | except pexpect.EOF: |
| 5473 | main.log.error( self.name + ": EOF exception found" ) |
| 5474 | main.log.error( self.name + ": " + self.handle.before ) |
| 5475 | main.cleanup() |
| 5476 | main.exit() |
| 5477 | except Exception: |
| 5478 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5479 | main.cleanup() |
| 5480 | main.exit() |
| 5481 | |
| 5482 | def vplsRemIface( self, network, iface ): |
| 5483 | """ |
| 5484 | CLI command to remove an interface from a VPLS network. |
| 5485 | Required arguments: |
| 5486 | network - Name of the network to remove the interface from. |
| 5487 | iface - Name of the interface to remove. |
| 5488 | returns: |
| 5489 | main.TRUE on success and main.FALSE on failure |
| 5490 | """ |
| 5491 | try: |
| 5492 | iface = str( iface ) |
| 5493 | cmdStr = "vpls rem-if " |
| 5494 | cmdStr += network + " " + iface |
| 5495 | output = self.sendline( cmdStr ) |
| 5496 | assert output is not None, "Error in sendline" |
| 5497 | assert "Command not found:" not in output, output |
| 5498 | assert "Error executing command" not in output, output |
| 5499 | assert "is not configured" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5500 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5501 | return main.TRUE |
| 5502 | except AssertionError: |
| 5503 | main.log.exception( "" ) |
| 5504 | return main.FALSE |
| 5505 | except TypeError: |
| 5506 | main.log.exception( self.name + ": Object not as expected" ) |
| 5507 | return main.FALSE |
| 5508 | except pexpect.EOF: |
| 5509 | main.log.error( self.name + ": EOF exception found" ) |
| 5510 | main.log.error( self.name + ": " + self.handle.before ) |
| 5511 | main.cleanup() |
| 5512 | main.exit() |
| 5513 | except Exception: |
| 5514 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5515 | main.cleanup() |
| 5516 | main.exit() |
| 5517 | |
| 5518 | def vplsClean( self ): |
| 5519 | """ |
| 5520 | Description: Clears the VPLS app configuration. |
| 5521 | Returns: main.TRUE on success and main.FALSE on failure |
| 5522 | """ |
| 5523 | try: |
| 5524 | cmdStr = "vpls clean" |
| 5525 | handle = self.sendline( cmdStr ) |
| 5526 | assert handle is not None, "Error in sendline" |
| 5527 | assert "Command not found:" not in handle, handle |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5528 | assert "still updating" not in handle, handle |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5529 | return handle |
| 5530 | except AssertionError: |
| 5531 | main.log.exception( "" ) |
| 5532 | return main.FALSE |
| 5533 | except TypeError: |
| 5534 | main.log.exception( self.name + ": Object not as expected" ) |
| 5535 | return main.FALSE |
| 5536 | except pexpect.EOF: |
| 5537 | main.log.error( self.name + ": EOF exception found" ) |
| 5538 | main.log.error( self.name + ": " + self.handle.before ) |
| 5539 | main.cleanup() |
| 5540 | main.exit() |
| 5541 | except Exception: |
| 5542 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5543 | main.cleanup() |
| 5544 | main.exit() |
| 5545 | |
| 5546 | def vplsSetEncap( self, network, encapType ): |
| 5547 | """ |
| 5548 | CLI command to add an interface to a VPLS network. |
| 5549 | Required arguments: |
| 5550 | network - Name of the network to create. |
| 5551 | encapType - Type of encapsulation. |
| 5552 | returns: |
| 5553 | main.TRUE on success and main.FALSE on failure |
| 5554 | """ |
| 5555 | try: |
| 5556 | network = str( network ) |
| 5557 | encapType = str( encapType ).upper() |
| 5558 | assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type" |
| 5559 | cmdStr = "vpls set-encap " |
| 5560 | cmdStr += network + " " + encapType |
| 5561 | output = self.sendline( cmdStr ) |
| 5562 | assert output is not None, "Error in sendline" |
| 5563 | assert "Command not found:" not in output, output |
| 5564 | assert "Error executing command" not in output, output |
| 5565 | assert "already associated to network" not in output, output |
| 5566 | assert "Encapsulation type " not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5567 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5568 | return main.TRUE |
| 5569 | except AssertionError: |
| 5570 | main.log.exception( "" ) |
| 5571 | return main.FALSE |
| 5572 | except TypeError: |
| 5573 | main.log.exception( self.name + ": Object not as expected" ) |
| 5574 | return main.FALSE |
| 5575 | except pexpect.EOF: |
| 5576 | main.log.error( self.name + ": EOF exception found" ) |
| 5577 | main.log.error( self.name + ": " + self.handle.before ) |
| 5578 | main.cleanup() |
| 5579 | main.exit() |
| 5580 | except Exception: |
| 5581 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5582 | main.cleanup() |
| 5583 | main.exit() |
| 5584 | |
| 5585 | def interfaces( self, jsonFormat=True ): |
| 5586 | """ |
| 5587 | Description: Returns result of interfaces command. |
| 5588 | Optional: |
| 5589 | * jsonFormat: enable json formatting of output |
| 5590 | Returns: |
| 5591 | The output of the command or None on error. |
| 5592 | """ |
| 5593 | try: |
| 5594 | cmdStr = "interfaces" |
| 5595 | if jsonFormat: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5596 | raise NotImplementedError |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5597 | cmdStr += " -j" |
| 5598 | handle = self.sendline( cmdStr ) |
| 5599 | assert handle is not None, "Error in sendline" |
| 5600 | assert "Command not found:" not in handle, handle |
| 5601 | return handle |
| 5602 | except AssertionError: |
| 5603 | main.log.exception( "" ) |
| 5604 | return None |
| 5605 | except TypeError: |
| 5606 | main.log.exception( self.name + ": Object not as expected" ) |
| 5607 | return None |
| 5608 | except pexpect.EOF: |
| 5609 | main.log.error( self.name + ": EOF exception found" ) |
| 5610 | main.log.error( self.name + ": " + self.handle.before ) |
| 5611 | main.cleanup() |
| 5612 | main.exit() |
| 5613 | except NotImplementedError: |
| 5614 | main.log.exception( self.name + ": Json output not supported") |
| 5615 | return None |
| 5616 | except Exception: |
| 5617 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5618 | main.cleanup() |
| 5619 | main.exit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5620 | |
| 5621 | def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ): |
| 5622 | ''' |
| 5623 | Get the timestamp of searchTerm from karaf log. |
| 5624 | |
| 5625 | Arguments: |
| 5626 | splitTerm_before and splitTerm_after: |
| 5627 | |
| 5628 | The terms that split the string that contains the timeStamp of |
| 5629 | searchTerm. For example, if that string is "xxxxxxxcreationTime = |
| 5630 | 1419510501xxxxxx", then the splitTerm_before is "CreationTime = " |
| 5631 | and the splitTerm_after is "x" |
| 5632 | |
| 5633 | others: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5634 | Please look at the "logsearch" Function in onosclidriver.py |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5635 | ''' |
| 5636 | if logNum < 0: |
| 5637 | main.log.error("Get wrong log number ") |
| 5638 | return main.ERROR |
| 5639 | lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum ) |
| 5640 | if len(lines) == 0: |
| 5641 | main.log.warn( "Captured timestamp string is empty" ) |
| 5642 | return main.ERROR |
| 5643 | lines = lines[ 0 ] |
| 5644 | try: |
| 5645 | assert type(lines) is str |
| 5646 | # get the target value |
| 5647 | line = lines.split( splitTerm_before ) |
| 5648 | key = line[ 1 ].split( splitTerm_after ) |
| 5649 | return int( key[ 0 ] ) |
| 5650 | except IndexError: |
| 5651 | main.log.warn( "Index Error!" ) |
| 5652 | return main.ERROR |
| 5653 | except AssertionError: |
| 5654 | main.log.warn( "Search Term Not Found " ) |
| 5655 | return main.ERROR |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5656 | |
| 5657 | def workQueueAdd( self, queueName, value ): |
| 5658 | """ |
| 5659 | CLI command to add a string to the specified Work Queue. |
| 5660 | This function uses the distributed primitives test app, which |
| 5661 | gives some cli access to distributed primitives for testing |
| 5662 | purposes only. |
| 5663 | |
| 5664 | Required arguments: |
| 5665 | queueName - The name of the queue to add to |
| 5666 | value - The value to add to the queue |
| 5667 | returns: |
| 5668 | main.TRUE on success, main.FALSE on failure and |
| 5669 | main.ERROR on error. |
| 5670 | """ |
| 5671 | try: |
| 5672 | queueName = str( queueName ) |
| 5673 | value = str( value ) |
| 5674 | prefix = "work-queue-test" |
| 5675 | operation = "add" |
| 5676 | cmdStr = " ".join( [ prefix, queueName, operation, value ] ) |
| 5677 | output = self.distPrimitivesSend( cmdStr ) |
| 5678 | if "Invalid operation name" in output: |
| 5679 | main.log.warn( output ) |
| 5680 | return main.ERROR |
| 5681 | elif "Done" in output: |
| 5682 | return main.TRUE |
| 5683 | except TypeError: |
| 5684 | main.log.exception( self.name + ": Object not as expected" ) |
| 5685 | return main.ERROR |
| 5686 | except Exception: |
| 5687 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5688 | main.cleanup() |
| 5689 | main.exit() |
| 5690 | |
| 5691 | def workQueueAddMultiple( self, queueName, value1, value2 ): |
| 5692 | """ |
| 5693 | CLI command to add two strings to the specified Work Queue. |
| 5694 | This function uses the distributed primitives test app, which |
| 5695 | gives some cli access to distributed primitives for testing |
| 5696 | purposes only. |
| 5697 | |
| 5698 | Required arguments: |
| 5699 | queueName - The name of the queue to add to |
| 5700 | value1 - The first value to add to the queue |
| 5701 | value2 - The second value to add to the queue |
| 5702 | returns: |
| 5703 | main.TRUE on success, main.FALSE on failure and |
| 5704 | main.ERROR on error. |
| 5705 | """ |
| 5706 | try: |
| 5707 | queueName = str( queueName ) |
| 5708 | value1 = str( value1 ) |
| 5709 | value2 = str( value2 ) |
| 5710 | prefix = "work-queue-test" |
| 5711 | operation = "addMultiple" |
| 5712 | cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] ) |
| 5713 | output = self.distPrimitivesSend( cmdStr ) |
| 5714 | if "Invalid operation name" in output: |
| 5715 | main.log.warn( output ) |
| 5716 | return main.ERROR |
| 5717 | elif "Done" in output: |
| 5718 | return main.TRUE |
| 5719 | except TypeError: |
| 5720 | main.log.exception( self.name + ": Object not as expected" ) |
| 5721 | return main.ERROR |
| 5722 | except Exception: |
| 5723 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5724 | main.cleanup() |
| 5725 | main.exit() |
| 5726 | |
| 5727 | def workQueueTakeAndComplete( self, queueName, number=1 ): |
| 5728 | """ |
| 5729 | CLI command to take a value from the specified Work Queue and compelte it. |
| 5730 | This function uses the distributed primitives test app, which |
| 5731 | gives some cli access to distributed primitives for testing |
| 5732 | purposes only. |
| 5733 | |
| 5734 | Required arguments: |
| 5735 | queueName - The name of the queue to add to |
| 5736 | number - The number of items to take and complete |
| 5737 | returns: |
| 5738 | main.TRUE on success, main.FALSE on failure and |
| 5739 | main.ERROR on error. |
| 5740 | """ |
| 5741 | try: |
| 5742 | queueName = str( queueName ) |
| 5743 | number = str( int( number ) ) |
| 5744 | prefix = "work-queue-test" |
| 5745 | operation = "takeAndComplete" |
| 5746 | cmdStr = " ".join( [ prefix, queueName, operation, number ] ) |
| 5747 | output = self.distPrimitivesSend( cmdStr ) |
| 5748 | if "Invalid operation name" in output: |
| 5749 | main.log.warn( output ) |
| 5750 | return main.ERROR |
| 5751 | elif "Done" in output: |
| 5752 | return main.TRUE |
| 5753 | except TypeError: |
| 5754 | main.log.exception( self.name + ": Object not as expected" ) |
| 5755 | return main.ERROR |
| 5756 | except Exception: |
| 5757 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5758 | main.cleanup() |
| 5759 | main.exit() |
| 5760 | |
| 5761 | def workQueueDestroy( self, queueName ): |
| 5762 | """ |
| 5763 | CLI command to destroy the specified Work Queue. |
| 5764 | This function uses the distributed primitives test app, which |
| 5765 | gives some cli access to distributed primitives for testing |
| 5766 | purposes only. |
| 5767 | |
| 5768 | Required arguments: |
| 5769 | queueName - The name of the queue to add to |
| 5770 | returns: |
| 5771 | main.TRUE on success, main.FALSE on failure and |
| 5772 | main.ERROR on error. |
| 5773 | """ |
| 5774 | try: |
| 5775 | queueName = str( queueName ) |
| 5776 | prefix = "work-queue-test" |
| 5777 | operation = "destroy" |
| 5778 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5779 | output = self.distPrimitivesSend( cmdStr ) |
| 5780 | if "Invalid operation name" in output: |
| 5781 | main.log.warn( output ) |
| 5782 | return main.ERROR |
| 5783 | return main.TRUE |
| 5784 | except TypeError: |
| 5785 | main.log.exception( self.name + ": Object not as expected" ) |
| 5786 | return main.ERROR |
| 5787 | except Exception: |
| 5788 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5789 | main.cleanup() |
| 5790 | main.exit() |
| 5791 | |
| 5792 | def workQueueTotalPending( self, queueName ): |
| 5793 | """ |
| 5794 | CLI command to get the Total Pending items of the specified Work Queue. |
| 5795 | This function uses the distributed primitives test app, which |
| 5796 | gives some cli access to distributed primitives for testing |
| 5797 | purposes only. |
| 5798 | |
| 5799 | Required arguments: |
| 5800 | queueName - The name of the queue to add to |
| 5801 | returns: |
| 5802 | The number of Pending items in the specified work queue or |
| 5803 | None on error |
| 5804 | """ |
| 5805 | try: |
| 5806 | queueName = str( queueName ) |
| 5807 | prefix = "work-queue-test" |
| 5808 | operation = "totalPending" |
| 5809 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5810 | output = self.distPrimitivesSend( cmdStr ) |
| 5811 | pattern = r'\d+' |
| 5812 | if "Invalid operation name" in output: |
| 5813 | main.log.warn( output ) |
| 5814 | return None |
| 5815 | else: |
| 5816 | match = re.search( pattern, output ) |
| 5817 | return match.group(0) |
| 5818 | except ( AttributeError, TypeError ): |
| 5819 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5820 | return None |
| 5821 | except Exception: |
| 5822 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5823 | main.cleanup() |
| 5824 | main.exit() |
| 5825 | |
| 5826 | def workQueueTotalCompleted( self, queueName ): |
| 5827 | """ |
| 5828 | CLI command to get the Total Completed items of the specified Work Queue. |
| 5829 | This function uses the distributed primitives test app, which |
| 5830 | gives some cli access to distributed primitives for testing |
| 5831 | purposes only. |
| 5832 | |
| 5833 | Required arguments: |
| 5834 | queueName - The name of the queue to add to |
| 5835 | returns: |
| 5836 | The number of complete items in the specified work queue or |
| 5837 | None on error |
| 5838 | """ |
| 5839 | try: |
| 5840 | queueName = str( queueName ) |
| 5841 | prefix = "work-queue-test" |
| 5842 | operation = "totalCompleted" |
| 5843 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5844 | output = self.distPrimitivesSend( cmdStr ) |
| 5845 | pattern = r'\d+' |
| 5846 | if "Invalid operation name" in output: |
| 5847 | main.log.warn( output ) |
| 5848 | return None |
| 5849 | else: |
| 5850 | match = re.search( pattern, output ) |
| 5851 | return match.group(0) |
| 5852 | except ( AttributeError, TypeError ): |
| 5853 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5854 | return None |
| 5855 | except Exception: |
| 5856 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5857 | main.cleanup() |
| 5858 | main.exit() |
| 5859 | |
| 5860 | def workQueueTotalInProgress( self, queueName ): |
| 5861 | """ |
| 5862 | CLI command to get the Total In Progress items of the specified Work Queue. |
| 5863 | This function uses the distributed primitives test app, which |
| 5864 | gives some cli access to distributed primitives for testing |
| 5865 | purposes only. |
| 5866 | |
| 5867 | Required arguments: |
| 5868 | queueName - The name of the queue to add to |
| 5869 | returns: |
| 5870 | The number of In Progress items in the specified work queue or |
| 5871 | None on error |
| 5872 | """ |
| 5873 | try: |
| 5874 | queueName = str( queueName ) |
| 5875 | prefix = "work-queue-test" |
| 5876 | operation = "totalInProgress" |
| 5877 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5878 | output = self.distPrimitivesSend( cmdStr ) |
| 5879 | pattern = r'\d+' |
| 5880 | if "Invalid operation name" in output: |
| 5881 | main.log.warn( output ) |
| 5882 | return None |
| 5883 | else: |
| 5884 | match = re.search( pattern, output ) |
| 5885 | return match.group(0) |
| 5886 | except ( AttributeError, TypeError ): |
| 5887 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5888 | return None |
| 5889 | except Exception: |
| 5890 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5891 | main.cleanup() |
| 5892 | main.exit() |