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 |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5 | Copyright 2014 Open Networking Foundation (ONF) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 14 | (at your option) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 24 | |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 37 | jeremyr@opennetworking.org |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 38 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 39 | import pexpect |
| 40 | import re |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 41 | import json |
| 42 | import types |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 43 | import time |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 44 | import os |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 45 | from drivers.common.clidriver import CLI |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 46 | from core.graph import Graph |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 47 | from cStringIO import StringIO |
| 48 | from itertools import izip |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 49 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 50 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 51 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 52 | def __init__( self ): |
| 53 | """ |
| 54 | Initialize client |
| 55 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 56 | self.name = None |
| 57 | self.home = None |
| 58 | self.handle = None |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 59 | self.karafUser = None |
| 60 | self.karafPass = None |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 61 | self.karafPrompt = "sdn@root >" # FIXME: make configurable |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 62 | self.graph = Graph() |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 63 | super( OnosCliDriver, self ).__init__() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 64 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 65 | def checkOptions( self, var, defaultVar ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 66 | if var is None or var == "": |
| 67 | return defaultVar |
| 68 | return var |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 69 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 70 | def connect( self, **connectargs ): |
| 71 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 72 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 73 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 74 | try: |
| 75 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 76 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 658ec01 | 2015-03-11 15:13:09 -0700 | [diff] [blame] | 77 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 78 | for key in self.options: |
| 79 | if key == "home": |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 80 | self.home = self.options[ key ] |
| 81 | elif key == "karaf_username": |
| 82 | self.karafUser = self.options[ key ] |
| 83 | elif key == "karaf_password": |
| 84 | self.karafPass = self.options[ key ] |
| 85 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 86 | self.home = self.checkOptions( self.home, "~/onos" ) |
| 87 | self.karafUser = self.checkOptions( self.karafUser, self.user_name ) |
| 88 | self.karafPass = self.checkOptions( self.karafPass, self.pwd ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 89 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 90 | for key in self.options: |
| 91 | if key == 'onosIp': |
| 92 | self.onosIp = self.options[ 'onosIp' ] |
| 93 | break |
| 94 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 95 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 96 | |
| 97 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 98 | if os.getenv( str( self.ip_address ) ) is not None: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 99 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 100 | else: |
| 101 | main.log.info( self.name + |
| 102 | ": Trying to connect to " + |
| 103 | self.ip_address ) |
| 104 | |
| 105 | except KeyError: |
| 106 | main.log.info( "Invalid host name," + |
| 107 | " connecting to local host instead" ) |
| 108 | self.ip_address = 'localhost' |
| 109 | except Exception as inst: |
| 110 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 111 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 112 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 113 | user_name=self.user_name, |
| 114 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 115 | port=self.port, |
| 116 | pwd=self.pwd, |
| 117 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 118 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 119 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 120 | self.handle.expect( self.prompt ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 121 | if self.handle: |
| 122 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 123 | else: |
| 124 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 125 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 126 | except TypeError: |
| 127 | main.log.exception( self.name + ": Object not as expected" ) |
| 128 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 129 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 130 | main.log.error( self.name + ": EOF exception found" ) |
| 131 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 132 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 133 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 134 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 135 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 136 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 137 | def disconnect( self ): |
| 138 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 139 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 140 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 141 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 142 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 143 | if self.handle: |
| 144 | i = self.logout() |
| 145 | if i == main.TRUE: |
| 146 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 147 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 148 | self.handle.sendline( "exit" ) |
| 149 | self.handle.expect( "closed" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 150 | except TypeError: |
| 151 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 152 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 153 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 154 | main.log.error( self.name + ": EOF exception found" ) |
| 155 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 156 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 157 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 158 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 159 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 160 | main.log.exception( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 161 | response = main.FALSE |
| 162 | return response |
| 163 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 164 | def logout( self ): |
| 165 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 166 | Sends 'logout' command to ONOS cli |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 167 | Returns main.TRUE if exited CLI and |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 168 | main.FALSE on timeout (not guranteed you are disconnected) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 169 | None on TypeError |
| 170 | Exits test on unknown error or pexpect exits unexpectedly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 171 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 172 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 173 | if self.handle: |
| 174 | self.handle.sendline( "" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 175 | i = self.handle.expect( [ self.karafPrompt, self.prompt, pexpect.TIMEOUT ], |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 176 | timeout=10 ) |
| 177 | if i == 0: # In ONOS CLI |
| 178 | self.handle.sendline( "logout" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 179 | j = self.handle.expect( [ self.prompt, |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 180 | "Command not found:", |
| 181 | pexpect.TIMEOUT ] ) |
| 182 | if j == 0: # Successfully logged out |
| 183 | return main.TRUE |
| 184 | elif j == 1 or j == 2: |
| 185 | # ONOS didn't fully load, and logout command isn't working |
| 186 | # or the command timed out |
| 187 | self.handle.send( "\x04" ) # send ctrl-d |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 188 | try: |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 189 | self.handle.expect( self.prompt ) |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 190 | except pexpect.TIMEOUT: |
| 191 | main.log.error( "ONOS did not respond to 'logout' or CTRL-d" ) |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 192 | return main.TRUE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 193 | else: # some other output |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 194 | main.log.warn( "Unknown repsonse to logout command: '{}'", |
| 195 | repr( self.handle.before ) ) |
| 196 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 197 | elif i == 1: # not in CLI |
| 198 | return main.TRUE |
| 199 | elif i == 3: # Timeout |
| 200 | return main.FALSE |
| 201 | else: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 202 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 203 | except TypeError: |
| 204 | main.log.exception( self.name + ": Object not as expected" ) |
| 205 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 206 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 207 | main.log.error( self.name + ": eof exception found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 208 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 209 | main.cleanAndExit() |
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!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 215 | main.cleanAndExit() |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 216 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 217 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 218 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 219 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 220 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 221 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 222 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 223 | try: |
| 224 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 225 | main.log.error( "Must define cellname" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 226 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 227 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 228 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 229 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 230 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 231 | # and that this driver will have to change accordingly |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 232 | self.handle.expect( str( cellname ) ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 233 | handleBefore = self.handle.before |
| 234 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 235 | # Get the rest of the handle |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 236 | self.handle.sendline( "" ) |
| 237 | self.handle.expect( self.prompt ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 238 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 239 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 240 | main.log.info( "Cell call returned: " + handleBefore + |
| 241 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 242 | |
| 243 | return main.TRUE |
| 244 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 245 | except TypeError: |
| 246 | main.log.exception( self.name + ": Object not as expected" ) |
| 247 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 248 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 249 | main.log.error( self.name + ": eof exception found" ) |
| 250 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 251 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 252 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 253 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 254 | main.cleanAndExit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 255 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 256 | def startOnosCli( self, ONOSIp, karafTimeout="", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 257 | commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 258 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 259 | karafTimeout is an optional argument. karafTimeout value passed |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 260 | by user would be used to set the current karaf shell idle timeout. |
| 261 | 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] | 262 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 263 | Below is an example to start a session with 60 seconds idle timeout |
| 264 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 265 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 266 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 267 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 268 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 269 | Note: karafTimeout is left as str so that this could be read |
| 270 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 271 | """ |
You Wang | f69ab39 | 2016-01-26 16:34:38 -0800 | [diff] [blame] | 272 | self.onosIp = ONOSIp |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 273 | try: |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 274 | # Check if we are already in the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 275 | self.handle.sendline( "" ) |
| 276 | x = self.handle.expect( [ |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 277 | self.prompt, self.karafPrompt ], commandlineTimeout ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 278 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 279 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 280 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 281 | |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 282 | # Not in CLI so login |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 283 | if waitForStart: |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 284 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
| 285 | startCliCommand = "onos-wait-for-start " |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 286 | else: |
| 287 | startCliCommand = "onos " |
| 288 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 289 | i = self.handle.expect( [ |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 290 | self.karafPrompt, |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 291 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 292 | |
| 293 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 294 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 295 | if karafTimeout: # FIXME: This doesn't look right |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 296 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 297 | "config:property-set -p org.apache.karaf.shell\ |
| 298 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 299 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 300 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 301 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 302 | self.handle.expect( self.karafPrompt ) |
| 303 | main.log.debug( self.handle.before ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 304 | return main.TRUE |
| 305 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 306 | # If failed, send ctrl+c to process and try again |
| 307 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 308 | self.handle.send( "\x03" ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 309 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 310 | i = self.handle.expect( [ self.karafPrompt, pexpect.TIMEOUT ], |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 311 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 312 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 313 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 314 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 315 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 316 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 317 | "config:property-set -p org.apache.karaf.shell\ |
| 318 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 319 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 320 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 321 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 322 | self.handle.expect( self.karafPrompt ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 323 | return main.TRUE |
| 324 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 325 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 326 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 327 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 328 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 329 | except TypeError: |
| 330 | main.log.exception( self.name + ": Object not as expected" ) |
| 331 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 332 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 333 | main.log.error( self.name + ": EOF exception found" ) |
| 334 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 335 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 336 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 337 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 338 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 339 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 340 | def startCellCli( self, karafTimeout="", |
| 341 | commandlineTimeout=10, onosStartTimeout=60 ): |
| 342 | """ |
| 343 | Start CLI on onos ecll handle. |
| 344 | |
| 345 | karafTimeout is an optional argument. karafTimeout value passed |
| 346 | by user would be used to set the current karaf shell idle timeout. |
| 347 | Note that when ever this property is modified the shell will exit and |
| 348 | the subsequent login would reflect new idle timeout. |
| 349 | Below is an example to start a session with 60 seconds idle timeout |
| 350 | ( input value is in milliseconds ): |
| 351 | |
| 352 | tValue = "60000" |
| 353 | |
| 354 | Note: karafTimeout is left as str so that this could be read |
| 355 | and passed to startOnosCli from PARAMS file as str. |
| 356 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 357 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 358 | try: |
| 359 | self.handle.sendline( "" ) |
| 360 | x = self.handle.expect( [ |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 361 | self.prompt, self.karafPrompt ], commandlineTimeout ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 362 | |
| 363 | if x == 1: |
| 364 | main.log.info( "ONOS cli is already running" ) |
| 365 | return main.TRUE |
| 366 | |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 367 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 368 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 369 | i = self.handle.expect( [ |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 370 | self.karafPrompt, |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 371 | pexpect.TIMEOUT ], onosStartTimeout ) |
| 372 | |
| 373 | if i == 0: |
| 374 | main.log.info( self.name + " CLI Started successfully" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 375 | if karafTimeout: # FIXME: This doesn't look right |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 376 | self.handle.sendline( |
| 377 | "config:property-set -p org.apache.karaf.shell\ |
| 378 | sshIdleTimeout " + |
| 379 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 380 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 381 | self.handle.sendline( "/opt/onos/bin/onos" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 382 | self.handle.expect( self.karafPrompt ) |
| 383 | main.log.debug( self.handle.before ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 384 | return main.TRUE |
| 385 | else: |
| 386 | # If failed, send ctrl+c to process and try again |
| 387 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 388 | self.handle.send( "\x03" ) |
| 389 | self.handle.sendline( "/opt/onos/bin/onos" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 390 | i = self.handle.expect( [ self.karafPrompt, pexpect.TIMEOUT ], |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 391 | timeout=30 ) |
| 392 | if i == 0: |
| 393 | main.log.info( self.name + " CLI Started " + |
| 394 | "successfully after retry attempt" ) |
| 395 | if karafTimeout: |
| 396 | self.handle.sendline( |
| 397 | "config:property-set -p org.apache.karaf.shell\ |
| 398 | sshIdleTimeout " + |
| 399 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 400 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 401 | self.handle.sendline( "/opt/onos/bin/onos" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 402 | self.handle.expect( self.karafPrompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 403 | return main.TRUE |
| 404 | else: |
| 405 | main.log.error( "Connection to CLI " + |
| 406 | self.name + " timeout" ) |
| 407 | return main.FALSE |
| 408 | |
| 409 | except TypeError: |
| 410 | main.log.exception( self.name + ": Object not as expected" ) |
| 411 | return None |
| 412 | except pexpect.EOF: |
| 413 | main.log.error( self.name + ": EOF exception found" ) |
| 414 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 415 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 416 | except Exception: |
| 417 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 418 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 419 | |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 420 | def log( self, cmdStr, level="", noExit=False ): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 421 | """ |
| 422 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 423 | returns main.TRUE on success |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 424 | returns main.FALSE if Error occurred |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 425 | if noExit is True, TestON will not exit, but clean up |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 426 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 427 | Level defaults to INFO |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 428 | if cmdStr has spaces then put quotes in the passed string |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 429 | """ |
| 430 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 431 | lvlStr = "" |
| 432 | if level: |
| 433 | lvlStr = "--level=" + level |
| 434 | |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 435 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 436 | self.handle.expect( "log:log" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 437 | self.handle.expect( self.karafPrompt ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 438 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 439 | response = self.handle.before |
| 440 | if re.search( "Error", response ): |
| 441 | return main.FALSE |
| 442 | return main.TRUE |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 443 | except pexpect.TIMEOUT: |
| 444 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 445 | if noExit: |
| 446 | main.cleanup() |
| 447 | return None |
| 448 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 449 | main.cleanAndExit() |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 450 | except pexpect.EOF: |
| 451 | main.log.error( self.name + ": EOF exception found" ) |
| 452 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 453 | if noExit: |
| 454 | main.cleanup() |
| 455 | return None |
| 456 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 457 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 458 | except Exception: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 459 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 460 | if noExit: |
| 461 | main.cleanup() |
| 462 | return None |
| 463 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 464 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 465 | |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 466 | def clearBuffer( self, debug=False, timeout=10, noExit=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 467 | """ |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 468 | Test cli connection and clear any left over output in the buffer |
| 469 | Optional Arguments: |
| 470 | debug - Defaults to False. If True, will enable debug logging. |
| 471 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 472 | before a timeout. |
| 473 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 474 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 475 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 476 | # Try to reconnect if disconnected from cli |
| 477 | self.handle.sendline( "" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 478 | i = self.handle.expect( [ self.karafPrompt, self.prompt, pexpect.TIMEOUT ] ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 479 | response = self.handle.before |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 480 | if i == 1: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 481 | main.log.error( self.name + ": onos cli session closed. " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 482 | if self.onosIp: |
| 483 | main.log.warn( "Trying to reconnect " + self.onosIp ) |
| 484 | reconnectResult = self.startOnosCli( self.onosIp ) |
| 485 | if reconnectResult: |
| 486 | main.log.info( self.name + ": onos cli session reconnected." ) |
| 487 | else: |
| 488 | main.log.error( self.name + ": reconnection failed." ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 489 | if noExit: |
| 490 | return None |
| 491 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 492 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 493 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 494 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 495 | if i == 2: |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 496 | main.log.warn( "Timeout when testing cli responsiveness" ) |
| 497 | main.log.debug( self.handle.before ) |
| 498 | self.handle.send( "\x03" ) # Send ctrl-c to clear previous output |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 499 | self.handle.expect( self.karafPrompt ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 500 | |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 501 | response += self.handle.before |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 502 | if debug: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 503 | main.log.debug( self.name + ": Raw output from sending ''" ) |
| 504 | main.log.debug( self.name + ": " + repr( response ) ) |
| 505 | except pexpect.TIMEOUT: |
| 506 | main.log.error( self.name + ": ONOS timeout" ) |
| 507 | main.log.debug( self.handle.before ) |
You Wang | 141b43b | 2018-06-26 16:50:18 -0700 | [diff] [blame] | 508 | self.handle.send( "\x03" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 509 | self.handle.expect( self.karafPrompt ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 510 | return None |
| 511 | except pexpect.EOF: |
| 512 | main.log.error( self.name + ": EOF exception found" ) |
| 513 | main.log.error( self.name + ": " + self.handle.before ) |
| 514 | if noExit: |
| 515 | return None |
| 516 | else: |
| 517 | main.cleanAndExit() |
| 518 | except Exception: |
| 519 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 520 | if noExit: |
| 521 | return None |
| 522 | else: |
| 523 | main.cleanAndExit() |
| 524 | |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 525 | def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 526 | """ |
| 527 | A wrapper around pexpect's sendline/expect. Will return all the output from a given command |
| 528 | |
| 529 | Required Arguments: |
| 530 | cmdStr - String to send to the pexpect session |
| 531 | |
| 532 | Optional Arguments: |
| 533 | showResponse - Defaults to False. If True will log the response. |
| 534 | debug - Defaults to False. If True, will enable debug logging. |
| 535 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 536 | before a timeout. |
| 537 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
| 538 | closed channel, but instead return None |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 539 | relaxedRegex - Defaults to True. If there is a pipe in the command send, will only try to match the last part of the piped command. |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 540 | |
| 541 | Warning: There are no sanity checking to commands sent using this method. |
| 542 | |
| 543 | """ |
| 544 | try: |
| 545 | # Try to reconnect if disconnected from cli |
| 546 | self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit ) |
| 547 | if debug: |
| 548 | # NOTE: This adds an average of .4 seconds per call |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 549 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 550 | self.log( logStr, noExit=noExit ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 551 | self.handle.sendline( cmdStr ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 552 | self.handle.expect( self.karafPrompt, timeout ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 553 | response = self.handle.before |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 554 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 555 | + self.name + "." ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 556 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 557 | main.log.debug( self.name + ": Raw output" ) |
| 558 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 559 | |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 560 | # Remove control codes from karaf 4.2.1 |
Jon Hall | 39e3ffe | 2018-12-05 11:40:29 -0800 | [diff] [blame^] | 561 | karafEscape = re.compile( r"('(0|1)~\'|\r\r\r\n\x1b\[A\x1b\[79C(x)?|\x1b(>|=)|\x1b\[90m~)" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 562 | response = karafEscape.sub( '', response ) |
| 563 | if debug: |
| 564 | main.log.debug( self.name + ": karafEscape output" ) |
| 565 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 566 | # Remove ANSI color control strings from output |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 567 | ansiEscape = re.compile( r'((\x9b|\x1b\[)[0-?]*[ -/]*[@-~])' ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 568 | response = ansiEscape.sub( '', response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 569 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 570 | main.log.debug( self.name + ": ansiEscape output" ) |
| 571 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 572 | |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 573 | # Remove ANSI color control strings from output |
| 574 | backspaceEscape = re.compile( r'((..\x08\x08)|(.|\s)\x08)' ) |
| 575 | response = backspaceEscape.sub( '', response ) |
| 576 | if debug: |
| 577 | main.log.debug( self.name + ": backspaceEscape output" ) |
| 578 | main.log.debug( self.name + ": " + repr( response ) ) |
| 579 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 580 | # Remove extra return chars that get added |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 581 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 582 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 583 | main.log.debug( self.name + ": Removed extra returns " + |
| 584 | "from output" ) |
| 585 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 586 | |
| 587 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 588 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 589 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 590 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 591 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 592 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 593 | # parse for just the output, remove the cmd from response |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 594 | if relaxedRegex: |
| 595 | # This was added because karaf 4.2 is stripping some characters from the command echo |
| 596 | endStr = cmdStr.split( '|' )[-1] |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 597 | output = response.split( endStr.strip(), 1 ) |
Jon Hall | 39e3ffe | 2018-12-05 11:40:29 -0800 | [diff] [blame^] | 598 | if len( output ) < 2: |
| 599 | main.log.warn( "Relaxing regex match to last 5 characters of the sent command" ) |
| 600 | output = response.split( endStr.strip()[-5:], 1 ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 601 | else: |
Jon Hall | 8c9dd1c | 2018-11-14 15:40:39 -0800 | [diff] [blame] | 602 | output = response.split( endStr.strip(), 1 ) |
| 603 | if len( output ) < 2: |
| 604 | main.log.warn( "Relaxing regex match to last 5 characters of the sent command" ) |
Jon Hall | 0623dd4 | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 605 | output = response.split( endStr.strip()[-5:], 1 ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 606 | if output: |
| 607 | if debug: |
| 608 | main.log.debug( self.name + ": split output" ) |
| 609 | for r in output: |
| 610 | main.log.debug( self.name + ": " + repr( r ) ) |
| 611 | output = output[ 1 ].strip() |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 612 | if showResponse: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 613 | main.log.info( "Response from ONOS: {}".format( output ) ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 614 | self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 615 | return output |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 616 | except pexpect.TIMEOUT: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 617 | main.log.error( self.name + ": ONOS timeout" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 618 | if debug: |
| 619 | main.log.debug( self.handle.before ) |
You Wang | 141b43b | 2018-06-26 16:50:18 -0700 | [diff] [blame] | 620 | self.handle.send( "\x03" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 621 | self.handle.expect( self.karafPrompt ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 622 | return None |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 623 | except IndexError: |
| 624 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 625 | main.log.debug( "response: {}".format( repr( response ) ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 626 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 627 | except TypeError: |
| 628 | main.log.exception( self.name + ": Object not as expected" ) |
| 629 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 630 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 631 | main.log.error( self.name + ": EOF exception found" ) |
| 632 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 633 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 634 | return None |
| 635 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 636 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 637 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 638 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 639 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 640 | return None |
| 641 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 642 | main.cleanAndExit() |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 643 | |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 644 | def lineCount( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True ): |
| 645 | """ |
| 646 | A wrapper around sendline(). Will return the number of lines returned or None on error |
| 647 | |
| 648 | Required Arguments: |
| 649 | cmdStr - String to send to the pexpect session |
| 650 | |
| 651 | Optional Arguments: |
| 652 | showResponse - Defaults to False. If True will log the response. |
| 653 | debug - Defaults to False. If True, will enable debug logging. |
| 654 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 655 | before a timeout. |
| 656 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
| 657 | closed channel, but instead return None |
| 658 | relaxedRegex - Defaults to True. If there is a pipe in the command send, will only try to match the last part of the piped command. |
| 659 | |
| 660 | Warning: There are no sanity checking to commands sent using this method. |
| 661 | |
| 662 | """ |
| 663 | try: |
| 664 | numLines = self.sendline( cmdStr, showResponse, debug, timeout, noExit, relaxedRegex ) |
Jon Hall | 8c9dd1c | 2018-11-14 15:40:39 -0800 | [diff] [blame] | 665 | parsed = re.search( "(\d+)\s+(\d+)", numLines ) |
| 666 | if not parsed: |
| 667 | main.log.error( "Warning, output of karaf's wc may have changed" ) |
| 668 | return None |
| 669 | return parsed.group( 1 ) |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 670 | except IndexError: |
| 671 | main.log.exception( self.name + ": Object not as expected" ) |
| 672 | main.log.debug( "response: {}".format( repr( response ) ) ) |
| 673 | return None |
| 674 | except TypeError: |
| 675 | main.log.exception( self.name + ": Object not as expected" ) |
| 676 | return None |
| 677 | except Exception: |
| 678 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 679 | if noExit: |
| 680 | return None |
| 681 | else: |
| 682 | main.cleanAndExit() |
| 683 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 684 | # IMPORTANT NOTE: |
| 685 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 686 | # the cli command changing 'a:b' with 'aB'. |
| 687 | # Ex ) onos:topology > onosTopology |
| 688 | # onos:links > onosLinks |
| 689 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 690 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 691 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 692 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 693 | Adds a new cluster node by ID and address information. |
| 694 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 695 | * nodeId |
| 696 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 697 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 698 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 699 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 700 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 701 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 702 | str( ONOSIp ) + " " + str( tcpPort ) |
| 703 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 704 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 705 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 706 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 707 | main.log.error( self.name + ": Error in adding node" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 708 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 709 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 710 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 711 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 712 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 713 | except AssertionError: |
| 714 | main.log.exception( "" ) |
| 715 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 716 | except TypeError: |
| 717 | main.log.exception( self.name + ": Object not as expected" ) |
| 718 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 719 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 720 | main.log.error( self.name + ": EOF exception found" ) |
| 721 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 722 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 723 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 724 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 725 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 726 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 727 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 728 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 729 | Removes a cluster by ID |
| 730 | Issues command: 'remove-node [<node-id>]' |
| 731 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 732 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 733 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 734 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 735 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 736 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 737 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 738 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 739 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 740 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 741 | main.log.error( self.name + ": Error in removing node" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 742 | main.log.error( handle ) |
| 743 | return main.FALSE |
| 744 | else: |
| 745 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 746 | except AssertionError: |
| 747 | main.log.exception( "" ) |
| 748 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 749 | except TypeError: |
| 750 | main.log.exception( self.name + ": Object not as expected" ) |
| 751 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 752 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 753 | main.log.error( self.name + ": EOF exception found" ) |
| 754 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 755 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 756 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 757 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 758 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 759 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 760 | def nodes( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 761 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 762 | List the nodes currently visible |
| 763 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 764 | Optional argument: |
| 765 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 766 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 767 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 768 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 769 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 770 | cmdStr += " -j" |
| 771 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 772 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 773 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 774 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 775 | except AssertionError: |
| 776 | main.log.exception( "" ) |
| 777 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 778 | except TypeError: |
| 779 | main.log.exception( self.name + ": Object not as expected" ) |
| 780 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 781 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 782 | main.log.error( self.name + ": EOF exception found" ) |
| 783 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 784 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 785 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 786 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 787 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 788 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 789 | def topology( self ): |
| 790 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 791 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 792 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 793 | Return: |
| 794 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 795 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 796 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 797 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 798 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 799 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 800 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 801 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 802 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 803 | except AssertionError: |
| 804 | main.log.exception( "" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 805 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 806 | except TypeError: |
| 807 | main.log.exception( self.name + ": Object not as expected" ) |
| 808 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 809 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 810 | main.log.error( self.name + ": EOF exception found" ) |
| 811 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 812 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 813 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 814 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 815 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 816 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 817 | def deviceRemove( self, deviceId ): |
| 818 | """ |
| 819 | Removes particular device from storage |
| 820 | |
| 821 | TODO: refactor this function |
| 822 | """ |
| 823 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 824 | cmdStr = "device-remove " + str( deviceId ) |
| 825 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 826 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 827 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 828 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 829 | main.log.error( self.name + ": Error in removing device" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 830 | main.log.error( handle ) |
| 831 | return main.FALSE |
| 832 | else: |
| 833 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 834 | except AssertionError: |
| 835 | main.log.exception( "" ) |
| 836 | return None |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 837 | except TypeError: |
| 838 | main.log.exception( self.name + ": Object not as expected" ) |
| 839 | return None |
| 840 | except pexpect.EOF: |
| 841 | main.log.error( self.name + ": EOF exception found" ) |
| 842 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 843 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 844 | except Exception: |
| 845 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 846 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 847 | |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 848 | def devices( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 849 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 850 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 851 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 852 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 853 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 854 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 855 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 856 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 857 | cmdStr += " -j" |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 858 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 859 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 860 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 861 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 862 | except AssertionError: |
| 863 | main.log.exception( "" ) |
| 864 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 865 | except TypeError: |
| 866 | main.log.exception( self.name + ": Object not as expected" ) |
| 867 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 868 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 869 | main.log.error( self.name + ": EOF exception found" ) |
| 870 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 871 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 872 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 873 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 874 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 875 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 876 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 877 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 878 | This balances the devices across all controllers |
| 879 | by issuing command: 'onos> onos:balance-masters' |
| 880 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 881 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 882 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 883 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 884 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 885 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 886 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 887 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 888 | main.log.error( self.name + ": Error in balancing masters" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 889 | main.log.error( handle ) |
| 890 | return main.FALSE |
| 891 | else: |
| 892 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 893 | except AssertionError: |
| 894 | main.log.exception( "" ) |
| 895 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 896 | except TypeError: |
| 897 | main.log.exception( self.name + ": Object not as expected" ) |
| 898 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 899 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 900 | main.log.error( self.name + ": EOF exception found" ) |
| 901 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 902 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 903 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 904 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 905 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 906 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 907 | def checkMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 908 | """ |
| 909 | Returns the output of the masters command. |
| 910 | Optional argument: |
| 911 | * jsonFormat - boolean indicating if you want output in json |
| 912 | """ |
| 913 | try: |
| 914 | cmdStr = "onos:masters" |
| 915 | if jsonFormat: |
| 916 | cmdStr += " -j" |
| 917 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 918 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 919 | assert "Command not found:" not in output, output |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 920 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 921 | except AssertionError: |
| 922 | main.log.exception( "" ) |
| 923 | return None |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 924 | except TypeError: |
| 925 | main.log.exception( self.name + ": Object not as expected" ) |
| 926 | return None |
| 927 | except pexpect.EOF: |
| 928 | main.log.error( self.name + ": EOF exception found" ) |
| 929 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 930 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 931 | except Exception: |
| 932 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 933 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 934 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 935 | def checkBalanceMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 936 | """ |
| 937 | Uses the master command to check that the devices' leadership |
| 938 | is evenly divided |
| 939 | |
| 940 | Dependencies: checkMasters() and summary() |
| 941 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 942 | Returns main.TRUE if the devices are balanced |
| 943 | Returns main.FALSE if the devices are unbalanced |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 944 | Exits on Exception |
| 945 | Returns None on TypeError |
| 946 | """ |
| 947 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 948 | summaryOutput = self.summary() |
| 949 | totalDevices = json.loads( summaryOutput )[ "devices" ] |
| 950 | except ( TypeError, ValueError ): |
| 951 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) ) |
| 952 | return None |
| 953 | try: |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 954 | totalOwnedDevices = 0 |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 955 | mastersOutput = self.checkMasters() |
| 956 | masters = json.loads( mastersOutput ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 957 | first = masters[ 0 ][ "size" ] |
| 958 | for master in masters: |
| 959 | totalOwnedDevices += master[ "size" ] |
| 960 | if master[ "size" ] > first + 1 or master[ "size" ] < first - 1: |
| 961 | main.log.error( "Mastership not balanced" ) |
| 962 | main.log.info( "\n" + self.checkMasters( False ) ) |
| 963 | return main.FALSE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 964 | main.log.info( "Mastership balanced between " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 965 | str( len( masters ) ) + " masters" ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 966 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 967 | except ( TypeError, ValueError ): |
| 968 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 969 | return None |
| 970 | except pexpect.EOF: |
| 971 | main.log.error( self.name + ": EOF exception found" ) |
| 972 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 973 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 974 | except Exception: |
| 975 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 976 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 977 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 978 | def links( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 979 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 980 | Lists all core links |
| 981 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 982 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 983 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 984 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 985 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 986 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 987 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 988 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 989 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 990 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 991 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 992 | except AssertionError: |
| 993 | main.log.exception( "" ) |
| 994 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 995 | except TypeError: |
| 996 | main.log.exception( self.name + ": Object not as expected" ) |
| 997 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 998 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 999 | main.log.error( self.name + ": EOF exception found" ) |
| 1000 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1001 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1002 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1003 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1004 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1005 | |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 1006 | def ports( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1007 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1008 | Lists all ports |
| 1009 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1010 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1011 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1012 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1013 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1014 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1015 | cmdStr += " -j" |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 1016 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1017 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1018 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1019 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1020 | except AssertionError: |
| 1021 | main.log.exception( "" ) |
| 1022 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1023 | except TypeError: |
| 1024 | main.log.exception( self.name + ": Object not as expected" ) |
| 1025 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1026 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1027 | main.log.error( self.name + ": EOF exception found" ) |
| 1028 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1029 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1030 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1031 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1032 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1033 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1034 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1035 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1036 | Lists all devices and the controllers with roles assigned to them |
| 1037 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1038 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1039 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1040 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1041 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1042 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1043 | cmdStr += " -j" |
| 1044 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1045 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1046 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1047 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1048 | except AssertionError: |
| 1049 | main.log.exception( "" ) |
| 1050 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1051 | except TypeError: |
| 1052 | main.log.exception( self.name + ": Object not as expected" ) |
| 1053 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1054 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1055 | main.log.error( self.name + ": EOF exception found" ) |
| 1056 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1057 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1058 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1059 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1060 | main.cleanAndExit() |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1061 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1062 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1063 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1064 | Given the a string containing the json representation of the "roles" |
| 1065 | cli command and a partial or whole device id, returns a json object |
| 1066 | containing the roles output for the first device whose id contains |
| 1067 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1068 | |
| 1069 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1070 | A dict of the role assignments for the given device or |
| 1071 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1072 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1073 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1074 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1075 | return None |
| 1076 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1077 | rawRoles = self.roles() |
| 1078 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1079 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1080 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1081 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1082 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1083 | return device |
| 1084 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1085 | except ( TypeError, ValueError ): |
| 1086 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1087 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 1088 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1089 | main.log.error( self.name + ": EOF exception found" ) |
| 1090 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1091 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1092 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1093 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1094 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1095 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1096 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1097 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1098 | Iterates through each device and checks if there is a master assigned |
| 1099 | Returns: main.TRUE if each device has a master |
| 1100 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1101 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1102 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1103 | rawRoles = self.roles() |
| 1104 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1105 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1106 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1107 | # print device |
| 1108 | if device[ 'master' ] == "none": |
| 1109 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1110 | return main.FALSE |
| 1111 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1112 | except ( TypeError, ValueError ): |
| 1113 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1114 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1115 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1116 | main.log.error( self.name + ": EOF exception found" ) |
| 1117 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1118 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1119 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1120 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1121 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1122 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1123 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1124 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1125 | Returns string of paths, and the cost. |
| 1126 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1127 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1128 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1129 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 1130 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1131 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1132 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1133 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1134 | main.log.error( self.name + ": Error in getting paths" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1135 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1136 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1137 | path = handle.split( ";" )[ 0 ] |
| 1138 | cost = handle.split( ";" )[ 1 ] |
| 1139 | return ( path, cost ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1140 | except AssertionError: |
| 1141 | main.log.exception( "" ) |
| 1142 | return ( handle, "Error" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1143 | except TypeError: |
| 1144 | main.log.exception( self.name + ": Object not as expected" ) |
| 1145 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1146 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1147 | main.log.error( self.name + ": EOF exception found" ) |
| 1148 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1149 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1150 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1151 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1152 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1153 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1154 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1155 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1156 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1157 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1158 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1159 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1160 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1161 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1162 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1163 | cmdStr += " -j" |
| 1164 | handle = self.sendline( cmdStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1165 | if handle: |
| 1166 | assert "Command not found:" not in handle, handle |
Jon Hall | baf5316 | 2015-12-17 17:04:34 -0800 | [diff] [blame] | 1167 | # TODO: Maybe make this less hardcoded |
| 1168 | # ConsistentMap Exceptions |
| 1169 | assert "org.onosproject.store.service" not in handle |
| 1170 | # Node not leader |
| 1171 | assert "java.lang.IllegalStateException" not in handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1172 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1173 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1174 | main.log.exception( self.name + ": Error in processing '" + cmdStr + "' " + |
Jeremy Songster | 6949cea | 2016-04-19 18:13:18 -0700 | [diff] [blame] | 1175 | "command: " + str( handle ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1176 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1177 | except TypeError: |
| 1178 | main.log.exception( self.name + ": Object not as expected" ) |
| 1179 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1180 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1181 | main.log.error( self.name + ": EOF exception found" ) |
| 1182 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1183 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1184 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1185 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1186 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1187 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1188 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1189 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1190 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1191 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1192 | 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] | 1193 | partial mac address |
| 1194 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1195 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1196 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1197 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1198 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1199 | return None |
| 1200 | else: |
| 1201 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1202 | rawHosts = self.hosts() |
| 1203 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1204 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1205 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1206 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1207 | if not host: |
| 1208 | pass |
| 1209 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1210 | return host |
| 1211 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1212 | except ( TypeError, ValueError ): |
| 1213 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1214 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1215 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1216 | main.log.error( self.name + ": EOF exception found" ) |
| 1217 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1218 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1219 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1220 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1221 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1222 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1223 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1224 | """ |
| 1225 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1226 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1227 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1228 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1229 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1230 | IMPORTANT: |
| 1231 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1232 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1233 | Furthermore, it assumes that value of VLAN is '-1' |
| 1234 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1235 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1236 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1237 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1238 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1239 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1240 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1241 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1242 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1243 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 1244 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 1245 | i = iter( str( hostHex ) ) |
| 1246 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 1247 | hostHex = hostHex + "/-1" |
| 1248 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1249 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1250 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1251 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1252 | except TypeError: |
| 1253 | main.log.exception( self.name + ": Object not as expected" ) |
| 1254 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1255 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1256 | main.log.error( self.name + ": EOF exception found" ) |
| 1257 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1258 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1259 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1260 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1261 | main.cleanAndExit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1262 | |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1263 | def verifyHostLocation( self, hostIp, location ): |
| 1264 | """ |
| 1265 | Description: |
| 1266 | Verify the host given is discovered in all locations expected |
| 1267 | Required: |
| 1268 | hostIp: IP address of the host |
| 1269 | location: expected location(s) of the given host. ex. "of:0000000000000005/8" |
| 1270 | Could be a string or list |
| 1271 | Returns: |
| 1272 | main.TRUE if host is discovered on all locations provided |
| 1273 | main.FALSE otherwise |
| 1274 | """ |
| 1275 | import json |
| 1276 | locations = [ location ] if isinstance( location, str ) else location |
| 1277 | assert isinstance( locations, list ), "Wrong type of location: {}".format( type( location ) ) |
| 1278 | try: |
| 1279 | hosts = self.hosts() |
| 1280 | hosts = json.loads( hosts ) |
| 1281 | targetHost = None |
| 1282 | for host in hosts: |
| 1283 | if hostIp in host[ "ipAddresses" ]: |
| 1284 | targetHost = host |
You Wang | fd80ab4 | 2018-05-10 17:21:53 -0700 | [diff] [blame] | 1285 | assert targetHost, "Not able to find host with IP {}".format( hostIp ) |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1286 | result = main.TRUE |
| 1287 | locationsDiscovered = [ loc[ "elementId" ] + "/" + loc[ "port" ] for loc in targetHost[ "locations" ] ] |
| 1288 | for loc in locations: |
| 1289 | discovered = False |
| 1290 | for locDiscovered in locationsDiscovered: |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1291 | locToMatch = locDiscovered if "/" in loc else locDiscovered.split( "/" )[0] |
| 1292 | if loc == locToMatch: |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1293 | main.log.debug( "Host {} discovered with location {}".format( hostIp, loc ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1294 | discovered = True |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1295 | break |
| 1296 | if discovered: |
| 1297 | locationsDiscovered.remove( locDiscovered ) |
| 1298 | else: |
| 1299 | main.log.warn( "Host {} not discovered with location {}".format( hostIp, loc ) ) |
| 1300 | result = main.FALSE |
| 1301 | if locationsDiscovered: |
| 1302 | main.log.warn( "Host {} is also discovered with location {}".format( hostIp, locationsDiscovered ) ) |
| 1303 | result = main.FALSE |
| 1304 | return result |
| 1305 | except KeyError: |
| 1306 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1307 | return None |
| 1308 | except pexpect.EOF: |
| 1309 | main.log.error( self.name + ": EOF exception found" ) |
| 1310 | main.log.error( self.name + ": " + self.handle.before ) |
| 1311 | main.cleanAndExit() |
| 1312 | except Exception: |
| 1313 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1314 | return None |
| 1315 | |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1316 | def verifyHostIp( self, hostList=[], prefix="" ): |
| 1317 | """ |
| 1318 | Description: |
| 1319 | Verify that all hosts have IP address assigned to them |
| 1320 | Optional: |
| 1321 | hostList: If specified, verifications only happen to the hosts |
| 1322 | in hostList |
| 1323 | prefix: at least one of the ip address assigned to the host |
| 1324 | needs to have the specified prefix |
| 1325 | Returns: |
| 1326 | main.TRUE if all hosts have specific IP address assigned; |
| 1327 | main.FALSE otherwise |
| 1328 | """ |
| 1329 | import json |
| 1330 | try: |
| 1331 | hosts = self.hosts() |
| 1332 | hosts = json.loads( hosts ) |
| 1333 | if not hostList: |
| 1334 | hostList = [ host[ "id" ] for host in hosts ] |
| 1335 | for host in hosts: |
| 1336 | hostId = host[ "id" ] |
| 1337 | if hostId not in hostList: |
| 1338 | continue |
| 1339 | ipList = host[ "ipAddresses" ] |
| 1340 | main.log.debug( self.name + ": IP list on host " + str( hostId ) + ": " + str( ipList ) ) |
| 1341 | if not ipList: |
| 1342 | main.log.warn( self.name + ": Failed to discover any IP addresses on host " + str( hostId ) ) |
| 1343 | else: |
| 1344 | if not any( ip.startswith( str( prefix ) ) for ip in ipList ): |
| 1345 | main.log.warn( self.name + ": None of the IPs on host " + str( hostId ) + " has prefix " + str( prefix ) ) |
| 1346 | else: |
| 1347 | main.log.debug( self.name + ": Found matching IP on host " + str( hostId ) ) |
| 1348 | hostList.remove( hostId ) |
| 1349 | if hostList: |
| 1350 | main.log.warn( self.name + ": failed to verify IP on following hosts: " + str( hostList) ) |
| 1351 | return main.FALSE |
| 1352 | else: |
| 1353 | return main.TRUE |
| 1354 | except KeyError: |
| 1355 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1356 | return None |
| 1357 | except pexpect.EOF: |
| 1358 | main.log.error( self.name + ": EOF exception found" ) |
| 1359 | main.log.error( self.name + ": " + self.handle.before ) |
| 1360 | main.cleanAndExit() |
| 1361 | except Exception: |
| 1362 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1363 | return None |
| 1364 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1365 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1366 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1367 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1368 | * hostIdOne: ONOS host id for host1 |
| 1369 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1370 | Optional: |
| 1371 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1372 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1373 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1374 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1375 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1376 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1377 | Returns: |
| 1378 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1379 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1380 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1381 | cmdStr = "add-host-intent " |
| 1382 | if vlanId: |
| 1383 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1384 | if setVlan: |
| 1385 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1386 | if encap: |
| 1387 | cmdStr += "--encapsulation " + str( encap ) + " " |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1388 | if bandwidth: |
| 1389 | cmdStr += "-b " + str( bandwidth ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1390 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1391 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1392 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1393 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1394 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1395 | main.log.error( self.name + ": Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1396 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1397 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1398 | else: |
| 1399 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1400 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1401 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1402 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1403 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1404 | else: |
| 1405 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1406 | main.log.debug( "Response from ONOS was: " + |
| 1407 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1408 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1409 | except AssertionError: |
| 1410 | main.log.exception( "" ) |
| 1411 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1412 | except TypeError: |
| 1413 | main.log.exception( self.name + ": Object not as expected" ) |
| 1414 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1415 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1416 | main.log.error( self.name + ": EOF exception found" ) |
| 1417 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1418 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1419 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1420 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1421 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1422 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1423 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1424 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1425 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1426 | * ingressDevice: device id of ingress device |
| 1427 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1428 | Optional: |
| 1429 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1430 | Description: |
| 1431 | Adds an optical intent by specifying an ingress and egress device |
| 1432 | Returns: |
| 1433 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1434 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1435 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1436 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1437 | " " + str( egressDevice ) |
| 1438 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1439 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1440 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1441 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1442 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1443 | main.log.error( self.name + ": Error in adding Optical intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1444 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1445 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1446 | main.log.info( "Optical intent installed between " + |
| 1447 | str( ingressDevice ) + " and " + |
| 1448 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1449 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1450 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1451 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1452 | else: |
| 1453 | main.log.error( "Error, intent ID not found" ) |
| 1454 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1455 | except AssertionError: |
| 1456 | main.log.exception( "" ) |
| 1457 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1458 | except TypeError: |
| 1459 | main.log.exception( self.name + ": Object not as expected" ) |
| 1460 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1461 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1462 | main.log.error( self.name + ": EOF exception found" ) |
| 1463 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1464 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1465 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1466 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1467 | main.cleanAndExit() |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1468 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1469 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1470 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1471 | ingressDevice, |
| 1472 | egressDevice, |
| 1473 | portIngress="", |
| 1474 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1475 | ethType="", |
| 1476 | ethSrc="", |
| 1477 | ethDst="", |
| 1478 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1479 | lambdaAlloc=False, |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1480 | protected=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1481 | ipProto="", |
| 1482 | ipSrc="", |
| 1483 | ipDst="", |
| 1484 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1485 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1486 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1487 | setVlan="", |
| 1488 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1489 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1490 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1491 | * ingressDevice: device id of ingress device |
| 1492 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1493 | Optional: |
| 1494 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1495 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1496 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1497 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1498 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1499 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1500 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1501 | * ipSrc: specify ip source address |
| 1502 | * ipDst: specify ip destination address |
| 1503 | * tcpSrc: specify tcp source port |
| 1504 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1505 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1506 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1507 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1508 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1509 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1510 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1511 | Returns: |
| 1512 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1513 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1514 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1515 | options developers provide for point-to-point |
| 1516 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1517 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1518 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1519 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1520 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1521 | if ethType: |
| 1522 | cmd += " --ethType " + str( ethType ) |
| 1523 | if ethSrc: |
| 1524 | cmd += " --ethSrc " + str( ethSrc ) |
| 1525 | if ethDst: |
| 1526 | cmd += " --ethDst " + str( ethDst ) |
| 1527 | if bandwidth: |
| 1528 | cmd += " --bandwidth " + str( bandwidth ) |
| 1529 | if lambdaAlloc: |
| 1530 | cmd += " --lambda " |
| 1531 | if ipProto: |
| 1532 | cmd += " --ipProto " + str( ipProto ) |
| 1533 | if ipSrc: |
| 1534 | cmd += " --ipSrc " + str( ipSrc ) |
| 1535 | if ipDst: |
| 1536 | cmd += " --ipDst " + str( ipDst ) |
| 1537 | if tcpSrc: |
| 1538 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1539 | if tcpDst: |
| 1540 | cmd += " --tcpDst " + str( tcpDst ) |
| 1541 | if vlanId: |
| 1542 | cmd += " -v " + str( vlanId ) |
| 1543 | if setVlan: |
| 1544 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1545 | if encap: |
| 1546 | cmd += " --encapsulation " + str( encap ) |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1547 | if protected: |
| 1548 | cmd += " --protect " |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1549 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1550 | # Check whether the user appended the port |
| 1551 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1552 | if "/" in ingressDevice: |
| 1553 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1554 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1555 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1556 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1557 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1558 | # Would it make sense to throw an exception and exit |
| 1559 | # the test? |
| 1560 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1561 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1562 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1563 | str( ingressDevice ) + "/" +\ |
| 1564 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1565 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1566 | if "/" in egressDevice: |
| 1567 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1568 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1569 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1570 | main.log.error( "You must specify the egress port" ) |
| 1571 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1572 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1573 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1574 | str( egressDevice ) + "/" +\ |
| 1575 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1576 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1577 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1578 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1579 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1580 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1581 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1582 | main.log.error( self.name + ": Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1583 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1584 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1585 | # TODO: print out all the options in this message? |
| 1586 | main.log.info( "Point-to-point intent installed between " + |
| 1587 | str( ingressDevice ) + " and " + |
| 1588 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1589 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1590 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1591 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1592 | else: |
| 1593 | main.log.error( "Error, intent ID not found" ) |
| 1594 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1595 | except AssertionError: |
| 1596 | main.log.exception( "" ) |
| 1597 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1598 | except TypeError: |
| 1599 | main.log.exception( self.name + ": Object not as expected" ) |
| 1600 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1601 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1602 | main.log.error( self.name + ": EOF exception found" ) |
| 1603 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1604 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1605 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1606 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1607 | main.cleanAndExit() |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1608 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1609 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1610 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1611 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1612 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1613 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1614 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1615 | ethType="", |
| 1616 | ethSrc="", |
| 1617 | ethDst="", |
| 1618 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1619 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1620 | ipProto="", |
| 1621 | ipSrc="", |
| 1622 | ipDst="", |
| 1623 | tcpSrc="", |
| 1624 | tcpDst="", |
| 1625 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1626 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1627 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1628 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1629 | partial=False, |
| 1630 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1631 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1632 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1633 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1634 | is same. That is, all ingress devices include port numbers |
| 1635 | with a "/" or all ingress devices could specify device |
| 1636 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1637 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1638 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1639 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1640 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1641 | Optional: |
| 1642 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1643 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1644 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1645 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1646 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1647 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1648 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1649 | * ipSrc: specify ip source address |
| 1650 | * ipDst: specify ip destination address |
| 1651 | * tcpSrc: specify tcp source port |
| 1652 | * tcpDst: specify tcp destination port |
| 1653 | * setEthSrc: action to Rewrite Source MAC Address |
| 1654 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1655 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1656 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1657 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1658 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1659 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1660 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1661 | Returns: |
| 1662 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1663 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1664 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1665 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1666 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1667 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1668 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1669 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1670 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1671 | if ethType: |
| 1672 | cmd += " --ethType " + str( ethType ) |
| 1673 | if ethSrc: |
| 1674 | cmd += " --ethSrc " + str( ethSrc ) |
| 1675 | if ethDst: |
| 1676 | cmd += " --ethDst " + str( ethDst ) |
| 1677 | if bandwidth: |
| 1678 | cmd += " --bandwidth " + str( bandwidth ) |
| 1679 | if lambdaAlloc: |
| 1680 | cmd += " --lambda " |
| 1681 | if ipProto: |
| 1682 | cmd += " --ipProto " + str( ipProto ) |
| 1683 | if ipSrc: |
| 1684 | cmd += " --ipSrc " + str( ipSrc ) |
| 1685 | if ipDst: |
| 1686 | cmd += " --ipDst " + str( ipDst ) |
| 1687 | if tcpSrc: |
| 1688 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1689 | if tcpDst: |
| 1690 | cmd += " --tcpDst " + str( tcpDst ) |
| 1691 | if setEthSrc: |
| 1692 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1693 | if setEthDst: |
| 1694 | cmd += " --setEthDst " + str( setEthDst ) |
| 1695 | if vlanId: |
| 1696 | cmd += " -v " + str( vlanId ) |
| 1697 | if setVlan: |
| 1698 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1699 | if partial: |
| 1700 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1701 | if encap: |
| 1702 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1703 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1704 | # Check whether the user appended the port |
| 1705 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1706 | |
| 1707 | if portIngressList is None: |
| 1708 | for ingressDevice in ingressDeviceList: |
| 1709 | if "/" in ingressDevice: |
| 1710 | cmd += " " + str( ingressDevice ) |
| 1711 | else: |
| 1712 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1713 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1714 | # TODO: perhaps more meaningful return |
| 1715 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1716 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1717 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1718 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1719 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1720 | cmd += " " + \ |
| 1721 | str( ingressDevice ) + "/" +\ |
| 1722 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1723 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1724 | main.log.error( "Device list and port list does not " + |
| 1725 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1726 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1727 | if "/" in egressDevice: |
| 1728 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1729 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1730 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1731 | main.log.error( "You must specify " + |
| 1732 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1733 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1734 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1735 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1736 | str( egressDevice ) + "/" +\ |
| 1737 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1738 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1739 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1740 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1741 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1742 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1743 | main.log.error( self.name + ": Error in adding multipoint-to-singlepoint " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1744 | "intent" ) |
| 1745 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1746 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1747 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1748 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1749 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1750 | else: |
| 1751 | main.log.error( "Error, intent ID not found" ) |
| 1752 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1753 | except AssertionError: |
| 1754 | main.log.exception( "" ) |
| 1755 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1756 | except TypeError: |
| 1757 | main.log.exception( self.name + ": Object not as expected" ) |
| 1758 | return None |
| 1759 | except pexpect.EOF: |
| 1760 | main.log.error( self.name + ": EOF exception found" ) |
| 1761 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1762 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1763 | except Exception: |
| 1764 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1765 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1766 | |
| 1767 | def addSinglepointToMultipointIntent( |
| 1768 | self, |
| 1769 | ingressDevice, |
| 1770 | egressDeviceList, |
| 1771 | portIngress="", |
| 1772 | portEgressList=None, |
| 1773 | ethType="", |
| 1774 | ethSrc="", |
| 1775 | ethDst="", |
| 1776 | bandwidth="", |
| 1777 | lambdaAlloc=False, |
| 1778 | ipProto="", |
| 1779 | ipSrc="", |
| 1780 | ipDst="", |
| 1781 | tcpSrc="", |
| 1782 | tcpDst="", |
| 1783 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1784 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1785 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1786 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1787 | partial=False, |
| 1788 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1789 | """ |
| 1790 | Note: |
| 1791 | This function assumes the format of all egress devices |
| 1792 | is same. That is, all egress devices include port numbers |
| 1793 | with a "/" or all egress devices could specify device |
| 1794 | ids and port numbers seperately. |
| 1795 | Required: |
| 1796 | * EgressDeviceList: List of device ids of egress device |
| 1797 | ( Atleast 2 eress devices required in the list ) |
| 1798 | * ingressDevice: device id of ingress device |
| 1799 | Optional: |
| 1800 | * ethType: specify ethType |
| 1801 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1802 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1803 | * bandwidth: specify bandwidth capacity of link |
| 1804 | * lambdaAlloc: if True, intent will allocate lambda |
| 1805 | for the specified intent |
| 1806 | * ipProto: specify ip protocol |
| 1807 | * ipSrc: specify ip source address |
| 1808 | * ipDst: specify ip destination address |
| 1809 | * tcpSrc: specify tcp source port |
| 1810 | * tcpDst: specify tcp destination port |
| 1811 | * setEthSrc: action to Rewrite Source MAC Address |
| 1812 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1813 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1814 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1815 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1816 | Description: |
| 1817 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1818 | specifying device id's and optional fields |
| 1819 | Returns: |
| 1820 | A string of the intent id or None on error |
| 1821 | |
| 1822 | NOTE: This function may change depending on the |
| 1823 | options developers provide for singlepoint-to-multipoint |
| 1824 | intent via cli |
| 1825 | """ |
| 1826 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1827 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1828 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1829 | if ethType: |
| 1830 | cmd += " --ethType " + str( ethType ) |
| 1831 | if ethSrc: |
| 1832 | cmd += " --ethSrc " + str( ethSrc ) |
| 1833 | if ethDst: |
| 1834 | cmd += " --ethDst " + str( ethDst ) |
| 1835 | if bandwidth: |
| 1836 | cmd += " --bandwidth " + str( bandwidth ) |
| 1837 | if lambdaAlloc: |
| 1838 | cmd += " --lambda " |
| 1839 | if ipProto: |
| 1840 | cmd += " --ipProto " + str( ipProto ) |
| 1841 | if ipSrc: |
| 1842 | cmd += " --ipSrc " + str( ipSrc ) |
| 1843 | if ipDst: |
| 1844 | cmd += " --ipDst " + str( ipDst ) |
| 1845 | if tcpSrc: |
| 1846 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1847 | if tcpDst: |
| 1848 | cmd += " --tcpDst " + str( tcpDst ) |
| 1849 | if setEthSrc: |
| 1850 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1851 | if setEthDst: |
| 1852 | cmd += " --setEthDst " + str( setEthDst ) |
| 1853 | if vlanId: |
| 1854 | cmd += " -v " + str( vlanId ) |
| 1855 | if setVlan: |
| 1856 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1857 | if partial: |
| 1858 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1859 | if encap: |
| 1860 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1861 | |
| 1862 | # Check whether the user appended the port |
| 1863 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1864 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1865 | if "/" in ingressDevice: |
| 1866 | cmd += " " + str( ingressDevice ) |
| 1867 | else: |
| 1868 | if not portIngress: |
| 1869 | main.log.error( "You must specify " + |
| 1870 | "the Ingress port" ) |
| 1871 | return main.FALSE |
| 1872 | |
| 1873 | cmd += " " +\ |
| 1874 | str( ingressDevice ) + "/" +\ |
| 1875 | str( portIngress ) |
| 1876 | |
| 1877 | if portEgressList is None: |
| 1878 | for egressDevice in egressDeviceList: |
| 1879 | if "/" in egressDevice: |
| 1880 | cmd += " " + str( egressDevice ) |
| 1881 | else: |
| 1882 | main.log.error( "You must specify " + |
| 1883 | "the egress port" ) |
| 1884 | # TODO: perhaps more meaningful return |
| 1885 | return main.FALSE |
| 1886 | else: |
| 1887 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1888 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1889 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1890 | cmd += " " + \ |
| 1891 | str( egressDevice ) + "/" +\ |
| 1892 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1893 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1894 | main.log.error( "Device list and port list does not " + |
| 1895 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1896 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1897 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1898 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1899 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1900 | # If error, return error message |
| 1901 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1902 | main.log.error( self.name + ": Error in adding singlepoint-to-multipoint " + |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1903 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1904 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1905 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1906 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1907 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1908 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1909 | else: |
| 1910 | main.log.error( "Error, intent ID not found" ) |
| 1911 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1912 | except AssertionError: |
| 1913 | main.log.exception( "" ) |
| 1914 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1915 | except TypeError: |
| 1916 | main.log.exception( self.name + ": Object not as expected" ) |
| 1917 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1918 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1919 | main.log.error( self.name + ": EOF exception found" ) |
| 1920 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1921 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1922 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1923 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1924 | main.cleanAndExit() |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1925 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1926 | def addMplsIntent( |
| 1927 | self, |
| 1928 | ingressDevice, |
| 1929 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1930 | ingressPort="", |
| 1931 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1932 | ethType="", |
| 1933 | ethSrc="", |
| 1934 | ethDst="", |
| 1935 | bandwidth="", |
| 1936 | lambdaAlloc=False, |
| 1937 | ipProto="", |
| 1938 | ipSrc="", |
| 1939 | ipDst="", |
| 1940 | tcpSrc="", |
| 1941 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1942 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1943 | egressLabel="", |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1944 | priority="" ): |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1945 | """ |
| 1946 | Required: |
| 1947 | * ingressDevice: device id of ingress device |
| 1948 | * egressDevice: device id of egress device |
| 1949 | Optional: |
| 1950 | * ethType: specify ethType |
| 1951 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1952 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1953 | * bandwidth: specify bandwidth capacity of link |
| 1954 | * lambdaAlloc: if True, intent will allocate lambda |
| 1955 | for the specified intent |
| 1956 | * ipProto: specify ip protocol |
| 1957 | * ipSrc: specify ip source address |
| 1958 | * ipDst: specify ip destination address |
| 1959 | * tcpSrc: specify tcp source port |
| 1960 | * tcpDst: specify tcp destination port |
| 1961 | * ingressLabel: Ingress MPLS label |
| 1962 | * egressLabel: Egress MPLS label |
| 1963 | Description: |
| 1964 | Adds MPLS intent by |
| 1965 | specifying device id's and optional fields |
| 1966 | Returns: |
| 1967 | A string of the intent id or None on error |
| 1968 | |
| 1969 | NOTE: This function may change depending on the |
| 1970 | options developers provide for MPLS |
| 1971 | intent via cli |
| 1972 | """ |
| 1973 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1974 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1975 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1976 | if ethType: |
| 1977 | cmd += " --ethType " + str( ethType ) |
| 1978 | if ethSrc: |
| 1979 | cmd += " --ethSrc " + str( ethSrc ) |
| 1980 | if ethDst: |
| 1981 | cmd += " --ethDst " + str( ethDst ) |
| 1982 | if bandwidth: |
| 1983 | cmd += " --bandwidth " + str( bandwidth ) |
| 1984 | if lambdaAlloc: |
| 1985 | cmd += " --lambda " |
| 1986 | if ipProto: |
| 1987 | cmd += " --ipProto " + str( ipProto ) |
| 1988 | if ipSrc: |
| 1989 | cmd += " --ipSrc " + str( ipSrc ) |
| 1990 | if ipDst: |
| 1991 | cmd += " --ipDst " + str( ipDst ) |
| 1992 | if tcpSrc: |
| 1993 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1994 | if tcpDst: |
| 1995 | cmd += " --tcpDst " + str( tcpDst ) |
| 1996 | if ingressLabel: |
| 1997 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 1998 | if egressLabel: |
| 1999 | cmd += " --egressLabel " + str( egressLabel ) |
| 2000 | if priority: |
| 2001 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2002 | |
| 2003 | # Check whether the user appended the port |
| 2004 | # or provided it as an input |
| 2005 | if "/" in ingressDevice: |
| 2006 | cmd += " " + str( ingressDevice ) |
| 2007 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2008 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2009 | main.log.error( "You must specify the ingress port" ) |
| 2010 | return None |
| 2011 | |
| 2012 | cmd += " " + \ |
| 2013 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2014 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2015 | |
| 2016 | if "/" in egressDevice: |
| 2017 | cmd += " " + str( egressDevice ) |
| 2018 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2019 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2020 | main.log.error( "You must specify the egress port" ) |
| 2021 | return None |
| 2022 | |
| 2023 | cmd += " " +\ |
| 2024 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2025 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2026 | |
| 2027 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2028 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2029 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2030 | # If error, return error message |
| 2031 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2032 | main.log.error( self.name + ": Error in adding mpls intent" ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2033 | return None |
| 2034 | else: |
| 2035 | # TODO: print out all the options in this message? |
| 2036 | main.log.info( "MPLS intent installed between " + |
| 2037 | str( ingressDevice ) + " and " + |
| 2038 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2039 | match = re.search( 'id=0x([\da-f]+),', handle ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2040 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2041 | return match.group()[ 3:-1 ] |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2042 | else: |
| 2043 | main.log.error( "Error, intent ID not found" ) |
| 2044 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2045 | except AssertionError: |
| 2046 | main.log.exception( "" ) |
| 2047 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2048 | except TypeError: |
| 2049 | main.log.exception( self.name + ": Object not as expected" ) |
| 2050 | return None |
| 2051 | except pexpect.EOF: |
| 2052 | main.log.error( self.name + ": EOF exception found" ) |
| 2053 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2054 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2055 | except Exception: |
| 2056 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2057 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2058 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2059 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 2060 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2061 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2062 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2063 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2064 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2065 | -p or --purge: Purge the intent from the store after removal |
| 2066 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2067 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 2068 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2069 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2070 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2071 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2072 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2073 | if purge: |
| 2074 | cmdStr += " -p" |
| 2075 | if sync: |
| 2076 | cmdStr += " -s" |
| 2077 | |
| 2078 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2079 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2080 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2081 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2082 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2083 | main.log.error( self.name + ": Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2084 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2085 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2086 | # TODO: Should this be main.TRUE |
| 2087 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2088 | except AssertionError: |
| 2089 | main.log.exception( "" ) |
| 2090 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2091 | except TypeError: |
| 2092 | main.log.exception( self.name + ": Object not as expected" ) |
| 2093 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2094 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2095 | main.log.error( self.name + ": EOF exception found" ) |
| 2096 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2097 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2098 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2099 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2100 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2101 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2102 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2103 | """ |
| 2104 | Description: |
| 2105 | Remove all the intents |
| 2106 | Optional args:- |
| 2107 | -s or --sync: Waits for the removal before returning |
| 2108 | -p or --purge: Purge the intent from the store after removal |
| 2109 | Returns: |
| 2110 | Returns main.TRUE if all intents are removed, otherwise returns |
| 2111 | main.FALSE; Returns None for exception |
| 2112 | """ |
| 2113 | try: |
| 2114 | cmdStr = "remove-intent" |
| 2115 | if purge: |
| 2116 | cmdStr += " -p" |
| 2117 | if sync: |
| 2118 | cmdStr += " -s" |
| 2119 | |
| 2120 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2121 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2122 | assert handle is not None, "Error in sendline" |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2123 | assert "Command not found:" not in handle, handle |
| 2124 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2125 | main.log.error( self.name + ": Error in removing intent" ) |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2126 | return main.FALSE |
| 2127 | else: |
| 2128 | return main.TRUE |
| 2129 | except AssertionError: |
| 2130 | main.log.exception( "" ) |
| 2131 | return None |
| 2132 | except TypeError: |
| 2133 | main.log.exception( self.name + ": Object not as expected" ) |
| 2134 | return None |
| 2135 | except pexpect.EOF: |
| 2136 | main.log.error( self.name + ": EOF exception found" ) |
| 2137 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2138 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2139 | except Exception: |
| 2140 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2141 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2142 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 2143 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2144 | """ |
| 2145 | Purges all WITHDRAWN Intents |
| 2146 | """ |
| 2147 | try: |
| 2148 | cmdStr = "purge-intents" |
| 2149 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2150 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2151 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2152 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2153 | main.log.error( self.name + ": Error in purging intents" ) |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2154 | return main.FALSE |
| 2155 | else: |
| 2156 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2157 | except AssertionError: |
| 2158 | main.log.exception( "" ) |
| 2159 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2160 | except TypeError: |
| 2161 | main.log.exception( self.name + ": Object not as expected" ) |
| 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 ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2166 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2167 | except Exception: |
| 2168 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2169 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2170 | |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 2171 | def wipeout( self ): |
| 2172 | """ |
| 2173 | Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS. |
| 2174 | """ |
| 2175 | try: |
| 2176 | cmdStr = "wipe-out please" |
| 2177 | handle = self.sendline( cmdStr, timeout=60 ) |
| 2178 | assert handle is not None, "Error in sendline" |
| 2179 | assert "Command not found:" not in handle, handle |
| 2180 | return main.TRUE |
| 2181 | except AssertionError: |
| 2182 | main.log.exception( "" ) |
| 2183 | return None |
| 2184 | except TypeError: |
| 2185 | main.log.exception( self.name + ": Object not as expected" ) |
| 2186 | return None |
| 2187 | except pexpect.EOF: |
| 2188 | main.log.error( self.name + ": EOF exception found" ) |
| 2189 | main.log.error( self.name + ": " + self.handle.before ) |
| 2190 | main.cleanAndExit() |
| 2191 | except Exception: |
| 2192 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2193 | main.cleanAndExit() |
| 2194 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2195 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2196 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2197 | NOTE: This method should be used after installing application: |
| 2198 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2199 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2200 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2201 | Description: |
| 2202 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2203 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2204 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2205 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2206 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2207 | cmdStr += " -j" |
| 2208 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2209 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2210 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2211 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2212 | except AssertionError: |
| 2213 | main.log.exception( "" ) |
| 2214 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2215 | except TypeError: |
| 2216 | main.log.exception( self.name + ": Object not as expected" ) |
| 2217 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2218 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2219 | main.log.error( self.name + ": EOF exception found" ) |
| 2220 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2221 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2222 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2223 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2224 | main.cleanAndExit() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2225 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2226 | def ipv4RouteNumber( self ): |
| 2227 | """ |
| 2228 | NOTE: This method should be used after installing application: |
| 2229 | onos-app-sdnip |
| 2230 | Description: |
| 2231 | Obtain the total IPv4 routes number in the system |
| 2232 | """ |
| 2233 | try: |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2234 | cmdStr = "routes -j" |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2235 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2236 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2237 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2238 | jsonResult = json.loads( handle ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2239 | return len( jsonResult[ 'routes4' ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2240 | except AssertionError: |
| 2241 | main.log.exception( "" ) |
| 2242 | return None |
| 2243 | except ( TypeError, ValueError ): |
| 2244 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2245 | return None |
| 2246 | except pexpect.EOF: |
| 2247 | main.log.error( self.name + ": EOF exception found" ) |
| 2248 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2249 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2250 | except Exception: |
| 2251 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2252 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2253 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2254 | # =============Function to check Bandwidth allocation======== |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2255 | def allocations( self, jsonFormat = True ): |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2256 | """ |
| 2257 | Description: |
| 2258 | Obtain Bandwidth Allocation Information from ONOS cli. |
| 2259 | """ |
| 2260 | try: |
| 2261 | cmdStr = "allocations" |
| 2262 | if jsonFormat: |
| 2263 | cmdStr += " -j" |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2264 | handle = self.sendline( cmdStr, timeout=300 ) |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2265 | assert handle is not None, "Error in sendline" |
| 2266 | assert "Command not found:" not in handle, handle |
| 2267 | return handle |
| 2268 | except AssertionError: |
| 2269 | main.log.exception( "" ) |
| 2270 | return None |
| 2271 | except ( TypeError, ValueError ): |
| 2272 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
| 2273 | return None |
| 2274 | except pexpect.EOF: |
| 2275 | main.log.error( self.name + ": EOF exception found" ) |
| 2276 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2277 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2278 | except Exception: |
| 2279 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2280 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2281 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2282 | def intents( self, jsonFormat = True, summary = False, **intentargs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2283 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2284 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2285 | Obtain intents from the ONOS cli. |
| 2286 | Optional: |
| 2287 | * jsonFormat: Enable output formatting in json, default to True |
| 2288 | * summary: Whether only output the intent summary, defaults to False |
| 2289 | * type: Only output a certain type of intent. This options is valid |
| 2290 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2291 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2292 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2293 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2294 | if summary: |
| 2295 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2296 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2297 | cmdStr += " -j" |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2298 | handle = self.sendline( cmdStr, timeout=300 ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2299 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2300 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2301 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2302 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2303 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2304 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2305 | intentType = "" |
| 2306 | # IF we want the summary of a specific intent type |
| 2307 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2308 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2309 | if intentType in jsonResult.keys(): |
| 2310 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2311 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2312 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2313 | return handle |
| 2314 | else: |
| 2315 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2316 | except AssertionError: |
| 2317 | main.log.exception( "" ) |
| 2318 | return None |
| 2319 | except ( TypeError, ValueError ): |
| 2320 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2321 | return None |
| 2322 | except pexpect.EOF: |
| 2323 | main.log.error( self.name + ": EOF exception found" ) |
| 2324 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2325 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2326 | except Exception: |
| 2327 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2328 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2329 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2330 | def getIntentState( self, intentsId, intentsJson=None ): |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2331 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2332 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2333 | Gets intent state. Accepts a single intent ID (string type) or a |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2334 | list of intent IDs. |
| 2335 | Parameters: |
| 2336 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2337 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2338 | Returns: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2339 | Returns the state (string type) of the ID if a single intent ID is |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2340 | accepted. |
| 2341 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2342 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2343 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2344 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2345 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2346 | try: |
| 2347 | state = "State is Undefined" |
| 2348 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2349 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2350 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2351 | rawJson = intentsJson |
| 2352 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2353 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2354 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2355 | if intentsId == intent[ 'id' ]: |
| 2356 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2357 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2358 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2359 | " in the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2360 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2361 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2362 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2363 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2364 | stateDict = {} |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2365 | for intent in parsedIntentsJson: |
| 2366 | if intentsId[ i ] == intent[ 'id' ]: |
| 2367 | stateDict[ 'state' ] = intent[ 'state' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2368 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2369 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2370 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2371 | if len( intentsId ) != len( dictList ): |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2372 | main.log.warn( "Could not find all intents in ONOS output" ) |
| 2373 | main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2374 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2375 | else: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2376 | main.log.info( "Invalid type for intentsId argument" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2377 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2378 | except ( TypeError, ValueError ): |
| 2379 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2380 | return None |
| 2381 | except pexpect.EOF: |
| 2382 | main.log.error( self.name + ": EOF exception found" ) |
| 2383 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2384 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2385 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2386 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2387 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2388 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2389 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2390 | """ |
| 2391 | Description: |
| 2392 | Check intents state |
| 2393 | Required: |
| 2394 | intentsId - List of intents ID to be checked |
| 2395 | Optional: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2396 | expectedState - Check the expected state(s) of each intents |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2397 | state in the list. |
| 2398 | *NOTE: You can pass in a list of expected state, |
| 2399 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2400 | Return: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2401 | Returns main.TRUE only if all intent are the same as expected states, |
| 2402 | otherwise returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2403 | """ |
| 2404 | try: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2405 | returnValue = main.TRUE |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2406 | # Generating a dictionary: intent id as a key and state as value |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2407 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2408 | # intentsDict = self.getIntentState( intentsId ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2409 | intentsDict = [] |
| 2410 | for intent in json.loads( self.intents() ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2411 | if isinstance( intentsId, types.StringType ) \ |
| 2412 | and intent.get( 'id' ) == intentsId: |
| 2413 | intentsDict.append( intent ) |
| 2414 | elif isinstance( intentsId, types.ListType ) \ |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2415 | and any( intent.get( 'id' ) == ids for ids in intentsId ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2416 | intentsDict.append( intent ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2417 | |
| 2418 | if not intentsDict: |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2419 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2420 | "getting intents state" ) |
| 2421 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2422 | |
| 2423 | if isinstance( expectedState, types.StringType ): |
| 2424 | for intents in intentsDict: |
| 2425 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2426 | main.log.debug( self.name + " : Intent ID - " + |
| 2427 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2428 | " actual state = " + |
| 2429 | intents.get( 'state' ) |
| 2430 | + " does not equal expected state = " |
| 2431 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2432 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2433 | elif isinstance( expectedState, types.ListType ): |
| 2434 | for intents in intentsDict: |
| 2435 | if not any( state == intents.get( 'state' ) for state in |
| 2436 | expectedState ): |
| 2437 | main.log.debug( self.name + " : Intent ID - " + |
| 2438 | intents.get( 'id' ) + |
| 2439 | " actual state = " + |
| 2440 | intents.get( 'state' ) + |
| 2441 | " does not equal expected states = " |
| 2442 | + str( expectedState ) ) |
| 2443 | returnValue = main.FALSE |
| 2444 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2445 | if returnValue == main.TRUE: |
| 2446 | main.log.info( self.name + ": All " + |
| 2447 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2448 | " intents are in " + str( expectedState ) + |
| 2449 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2450 | return returnValue |
| 2451 | except TypeError: |
| 2452 | main.log.exception( self.name + ": Object not as expected" ) |
| 2453 | return None |
| 2454 | except pexpect.EOF: |
| 2455 | main.log.error( self.name + ": EOF exception found" ) |
| 2456 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2457 | main.cleanAndExit() |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2458 | except Exception: |
| 2459 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2460 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2461 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2462 | def compareBandwidthAllocations( self, expectedAllocations ): |
| 2463 | """ |
| 2464 | Description: |
| 2465 | Compare the allocated bandwidth with the given allocations |
| 2466 | Required: |
| 2467 | expectedAllocations - The expected ONOS output of the allocations command |
| 2468 | Return: |
| 2469 | Returns main.TRUE only if all intent are the same as expected states, |
| 2470 | otherwise returns main.FALSE. |
| 2471 | """ |
| 2472 | # FIXME: Convert these string comparisons to object comparisons |
| 2473 | try: |
| 2474 | returnValue = main.TRUE |
| 2475 | bandwidthFailed = False |
| 2476 | rawAlloc = self.allocations() |
| 2477 | expectedFormat = StringIO( expectedAllocations ) |
| 2478 | ONOSOutput = StringIO( rawAlloc ) |
| 2479 | main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ), |
| 2480 | str( expectedFormat ) ) ) |
| 2481 | |
| 2482 | for actual, expected in izip( ONOSOutput, expectedFormat ): |
| 2483 | actual = actual.rstrip() |
| 2484 | expected = expected.rstrip() |
| 2485 | main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) ) |
| 2486 | if actual != expected and 'allocated' in actual and 'allocated' in expected: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2487 | marker1 = actual.find( 'allocated' ) |
| 2488 | m1 = actual[ :marker1 ] |
| 2489 | marker2 = expected.find( 'allocated' ) |
| 2490 | m2 = expected[ :marker2 ] |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2491 | if m1 != m2: |
| 2492 | bandwidthFailed = True |
| 2493 | elif actual != expected and 'allocated' not in actual and 'allocated' not in expected: |
| 2494 | bandwidthFailed = True |
| 2495 | expectedFormat.close() |
| 2496 | ONOSOutput.close() |
| 2497 | |
| 2498 | if bandwidthFailed: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2499 | main.log.error( "Bandwidth not allocated correctly using Intents!!" ) |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2500 | returnValue = main.FALSE |
| 2501 | return returnValue |
| 2502 | except TypeError: |
| 2503 | main.log.exception( self.name + ": Object not as expected" ) |
| 2504 | return None |
| 2505 | except pexpect.EOF: |
| 2506 | main.log.error( self.name + ": EOF exception found" ) |
| 2507 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2508 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2509 | except Exception: |
| 2510 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2511 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2512 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2513 | def compareIntent( self, intentDict ): |
| 2514 | """ |
| 2515 | Description: |
| 2516 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2517 | Return: |
| 2518 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2519 | Arguments: |
| 2520 | intentDict: a dictionary which maps intent ids to intent states |
| 2521 | """ |
| 2522 | try: |
| 2523 | intentsRaw = self.intents() |
| 2524 | intentsJson = json.loads( intentsRaw ) |
| 2525 | intentDictONOS = {} |
| 2526 | for intent in intentsJson: |
| 2527 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2528 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2529 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2530 | 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] | 2531 | str( len( intentDict ) ) + " expected and " + |
| 2532 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2533 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2534 | for intentID in intentDict.keys(): |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2535 | if intentID not in intentDictONOS.keys(): |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2536 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2537 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2538 | else: |
| 2539 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2540 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2541 | " expected state is " + intentDict[ intentID ] + |
| 2542 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2543 | returnValue = main.FALSE |
| 2544 | intentDictONOS.pop( intentID ) |
| 2545 | if len( intentDictONOS ) > 0: |
| 2546 | returnValue = main.FALSE |
| 2547 | for intentID in intentDictONOS.keys(): |
| 2548 | 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] | 2549 | if returnValue == main.TRUE: |
| 2550 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2551 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2552 | except KeyError: |
| 2553 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2554 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2555 | except ( TypeError, ValueError ): |
| 2556 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2557 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2558 | except pexpect.EOF: |
| 2559 | main.log.error( self.name + ": EOF exception found" ) |
| 2560 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2561 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2562 | except Exception: |
| 2563 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2564 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2565 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2566 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2567 | """ |
| 2568 | Description: |
| 2569 | Check the number of installed intents. |
| 2570 | Optional: |
| 2571 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2572 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2573 | Return: |
| 2574 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2575 | , otherwise, returns main.FALSE. |
| 2576 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2577 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2578 | try: |
| 2579 | cmd = "intents -s -j" |
| 2580 | |
| 2581 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2582 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2583 | if response is None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2584 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2585 | response = json.loads( response ) |
| 2586 | |
| 2587 | # get total and installed number, see if they are match |
| 2588 | allState = response.get( 'all' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2589 | if allState.get( 'total' ) == allState.get( 'installed' ): |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2590 | main.log.info( 'Total Intents: {} Installed Intents: {}'.format( |
| 2591 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2592 | return main.TRUE |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2593 | main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format( |
| 2594 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2595 | return main.FALSE |
| 2596 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2597 | except ( TypeError, ValueError ): |
| 2598 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2599 | return None |
| 2600 | except pexpect.EOF: |
| 2601 | main.log.error( self.name + ": EOF exception found" ) |
| 2602 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2603 | if noExit: |
| 2604 | return main.FALSE |
| 2605 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2606 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2607 | except pexpect.TIMEOUT: |
| 2608 | main.log.error( self.name + ": ONOS timeout" ) |
| 2609 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2610 | except Exception: |
| 2611 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2612 | if noExit: |
| 2613 | return main.FALSE |
| 2614 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2615 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2616 | |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2617 | def flows( self, state="any", jsonFormat=True, timeout=60, noExit=False, noCore=False, device=""): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2618 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2619 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2620 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2621 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2622 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2623 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2624 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2625 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2626 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2627 | if jsonFormat: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2628 | cmdStr += " -j" |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2629 | if noCore: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2630 | cmdStr += " -n" |
| 2631 | cmdStr += " " + state |
| 2632 | cmdStr += " " + device |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2633 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2634 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2635 | assert "Command not found:" not in handle, handle |
| 2636 | if re.search( "Error:", handle ): |
| 2637 | main.log.error( self.name + ": flows() response: " + |
| 2638 | str( handle ) ) |
| 2639 | return handle |
| 2640 | except AssertionError: |
| 2641 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2642 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2643 | except TypeError: |
| 2644 | main.log.exception( self.name + ": Object not as expected" ) |
| 2645 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2646 | except pexpect.TIMEOUT: |
| 2647 | main.log.error( self.name + ": ONOS timeout" ) |
| 2648 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2649 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2650 | main.log.error( self.name + ": EOF exception found" ) |
| 2651 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2652 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2653 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2654 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2655 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2656 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2657 | def checkFlowCount( self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2658 | count = self.getTotalFlowsNum( timeout=timeout ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2659 | count = int( count ) if count else 0 |
| 2660 | return count if ( count > min ) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2661 | |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2662 | def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2663 | """ |
| 2664 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2665 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2666 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2667 | if the count of those states is 0, which means all current flows |
| 2668 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2669 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2670 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2671 | Return: |
| 2672 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2673 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2674 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2675 | """ |
| 2676 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2677 | states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2678 | checkedStates = [] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2679 | statesCount = [ 0, 0, 0, 0 ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2680 | for s in states: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2681 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2682 | if rawFlows: |
| 2683 | # if we didn't get flows or flows function return None, we should return |
| 2684 | # main.Flase |
| 2685 | checkedStates.append( json.loads( rawFlows ) ) |
| 2686 | else: |
| 2687 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2688 | for i in range( len( states ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2689 | for c in checkedStates[ i ]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2690 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2691 | statesCount[ i ] += int( c.get( "flowCount" ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2692 | except TypeError: |
| 2693 | main.log.exception( "Json object not as expected" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2694 | main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2695 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2696 | # We want to count PENDING_ADD if isPENDING is true |
| 2697 | if isPENDING: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2698 | if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2699 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2700 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2701 | if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2702 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2703 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2704 | except ( TypeError, ValueError ): |
| 2705 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2706 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2707 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2708 | except AssertionError: |
| 2709 | main.log.exception( "" ) |
| 2710 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2711 | except pexpect.TIMEOUT: |
| 2712 | main.log.error( self.name + ": ONOS timeout" ) |
| 2713 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2714 | except pexpect.EOF: |
| 2715 | main.log.error( self.name + ": EOF exception found" ) |
| 2716 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2717 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2718 | except Exception: |
| 2719 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2720 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2721 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2722 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2723 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2724 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2725 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2726 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2727 | a specific point-to-point intent definition |
| 2728 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2729 | * ingress: specify source dpid |
| 2730 | * egress: specify destination dpid |
| 2731 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2732 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2733 | * offset: the keyOffset is where the next batch of intents |
| 2734 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2735 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2736 | * getResponse: If set to True, function will return ONOS response. |
| 2737 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2738 | Returns: If failed to push test intents, it will returen None, |
| 2739 | if successful, return true. |
| 2740 | Timeout expection will return None, |
| 2741 | TypeError will return false |
| 2742 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2743 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2744 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2745 | if background: |
| 2746 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2747 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2748 | back = "" |
| 2749 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2750 | ingress, |
| 2751 | egress, |
| 2752 | batchSize, |
| 2753 | offset, |
| 2754 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2755 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2756 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2757 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2758 | main.log.info( response ) |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2759 | if getResponse: |
| 2760 | return response |
| 2761 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2762 | # TODO: We should handle if there is failure in installation |
| 2763 | return main.TRUE |
| 2764 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2765 | except AssertionError: |
| 2766 | main.log.exception( "" ) |
| 2767 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2768 | except pexpect.TIMEOUT: |
| 2769 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2770 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2771 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2772 | main.log.error( self.name + ": EOF exception found" ) |
| 2773 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2774 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2775 | except TypeError: |
| 2776 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2777 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2778 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2779 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2780 | main.cleanAndExit() |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2781 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2782 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2783 | """ |
| 2784 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2785 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2786 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2787 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2788 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2789 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2790 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2791 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2792 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2793 | cmd = "flows -c added" |
| 2794 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2795 | if rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2796 | rawFlows = rawFlows.split( "\n" ) |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2797 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2798 | for l in rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2799 | totalFlows += int( l.split( "Count=" )[ 1 ] ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2800 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2801 | main.log.error( "Response not as expected!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2802 | return None |
| 2803 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2804 | |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2805 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2806 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2807 | return None |
| 2808 | except pexpect.EOF: |
| 2809 | main.log.error( self.name + ": EOF exception found" ) |
| 2810 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2811 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2812 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2813 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2814 | except pexpect.TIMEOUT: |
| 2815 | main.log.error( self.name + ": ONOS timeout" ) |
| 2816 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2817 | except Exception: |
| 2818 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2819 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2820 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2821 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2822 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2823 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2824 | """ |
| 2825 | Description: |
| 2826 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2827 | Optional: |
| 2828 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2829 | Return: |
| 2830 | The number of intents |
| 2831 | """ |
| 2832 | try: |
| 2833 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2834 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2835 | if response is None: |
| 2836 | return -1 |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2837 | response = json.loads( response ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2838 | return int( response.get( "intents" ) ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2839 | except ( TypeError, ValueError ): |
| 2840 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2841 | return None |
| 2842 | except pexpect.EOF: |
| 2843 | main.log.error( self.name + ": EOF exception found" ) |
| 2844 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2845 | if noExit: |
| 2846 | return -1 |
| 2847 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2848 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2849 | except Exception: |
| 2850 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2851 | if noExit: |
| 2852 | return -1 |
| 2853 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2854 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2855 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2856 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2857 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2858 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2859 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2860 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2861 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2862 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2863 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2864 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2865 | cmdStr += " -j" |
| 2866 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2867 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2868 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2869 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2870 | except AssertionError: |
| 2871 | main.log.exception( "" ) |
| 2872 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2873 | except TypeError: |
| 2874 | main.log.exception( self.name + ": Object not as expected" ) |
| 2875 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2876 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2877 | main.log.error( self.name + ": EOF exception found" ) |
| 2878 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2879 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2880 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2881 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2882 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2883 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2884 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2885 | """ |
| 2886 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2887 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2888 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2889 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2890 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2891 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2892 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2893 | cmdStr += " -j" |
| 2894 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2895 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2896 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2897 | if handle: |
| 2898 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2899 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2900 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2901 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2902 | else: |
| 2903 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2904 | except AssertionError: |
| 2905 | main.log.exception( "" ) |
| 2906 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2907 | except TypeError: |
| 2908 | main.log.exception( self.name + ": Object not as expected" ) |
| 2909 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2910 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2911 | main.log.error( self.name + ": EOF exception found" ) |
| 2912 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2913 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2914 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2915 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2916 | main.cleanAndExit() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2917 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2918 | # Wrapper functions **************** |
| 2919 | # Wrapper functions use existing driver |
| 2920 | # functions and extends their use case. |
| 2921 | # For example, we may use the output of |
| 2922 | # a normal driver function, and parse it |
| 2923 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2924 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2925 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2926 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2927 | Description: |
| 2928 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2929 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2930 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2931 | # Obtain output of intents function |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2932 | intentsStr = self.intents( jsonFormat=True ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 2933 | if intentsStr is None: |
| 2934 | raise TypeError |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2935 | # Convert to a dictionary |
| 2936 | intents = json.loads( intentsStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2937 | intentIdList = [] |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2938 | for intent in intents: |
| 2939 | intentIdList.append( intent[ 'id' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2940 | return intentIdList |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2941 | except TypeError: |
| 2942 | main.log.exception( self.name + ": Object not as expected" ) |
| 2943 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2944 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2945 | main.log.error( self.name + ": EOF exception found" ) |
| 2946 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2947 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2948 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2949 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2950 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2951 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2952 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2953 | """ |
| 2954 | Determine the number of flow rules for the given device id that are |
| 2955 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2956 | Params: |
| 2957 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2958 | """ |
| 2959 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2960 | if core: |
| 2961 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2962 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2963 | else: |
| 2964 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2965 | "grep 'state=ADDED' | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 2966 | handle = self.lineCount( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2967 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2968 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2969 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2970 | except AssertionError: |
| 2971 | main.log.exception( "" ) |
| 2972 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2973 | except pexpect.EOF: |
| 2974 | main.log.error( self.name + ": EOF exception found" ) |
| 2975 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2976 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2977 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2978 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2979 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2980 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2981 | def groupAddedCount( self, deviceId, core=False ): |
| 2982 | """ |
| 2983 | Determine the number of group rules for the given device id that are |
| 2984 | in the added state |
| 2985 | Params: |
| 2986 | core: if True, only return the number of core groups added |
| 2987 | """ |
| 2988 | try: |
| 2989 | if core: |
| 2990 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 2991 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2992 | else: |
| 2993 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 2994 | "grep 'state=ADDED' | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 2995 | handle = self.lineCount( cmdStr ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2996 | assert handle is not None, "Error in sendline" |
| 2997 | assert "Command not found:" not in handle, handle |
| 2998 | return handle |
| 2999 | except AssertionError: |
| 3000 | main.log.exception( "" ) |
| 3001 | return None |
| 3002 | except pexpect.EOF: |
| 3003 | main.log.error( self.name + ": EOF exception found" ) |
| 3004 | main.log.error( self.name + ": " + self.handle.before ) |
| 3005 | main.cleanAndExit() |
| 3006 | except Exception: |
| 3007 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3008 | main.cleanAndExit() |
| 3009 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 3010 | def addStaticRoute( self, subnet, intf): |
| 3011 | """ |
| 3012 | Adds a static route to onos. |
| 3013 | Params: |
| 3014 | subnet: The subnet reaching through this route |
| 3015 | intf: The interface this route is reachable through |
| 3016 | """ |
| 3017 | try: |
| 3018 | cmdStr = "route-add " + subnet + " " + intf |
| 3019 | handle = self.sendline( cmdStr ) |
| 3020 | assert handle is not None, "Error in sendline" |
| 3021 | assert "Command not found:" not in handle, handle |
| 3022 | return handle |
| 3023 | except AssertionError: |
| 3024 | main.log.exception( "" ) |
| 3025 | return None |
| 3026 | except pexpect.EOF: |
| 3027 | main.log.error( self.name + ": EOF exception found" ) |
| 3028 | main.log.error( self.name + ": " + self.handle.before ) |
| 3029 | main.cleanAndExit() |
| 3030 | except Exception: |
| 3031 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3032 | main.cleanAndExit() |
| 3033 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3034 | def checkGroupAddedCount( self, deviceId, expectedGroupCount=0, core=False, comparison=0): |
| 3035 | """ |
| 3036 | Description: |
| 3037 | Check whether the number of groups for the given device id that |
| 3038 | are in ADDED state is bigger than minGroupCount. |
| 3039 | Required: |
| 3040 | * deviceId: device id to check the number of added group rules |
| 3041 | Optional: |
| 3042 | * minGroupCount: the number of groups to compare |
| 3043 | * core: if True, only check the number of core groups added |
| 3044 | * comparison: if 0, compare with greater than minFlowCount |
| 3045 | * if 1, compare with equal to minFlowCount |
| 3046 | Return: |
| 3047 | Returns the number of groups if it is bigger than minGroupCount, |
| 3048 | returns main.FALSE otherwise. |
| 3049 | """ |
| 3050 | count = self.groupAddedCount( deviceId, core ) |
| 3051 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 3052 | main.log.debug( "found {} groups".format( count ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3053 | return count if ((count > expectedGroupCount) if (comparison == 0) else (count == expectedGroupCount)) else main.FALSE |
| 3054 | |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3055 | def getGroups( self, deviceId, groupType="any" ): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3056 | """ |
| 3057 | Retrieve groups from a specific device. |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3058 | deviceId: Id of the device from which we retrieve groups |
| 3059 | groupType: Type of group |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3060 | """ |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3061 | try: |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3062 | groupCmd = "groups -t {0} any {1}".format( groupType, deviceId ) |
| 3063 | handle = self.sendline( groupCmd ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3064 | assert handle is not None, "Error in sendline" |
| 3065 | assert "Command not found:" not in handle, handle |
| 3066 | return handle |
| 3067 | except AssertionError: |
| 3068 | main.log.exception( "" ) |
| 3069 | return None |
| 3070 | except TypeError: |
| 3071 | main.log.exception( self.name + ": Object not as expected" ) |
| 3072 | return None |
| 3073 | except pexpect.EOF: |
| 3074 | main.log.error( self.name + ": EOF exception found" ) |
| 3075 | main.log.error( self.name + ": " + self.handle.before ) |
| 3076 | main.cleanAndExit() |
| 3077 | except Exception: |
| 3078 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3079 | main.cleanAndExit() |
| 3080 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3081 | def checkFlowAddedCount( self, deviceId, expectedFlowCount=0, core=False, comparison=0): |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3082 | """ |
| 3083 | Description: |
| 3084 | Check whether the number of flow rules for the given device id that |
| 3085 | are in ADDED state is bigger than minFlowCount. |
| 3086 | Required: |
| 3087 | * deviceId: device id to check the number of added flow rules |
| 3088 | Optional: |
| 3089 | * minFlowCount: the number of flow rules to compare |
| 3090 | * core: if True, only check the number of core flows added |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3091 | * comparison: if 0, compare with greater than minFlowCount |
| 3092 | * if 1, compare with equal to minFlowCount |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3093 | Return: |
| 3094 | Returns the number of flow rules if it is bigger than minFlowCount, |
| 3095 | returns main.FALSE otherwise. |
| 3096 | """ |
| 3097 | count = self.flowAddedCount( deviceId, core ) |
| 3098 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 3099 | main.log.debug( "found {} flows".format( count ) ) |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 3100 | return count if ((count > expectedFlowCount) if (comparison == 0) else (count == expectedFlowCount)) else main.FALSE |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3101 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3102 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3103 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3104 | Use 'devices' function to obtain list of all devices |
| 3105 | and parse the result to obtain a list of all device |
| 3106 | id's. Returns this list. Returns empty list if no |
| 3107 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3108 | List is ordered sequentially |
| 3109 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3110 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3111 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3112 | the ids. By obtaining the list of device ids on the fly, |
| 3113 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3114 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3115 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3116 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3117 | devicesStr = self.devices( jsonFormat=False ) |
| 3118 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3119 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3120 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3121 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3122 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3123 | |
| 3124 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3125 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3126 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3127 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3128 | # Split list further into arguments before and after string |
| 3129 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3130 | # append to idList |
| 3131 | for arg in tempList: |
| 3132 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 3133 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3134 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3135 | except TypeError: |
| 3136 | main.log.exception( self.name + ": Object not as expected" ) |
| 3137 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3138 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3139 | main.log.error( self.name + ": EOF exception found" ) |
| 3140 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3141 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3142 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3143 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3144 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3145 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3146 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3147 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3148 | Uses 'nodes' function to obtain list of all nodes |
| 3149 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3150 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3151 | Returns: |
| 3152 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3153 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3154 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3155 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3156 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3157 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 3158 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3159 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3160 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3161 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3162 | nodesJson = json.loads( nodesStr ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3163 | idList = [ node.get( 'id' ) for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3164 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3165 | except ( TypeError, ValueError ): |
| 3166 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3167 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3168 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3169 | main.log.error( self.name + ": EOF exception found" ) |
| 3170 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3171 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3172 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3173 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3174 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3175 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3176 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3177 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3178 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 3179 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3180 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3181 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3182 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3183 | return None |
| 3184 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3185 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3186 | rawDevices = self.devices() |
| 3187 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3188 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3189 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3190 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 3191 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3192 | return device |
| 3193 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3194 | except ( TypeError, ValueError ): |
| 3195 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3196 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3197 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3198 | main.log.error( self.name + ": EOF exception found" ) |
| 3199 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3200 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3201 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3202 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3203 | main.cleanAndExit() |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3204 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3205 | def getTopology( self, topologyOutput ): |
| 3206 | """ |
| 3207 | Definition: |
| 3208 | Loads a json topology output |
| 3209 | Return: |
| 3210 | topology = current ONOS topology |
| 3211 | """ |
| 3212 | import json |
| 3213 | try: |
| 3214 | # either onos:topology or 'topology' will work in CLI |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3215 | topology = json.loads( topologyOutput ) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 3216 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3217 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 3218 | except ( TypeError, ValueError ): |
| 3219 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 3220 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3221 | except pexpect.EOF: |
| 3222 | main.log.error( self.name + ": EOF exception found" ) |
| 3223 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3224 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3225 | except Exception: |
| 3226 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3227 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3228 | |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3229 | def checkStatus( self, numoswitch, numolink = -1, numoctrl = -1, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3230 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3231 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3232 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3233 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3234 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3235 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3236 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3237 | numoctrl = expected number of controllers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3238 | logLevel = level to log to. |
| 3239 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3240 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3241 | Returns: main.TRUE if the number of switches and links are correct, |
| 3242 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3243 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3244 | """ |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3245 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3246 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 3247 | summary = self.summary() |
| 3248 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 3249 | except ( TypeError, ValueError ): |
| 3250 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 3251 | return main.ERROR |
| 3252 | try: |
| 3253 | topology = self.getTopology( self.topology() ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 3254 | if topology == {} or topology is None or summary == {} or summary is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3255 | return main.ERROR |
| 3256 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3257 | # Is the number of switches is what we expected |
| 3258 | devices = topology.get( 'devices', False ) |
| 3259 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3260 | nodes = summary.get( 'nodes', False ) |
| 3261 | if devices is False or links is False or nodes is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3262 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3263 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3264 | # Is the number of links is what we expected |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3265 | linkCheck = ( int( links ) == int( numolink ) ) or int( numolink ) == -1 |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3266 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
| 3267 | if switchCheck and linkCheck and nodeCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3268 | # We expected the correct numbers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3269 | output = output + "The number of links and switches match "\ |
| 3270 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3271 | result = main.TRUE |
| 3272 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3273 | output = output + \ |
| 3274 | "The number of links and switches does not match " + \ |
| 3275 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3276 | result = main.FALSE |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3277 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 3278 | output = output + " (%i expected) " % int( numoswitch ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3279 | if int( numolink ) > 0: |
| 3280 | output = output + "and %i links " % int( links ) |
| 3281 | output = output + "(%i expected)" % int( numolink ) |
YPZhang | d7e4b6e | 2016-06-17 16:07:55 -0700 | [diff] [blame] | 3282 | if int( numoctrl ) > 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3283 | output = output + "and %i controllers " % int( nodes ) |
| 3284 | output = output + "(%i expected)" % int( numoctrl ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3285 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3286 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3287 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3288 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3289 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3290 | main.log.info( output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3291 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3292 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3293 | main.log.error( self.name + ": EOF exception found" ) |
| 3294 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3295 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3296 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3297 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3298 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3299 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3300 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3301 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3302 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3303 | deviceId must be the id of a device as seen in the onos devices command |
| 3304 | 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] | 3305 | role must be either master, standby, or none |
| 3306 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3307 | Returns: |
| 3308 | main.TRUE or main.FALSE based on argument verification and |
| 3309 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3310 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3311 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3312 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3313 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3314 | cmdStr = "device-role " +\ |
| 3315 | str( deviceId ) + " " +\ |
| 3316 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3317 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3318 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3319 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3320 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3321 | if re.search( "Error", handle ): |
| 3322 | # end color output to escape any colours |
| 3323 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3324 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3325 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3326 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3327 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3328 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3329 | main.log.error( "Invalid 'role' given to device_role(). " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3330 | "Value was '" + str( role ) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3331 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3332 | except AssertionError: |
| 3333 | main.log.exception( "" ) |
| 3334 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3335 | except TypeError: |
| 3336 | main.log.exception( self.name + ": Object not as expected" ) |
| 3337 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3338 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3339 | main.log.error( self.name + ": EOF exception found" ) |
| 3340 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3341 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3342 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3343 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3344 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3345 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3346 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3347 | """ |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3348 | Lists all topology clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 3349 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3350 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3351 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3352 | try: |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3353 | cmdStr = "topo-clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3354 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3355 | cmdStr += " -j" |
| 3356 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3357 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3358 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3359 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3360 | except AssertionError: |
| 3361 | main.log.exception( "" ) |
| 3362 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3363 | except TypeError: |
| 3364 | main.log.exception( self.name + ": Object not as expected" ) |
| 3365 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3366 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3367 | main.log.error( self.name + ": EOF exception found" ) |
| 3368 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3369 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3370 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3371 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3372 | main.cleanAndExit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3373 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3374 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3375 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3376 | CLI command to get the current leader for the Election test application |
| 3377 | NOTE: Requires installation of the onos-app-election feature |
| 3378 | Returns: Node IP of the leader if one exists |
| 3379 | None if none exists |
| 3380 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3381 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3382 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3383 | cmdStr = "election-test-leader" |
| 3384 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3385 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3386 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3387 | # Leader |
| 3388 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3389 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3390 | nodeSearch = re.search( leaderPattern, response ) |
| 3391 | if nodeSearch: |
| 3392 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3393 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3394 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3395 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3396 | # no leader |
| 3397 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3398 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3399 | nullSearch = re.search( nullPattern, response ) |
| 3400 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3401 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3402 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3403 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3404 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3405 | main.log.error( self.name + ": Error in electionTestLeader on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3406 | ": " + "unexpected response" ) |
| 3407 | main.log.error( repr( response ) ) |
| 3408 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3409 | except AssertionError: |
| 3410 | main.log.exception( "" ) |
| 3411 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3412 | except TypeError: |
| 3413 | main.log.exception( self.name + ": Object not as expected" ) |
| 3414 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3415 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3416 | main.log.error( self.name + ": EOF exception found" ) |
| 3417 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3418 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3419 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3420 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3421 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3422 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3423 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3424 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3425 | CLI command to run for leadership of the Election test application. |
| 3426 | NOTE: Requires installation of the onos-app-election feature |
| 3427 | Returns: Main.TRUE on success |
| 3428 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3429 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3430 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3431 | cmdStr = "election-test-run" |
| 3432 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3433 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3434 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3435 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3436 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3437 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3438 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3439 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3440 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3441 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3442 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3443 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3444 | main.log.error( self.name + ": Error in electionTestRun on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3445 | ": " + "unexpected response" ) |
| 3446 | main.log.error( repr( response ) ) |
| 3447 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3448 | except AssertionError: |
| 3449 | main.log.exception( "" ) |
| 3450 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3451 | except TypeError: |
| 3452 | main.log.exception( self.name + ": Object not as expected" ) |
| 3453 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3454 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3455 | main.log.error( self.name + ": EOF exception found" ) |
| 3456 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3457 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3458 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3459 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3460 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3461 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3462 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3463 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3464 | * CLI command to withdraw the local node from leadership election for |
| 3465 | * the Election test application. |
| 3466 | #NOTE: Requires installation of the onos-app-election feature |
| 3467 | Returns: Main.TRUE on success |
| 3468 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3469 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3470 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3471 | cmdStr = "election-test-withdraw" |
| 3472 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3473 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3474 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3475 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3476 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3477 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3478 | if re.search( successPattern, response ): |
| 3479 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3480 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3481 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3482 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3483 | main.log.error( self.name + ": Error in electionTestWithdraw on " + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3484 | self.name + ": " + "unexpected response" ) |
| 3485 | main.log.error( repr( response ) ) |
| 3486 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3487 | except AssertionError: |
| 3488 | main.log.exception( "" ) |
| 3489 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3490 | except TypeError: |
| 3491 | main.log.exception( self.name + ": Object not as expected" ) |
| 3492 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3493 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3494 | main.log.error( self.name + ": EOF exception found" ) |
| 3495 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3496 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3497 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3498 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3499 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3500 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3501 | def getDevicePortsEnabledCount( self, dpid ): |
| 3502 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3503 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3504 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3505 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3506 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3507 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3508 | output = self.lineCount( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3509 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3510 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3511 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3512 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3513 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3514 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3515 | except AssertionError: |
| 3516 | main.log.exception( "" ) |
| 3517 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3518 | except TypeError: |
| 3519 | main.log.exception( self.name + ": Object not as expected" ) |
| 3520 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3521 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3522 | main.log.error( self.name + ": EOF exception found" ) |
| 3523 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3524 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3525 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3526 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3527 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3528 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3529 | def getDeviceLinksActiveCount( self, dpid ): |
| 3530 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3531 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3532 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3533 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3534 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3535 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3536 | output = self.lineCount( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3537 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3538 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3539 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3540 | main.log.error( self.name + ": Error in getting ports " ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3541 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3542 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3543 | except AssertionError: |
| 3544 | main.log.exception( "" ) |
| 3545 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3546 | except TypeError: |
| 3547 | main.log.exception( self.name + ": Object not as expected" ) |
| 3548 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3549 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3550 | main.log.error( self.name + ": EOF exception found" ) |
| 3551 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3552 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3553 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3554 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3555 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3556 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3557 | def getAllIntentIds( self ): |
| 3558 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3559 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3560 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3561 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3562 | cmdStr = "onos:intents | grep id=" |
| 3563 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3564 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3565 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3566 | if re.search( "Error", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3567 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3568 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3569 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3570 | except AssertionError: |
| 3571 | main.log.exception( "" ) |
| 3572 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3573 | except TypeError: |
| 3574 | main.log.exception( self.name + ": Object not as expected" ) |
| 3575 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3576 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3577 | main.log.error( self.name + ": EOF exception found" ) |
| 3578 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3579 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3580 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3581 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3582 | main.cleanAndExit() |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3583 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3584 | def intentSummary( self ): |
| 3585 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3586 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3587 | """ |
| 3588 | try: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3589 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3590 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3591 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3592 | states.append( intent.get( 'state', None ) ) |
| 3593 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3594 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3595 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3596 | except ( TypeError, ValueError ): |
| 3597 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3598 | return None |
| 3599 | except pexpect.EOF: |
| 3600 | main.log.error( self.name + ": EOF exception found" ) |
| 3601 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3602 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3603 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3604 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3605 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3606 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3607 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3608 | """ |
| 3609 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3610 | Optional argument: |
| 3611 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3612 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3613 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3614 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3615 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3616 | cmdStr += " -j" |
| 3617 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3618 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3619 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3620 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3621 | except AssertionError: |
| 3622 | main.log.exception( "" ) |
| 3623 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3624 | except TypeError: |
| 3625 | main.log.exception( self.name + ": Object not as expected" ) |
| 3626 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3627 | except pexpect.EOF: |
| 3628 | main.log.error( self.name + ": EOF exception found" ) |
| 3629 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3630 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3631 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3632 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3633 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3634 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3635 | def leaderCandidates( self, jsonFormat=True ): |
| 3636 | """ |
| 3637 | Returns the output of the leaders -c command. |
| 3638 | Optional argument: |
| 3639 | * jsonFormat - boolean indicating if you want output in json |
| 3640 | """ |
| 3641 | try: |
| 3642 | cmdStr = "onos:leaders -c" |
| 3643 | if jsonFormat: |
| 3644 | cmdStr += " -j" |
| 3645 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3646 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3647 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3648 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3649 | except AssertionError: |
| 3650 | main.log.exception( "" ) |
| 3651 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3652 | except TypeError: |
| 3653 | main.log.exception( self.name + ": Object not as expected" ) |
| 3654 | return None |
| 3655 | except pexpect.EOF: |
| 3656 | main.log.error( self.name + ": EOF exception found" ) |
| 3657 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3658 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3659 | except Exception: |
| 3660 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3661 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3662 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3663 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3664 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3665 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3666 | topic parameter and an empty list if the topic doesn't exist |
| 3667 | If no leader is elected leader in the returned list will be "none" |
| 3668 | Returns None if there is a type error processing the json object |
| 3669 | """ |
| 3670 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3671 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3672 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3673 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3674 | assert "Command not found:" not in rawOutput, rawOutput |
| 3675 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3676 | results = [] |
| 3677 | for dict in output: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3678 | if dict[ "topic" ] == topic: |
| 3679 | leader = dict[ "leader" ] |
| 3680 | candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3681 | results.append( leader ) |
| 3682 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3683 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3684 | except AssertionError: |
| 3685 | main.log.exception( "" ) |
| 3686 | return None |
| 3687 | except ( TypeError, ValueError ): |
| 3688 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3689 | return None |
| 3690 | except pexpect.EOF: |
| 3691 | main.log.error( self.name + ": EOF exception found" ) |
| 3692 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3693 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3694 | except Exception: |
| 3695 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3696 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3697 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3698 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3699 | """ |
| 3700 | Returns the output of the intent Pending map. |
| 3701 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3702 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3703 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3704 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3705 | cmdStr += " -j" |
| 3706 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3707 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3708 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3709 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3710 | except AssertionError: |
| 3711 | main.log.exception( "" ) |
| 3712 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3713 | except TypeError: |
| 3714 | main.log.exception( self.name + ": Object not as expected" ) |
| 3715 | return None |
| 3716 | except pexpect.EOF: |
| 3717 | main.log.error( self.name + ": EOF exception found" ) |
| 3718 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3719 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3720 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3721 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3722 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3723 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3724 | def partitions( self, candidates=False, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3725 | """ |
| 3726 | Returns the output of the raft partitions command for ONOS. |
| 3727 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3728 | # Sample JSON |
| 3729 | # { |
| 3730 | # "leader": "tcp://10.128.30.11:7238", |
| 3731 | # "members": [ |
| 3732 | # "tcp://10.128.30.11:7238", |
| 3733 | # "tcp://10.128.30.17:7238", |
| 3734 | # "tcp://10.128.30.13:7238", |
| 3735 | # ], |
| 3736 | # "name": "p1", |
| 3737 | # "term": 3 |
| 3738 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3739 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3740 | cmdStr = "onos:partitions" |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3741 | if candidates: |
| 3742 | cmdStr += " -c" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3743 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3744 | cmdStr += " -j" |
| 3745 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3746 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3747 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3748 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3749 | except AssertionError: |
| 3750 | main.log.exception( "" ) |
| 3751 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3752 | except TypeError: |
| 3753 | main.log.exception( self.name + ": Object not as expected" ) |
| 3754 | return None |
| 3755 | except pexpect.EOF: |
| 3756 | main.log.error( self.name + ": EOF exception found" ) |
| 3757 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3758 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3759 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3760 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3761 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3762 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3763 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3764 | """ |
| 3765 | Returns the output of the apps command for ONOS. This command lists |
| 3766 | information about installed ONOS applications |
| 3767 | """ |
| 3768 | # Sample JSON object |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3769 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3770 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3771 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3772 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3773 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3774 | cmdStr = "onos:apps" |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3775 | if summary: |
| 3776 | cmdStr += " -s" |
| 3777 | if active: |
| 3778 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3779 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3780 | cmdStr += " -j" |
| 3781 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3782 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3783 | assert "Command not found:" not in output, output |
| 3784 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3785 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3786 | # FIXME: look at specific exceptions/Errors |
| 3787 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3788 | main.log.exception( self.name + ": Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3789 | return None |
| 3790 | except TypeError: |
| 3791 | main.log.exception( self.name + ": Object not as expected" ) |
| 3792 | return None |
| 3793 | except pexpect.EOF: |
| 3794 | main.log.error( self.name + ": EOF exception found" ) |
| 3795 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3796 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3797 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3798 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3799 | main.cleanAndExit() |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3800 | |
You Wang | cdc51fe | 2018-08-12 17:14:56 -0700 | [diff] [blame] | 3801 | def appStatus( self, appName ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3802 | """ |
| 3803 | Uses the onos:apps cli command to return the status of an application. |
| 3804 | Returns: |
| 3805 | "ACTIVE" - If app is installed and activated |
| 3806 | "INSTALLED" - If app is installed and deactivated |
| 3807 | "UNINSTALLED" - If app is not installed |
| 3808 | None - on error |
| 3809 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3810 | try: |
| 3811 | if not isinstance( appName, types.StringType ): |
| 3812 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3813 | " a string" ) |
| 3814 | return None |
| 3815 | output = self.apps( jsonFormat=True ) |
| 3816 | appsJson = json.loads( output ) |
| 3817 | state = None |
| 3818 | for app in appsJson: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3819 | if appName == app.get( 'name' ): |
| 3820 | state = app.get( 'state' ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3821 | break |
| 3822 | if state == "ACTIVE" or state == "INSTALLED": |
| 3823 | return state |
| 3824 | elif state is None: |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 3825 | main.log.warn( "{} app not found".format( appName ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3826 | return "UNINSTALLED" |
| 3827 | elif state: |
| 3828 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3829 | str( state ) ) |
| 3830 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3831 | except ( TypeError, ValueError ): |
| 3832 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3833 | return None |
| 3834 | except pexpect.EOF: |
| 3835 | main.log.error( self.name + ": EOF exception found" ) |
| 3836 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3837 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3838 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3839 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3840 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3841 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3842 | def app( self, appName, option ): |
| 3843 | """ |
| 3844 | Interacts with the app command for ONOS. This command manages |
| 3845 | application inventory. |
| 3846 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3847 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3848 | # Validate argument types |
| 3849 | valid = True |
| 3850 | if not isinstance( appName, types.StringType ): |
| 3851 | main.log.error( self.name + ".app(): appName must be a " + |
| 3852 | "string" ) |
| 3853 | valid = False |
| 3854 | if not isinstance( option, types.StringType ): |
| 3855 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3856 | valid = False |
| 3857 | if not valid: |
| 3858 | return main.FALSE |
| 3859 | # Validate Option |
| 3860 | option = option.lower() |
| 3861 | # NOTE: Install may become a valid option |
| 3862 | if option == "activate": |
| 3863 | pass |
| 3864 | elif option == "deactivate": |
| 3865 | pass |
| 3866 | elif option == "uninstall": |
| 3867 | pass |
| 3868 | else: |
| 3869 | # Invalid option |
| 3870 | main.log.error( "The ONOS app command argument only takes " + |
| 3871 | "the values: (activate|deactivate|uninstall)" + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3872 | "; was given '" + option + "'" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3873 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3874 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3875 | output = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3876 | assert output is not None, "Error in sendline" |
| 3877 | assert "Command not found:" not in output, output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3878 | if "Error executing command" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3879 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3880 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3881 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3882 | elif "No such application" in output: |
| 3883 | main.log.error( "The application '" + appName + |
| 3884 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3885 | return main.FALSE |
| 3886 | elif "Command not found:" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3887 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3888 | str( output ) ) |
| 3889 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3890 | elif "Unsupported command:" in output: |
| 3891 | main.log.error( "Incorrect command given to 'app': " + |
| 3892 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3893 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3894 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3895 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3896 | return main.TRUE |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3897 | except AssertionError: |
| 3898 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 3899 | return main.ERROR |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3900 | except TypeError: |
| 3901 | main.log.exception( self.name + ": Object not as expected" ) |
| 3902 | return main.ERROR |
| 3903 | except pexpect.EOF: |
| 3904 | main.log.error( self.name + ": EOF exception found" ) |
| 3905 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3906 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3907 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3908 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3909 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3910 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3911 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3912 | """ |
| 3913 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3914 | appName is the hierarchical app name, not the feature name |
| 3915 | If check is True, method will check the status of the app after the |
| 3916 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3917 | Returns main.TRUE if the command was successfully sent |
| 3918 | main.FALSE if the cli responded with an error or given |
| 3919 | incorrect input |
| 3920 | """ |
| 3921 | try: |
| 3922 | if not isinstance( appName, types.StringType ): |
| 3923 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3924 | " a string" ) |
| 3925 | return main.FALSE |
| 3926 | status = self.appStatus( appName ) |
| 3927 | if status == "INSTALLED": |
| 3928 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3929 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3930 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3931 | status = self.appStatus( appName ) |
| 3932 | if status == "ACTIVE": |
| 3933 | return main.TRUE |
| 3934 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3935 | main.log.debug( "The state of application " + |
| 3936 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3937 | time.sleep( 1 ) |
| 3938 | return main.FALSE |
| 3939 | else: # not 'check' or command didn't succeed |
| 3940 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3941 | elif status == "ACTIVE": |
| 3942 | return main.TRUE |
| 3943 | elif status == "UNINSTALLED": |
| 3944 | main.log.error( self.name + ": Tried to activate the " + |
| 3945 | "application '" + appName + "' which is not " + |
| 3946 | "installed." ) |
| 3947 | else: |
| 3948 | main.log.error( "Unexpected return value from appStatus: " + |
| 3949 | str( status ) ) |
| 3950 | return main.ERROR |
| 3951 | except TypeError: |
| 3952 | main.log.exception( self.name + ": Object not as expected" ) |
| 3953 | return main.ERROR |
| 3954 | except pexpect.EOF: |
| 3955 | main.log.error( self.name + ": EOF exception found" ) |
| 3956 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3957 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3958 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3959 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3960 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3961 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3962 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3963 | """ |
| 3964 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3965 | appName is the hierarchical app name, not the feature name |
| 3966 | If check is True, method will check the status of the app after the |
| 3967 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3968 | Returns main.TRUE if the command was successfully sent |
| 3969 | main.FALSE if the cli responded with an error or given |
| 3970 | incorrect input |
| 3971 | """ |
| 3972 | try: |
| 3973 | if not isinstance( appName, types.StringType ): |
| 3974 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 3975 | "be a string" ) |
| 3976 | return main.FALSE |
| 3977 | status = self.appStatus( appName ) |
| 3978 | if status == "INSTALLED": |
| 3979 | return main.TRUE |
| 3980 | elif status == "ACTIVE": |
| 3981 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3982 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3983 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3984 | status = self.appStatus( appName ) |
| 3985 | if status == "INSTALLED": |
| 3986 | return main.TRUE |
| 3987 | else: |
| 3988 | time.sleep( 1 ) |
| 3989 | return main.FALSE |
| 3990 | else: # not check or command didn't succeed |
| 3991 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3992 | elif status == "UNINSTALLED": |
| 3993 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 3994 | "application '" + appName + "' which is not " + |
| 3995 | "installed." ) |
| 3996 | return main.TRUE |
| 3997 | else: |
| 3998 | main.log.error( "Unexpected return value from appStatus: " + |
| 3999 | str( status ) ) |
| 4000 | return main.ERROR |
| 4001 | except TypeError: |
| 4002 | main.log.exception( self.name + ": Object not as expected" ) |
| 4003 | return main.ERROR |
| 4004 | except pexpect.EOF: |
| 4005 | main.log.error( self.name + ": EOF exception found" ) |
| 4006 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4007 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4008 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4009 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4010 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4011 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4012 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4013 | """ |
| 4014 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4015 | appName is the hierarchical app name, not the feature name |
| 4016 | If check is True, method will check the status of the app after the |
| 4017 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4018 | Returns main.TRUE if the command was successfully sent |
| 4019 | main.FALSE if the cli responded with an error or given |
| 4020 | incorrect input |
| 4021 | """ |
| 4022 | # TODO: check with Thomas about the state machine for apps |
| 4023 | try: |
| 4024 | if not isinstance( appName, types.StringType ): |
| 4025 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 4026 | "be a string" ) |
| 4027 | return main.FALSE |
| 4028 | status = self.appStatus( appName ) |
| 4029 | if status == "INSTALLED": |
| 4030 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4031 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4032 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4033 | status = self.appStatus( appName ) |
| 4034 | if status == "UNINSTALLED": |
| 4035 | return main.TRUE |
| 4036 | else: |
| 4037 | time.sleep( 1 ) |
| 4038 | return main.FALSE |
| 4039 | else: # not check or command didn't succeed |
| 4040 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4041 | elif status == "ACTIVE": |
| 4042 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 4043 | "application '" + appName + "' which is " + |
| 4044 | "currently active." ) |
| 4045 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4046 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4047 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4048 | status = self.appStatus( appName ) |
| 4049 | if status == "UNINSTALLED": |
| 4050 | return main.TRUE |
| 4051 | else: |
| 4052 | time.sleep( 1 ) |
| 4053 | return main.FALSE |
| 4054 | else: # not check or command didn't succeed |
| 4055 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4056 | elif status == "UNINSTALLED": |
| 4057 | return main.TRUE |
| 4058 | else: |
| 4059 | main.log.error( "Unexpected return value from appStatus: " + |
| 4060 | str( status ) ) |
| 4061 | return main.ERROR |
| 4062 | except TypeError: |
| 4063 | main.log.exception( self.name + ": Object not as expected" ) |
| 4064 | return main.ERROR |
| 4065 | except pexpect.EOF: |
| 4066 | main.log.error( self.name + ": EOF exception found" ) |
| 4067 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4068 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4069 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4070 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4071 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4072 | |
| 4073 | def appIDs( self, jsonFormat=True ): |
| 4074 | """ |
| 4075 | Show the mappings between app id and app names given by the 'app-ids' |
| 4076 | cli command |
| 4077 | """ |
| 4078 | try: |
| 4079 | cmdStr = "app-ids" |
| 4080 | if jsonFormat: |
| 4081 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4082 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4083 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4084 | assert "Command not found:" not in output, output |
| 4085 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4086 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4087 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4088 | main.log.exception( self.name + ": Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4089 | return None |
| 4090 | except TypeError: |
| 4091 | main.log.exception( self.name + ": Object not as expected" ) |
| 4092 | return None |
| 4093 | except pexpect.EOF: |
| 4094 | main.log.error( self.name + ": EOF exception found" ) |
| 4095 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4096 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4097 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4098 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4099 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4100 | |
| 4101 | def appToIDCheck( self ): |
| 4102 | """ |
| 4103 | This method will check that each application's ID listed in 'apps' is |
| 4104 | the same as the ID listed in 'app-ids'. The check will also check that |
| 4105 | there are no duplicate IDs issued. Note that an app ID should be |
| 4106 | a globaly unique numerical identifier for app/app-like features. Once |
| 4107 | an ID is registered, the ID is never freed up so that if an app is |
| 4108 | reinstalled it will have the same ID. |
| 4109 | |
| 4110 | Returns: main.TRUE if the check passes and |
| 4111 | main.FALSE if the check fails or |
| 4112 | main.ERROR if there is some error in processing the test |
| 4113 | """ |
| 4114 | try: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4115 | # Grab IDs |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4116 | rawJson = self.appIDs( jsonFormat=True ) |
| 4117 | if rawJson: |
| 4118 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4119 | else: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4120 | main.log.error( "app-ids returned nothing: " + repr( rawJson ) ) |
| 4121 | return main.FALSE |
| 4122 | |
| 4123 | # Grab Apps |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4124 | rawJson = self.apps( jsonFormat=True ) |
| 4125 | if rawJson: |
| 4126 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4127 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4128 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4129 | return main.FALSE |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4130 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4131 | result = main.TRUE |
| 4132 | for app in apps: |
| 4133 | appID = app.get( 'id' ) |
| 4134 | if appID is None: |
| 4135 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4136 | result = main.FALSE |
| 4137 | appName = app.get( 'name' ) |
| 4138 | if appName is None: |
| 4139 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4140 | result = main.FALSE |
| 4141 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4142 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4143 | if not current: # if ids doesn't have this id |
| 4144 | result = main.FALSE |
| 4145 | main.log.error( "'app-ids' does not have the ID for " + |
| 4146 | str( appName ) + " that apps does." ) |
Jon Hall | b9d381e | 2018-02-05 12:02:10 -0800 | [diff] [blame] | 4147 | main.log.debug( "apps command returned: " + str( app ) + |
| 4148 | "; app-ids has: " + str( ids ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4149 | elif len( current ) > 1: |
| 4150 | # there is more than one app with this ID |
| 4151 | result = main.FALSE |
| 4152 | # We will log this later in the method |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4153 | elif not current[ 0 ][ 'name' ] == appName: |
| 4154 | currentName = current[ 0 ][ 'name' ] |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4155 | result = main.FALSE |
| 4156 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 4157 | " registered under id:" + str( appID ) + |
| 4158 | " but 'apps' has " + str( appName ) ) |
| 4159 | else: |
| 4160 | pass # id and name match! |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4161 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4162 | # now make sure that app-ids has no duplicates |
| 4163 | idsList = [] |
| 4164 | namesList = [] |
| 4165 | for item in ids: |
| 4166 | idsList.append( item[ 'id' ] ) |
| 4167 | namesList.append( item[ 'name' ] ) |
| 4168 | if len( idsList ) != len( set( idsList ) ) or\ |
| 4169 | len( namesList ) != len( set( namesList ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4170 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 4171 | + json.dumps( ids, |
| 4172 | sort_keys=True, |
| 4173 | indent=4, |
| 4174 | separators=( ',', ': ' ) ) ) |
| 4175 | result = main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4176 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4177 | except ( TypeError, ValueError ): |
| 4178 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4179 | return main.ERROR |
| 4180 | except pexpect.EOF: |
| 4181 | main.log.error( self.name + ": EOF exception found" ) |
| 4182 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4183 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4184 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4185 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4186 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4187 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4188 | def getCfg( self, component=None, propName=None, short=False, |
| 4189 | jsonFormat=True ): |
| 4190 | """ |
| 4191 | Get configuration settings from onos cli |
| 4192 | Optional arguments: |
| 4193 | component - Optionally only list configurations for a specific |
| 4194 | component. If None, all components with configurations |
| 4195 | are displayed. Case Sensitive string. |
| 4196 | propName - If component is specified, propName option will show |
| 4197 | only this specific configuration from that component. |
| 4198 | Case Sensitive string. |
| 4199 | jsonFormat - Returns output as json. Note that this will override |
| 4200 | the short option |
| 4201 | short - Short, less verbose, version of configurations. |
| 4202 | This is overridden by the json option |
| 4203 | returns: |
| 4204 | Output from cli as a string or None on error |
| 4205 | """ |
| 4206 | try: |
| 4207 | baseStr = "cfg" |
| 4208 | cmdStr = " get" |
| 4209 | componentStr = "" |
| 4210 | if component: |
| 4211 | componentStr += " " + component |
| 4212 | if propName: |
| 4213 | componentStr += " " + propName |
| 4214 | if jsonFormat: |
| 4215 | baseStr += " -j" |
| 4216 | elif short: |
| 4217 | baseStr += " -s" |
| 4218 | output = self.sendline( baseStr + cmdStr + componentStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4219 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4220 | assert "Command not found:" not in output, output |
| 4221 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4222 | return output |
| 4223 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4224 | main.log.exception( self.name + ": Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4225 | return None |
| 4226 | except TypeError: |
| 4227 | main.log.exception( self.name + ": Object not as expected" ) |
| 4228 | return None |
| 4229 | except pexpect.EOF: |
| 4230 | main.log.error( self.name + ": EOF exception found" ) |
| 4231 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4232 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4233 | except Exception: |
| 4234 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4235 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4236 | |
| 4237 | def setCfg( self, component, propName, value=None, check=True ): |
| 4238 | """ |
| 4239 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4240 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4241 | component - The case sensitive name of the component whose |
| 4242 | property is to be set |
| 4243 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4244 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4245 | value - The value to set the property to. If None, will unset the |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4246 | property and revert it to it's default value(if applicable) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4247 | check - Boolean, Check whether the option was successfully set this |
| 4248 | only applies when a value is given. |
| 4249 | returns: |
| 4250 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 4251 | will return main.TRUE unless there is an error |
| 4252 | """ |
| 4253 | try: |
| 4254 | baseStr = "cfg" |
| 4255 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 4256 | if value is not None: |
| 4257 | cmdStr += " " + str( value ) |
| 4258 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4259 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4260 | assert "Command not found:" not in output, output |
| 4261 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4262 | if value and check: |
| 4263 | results = self.getCfg( component=str( component ), |
| 4264 | propName=str( propName ), |
| 4265 | jsonFormat=True ) |
| 4266 | # Check if current value is what we just set |
| 4267 | try: |
| 4268 | jsonOutput = json.loads( results ) |
| 4269 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4270 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4271 | main.log.exception( "Error parsing cfg output" ) |
| 4272 | main.log.error( "output:" + repr( results ) ) |
| 4273 | return main.FALSE |
| 4274 | if current == str( value ): |
| 4275 | return main.TRUE |
| 4276 | return main.FALSE |
| 4277 | return main.TRUE |
| 4278 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4279 | main.log.exception( self.name + ": Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4280 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4281 | except ( TypeError, ValueError ): |
| 4282 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4283 | return main.FALSE |
| 4284 | except pexpect.EOF: |
| 4285 | main.log.error( self.name + ": EOF exception found" ) |
| 4286 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4287 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4288 | except Exception: |
| 4289 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4290 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4291 | |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4292 | def distPrimitivesSend( self, cmd ): |
| 4293 | """ |
| 4294 | Function to handle sending cli commands for the distributed primitives test app |
| 4295 | |
| 4296 | This command will catch some exceptions and retry the command on some |
| 4297 | specific store exceptions. |
| 4298 | |
| 4299 | Required arguments: |
| 4300 | cmd - The command to send to the cli |
| 4301 | returns: |
| 4302 | string containing the cli output |
| 4303 | None on Error |
| 4304 | """ |
| 4305 | try: |
| 4306 | output = self.sendline( cmd ) |
| 4307 | try: |
| 4308 | assert output is not None, "Error in sendline" |
| 4309 | # TODO: Maybe make this less hardcoded |
| 4310 | # ConsistentMap Exceptions |
| 4311 | assert "org.onosproject.store.service" not in output |
| 4312 | # Node not leader |
| 4313 | assert "java.lang.IllegalStateException" not in output |
| 4314 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4315 | main.log.error( self.name + ": Error in processing '" + cmd + "' " + |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4316 | "command: " + str( output ) ) |
| 4317 | retryTime = 30 # Conservative time, given by Madan |
| 4318 | main.log.info( "Waiting " + str( retryTime ) + |
| 4319 | "seconds before retrying." ) |
| 4320 | time.sleep( retryTime ) # Due to change in mastership |
| 4321 | output = self.sendline( cmd ) |
| 4322 | assert output is not None, "Error in sendline" |
| 4323 | assert "Command not found:" not in output, output |
| 4324 | assert "Error executing command" not in output, output |
| 4325 | main.log.info( self.name + ": " + output ) |
| 4326 | return output |
| 4327 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4328 | main.log.exception( self.name + ": Error in processing '" + cmd + "' command." ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4329 | return None |
| 4330 | except TypeError: |
| 4331 | main.log.exception( self.name + ": Object not as expected" ) |
| 4332 | return None |
| 4333 | except pexpect.EOF: |
| 4334 | main.log.error( self.name + ": EOF exception found" ) |
| 4335 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4336 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4337 | except Exception: |
| 4338 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4339 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4340 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4341 | def setTestAdd( self, setName, values ): |
| 4342 | """ |
| 4343 | CLI command to add elements to a distributed set. |
| 4344 | Arguments: |
| 4345 | setName - The name of the set to add to. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4346 | values - The value(s) to add to the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4347 | Example usages: |
| 4348 | setTestAdd( "set1", "a b c" ) |
| 4349 | setTestAdd( "set2", "1" ) |
| 4350 | returns: |
| 4351 | main.TRUE on success OR |
| 4352 | main.FALSE if elements were already in the set OR |
| 4353 | main.ERROR on error |
| 4354 | """ |
| 4355 | try: |
| 4356 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4357 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4358 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 4359 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4360 | if re.search( positiveMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4361 | return main.TRUE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4362 | elif re.search( negativeMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4363 | return main.FALSE |
| 4364 | else: |
| 4365 | main.log.error( self.name + ": setTestAdd did not" + |
| 4366 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4367 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4368 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4369 | except TypeError: |
| 4370 | main.log.exception( self.name + ": Object not as expected" ) |
| 4371 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4372 | except Exception: |
| 4373 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4374 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4375 | |
| 4376 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 4377 | """ |
| 4378 | CLI command to remove elements from a distributed set. |
| 4379 | Required arguments: |
| 4380 | setName - The name of the set to remove from. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4381 | values - The value(s) to remove from the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4382 | Optional arguments: |
| 4383 | clear - Clear all elements from the set |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4384 | retain - Retain only the given values. (intersection of the |
| 4385 | original set and the given set) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4386 | returns: |
| 4387 | main.TRUE on success OR |
| 4388 | main.FALSE if the set was not changed OR |
| 4389 | main.ERROR on error |
| 4390 | """ |
| 4391 | try: |
| 4392 | cmdStr = "set-test-remove " |
| 4393 | if clear: |
| 4394 | cmdStr += "-c " + str( setName ) |
| 4395 | elif retain: |
| 4396 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4397 | else: |
| 4398 | cmdStr += str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4399 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4400 | if clear: |
| 4401 | pattern = "Set " + str( setName ) + " cleared" |
| 4402 | if re.search( pattern, output ): |
| 4403 | return main.TRUE |
| 4404 | elif retain: |
| 4405 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4406 | "only elements of set \[(.*)\]" |
| 4407 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4408 | "retaining only elements of the set " +\ |
| 4409 | "\[(.*)\]" |
| 4410 | if re.search( positivePattern, output ): |
| 4411 | return main.TRUE |
| 4412 | elif re.search( negativePattern, output ): |
| 4413 | return main.FALSE |
| 4414 | else: |
| 4415 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4416 | str( setName ) |
| 4417 | if ( len( values.split() ) == 1 ): |
| 4418 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4419 | str( setName ) |
| 4420 | else: |
| 4421 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4422 | str( setName ) |
| 4423 | if re.search( positivePattern, output ): |
| 4424 | return main.TRUE |
| 4425 | elif re.search( negativePattern, output ): |
| 4426 | return main.FALSE |
| 4427 | main.log.error( self.name + ": setTestRemove did not" + |
| 4428 | " match expected output" ) |
| 4429 | main.log.debug( self.name + " expected: " + pattern ) |
| 4430 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4431 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4432 | except TypeError: |
| 4433 | main.log.exception( self.name + ": Object not as expected" ) |
| 4434 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4435 | except Exception: |
| 4436 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4437 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4438 | |
| 4439 | def setTestGet( self, setName, values="" ): |
| 4440 | """ |
| 4441 | CLI command to get the elements in a distributed set. |
| 4442 | Required arguments: |
| 4443 | setName - The name of the set to remove from. |
| 4444 | Optional arguments: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4445 | values - The value(s) to check if in the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4446 | returns: |
| 4447 | main.ERROR on error OR |
| 4448 | A list of elements in the set if no optional arguments are |
| 4449 | supplied OR |
| 4450 | A tuple containing the list then: |
| 4451 | main.FALSE if the given values are not in the set OR |
| 4452 | main.TRUE if the given values are in the set OR |
| 4453 | """ |
| 4454 | try: |
| 4455 | values = str( values ).strip() |
| 4456 | setName = str( setName ).strip() |
| 4457 | length = len( values.split() ) |
| 4458 | containsCheck = None |
| 4459 | # Patterns to match |
| 4460 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4461 | pattern = "Items in set " + setName + ":\r\n" + setPattern |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4462 | containsTrue = "Set " + setName + " contains the value " + values |
| 4463 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4464 | values |
| 4465 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4466 | setPattern |
| 4467 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4468 | " subset " + setPattern |
| 4469 | |
| 4470 | cmdStr = "set-test-get " |
| 4471 | cmdStr += setName + " " + values |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4472 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4473 | if length == 0: |
| 4474 | match = re.search( pattern, output ) |
| 4475 | else: # if given values |
| 4476 | if length == 1: # Contains output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4477 | patternTrue = pattern + "\r\n" + containsTrue |
| 4478 | patternFalse = pattern + "\r\n" + containsFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4479 | else: # ContainsAll output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4480 | patternTrue = pattern + "\r\n" + containsAllTrue |
| 4481 | patternFalse = pattern + "\r\n" + containsAllFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4482 | matchTrue = re.search( patternTrue, output ) |
| 4483 | matchFalse = re.search( patternFalse, output ) |
| 4484 | if matchTrue: |
| 4485 | containsCheck = main.TRUE |
| 4486 | match = matchTrue |
| 4487 | elif matchFalse: |
| 4488 | containsCheck = main.FALSE |
| 4489 | match = matchFalse |
| 4490 | else: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4491 | main.log.error( self.name + " setTestGet did not match " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4492 | "expected output" ) |
| 4493 | main.log.debug( self.name + " expected: " + pattern ) |
| 4494 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4495 | match = None |
| 4496 | if match: |
| 4497 | setMatch = match.group( 1 ) |
| 4498 | if setMatch == '': |
| 4499 | setList = [] |
| 4500 | else: |
| 4501 | setList = setMatch.split( ", " ) |
| 4502 | if length > 0: |
| 4503 | return ( setList, containsCheck ) |
| 4504 | else: |
| 4505 | return setList |
| 4506 | else: # no match |
| 4507 | main.log.error( self.name + ": setTestGet did not" + |
| 4508 | " match expected output" ) |
| 4509 | main.log.debug( self.name + " expected: " + pattern ) |
| 4510 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4511 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4512 | except TypeError: |
| 4513 | main.log.exception( self.name + ": Object not as expected" ) |
| 4514 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4515 | except Exception: |
| 4516 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4517 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4518 | |
| 4519 | def setTestSize( self, setName ): |
| 4520 | """ |
| 4521 | CLI command to get the elements in a distributed set. |
| 4522 | Required arguments: |
| 4523 | setName - The name of the set to remove from. |
| 4524 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4525 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4526 | None on error |
| 4527 | """ |
| 4528 | try: |
| 4529 | # TODO: Should this check against the number of elements returned |
| 4530 | # and then return true/false based on that? |
| 4531 | setName = str( setName ).strip() |
| 4532 | # Patterns to match |
| 4533 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4534 | pattern = "There are (\d+) items in set " + setName + ":\r\n" +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4535 | setPattern |
| 4536 | cmdStr = "set-test-get -s " |
| 4537 | cmdStr += setName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4538 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4539 | if output: |
| 4540 | match = re.search( pattern, output ) |
| 4541 | if match: |
| 4542 | setSize = int( match.group( 1 ) ) |
| 4543 | setMatch = match.group( 2 ) |
| 4544 | if len( setMatch.split() ) == setSize: |
| 4545 | main.log.info( "The size returned by " + self.name + |
| 4546 | " matches the number of elements in " + |
| 4547 | "the returned set" ) |
| 4548 | else: |
| 4549 | main.log.error( "The size returned by " + self.name + |
| 4550 | " does not match the number of " + |
| 4551 | "elements in the returned set." ) |
| 4552 | return setSize |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4553 | else: # no match |
| 4554 | main.log.error( self.name + ": setTestGet did not" + |
| 4555 | " match expected output" ) |
| 4556 | main.log.debug( self.name + " expected: " + pattern ) |
| 4557 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4558 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4559 | except TypeError: |
| 4560 | main.log.exception( self.name + ": Object not as expected" ) |
| 4561 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4562 | except Exception: |
| 4563 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4564 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4565 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4566 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4567 | """ |
| 4568 | Command to list the various counters in the system. |
| 4569 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4570 | if jsonFormat, a string of the json object returned by the cli |
| 4571 | command |
| 4572 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4573 | None on error |
| 4574 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4575 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4576 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4577 | if jsonFormat: |
| 4578 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4579 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4580 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4581 | assert "Command not found:" not in output, output |
| 4582 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4583 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4584 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4585 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4586 | main.log.exception( self.name + ": Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4587 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4588 | except TypeError: |
| 4589 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4590 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4591 | except pexpect.EOF: |
| 4592 | main.log.error( self.name + ": EOF exception found" ) |
| 4593 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4594 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4595 | except Exception: |
| 4596 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4597 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4598 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4599 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4600 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4601 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4602 | Required arguments: |
| 4603 | counter - The name of the counter to increment. |
| 4604 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4605 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4606 | returns: |
| 4607 | integer value of the counter or |
| 4608 | None on Error |
| 4609 | """ |
| 4610 | try: |
| 4611 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4612 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4613 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4614 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4615 | if delta != 1: |
| 4616 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4617 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4618 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4619 | match = re.search( pattern, output ) |
| 4620 | if match: |
| 4621 | return int( match.group( 1 ) ) |
| 4622 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4623 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4624 | " match expected output." ) |
| 4625 | main.log.debug( self.name + " expected: " + pattern ) |
| 4626 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4627 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4628 | except TypeError: |
| 4629 | main.log.exception( self.name + ": Object not as expected" ) |
| 4630 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4631 | except Exception: |
| 4632 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4633 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4634 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4635 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4636 | """ |
| 4637 | CLI command to get a distributed counter then add a delta to it. |
| 4638 | Required arguments: |
| 4639 | counter - The name of the counter to increment. |
| 4640 | Optional arguments: |
| 4641 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4642 | returns: |
| 4643 | integer value of the counter or |
| 4644 | None on Error |
| 4645 | """ |
| 4646 | try: |
| 4647 | counter = str( counter ) |
| 4648 | delta = int( delta ) |
| 4649 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4650 | cmdStr += counter |
| 4651 | if delta != 1: |
| 4652 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4653 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4654 | pattern = counter + " was updated to (-?\d+)" |
| 4655 | match = re.search( pattern, output ) |
| 4656 | if match: |
| 4657 | return int( match.group( 1 ) ) |
| 4658 | else: |
| 4659 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4660 | " match expected output." ) |
| 4661 | main.log.debug( self.name + " expected: " + pattern ) |
| 4662 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4663 | return None |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4664 | except TypeError: |
| 4665 | main.log.exception( self.name + ": Object not as expected" ) |
| 4666 | return None |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4667 | except Exception: |
| 4668 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4669 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4670 | |
| 4671 | def valueTestGet( self, valueName ): |
| 4672 | """ |
| 4673 | CLI command to get the value of an atomic value. |
| 4674 | Required arguments: |
| 4675 | valueName - The name of the value to get. |
| 4676 | returns: |
| 4677 | string value of the value or |
| 4678 | None on Error |
| 4679 | """ |
| 4680 | try: |
| 4681 | valueName = str( valueName ) |
| 4682 | cmdStr = "value-test " |
| 4683 | operation = "get" |
| 4684 | cmdStr = "value-test {} {}".format( valueName, |
| 4685 | operation ) |
| 4686 | output = self.distPrimitivesSend( cmdStr ) |
| 4687 | pattern = "(\w+)" |
| 4688 | match = re.search( pattern, output ) |
| 4689 | if match: |
| 4690 | return match.group( 1 ) |
| 4691 | else: |
| 4692 | main.log.error( self.name + ": valueTestGet did not" + |
| 4693 | " match expected output." ) |
| 4694 | main.log.debug( self.name + " expected: " + pattern ) |
| 4695 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4696 | return None |
| 4697 | except TypeError: |
| 4698 | main.log.exception( self.name + ": Object not as expected" ) |
| 4699 | return None |
| 4700 | except Exception: |
| 4701 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4702 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4703 | |
| 4704 | def valueTestSet( self, valueName, newValue ): |
| 4705 | """ |
| 4706 | CLI command to set the value of an atomic value. |
| 4707 | Required arguments: |
| 4708 | valueName - The name of the value to set. |
| 4709 | newValue - The value to assign to the given value. |
| 4710 | returns: |
| 4711 | main.TRUE on success or |
| 4712 | main.ERROR on Error |
| 4713 | """ |
| 4714 | try: |
| 4715 | valueName = str( valueName ) |
| 4716 | newValue = str( newValue ) |
| 4717 | operation = "set" |
| 4718 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4719 | operation, |
| 4720 | newValue ) |
| 4721 | output = self.distPrimitivesSend( cmdStr ) |
| 4722 | if output is not None: |
| 4723 | return main.TRUE |
| 4724 | else: |
| 4725 | return main.ERROR |
| 4726 | except TypeError: |
| 4727 | main.log.exception( self.name + ": Object not as expected" ) |
| 4728 | return main.ERROR |
| 4729 | except Exception: |
| 4730 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4731 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4732 | |
| 4733 | def valueTestCompareAndSet( self, valueName, oldValue, newValue ): |
| 4734 | """ |
| 4735 | CLI command to compareAndSet the value of an atomic value. |
| 4736 | Required arguments: |
| 4737 | valueName - The name of the value. |
| 4738 | oldValue - Compare the current value of the atomic value to this |
| 4739 | newValue - If the value equals oldValue, set the value to newValue |
| 4740 | returns: |
| 4741 | main.TRUE on success or |
| 4742 | main.FALSE on failure or |
| 4743 | main.ERROR on Error |
| 4744 | """ |
| 4745 | try: |
| 4746 | valueName = str( valueName ) |
| 4747 | oldValue = str( oldValue ) |
| 4748 | newValue = str( newValue ) |
| 4749 | operation = "compareAndSet" |
| 4750 | cmdStr = "value-test {} {} {} {}".format( valueName, |
| 4751 | operation, |
| 4752 | oldValue, |
| 4753 | newValue ) |
| 4754 | output = self.distPrimitivesSend( cmdStr ) |
| 4755 | pattern = "(\w+)" |
| 4756 | match = re.search( pattern, output ) |
| 4757 | if match: |
| 4758 | result = match.group( 1 ) |
| 4759 | if result == "true": |
| 4760 | return main.TRUE |
| 4761 | elif result == "false": |
| 4762 | return main.FALSE |
| 4763 | else: |
| 4764 | main.log.error( self.name + ": valueTestCompareAndSet did not" + |
| 4765 | " match expected output." ) |
| 4766 | main.log.debug( self.name + " expected: " + pattern ) |
| 4767 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4768 | return main.ERROR |
| 4769 | except TypeError: |
| 4770 | main.log.exception( self.name + ": Object not as expected" ) |
| 4771 | return main.ERROR |
| 4772 | except Exception: |
| 4773 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4774 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4775 | |
| 4776 | def valueTestGetAndSet( self, valueName, newValue ): |
| 4777 | """ |
| 4778 | CLI command to getAndSet the value of an atomic value. |
| 4779 | Required arguments: |
| 4780 | valueName - The name of the value to get. |
| 4781 | newValue - The value to assign to the given value |
| 4782 | returns: |
| 4783 | string value of the value or |
| 4784 | None on Error |
| 4785 | """ |
| 4786 | try: |
| 4787 | valueName = str( valueName ) |
| 4788 | cmdStr = "value-test " |
| 4789 | operation = "getAndSet" |
| 4790 | cmdStr += valueName + " " + operation |
| 4791 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4792 | operation, |
| 4793 | newValue ) |
| 4794 | output = self.distPrimitivesSend( cmdStr ) |
| 4795 | pattern = "(\w+)" |
| 4796 | match = re.search( pattern, output ) |
| 4797 | if match: |
| 4798 | return match.group( 1 ) |
| 4799 | else: |
| 4800 | main.log.error( self.name + ": valueTestGetAndSet did not" + |
| 4801 | " match expected output." ) |
| 4802 | main.log.debug( self.name + " expected: " + pattern ) |
| 4803 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4804 | return None |
| 4805 | except TypeError: |
| 4806 | main.log.exception( self.name + ": Object not as expected" ) |
| 4807 | return None |
| 4808 | except Exception: |
| 4809 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4810 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4811 | |
| 4812 | def valueTestDestroy( self, valueName ): |
| 4813 | """ |
| 4814 | CLI command to destroy an atomic value. |
| 4815 | Required arguments: |
| 4816 | valueName - The name of the value to destroy. |
| 4817 | returns: |
| 4818 | main.TRUE on success or |
| 4819 | main.ERROR on Error |
| 4820 | """ |
| 4821 | try: |
| 4822 | valueName = str( valueName ) |
| 4823 | cmdStr = "value-test " |
| 4824 | operation = "destroy" |
| 4825 | cmdStr += valueName + " " + operation |
| 4826 | output = self.distPrimitivesSend( cmdStr ) |
| 4827 | if output is not None: |
| 4828 | return main.TRUE |
| 4829 | else: |
| 4830 | return main.ERROR |
| 4831 | except TypeError: |
| 4832 | main.log.exception( self.name + ": Object not as expected" ) |
| 4833 | return main.ERROR |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4834 | except Exception: |
| 4835 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4836 | main.cleanAndExit() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4837 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4838 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4839 | """ |
| 4840 | Description: Execute summary command in onos |
| 4841 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4842 | no output |
| 4843 | |
| 4844 | """ |
| 4845 | try: |
| 4846 | cmdStr = "summary" |
| 4847 | if jsonFormat: |
| 4848 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4849 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4850 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4851 | assert "Command not found:" not in handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4852 | assert "Error:" not in handle, handle |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 4853 | assert "Error executing" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4854 | if not handle: |
| 4855 | main.log.error( self.name + ": There is no output in " + |
| 4856 | "summary command" ) |
| 4857 | return main.FALSE |
| 4858 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4859 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4860 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4861 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4862 | except TypeError: |
| 4863 | main.log.exception( self.name + ": Object not as expected" ) |
| 4864 | return None |
| 4865 | except pexpect.EOF: |
| 4866 | main.log.error( self.name + ": EOF exception found" ) |
| 4867 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4868 | main.cleanAndExit() |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4869 | except Exception: |
| 4870 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4871 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4872 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4873 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4874 | """ |
| 4875 | CLI command to get the value of a key in a consistent map using |
| 4876 | transactions. This a test function and can only get keys from the |
| 4877 | test map hard coded into the cli command |
| 4878 | Required arguments: |
| 4879 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4880 | returns: |
| 4881 | The string value of the key or |
| 4882 | None on Error |
| 4883 | """ |
| 4884 | try: |
| 4885 | keyName = str( keyName ) |
| 4886 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4887 | cmdStr += keyName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4888 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4889 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4890 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4891 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4892 | return None |
| 4893 | else: |
| 4894 | match = re.search( pattern, output ) |
| 4895 | if match: |
| 4896 | return match.groupdict()[ 'value' ] |
| 4897 | else: |
| 4898 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4899 | " match expected output." ) |
| 4900 | main.log.debug( self.name + " expected: " + pattern ) |
| 4901 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4902 | return None |
| 4903 | except TypeError: |
| 4904 | main.log.exception( self.name + ": Object not as expected" ) |
| 4905 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4906 | except Exception: |
| 4907 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4908 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4909 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4910 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4911 | """ |
| 4912 | CLI command to put a value into 'numKeys' number of keys in a |
| 4913 | consistent map using transactions. This a test function and can only |
| 4914 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4915 | Required arguments: |
| 4916 | numKeys - Number of keys to add the value to |
| 4917 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4918 | returns: |
| 4919 | A dictionary whose keys are the name of the keys put into the map |
| 4920 | and the values of the keys are dictionaries whose key-values are |
| 4921 | 'value': value put into map and optionaly |
| 4922 | 'oldValue': Previous value in the key or |
| 4923 | None on Error |
| 4924 | |
| 4925 | Example output |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4926 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4927 | 'Key2': {'value': 'Testing'} } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4928 | """ |
| 4929 | try: |
| 4930 | numKeys = str( numKeys ) |
| 4931 | value = str( value ) |
| 4932 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4933 | cmdStr += numKeys + " " + value |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4934 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4935 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4936 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4937 | results = {} |
| 4938 | for line in output.splitlines(): |
| 4939 | new = re.search( newPattern, line ) |
| 4940 | updated = re.search( updatedPattern, line ) |
| 4941 | if new: |
| 4942 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 4943 | elif updated: |
| 4944 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4945 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4946 | else: |
| 4947 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4948 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4949 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 4950 | newPattern, |
| 4951 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4952 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4953 | return results |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4954 | except ( TypeError, AttributeError ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4955 | main.log.exception( self.name + ": Object not as expected" ) |
| 4956 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4957 | except Exception: |
| 4958 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4959 | main.cleanAndExit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4960 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4961 | def maps( self, jsonFormat=True ): |
| 4962 | """ |
| 4963 | Description: Returns result of onos:maps |
| 4964 | Optional: |
| 4965 | * jsonFormat: enable json formatting of output |
| 4966 | """ |
| 4967 | try: |
| 4968 | cmdStr = "maps" |
| 4969 | if jsonFormat: |
| 4970 | cmdStr += " -j" |
| 4971 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4972 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4973 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4974 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4975 | except AssertionError: |
| 4976 | main.log.exception( "" ) |
| 4977 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4978 | except TypeError: |
| 4979 | main.log.exception( self.name + ": Object not as expected" ) |
| 4980 | return None |
| 4981 | except pexpect.EOF: |
| 4982 | main.log.error( self.name + ": EOF exception found" ) |
| 4983 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4984 | main.cleanAndExit() |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4985 | except Exception: |
| 4986 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4987 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4988 | |
| 4989 | def getSwController( self, uri, jsonFormat=True ): |
| 4990 | """ |
| 4991 | Descrition: Gets the controller information from the device |
| 4992 | """ |
| 4993 | try: |
| 4994 | cmd = "device-controllers " |
| 4995 | if jsonFormat: |
| 4996 | cmd += "-j " |
| 4997 | response = self.sendline( cmd + uri ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4998 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4999 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5000 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5001 | except AssertionError: |
| 5002 | main.log.exception( "" ) |
| 5003 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5004 | except TypeError: |
| 5005 | main.log.exception( self.name + ": Object not as expected" ) |
| 5006 | return None |
| 5007 | except pexpect.EOF: |
| 5008 | main.log.error( self.name + ": EOF exception found" ) |
| 5009 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5010 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5011 | except Exception: |
| 5012 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5013 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5014 | |
| 5015 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 5016 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5017 | Descrition: sets the controller(s) for the specified device |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5018 | |
| 5019 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5020 | Required: uri - String: The uri of the device(switch). |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5021 | ip - String or List: The ip address of the controller. |
| 5022 | This parameter can be formed in a couple of different ways. |
| 5023 | VALID: |
| 5024 | 10.0.0.1 - just the ip address |
| 5025 | tcp:10.0.0.1 - the protocol and the ip address |
| 5026 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 5027 | so that you can add controllers with different |
| 5028 | protocols and ports |
| 5029 | INVALID: |
| 5030 | 10.0.0.1:6653 - this is not supported by ONOS |
| 5031 | |
| 5032 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 5033 | port - The port number. |
| 5034 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 5035 | |
| 5036 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 5037 | """ |
| 5038 | try: |
| 5039 | cmd = "device-setcontrollers" |
| 5040 | |
| 5041 | if jsonFormat: |
| 5042 | cmd += " -j" |
| 5043 | cmd += " " + uri |
| 5044 | if isinstance( ip, str ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5045 | ip = [ ip ] |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5046 | for item in ip: |
| 5047 | if ":" in item: |
| 5048 | sitem = item.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5049 | if len( sitem ) == 3: |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5050 | cmd += " " + item |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5051 | elif "." in sitem[ 1 ]: |
| 5052 | cmd += " {}:{}".format( item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5053 | else: |
| 5054 | main.log.error( "Malformed entry: " + item ) |
| 5055 | raise TypeError |
| 5056 | else: |
| 5057 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5058 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5059 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5060 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5061 | if "Error" in response: |
| 5062 | main.log.error( response ) |
| 5063 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5064 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5065 | except AssertionError: |
| 5066 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5067 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5068 | except TypeError: |
| 5069 | main.log.exception( self.name + ": Object not as expected" ) |
| 5070 | return main.FALSE |
| 5071 | except pexpect.EOF: |
| 5072 | main.log.error( self.name + ": EOF exception found" ) |
| 5073 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5074 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5075 | except Exception: |
| 5076 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5077 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5078 | |
| 5079 | def removeDevice( self, device ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5080 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5081 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5082 | Remove a device from ONOS by passing the uri of the device(s). |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5083 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5084 | device - (str or list) the id or uri of the device ex. "of:0000000000000001" |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5085 | Returns: |
| 5086 | Returns main.FALSE if an exception is thrown or an error is present |
| 5087 | in the response. Otherwise, returns main.TRUE. |
| 5088 | NOTE: |
| 5089 | If a host cannot be removed, then this function will return main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5090 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5091 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5092 | if isinstance( device, str ): |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 5093 | deviceStr = device |
| 5094 | device = [] |
| 5095 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5096 | |
| 5097 | for d in device: |
| 5098 | time.sleep( 1 ) |
| 5099 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5100 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5101 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5102 | if "Error" in response: |
| 5103 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 5104 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5105 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5106 | except AssertionError: |
| 5107 | main.log.exception( "" ) |
| 5108 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5109 | except TypeError: |
| 5110 | main.log.exception( self.name + ": Object not as expected" ) |
| 5111 | return main.FALSE |
| 5112 | except pexpect.EOF: |
| 5113 | main.log.error( self.name + ": EOF exception found" ) |
| 5114 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5115 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5116 | except Exception: |
| 5117 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5118 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5119 | |
| 5120 | def removeHost( self, host ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5121 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5122 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5123 | Remove a host from ONOS by passing the id of the host(s) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5124 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5125 | hostId - (str or list) the id or mac of the host ex. "00:00:00:00:00:01" |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5126 | Returns: |
| 5127 | Returns main.FALSE if an exception is thrown or an error is present |
| 5128 | in the response. Otherwise, returns main.TRUE. |
| 5129 | NOTE: |
| 5130 | If a host cannot be removed, then this function will return main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5131 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5132 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5133 | if isinstance( host, str ): |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5134 | host = list( host ) |
| 5135 | |
| 5136 | for h in host: |
| 5137 | time.sleep( 1 ) |
| 5138 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5139 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5140 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5141 | if "Error" in response: |
| 5142 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 5143 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5144 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5145 | except AssertionError: |
| 5146 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5147 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5148 | except TypeError: |
| 5149 | main.log.exception( self.name + ": Object not as expected" ) |
| 5150 | return main.FALSE |
| 5151 | except pexpect.EOF: |
| 5152 | main.log.error( self.name + ": EOF exception found" ) |
| 5153 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5154 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5155 | except Exception: |
| 5156 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5157 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5158 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5159 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5160 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5161 | Description: |
| 5162 | Bring link down or up in the null-provider. |
| 5163 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5164 | begin - (string) One end of a device or switch. |
| 5165 | end - (string) the other end of the device or switch |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5166 | returns: |
| 5167 | main.TRUE if no exceptions were thrown and no Errors are |
| 5168 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5169 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5170 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5171 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5172 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5173 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5174 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5175 | if "Error" in response or "Failure" in response: |
| 5176 | main.log.error( response ) |
| 5177 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5178 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5179 | except AssertionError: |
| 5180 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5181 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5182 | except TypeError: |
| 5183 | main.log.exception( self.name + ": Object not as expected" ) |
| 5184 | return main.FALSE |
| 5185 | except pexpect.EOF: |
| 5186 | main.log.error( self.name + ": EOF exception found" ) |
| 5187 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5188 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5189 | except Exception: |
| 5190 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5191 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5192 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5193 | def portstate( self, dpid, port, state ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5194 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5195 | Description: |
| 5196 | Changes the state of port in an OF switch by means of the |
| 5197 | PORTSTATUS OF messages. |
| 5198 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5199 | dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102' |
| 5200 | port - (string) target port in the device. Ex: '2' |
| 5201 | state - (string) target state (enable or disable) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5202 | returns: |
| 5203 | main.TRUE if no exceptions were thrown and no Errors are |
| 5204 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5205 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5206 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5207 | state = state.lower() |
| 5208 | assert state == 'enable' or state == 'disable', "Unknown state" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5209 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5210 | response = self.sendline( cmd, showResponse=True ) |
| 5211 | assert response is not None, "Error in sendline" |
| 5212 | assert "Command not found:" not in response, response |
| 5213 | if "Error" in response or "Failure" in response: |
| 5214 | main.log.error( response ) |
| 5215 | return main.FALSE |
| 5216 | return main.TRUE |
| 5217 | except AssertionError: |
| 5218 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5219 | return main.FALSE |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5220 | except TypeError: |
| 5221 | main.log.exception( self.name + ": Object not as expected" ) |
| 5222 | return main.FALSE |
| 5223 | except pexpect.EOF: |
| 5224 | main.log.error( self.name + ": EOF exception found" ) |
| 5225 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5226 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5227 | except Exception: |
| 5228 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5229 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5230 | |
| 5231 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 5232 | """ |
| 5233 | Set the logging level to lvl for a specific app |
| 5234 | returns main.TRUE on success |
| 5235 | returns main.FALSE if Error occurred |
| 5236 | if noExit is True, TestON will not exit, but clean up |
| 5237 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 5238 | Level defaults to INFO |
| 5239 | """ |
| 5240 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5241 | self.handle.sendline( "log:set %s %s" % ( level, app ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 5242 | self.handle.expect( self.karafPrompt ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5243 | |
| 5244 | response = self.handle.before |
| 5245 | if re.search( "Error", response ): |
| 5246 | return main.FALSE |
| 5247 | return main.TRUE |
| 5248 | except pexpect.TIMEOUT: |
| 5249 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5250 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5251 | except pexpect.EOF: |
| 5252 | main.log.error( self.name + ": EOF exception found" ) |
| 5253 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5254 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5255 | except Exception: |
| 5256 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5257 | main.cleanAndExit() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5258 | |
| 5259 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 5260 | """ |
| 5261 | Return a dictionary which describes the latest network topology data as a |
| 5262 | graph. |
| 5263 | An example of the dictionary: |
| 5264 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 5265 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 5266 | Each vertex should at least have an 'edges' attribute which describes the |
| 5267 | adjacency information. The value of 'edges' attribute is also represented by |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5268 | a dictionary, which maps each edge (identified by the neighbor vertex) to a |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5269 | list of attributes. |
| 5270 | An example of the edges dictionary: |
| 5271 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 5272 | vertex3: { 'port': ..., 'weight': ... } } |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5273 | If includeHost == True, all hosts (and host-switch links) will be included |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5274 | in topology data. |
| 5275 | """ |
| 5276 | graphDict = {} |
| 5277 | try: |
| 5278 | links = self.links() |
| 5279 | links = json.loads( links ) |
| 5280 | devices = self.devices() |
| 5281 | devices = json.loads( devices ) |
| 5282 | idToDevice = {} |
| 5283 | for device in devices: |
| 5284 | idToDevice[ device[ 'id' ] ] = device |
| 5285 | if includeHost: |
| 5286 | hosts = self.hosts() |
| 5287 | # FIXME: support 'includeHost' argument |
| 5288 | for link in links: |
| 5289 | nodeA = link[ 'src' ][ 'device' ] |
| 5290 | nodeB = link[ 'dst' ][ 'device' ] |
| 5291 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5292 | if nodeA not in graphDict.keys(): |
| 5293 | graphDict[ nodeA ] = { 'edges': {}, |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5294 | 'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ], |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5295 | 'type': idToDevice[ nodeA ][ 'type' ], |
| 5296 | 'available': idToDevice[ nodeA ][ 'available' ], |
| 5297 | 'role': idToDevice[ nodeA ][ 'role' ], |
| 5298 | 'mfr': idToDevice[ nodeA ][ 'mfr' ], |
| 5299 | 'hw': idToDevice[ nodeA ][ 'hw' ], |
| 5300 | 'sw': idToDevice[ nodeA ][ 'sw' ], |
| 5301 | 'serial': idToDevice[ nodeA ][ 'serial' ], |
| 5302 | 'chassisId': idToDevice[ nodeA ][ 'chassisId' ], |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5303 | 'annotations': idToDevice[ nodeA ][ 'annotations' ]} |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5304 | else: |
| 5305 | # Assert nodeB is not connected to any current links of nodeA |
| 5306 | assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5307 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ], |
| 5308 | 'type': link[ 'type' ], |
| 5309 | 'state': link[ 'state' ] } |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5310 | return graphDict |
| 5311 | except ( TypeError, ValueError ): |
| 5312 | main.log.exception( self.name + ": Object not as expected" ) |
| 5313 | return None |
| 5314 | except KeyError: |
| 5315 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5316 | return None |
| 5317 | except AssertionError: |
| 5318 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5319 | return None |
| 5320 | except pexpect.EOF: |
| 5321 | main.log.error( self.name + ": EOF exception found" ) |
| 5322 | main.log.error( self.name + ": " + self.handle.before ) |
| 5323 | return None |
| 5324 | except Exception: |
| 5325 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5326 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5327 | |
| 5328 | def getIntentPerfSummary( self ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5329 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5330 | Send command to check intent-perf summary |
| 5331 | Returns: dictionary for intent-perf summary |
| 5332 | if something wrong, function will return None |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5333 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5334 | cmd = "intent-perf -s" |
| 5335 | respDic = {} |
| 5336 | resp = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 5337 | assert resp is not None, "Error in sendline" |
| 5338 | assert "Command not found:" not in resp, resp |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5339 | try: |
| 5340 | # Generate the dictionary to return |
| 5341 | for l in resp.split( "\n" ): |
| 5342 | # Delete any white space in line |
| 5343 | temp = re.sub( r'\s+', '', l ) |
| 5344 | temp = temp.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5345 | respDic[ temp[ 0 ] ] = temp[ 1 ] |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5346 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5347 | except ( TypeError, ValueError ): |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5348 | main.log.exception( self.name + ": Object not as expected" ) |
| 5349 | return None |
| 5350 | except KeyError: |
| 5351 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5352 | return None |
| 5353 | except AssertionError: |
| 5354 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5355 | return None |
| 5356 | except pexpect.EOF: |
| 5357 | main.log.error( self.name + ": EOF exception found" ) |
| 5358 | main.log.error( self.name + ": " + self.handle.before ) |
| 5359 | return None |
| 5360 | except Exception: |
| 5361 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5362 | return None |
| 5363 | return respDic |
| 5364 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5365 | def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ): |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5366 | """ |
| 5367 | Searches the latest ONOS log file for the given search term and |
| 5368 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5369 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5370 | Arguments: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5371 | searchTerm: |
| 5372 | The string to grep from the ONOS log. |
| 5373 | startLine: |
| 5374 | The term that decides which line is the start to search the searchTerm in |
| 5375 | the karaf log. For now, startTerm only works in 'first' mode. |
| 5376 | logNum: |
| 5377 | In some extreme cases, one karaf log is not big enough to contain all the |
| 5378 | information.Because of this, search mutiply logs is necessary to capture |
| 5379 | the right result. logNum is the number of karaf logs that we need to search |
| 5380 | the searchTerm. |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5381 | mode: |
| 5382 | all: return all the strings that contain the search term |
| 5383 | last: return the last string that contains the search term |
| 5384 | first: return the first string that contains the search term |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5385 | num: return the number of times that the searchTerm appears in the log |
| 5386 | total: return how many lines in karaf log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5387 | """ |
| 5388 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5389 | assert isinstance( searchTerm, str ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5390 | # Build the log paths string |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5391 | logPath = '/opt/onos/log/karaf.log.' |
| 5392 | logPaths = '/opt/onos/log/karaf.log' |
| 5393 | for i in range( 1, logNum ): |
| 5394 | logPaths = logPath + str( i ) + " " + logPaths |
| 5395 | cmd = "cat " + logPaths |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5396 | if startLine: |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5397 | # 100000000 is just a extreme large number to make sure this function can |
| 5398 | # grep all the lines after startLine |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5399 | cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'" |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5400 | if mode == 'all': |
| 5401 | cmd = cmd + " | grep \'" + searchTerm + "\'" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5402 | elif mode == 'last': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5403 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5404 | elif mode == 'first': |
| 5405 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1" |
| 5406 | elif mode == 'num': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5407 | cmd = cmd + " | grep -c \'" + searchTerm + "\'" |
You Wang | 118ba58 | 2017-01-02 17:14:43 -0800 | [diff] [blame] | 5408 | num = self.sendline( cmd ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5409 | return num |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5410 | elif mode == 'total': |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 5411 | totalLines = self.lineCount( "cat /opt/onos/log/karaf.log | wc -l" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5412 | return int( totalLines ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5413 | else: |
| 5414 | main.log.error( self.name + " unsupported mode" ) |
| 5415 | return main.ERROR |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5416 | before = self.sendline( cmd ) |
| 5417 | before = before.splitlines() |
| 5418 | # make sure the returned list only contains the search term |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5419 | returnLines = [ line for line in before if searchTerm in line ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5420 | return returnLines |
| 5421 | except AssertionError: |
| 5422 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5423 | return None |
| 5424 | except pexpect.EOF: |
| 5425 | main.log.error( self.name + ": EOF exception found" ) |
| 5426 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5427 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5428 | except pexpect.TIMEOUT: |
| 5429 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5430 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5431 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5432 | except Exception: |
| 5433 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5434 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5435 | |
| 5436 | def vplsShow( self, jsonFormat=True ): |
| 5437 | """ |
| 5438 | Description: Returns result of onos:vpls show, which should list the |
| 5439 | configured VPLS networks and the assigned interfaces. |
| 5440 | Optional: |
| 5441 | * jsonFormat: enable json formatting of output |
| 5442 | Returns: |
| 5443 | The output of the command or None on error. |
| 5444 | """ |
| 5445 | try: |
| 5446 | cmdStr = "vpls show" |
| 5447 | if jsonFormat: |
| 5448 | raise NotImplementedError |
| 5449 | cmdStr += " -j" |
| 5450 | handle = self.sendline( cmdStr ) |
| 5451 | assert handle is not None, "Error in sendline" |
| 5452 | assert "Command not found:" not in handle, handle |
| 5453 | return handle |
| 5454 | except AssertionError: |
| 5455 | main.log.exception( "" ) |
| 5456 | return None |
| 5457 | except TypeError: |
| 5458 | main.log.exception( self.name + ": Object not as expected" ) |
| 5459 | return None |
| 5460 | except pexpect.EOF: |
| 5461 | main.log.error( self.name + ": EOF exception found" ) |
| 5462 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5463 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5464 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5465 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5466 | return None |
| 5467 | except Exception: |
| 5468 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5469 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5470 | |
| 5471 | def parseVplsShow( self ): |
| 5472 | """ |
| 5473 | Parse the cli output of 'vpls show' into json output. This is required |
| 5474 | as there is currently no json output available. |
| 5475 | """ |
| 5476 | try: |
| 5477 | output = [] |
| 5478 | raw = self.vplsShow( jsonFormat=False ) |
| 5479 | namePat = "VPLS name: (?P<name>\w+)" |
| 5480 | interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]" |
| 5481 | encapPat = "Encapsulation: (?P<encap>\w+)" |
| 5482 | pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] ) |
| 5483 | mIter = re.finditer( pattern, raw ) |
| 5484 | for match in mIter: |
| 5485 | item = {} |
| 5486 | item[ 'name' ] = match.group( 'name' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5487 | ifaces = match.group( 'interfaces' ).split( ', ' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5488 | if ifaces == [ "" ]: |
| 5489 | ifaces = [] |
| 5490 | item[ 'interfaces' ] = ifaces |
| 5491 | encap = match.group( 'encap' ) |
| 5492 | if encap != 'NONE': |
| 5493 | item[ 'encapsulation' ] = encap.lower() |
| 5494 | output.append( item ) |
| 5495 | return output |
| 5496 | except Exception: |
| 5497 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5498 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5499 | |
| 5500 | def vplsList( self, jsonFormat=True ): |
| 5501 | """ |
| 5502 | Description: Returns result of onos:vpls list, which should list the |
| 5503 | configured VPLS networks. |
| 5504 | Optional: |
| 5505 | * jsonFormat: enable json formatting of output |
| 5506 | """ |
| 5507 | try: |
| 5508 | cmdStr = "vpls list" |
| 5509 | if jsonFormat: |
| 5510 | raise NotImplementedError |
| 5511 | cmdStr += " -j" |
| 5512 | handle = self.sendline( cmdStr ) |
| 5513 | assert handle is not None, "Error in sendline" |
| 5514 | assert "Command not found:" not in handle, handle |
| 5515 | return handle |
| 5516 | except AssertionError: |
| 5517 | main.log.exception( "" ) |
| 5518 | return None |
| 5519 | except TypeError: |
| 5520 | main.log.exception( self.name + ": Object not as expected" ) |
| 5521 | return None |
| 5522 | except pexpect.EOF: |
| 5523 | main.log.error( self.name + ": EOF exception found" ) |
| 5524 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5525 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5526 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5527 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5528 | return None |
| 5529 | except Exception: |
| 5530 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5531 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5532 | |
| 5533 | def vplsCreate( self, network ): |
| 5534 | """ |
| 5535 | CLI command to create a new VPLS network. |
| 5536 | Required arguments: |
| 5537 | network - String name of the network to create. |
| 5538 | returns: |
| 5539 | main.TRUE on success and main.FALSE on failure |
| 5540 | """ |
| 5541 | try: |
| 5542 | network = str( network ) |
| 5543 | cmdStr = "vpls create " |
| 5544 | cmdStr += network |
| 5545 | output = self.sendline( cmdStr ) |
| 5546 | assert output is not None, "Error in sendline" |
| 5547 | assert "Command not found:" not in output, output |
| 5548 | assert "Error executing command" not in output, output |
| 5549 | assert "VPLS already exists:" not in output, output |
| 5550 | return main.TRUE |
| 5551 | except AssertionError: |
| 5552 | main.log.exception( "" ) |
| 5553 | return main.FALSE |
| 5554 | except TypeError: |
| 5555 | main.log.exception( self.name + ": Object not as expected" ) |
| 5556 | return main.FALSE |
| 5557 | except pexpect.EOF: |
| 5558 | main.log.error( self.name + ": EOF exception found" ) |
| 5559 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5560 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5561 | except Exception: |
| 5562 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5563 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5564 | |
| 5565 | def vplsDelete( self, network ): |
| 5566 | """ |
| 5567 | CLI command to delete a VPLS network. |
| 5568 | Required arguments: |
| 5569 | network - Name of the network to delete. |
| 5570 | returns: |
| 5571 | main.TRUE on success and main.FALSE on failure |
| 5572 | """ |
| 5573 | try: |
| 5574 | network = str( network ) |
| 5575 | cmdStr = "vpls delete " |
| 5576 | cmdStr += network |
| 5577 | output = self.sendline( cmdStr ) |
| 5578 | assert output is not None, "Error in sendline" |
| 5579 | assert "Command not found:" not in output, output |
| 5580 | assert "Error executing command" not in output, output |
| 5581 | assert " not found" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5582 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5583 | return main.TRUE |
| 5584 | except AssertionError: |
| 5585 | main.log.exception( "" ) |
| 5586 | return main.FALSE |
| 5587 | except TypeError: |
| 5588 | main.log.exception( self.name + ": Object not as expected" ) |
| 5589 | return main.FALSE |
| 5590 | except pexpect.EOF: |
| 5591 | main.log.error( self.name + ": EOF exception found" ) |
| 5592 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5593 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5594 | except Exception: |
| 5595 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5596 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5597 | |
| 5598 | def vplsAddIface( self, network, iface ): |
| 5599 | """ |
| 5600 | CLI command to add an interface to a VPLS network. |
| 5601 | Required arguments: |
| 5602 | network - Name of the network to add the interface to. |
| 5603 | iface - The ONOS name for an interface. |
| 5604 | returns: |
| 5605 | main.TRUE on success and main.FALSE on failure |
| 5606 | """ |
| 5607 | try: |
| 5608 | network = str( network ) |
| 5609 | iface = str( iface ) |
| 5610 | cmdStr = "vpls add-if " |
| 5611 | cmdStr += network + " " + iface |
| 5612 | output = self.sendline( cmdStr ) |
| 5613 | assert output is not None, "Error in sendline" |
| 5614 | assert "Command not found:" not in output, output |
| 5615 | assert "Error executing command" not in output, output |
| 5616 | assert "already associated to network" not in output, output |
| 5617 | assert "Interface cannot be added." not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5618 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5619 | return main.TRUE |
| 5620 | except AssertionError: |
| 5621 | main.log.exception( "" ) |
| 5622 | return main.FALSE |
| 5623 | except TypeError: |
| 5624 | main.log.exception( self.name + ": Object not as expected" ) |
| 5625 | return main.FALSE |
| 5626 | except pexpect.EOF: |
| 5627 | main.log.error( self.name + ": EOF exception found" ) |
| 5628 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5629 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5630 | except Exception: |
| 5631 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5632 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5633 | |
| 5634 | def vplsRemIface( self, network, iface ): |
| 5635 | """ |
| 5636 | CLI command to remove an interface from a VPLS network. |
| 5637 | Required arguments: |
| 5638 | network - Name of the network to remove the interface from. |
| 5639 | iface - Name of the interface to remove. |
| 5640 | returns: |
| 5641 | main.TRUE on success and main.FALSE on failure |
| 5642 | """ |
| 5643 | try: |
| 5644 | iface = str( iface ) |
| 5645 | cmdStr = "vpls rem-if " |
| 5646 | cmdStr += network + " " + iface |
| 5647 | output = self.sendline( cmdStr ) |
| 5648 | assert output is not None, "Error in sendline" |
| 5649 | assert "Command not found:" not in output, output |
| 5650 | assert "Error executing command" not in output, output |
| 5651 | assert "is not configured" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5652 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5653 | return main.TRUE |
| 5654 | except AssertionError: |
| 5655 | main.log.exception( "" ) |
| 5656 | return main.FALSE |
| 5657 | except TypeError: |
| 5658 | main.log.exception( self.name + ": Object not as expected" ) |
| 5659 | return main.FALSE |
| 5660 | except pexpect.EOF: |
| 5661 | main.log.error( self.name + ": EOF exception found" ) |
| 5662 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5663 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5664 | except Exception: |
| 5665 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5666 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5667 | |
| 5668 | def vplsClean( self ): |
| 5669 | """ |
| 5670 | Description: Clears the VPLS app configuration. |
| 5671 | Returns: main.TRUE on success and main.FALSE on failure |
| 5672 | """ |
| 5673 | try: |
| 5674 | cmdStr = "vpls clean" |
| 5675 | handle = self.sendline( cmdStr ) |
| 5676 | assert handle is not None, "Error in sendline" |
| 5677 | assert "Command not found:" not in handle, handle |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5678 | assert "still updating" not in handle, handle |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5679 | return handle |
| 5680 | except AssertionError: |
| 5681 | main.log.exception( "" ) |
| 5682 | return main.FALSE |
| 5683 | except TypeError: |
| 5684 | main.log.exception( self.name + ": Object not as expected" ) |
| 5685 | return main.FALSE |
| 5686 | except pexpect.EOF: |
| 5687 | main.log.error( self.name + ": EOF exception found" ) |
| 5688 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5689 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5690 | except Exception: |
| 5691 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5692 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5693 | |
| 5694 | def vplsSetEncap( self, network, encapType ): |
| 5695 | """ |
| 5696 | CLI command to add an interface to a VPLS network. |
| 5697 | Required arguments: |
| 5698 | network - Name of the network to create. |
| 5699 | encapType - Type of encapsulation. |
| 5700 | returns: |
| 5701 | main.TRUE on success and main.FALSE on failure |
| 5702 | """ |
| 5703 | try: |
| 5704 | network = str( network ) |
| 5705 | encapType = str( encapType ).upper() |
| 5706 | assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type" |
| 5707 | cmdStr = "vpls set-encap " |
| 5708 | cmdStr += network + " " + encapType |
| 5709 | output = self.sendline( cmdStr ) |
| 5710 | assert output is not None, "Error in sendline" |
| 5711 | assert "Command not found:" not in output, output |
| 5712 | assert "Error executing command" not in output, output |
| 5713 | assert "already associated to network" not in output, output |
| 5714 | assert "Encapsulation type " not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5715 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5716 | return main.TRUE |
| 5717 | except AssertionError: |
| 5718 | main.log.exception( "" ) |
| 5719 | return main.FALSE |
| 5720 | except TypeError: |
| 5721 | main.log.exception( self.name + ": Object not as expected" ) |
| 5722 | return main.FALSE |
| 5723 | except pexpect.EOF: |
| 5724 | main.log.error( self.name + ": EOF exception found" ) |
| 5725 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5726 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5727 | except Exception: |
| 5728 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5729 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5730 | |
| 5731 | def interfaces( self, jsonFormat=True ): |
| 5732 | """ |
| 5733 | Description: Returns result of interfaces command. |
| 5734 | Optional: |
| 5735 | * jsonFormat: enable json formatting of output |
| 5736 | Returns: |
| 5737 | The output of the command or None on error. |
| 5738 | """ |
| 5739 | try: |
| 5740 | cmdStr = "interfaces" |
| 5741 | if jsonFormat: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5742 | raise NotImplementedError |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5743 | cmdStr += " -j" |
| 5744 | handle = self.sendline( cmdStr ) |
| 5745 | assert handle is not None, "Error in sendline" |
| 5746 | assert "Command not found:" not in handle, handle |
| 5747 | return handle |
| 5748 | except AssertionError: |
| 5749 | main.log.exception( "" ) |
| 5750 | return None |
| 5751 | except TypeError: |
| 5752 | main.log.exception( self.name + ": Object not as expected" ) |
| 5753 | return None |
| 5754 | except pexpect.EOF: |
| 5755 | main.log.error( self.name + ": EOF exception found" ) |
| 5756 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5757 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5758 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5759 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5760 | return None |
| 5761 | except Exception: |
| 5762 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5763 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5764 | |
| 5765 | def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5766 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5767 | Get the timestamp of searchTerm from karaf log. |
| 5768 | |
| 5769 | Arguments: |
| 5770 | splitTerm_before and splitTerm_after: |
| 5771 | |
| 5772 | The terms that split the string that contains the timeStamp of |
| 5773 | searchTerm. For example, if that string is "xxxxxxxcreationTime = |
| 5774 | 1419510501xxxxxx", then the splitTerm_before is "CreationTime = " |
| 5775 | and the splitTerm_after is "x" |
| 5776 | |
| 5777 | others: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5778 | Please look at the "logsearch" Function in onosclidriver.py |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5779 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5780 | if logNum < 0: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5781 | main.log.error( "Get wrong log number ") |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5782 | return main.ERROR |
| 5783 | lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5784 | if len( lines ) == 0: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5785 | main.log.warn( "Captured timestamp string is empty" ) |
| 5786 | return main.ERROR |
| 5787 | lines = lines[ 0 ] |
| 5788 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5789 | assert isinstance( lines, str ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5790 | # get the target value |
| 5791 | line = lines.split( splitTerm_before ) |
| 5792 | key = line[ 1 ].split( splitTerm_after ) |
| 5793 | return int( key[ 0 ] ) |
| 5794 | except IndexError: |
| 5795 | main.log.warn( "Index Error!" ) |
| 5796 | return main.ERROR |
| 5797 | except AssertionError: |
| 5798 | main.log.warn( "Search Term Not Found " ) |
| 5799 | return main.ERROR |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5800 | |
| 5801 | def workQueueAdd( self, queueName, value ): |
| 5802 | """ |
| 5803 | CLI command to add a string to the specified Work Queue. |
| 5804 | This function uses the distributed primitives test app, which |
| 5805 | gives some cli access to distributed primitives for testing |
| 5806 | purposes only. |
| 5807 | |
| 5808 | Required arguments: |
| 5809 | queueName - The name of the queue to add to |
| 5810 | value - The value to add to the queue |
| 5811 | returns: |
| 5812 | main.TRUE on success, main.FALSE on failure and |
| 5813 | main.ERROR on error. |
| 5814 | """ |
| 5815 | try: |
| 5816 | queueName = str( queueName ) |
| 5817 | value = str( value ) |
| 5818 | prefix = "work-queue-test" |
| 5819 | operation = "add" |
| 5820 | cmdStr = " ".join( [ prefix, queueName, operation, value ] ) |
| 5821 | output = self.distPrimitivesSend( cmdStr ) |
| 5822 | if "Invalid operation name" in output: |
| 5823 | main.log.warn( output ) |
| 5824 | return main.ERROR |
| 5825 | elif "Done" in output: |
| 5826 | return main.TRUE |
| 5827 | except TypeError: |
| 5828 | main.log.exception( self.name + ": Object not as expected" ) |
| 5829 | return main.ERROR |
| 5830 | except Exception: |
| 5831 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5832 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5833 | |
| 5834 | def workQueueAddMultiple( self, queueName, value1, value2 ): |
| 5835 | """ |
| 5836 | CLI command to add two strings to the specified Work Queue. |
| 5837 | This function uses the distributed primitives test app, which |
| 5838 | gives some cli access to distributed primitives for testing |
| 5839 | purposes only. |
| 5840 | |
| 5841 | Required arguments: |
| 5842 | queueName - The name of the queue to add to |
| 5843 | value1 - The first value to add to the queue |
| 5844 | value2 - The second value to add to the queue |
| 5845 | returns: |
| 5846 | main.TRUE on success, main.FALSE on failure and |
| 5847 | main.ERROR on error. |
| 5848 | """ |
| 5849 | try: |
| 5850 | queueName = str( queueName ) |
| 5851 | value1 = str( value1 ) |
| 5852 | value2 = str( value2 ) |
| 5853 | prefix = "work-queue-test" |
| 5854 | operation = "addMultiple" |
| 5855 | cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] ) |
| 5856 | output = self.distPrimitivesSend( cmdStr ) |
| 5857 | if "Invalid operation name" in output: |
| 5858 | main.log.warn( output ) |
| 5859 | return main.ERROR |
| 5860 | elif "Done" in output: |
| 5861 | return main.TRUE |
| 5862 | except TypeError: |
| 5863 | main.log.exception( self.name + ": Object not as expected" ) |
| 5864 | return main.ERROR |
| 5865 | except Exception: |
| 5866 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5867 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5868 | |
| 5869 | def workQueueTakeAndComplete( self, queueName, number=1 ): |
| 5870 | """ |
| 5871 | CLI command to take a value from the specified Work Queue and compelte it. |
| 5872 | This function uses the distributed primitives test app, which |
| 5873 | gives some cli access to distributed primitives for testing |
| 5874 | purposes only. |
| 5875 | |
| 5876 | Required arguments: |
| 5877 | queueName - The name of the queue to add to |
| 5878 | number - The number of items to take and complete |
| 5879 | returns: |
| 5880 | main.TRUE on success, main.FALSE on failure and |
| 5881 | main.ERROR on error. |
| 5882 | """ |
| 5883 | try: |
| 5884 | queueName = str( queueName ) |
| 5885 | number = str( int( number ) ) |
| 5886 | prefix = "work-queue-test" |
| 5887 | operation = "takeAndComplete" |
| 5888 | cmdStr = " ".join( [ prefix, queueName, operation, number ] ) |
| 5889 | output = self.distPrimitivesSend( cmdStr ) |
| 5890 | if "Invalid operation name" in output: |
| 5891 | main.log.warn( output ) |
| 5892 | return main.ERROR |
| 5893 | elif "Done" in output: |
| 5894 | return main.TRUE |
| 5895 | except TypeError: |
| 5896 | main.log.exception( self.name + ": Object not as expected" ) |
| 5897 | return main.ERROR |
| 5898 | except Exception: |
| 5899 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5900 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5901 | |
| 5902 | def workQueueDestroy( self, queueName ): |
| 5903 | """ |
| 5904 | CLI command to destroy the specified Work Queue. |
| 5905 | This function uses the distributed primitives test app, which |
| 5906 | gives some cli access to distributed primitives for testing |
| 5907 | purposes only. |
| 5908 | |
| 5909 | Required arguments: |
| 5910 | queueName - The name of the queue to add to |
| 5911 | returns: |
| 5912 | main.TRUE on success, main.FALSE on failure and |
| 5913 | main.ERROR on error. |
| 5914 | """ |
| 5915 | try: |
| 5916 | queueName = str( queueName ) |
| 5917 | prefix = "work-queue-test" |
| 5918 | operation = "destroy" |
| 5919 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5920 | output = self.distPrimitivesSend( cmdStr ) |
| 5921 | if "Invalid operation name" in output: |
| 5922 | main.log.warn( output ) |
| 5923 | return main.ERROR |
| 5924 | return main.TRUE |
| 5925 | except TypeError: |
| 5926 | main.log.exception( self.name + ": Object not as expected" ) |
| 5927 | return main.ERROR |
| 5928 | except Exception: |
| 5929 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5930 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5931 | |
| 5932 | def workQueueTotalPending( self, queueName ): |
| 5933 | """ |
| 5934 | CLI command to get the Total Pending items of the specified Work Queue. |
| 5935 | This function uses the distributed primitives test app, which |
| 5936 | gives some cli access to distributed primitives for testing |
| 5937 | purposes only. |
| 5938 | |
| 5939 | Required arguments: |
| 5940 | queueName - The name of the queue to add to |
| 5941 | returns: |
| 5942 | The number of Pending items in the specified work queue or |
| 5943 | None on error |
| 5944 | """ |
| 5945 | try: |
| 5946 | queueName = str( queueName ) |
| 5947 | prefix = "work-queue-test" |
| 5948 | operation = "totalPending" |
| 5949 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5950 | output = self.distPrimitivesSend( cmdStr ) |
| 5951 | pattern = r'\d+' |
| 5952 | if "Invalid operation name" in output: |
| 5953 | main.log.warn( output ) |
| 5954 | return None |
| 5955 | else: |
| 5956 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5957 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5958 | except ( AttributeError, TypeError ): |
| 5959 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5960 | return None |
| 5961 | except Exception: |
| 5962 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5963 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5964 | |
| 5965 | def workQueueTotalCompleted( self, queueName ): |
| 5966 | """ |
| 5967 | CLI command to get the Total Completed items of the specified Work Queue. |
| 5968 | This function uses the distributed primitives test app, which |
| 5969 | gives some cli access to distributed primitives for testing |
| 5970 | purposes only. |
| 5971 | |
| 5972 | Required arguments: |
| 5973 | queueName - The name of the queue to add to |
| 5974 | returns: |
| 5975 | The number of complete items in the specified work queue or |
| 5976 | None on error |
| 5977 | """ |
| 5978 | try: |
| 5979 | queueName = str( queueName ) |
| 5980 | prefix = "work-queue-test" |
| 5981 | operation = "totalCompleted" |
| 5982 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5983 | output = self.distPrimitivesSend( cmdStr ) |
| 5984 | pattern = r'\d+' |
| 5985 | if "Invalid operation name" in output: |
| 5986 | main.log.warn( output ) |
| 5987 | return None |
| 5988 | else: |
| 5989 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5990 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5991 | except ( AttributeError, TypeError ): |
| 5992 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5993 | return None |
| 5994 | except Exception: |
| 5995 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5996 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5997 | |
| 5998 | def workQueueTotalInProgress( self, queueName ): |
| 5999 | """ |
| 6000 | CLI command to get the Total In Progress items of the specified Work Queue. |
| 6001 | This function uses the distributed primitives test app, which |
| 6002 | gives some cli access to distributed primitives for testing |
| 6003 | purposes only. |
| 6004 | |
| 6005 | Required arguments: |
| 6006 | queueName - The name of the queue to add to |
| 6007 | returns: |
| 6008 | The number of In Progress items in the specified work queue or |
| 6009 | None on error |
| 6010 | """ |
| 6011 | try: |
| 6012 | queueName = str( queueName ) |
| 6013 | prefix = "work-queue-test" |
| 6014 | operation = "totalInProgress" |
| 6015 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 6016 | output = self.distPrimitivesSend( cmdStr ) |
| 6017 | pattern = r'\d+' |
| 6018 | if "Invalid operation name" in output: |
| 6019 | main.log.warn( output ) |
| 6020 | return None |
| 6021 | else: |
| 6022 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 6023 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6024 | except ( AttributeError, TypeError ): |
| 6025 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 6026 | return None |
| 6027 | except Exception: |
| 6028 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 6029 | main.cleanAndExit() |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 6030 | |
| 6031 | def events( self, args='-a' ): |
| 6032 | """ |
| 6033 | Description: Returns events -a command output |
| 6034 | Optional: |
| 6035 | add other arguments |
| 6036 | """ |
| 6037 | try: |
| 6038 | cmdStr = "events" |
| 6039 | if args: |
| 6040 | cmdStr += " " + args |
| 6041 | handle = self.sendline( cmdStr ) |
| 6042 | assert handle is not None, "Error in sendline" |
| 6043 | assert "Command not found:" not in handle, handle |
| 6044 | return handle |
| 6045 | except AssertionError: |
| 6046 | main.log.exception( "" ) |
| 6047 | return None |
| 6048 | except TypeError: |
| 6049 | main.log.exception( self.name + ": Object not as expected" ) |
| 6050 | return None |
| 6051 | except pexpect.EOF: |
| 6052 | main.log.error( self.name + ": EOF exception found" ) |
| 6053 | main.log.error( self.name + ": " + self.handle.before ) |
| 6054 | main.cleanAndExit() |
| 6055 | except Exception: |
| 6056 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6057 | main.cleanAndExit() |
| 6058 | |
| 6059 | def getMaster( self, deviceID ): |
| 6060 | """ |
| 6061 | Description: Obtains current master using "roles" command for a specific deviceID |
| 6062 | """ |
| 6063 | try: |
| 6064 | return str( self.getRole( deviceID )[ 'master' ] ) |
| 6065 | except AssertionError: |
| 6066 | main.log.exception( "" ) |
| 6067 | return None |
| 6068 | except TypeError: |
| 6069 | main.log.exception( self.name + ": Object not as expected" ) |
| 6070 | return None |
| 6071 | except pexpect.EOF: |
| 6072 | main.log.error( self.name + ": EOF exception found" ) |
| 6073 | main.log.error( self.name + ": " + self.handle.before ) |
| 6074 | main.cleanAndExit() |
| 6075 | except Exception: |
| 6076 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 6077 | main.cleanAndExit() |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 6078 | |
| 6079 | def issu( self ): |
| 6080 | """ |
| 6081 | Short summary of In-Service Software Upgrade status |
| 6082 | |
| 6083 | Returns the output of the cli command or None on Error |
| 6084 | """ |
| 6085 | try: |
| 6086 | cmdStr = "issu" |
| 6087 | handle = self.sendline( cmdStr ) |
| 6088 | assert handle is not None, "Error in sendline" |
| 6089 | assert "Command not found:" not in handle, handle |
| 6090 | assert "Unsupported command:" not in handle, handle |
| 6091 | return handle |
| 6092 | except AssertionError: |
| 6093 | main.log.exception( "" ) |
| 6094 | return None |
| 6095 | except TypeError: |
| 6096 | main.log.exception( self.name + ": Object not as expected" ) |
| 6097 | return None |
| 6098 | except pexpect.EOF: |
| 6099 | main.log.error( self.name + ": EOF exception found" ) |
| 6100 | main.log.error( self.name + ": " + self.handle.before ) |
| 6101 | main.cleanAndExit() |
| 6102 | except Exception: |
| 6103 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6104 | main.cleanAndExit() |
| 6105 | |
| 6106 | def issuInit( self ): |
| 6107 | """ |
| 6108 | Initiates an In-Service Software Upgrade |
| 6109 | |
| 6110 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6111 | """ |
| 6112 | try: |
| 6113 | cmdStr = "issu init" |
| 6114 | handle = self.sendline( cmdStr ) |
| 6115 | assert handle is not None, "Error in sendline" |
| 6116 | assert "Command not found:" not in handle, handle |
| 6117 | assert "Unsupported command:" not in handle, handle |
| 6118 | if "Initialized" in handle: |
| 6119 | return main.TRUE |
| 6120 | else: |
| 6121 | return main.FALSE |
| 6122 | except AssertionError: |
| 6123 | main.log.exception( "" ) |
| 6124 | return main.ERROR |
| 6125 | except TypeError: |
| 6126 | main.log.exception( self.name + ": Object not as expected" ) |
| 6127 | return main.ERROR |
| 6128 | except pexpect.EOF: |
| 6129 | main.log.error( self.name + ": EOF exception found" ) |
| 6130 | main.log.error( self.name + ": " + self.handle.before ) |
| 6131 | main.cleanAndExit() |
| 6132 | except Exception: |
| 6133 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6134 | main.cleanAndExit() |
| 6135 | |
| 6136 | def issuUpgrade( self ): |
| 6137 | """ |
| 6138 | Transitions stores to upgraded nodes |
| 6139 | |
| 6140 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6141 | """ |
| 6142 | try: |
| 6143 | cmdStr = "issu upgrade" |
| 6144 | handle = self.sendline( cmdStr ) |
| 6145 | assert handle is not None, "Error in sendline" |
| 6146 | assert "Command not found:" not in handle, handle |
| 6147 | assert "Unsupported command:" not in handle, handle |
| 6148 | if "Upgraded" in handle: |
| 6149 | return main.TRUE |
| 6150 | else: |
| 6151 | return main.FALSE |
| 6152 | except AssertionError: |
| 6153 | main.log.exception( "" ) |
| 6154 | return main.ERROR |
| 6155 | except TypeError: |
| 6156 | main.log.exception( self.name + ": Object not as expected" ) |
| 6157 | return main.ERROR |
| 6158 | except pexpect.EOF: |
| 6159 | main.log.error( self.name + ": EOF exception found" ) |
| 6160 | main.log.error( self.name + ": " + self.handle.before ) |
| 6161 | main.cleanAndExit() |
| 6162 | except Exception: |
| 6163 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6164 | main.cleanAndExit() |
| 6165 | |
| 6166 | def issuCommit( self ): |
| 6167 | """ |
| 6168 | Finalizes an In-Service Software Upgrade |
| 6169 | |
| 6170 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6171 | """ |
| 6172 | try: |
| 6173 | cmdStr = "issu commit" |
| 6174 | handle = self.sendline( cmdStr ) |
| 6175 | assert handle is not None, "Error in sendline" |
| 6176 | assert "Command not found:" not in handle, handle |
| 6177 | assert "Unsupported command:" not in handle, handle |
| 6178 | # TODO: Check the version returned by this command |
| 6179 | if "Committed version" in handle: |
| 6180 | return main.TRUE |
| 6181 | else: |
| 6182 | return main.FALSE |
| 6183 | except AssertionError: |
| 6184 | main.log.exception( "" ) |
| 6185 | return main.ERROR |
| 6186 | except TypeError: |
| 6187 | main.log.exception( self.name + ": Object not as expected" ) |
| 6188 | return main.ERROR |
| 6189 | except pexpect.EOF: |
| 6190 | main.log.error( self.name + ": EOF exception found" ) |
| 6191 | main.log.error( self.name + ": " + self.handle.before ) |
| 6192 | main.cleanAndExit() |
| 6193 | except Exception: |
| 6194 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6195 | main.cleanAndExit() |
| 6196 | |
| 6197 | def issuRollback( self ): |
| 6198 | """ |
| 6199 | Rolls back an In-Service Software Upgrade |
| 6200 | |
| 6201 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6202 | """ |
| 6203 | try: |
| 6204 | cmdStr = "issu rollback" |
| 6205 | handle = self.sendline( cmdStr ) |
| 6206 | assert handle is not None, "Error in sendline" |
| 6207 | assert "Command not found:" not in handle, handle |
| 6208 | assert "Unsupported command:" not in handle, handle |
| 6209 | # TODO: Check the version returned by this command |
| 6210 | if "Rolled back to version" in handle: |
| 6211 | return main.TRUE |
| 6212 | else: |
| 6213 | return main.FALSE |
| 6214 | except AssertionError: |
| 6215 | main.log.exception( "" ) |
| 6216 | return main.ERROR |
| 6217 | except TypeError: |
| 6218 | main.log.exception( self.name + ": Object not as expected" ) |
| 6219 | return main.ERROR |
| 6220 | except pexpect.EOF: |
| 6221 | main.log.error( self.name + ": EOF exception found" ) |
| 6222 | main.log.error( self.name + ": " + self.handle.before ) |
| 6223 | main.cleanAndExit() |
| 6224 | except Exception: |
| 6225 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6226 | main.cleanAndExit() |
| 6227 | |
| 6228 | def issuReset( self ): |
| 6229 | """ |
| 6230 | Resets the In-Service Software Upgrade status after a rollback |
| 6231 | |
| 6232 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6233 | """ |
| 6234 | try: |
| 6235 | cmdStr = "issu reset" |
| 6236 | handle = self.sendline( cmdStr ) |
| 6237 | assert handle is not None, "Error in sendline" |
| 6238 | assert "Command not found:" not in handle, handle |
| 6239 | assert "Unsupported command:" not in handle, handle |
| 6240 | # TODO: Check the version returned by this command |
| 6241 | if "Reset version" in handle: |
| 6242 | return main.TRUE |
| 6243 | else: |
| 6244 | return main.FALSE |
| 6245 | except AssertionError: |
| 6246 | main.log.exception( "" ) |
| 6247 | return main.ERROR |
| 6248 | except TypeError: |
| 6249 | main.log.exception( self.name + ": Object not as expected" ) |
| 6250 | return main.ERROR |
| 6251 | except pexpect.EOF: |
| 6252 | main.log.error( self.name + ": EOF exception found" ) |
| 6253 | main.log.error( self.name + ": " + self.handle.before ) |
| 6254 | main.cleanAndExit() |
| 6255 | except Exception: |
| 6256 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6257 | main.cleanAndExit() |
| 6258 | |
| 6259 | def issuStatus( self ): |
| 6260 | """ |
| 6261 | Status of an In-Service Software Upgrade |
| 6262 | |
| 6263 | Returns the output of the cli command or None on Error |
| 6264 | """ |
| 6265 | try: |
| 6266 | cmdStr = "issu status" |
| 6267 | handle = self.sendline( cmdStr ) |
| 6268 | assert handle is not None, "Error in sendline" |
| 6269 | assert "Command not found:" not in handle, handle |
| 6270 | assert "Unsupported command:" not in handle, handle |
| 6271 | return handle |
| 6272 | except AssertionError: |
| 6273 | main.log.exception( "" ) |
| 6274 | return None |
| 6275 | except TypeError: |
| 6276 | main.log.exception( self.name + ": Object not as expected" ) |
| 6277 | return None |
| 6278 | except pexpect.EOF: |
| 6279 | main.log.error( self.name + ": EOF exception found" ) |
| 6280 | main.log.error( self.name + ": " + self.handle.before ) |
| 6281 | main.cleanAndExit() |
| 6282 | except Exception: |
| 6283 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6284 | main.cleanAndExit() |
| 6285 | |
| 6286 | def issuVersion( self ): |
| 6287 | """ |
| 6288 | Get the version of an In-Service Software Upgrade |
| 6289 | |
| 6290 | Returns the output of the cli command or None on Error |
| 6291 | """ |
| 6292 | try: |
| 6293 | cmdStr = "issu version" |
| 6294 | handle = self.sendline( cmdStr ) |
| 6295 | assert handle is not None, "Error in sendline" |
| 6296 | assert "Command not found:" not in handle, handle |
| 6297 | assert "Unsupported command:" not in handle, handle |
| 6298 | return handle |
| 6299 | except AssertionError: |
| 6300 | main.log.exception( "" ) |
| 6301 | return None |
| 6302 | except TypeError: |
| 6303 | main.log.exception( self.name + ": Object not as expected" ) |
| 6304 | return None |
| 6305 | except pexpect.EOF: |
| 6306 | main.log.error( self.name + ": EOF exception found" ) |
| 6307 | main.log.error( self.name + ": " + self.handle.before ) |
| 6308 | main.cleanAndExit() |
| 6309 | except Exception: |
| 6310 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6311 | main.cleanAndExit() |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6312 | |
| 6313 | def mcastJoin( self, sIP, groupIP, sPort, dPorts ): |
| 6314 | """ |
| 6315 | Create a multicast route by calling 'mcast-join' command |
| 6316 | sIP: source IP of the multicast route |
| 6317 | groupIP: group IP of the multicast route |
| 6318 | sPort: source port (e.g. of:0000000000000001/3 ) of the multicast route |
| 6319 | dPorts: a list of destination ports of the multicast route |
| 6320 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6321 | """ |
| 6322 | try: |
| 6323 | cmdStr = "mcast-join" |
| 6324 | cmdStr += " " + str( sIP ) |
| 6325 | cmdStr += " " + str( groupIP ) |
| 6326 | cmdStr += " " + str( sPort ) |
| 6327 | assert isinstance( dPorts, list ) |
| 6328 | for dPort in dPorts: |
| 6329 | cmdStr += " " + str( dPort ) |
| 6330 | handle = self.sendline( cmdStr ) |
| 6331 | assert handle is not None, "Error in sendline" |
| 6332 | assert "Command not found:" not in handle, handle |
| 6333 | assert "Unsupported command:" not in handle, handle |
| 6334 | assert "Error executing command" not in handle, handle |
| 6335 | if "Added the mcast route" in handle: |
| 6336 | return main.TRUE |
| 6337 | else: |
| 6338 | return main.FALSE |
| 6339 | except AssertionError: |
| 6340 | main.log.exception( "" ) |
| 6341 | return None |
| 6342 | except TypeError: |
| 6343 | main.log.exception( self.name + ": Object not as expected" ) |
| 6344 | return None |
| 6345 | except pexpect.EOF: |
| 6346 | main.log.error( self.name + ": EOF exception found" ) |
| 6347 | main.log.error( self.name + ": " + self.handle.before ) |
| 6348 | main.cleanAndExit() |
| 6349 | except Exception: |
| 6350 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6351 | main.cleanAndExit() |
| 6352 | |
| 6353 | def mcastDelete( self, sIP, groupIP, dPorts ): |
| 6354 | """ |
| 6355 | Delete a multicast route by calling 'mcast-delete' command |
| 6356 | sIP: source IP of the multicast route |
| 6357 | groupIP: group IP of the multicast route |
| 6358 | dPorts: a list of destination ports of the multicast route |
| 6359 | Returns main.TRUE if mcast route is deleted; Otherwise main.FALSE |
| 6360 | """ |
| 6361 | try: |
| 6362 | cmdStr = "mcast-delete" |
| 6363 | cmdStr += " " + str( sIP ) |
| 6364 | cmdStr += " " + str( groupIP ) |
| 6365 | assert isinstance( dPorts, list ) |
| 6366 | for dPort in dPorts: |
| 6367 | cmdStr += " " + str( dPort ) |
| 6368 | handle = self.sendline( cmdStr ) |
| 6369 | assert handle is not None, "Error in sendline" |
| 6370 | assert "Command not found:" not in handle, handle |
| 6371 | assert "Unsupported command:" not in handle, handle |
| 6372 | assert "Error executing command" not in handle, handle |
| 6373 | if "Updated the mcast route" in handle: |
| 6374 | return main.TRUE |
| 6375 | else: |
| 6376 | return main.FALSE |
| 6377 | except AssertionError: |
| 6378 | main.log.exception( "" ) |
| 6379 | return None |
| 6380 | except TypeError: |
| 6381 | main.log.exception( self.name + ": Object not as expected" ) |
| 6382 | return None |
| 6383 | except pexpect.EOF: |
| 6384 | main.log.error( self.name + ": EOF exception found" ) |
| 6385 | main.log.error( self.name + ": " + self.handle.before ) |
| 6386 | main.cleanAndExit() |
| 6387 | except Exception: |
| 6388 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6389 | main.cleanAndExit() |
| 6390 | |
| 6391 | def mcastHostJoin( self, sAddr, gAddr, srcs, sinks ): |
| 6392 | """ |
| 6393 | Create a multicast route by calling 'mcast-host-join' command |
| 6394 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6395 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6396 | srcs: a list of HostId of the sources e.g. ["00:AA:00:00:00:01/None"] |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6397 | sinks: a list of HostId of the sinks e.g. ["00:AA:00:00:01:05/40"] |
| 6398 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6399 | """ |
| 6400 | try: |
| 6401 | cmdStr = "mcast-host-join" |
| 6402 | cmdStr += " -sAddr " + str( sAddr ) |
| 6403 | cmdStr += " -gAddr " + str( gAddr ) |
| 6404 | assert isinstance( srcs, list ) |
| 6405 | for src in srcs: |
| 6406 | cmdStr += " -srcs " + str( src ) |
| 6407 | assert isinstance( sinks, list ) |
| 6408 | for sink in sinks: |
| 6409 | cmdStr += " -sinks " + str( sink ) |
| 6410 | handle = self.sendline( cmdStr ) |
| 6411 | assert handle is not None, "Error in sendline" |
| 6412 | assert "Command not found:" not in handle, handle |
| 6413 | assert "Unsupported command:" not in handle, handle |
| 6414 | assert "Error executing command" not in handle, handle |
| 6415 | if "Added the mcast route" in handle: |
| 6416 | return main.TRUE |
| 6417 | else: |
| 6418 | return main.FALSE |
| 6419 | except AssertionError: |
| 6420 | main.log.exception( "" ) |
| 6421 | return None |
| 6422 | except TypeError: |
| 6423 | main.log.exception( self.name + ": Object not as expected" ) |
| 6424 | return None |
| 6425 | except pexpect.EOF: |
| 6426 | main.log.error( self.name + ": EOF exception found" ) |
| 6427 | main.log.error( self.name + ": " + self.handle.before ) |
| 6428 | main.cleanAndExit() |
| 6429 | except Exception: |
| 6430 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6431 | main.cleanAndExit() |
| 6432 | |
| 6433 | def mcastHostDelete( self, sAddr, gAddr, host=None ): |
| 6434 | """ |
| 6435 | Delete multicast sink(s) by calling 'mcast-host-delete' command |
| 6436 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6437 | gAddr: specifies multicast group address |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 6438 | host: HostId of the sink e.g. "00:AA:00:00:01:05/40", |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6439 | will delete the route if not specified |
| 6440 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6441 | """ |
| 6442 | try: |
| 6443 | cmdStr = "mcast-host-delete" |
| 6444 | cmdStr += " -sAddr " + str( sAddr ) |
| 6445 | cmdStr += " -gAddr " + str( gAddr ) |
| 6446 | if host: |
| 6447 | cmdStr += " -h " + str( host ) |
| 6448 | handle = self.sendline( cmdStr ) |
| 6449 | assert handle is not None, "Error in sendline" |
| 6450 | assert "Command not found:" not in handle, handle |
| 6451 | assert "Unsupported command:" not in handle, handle |
| 6452 | assert "Error executing command" not in handle, handle |
| 6453 | if "Updated the mcast route" in handle: |
| 6454 | return main.TRUE |
| 6455 | elif "Deleted the mcast route" in handle: |
| 6456 | return main.TRUE |
| 6457 | else: |
| 6458 | return main.FALSE |
| 6459 | except AssertionError: |
| 6460 | main.log.exception( "" ) |
| 6461 | return None |
| 6462 | except TypeError: |
| 6463 | main.log.exception( self.name + ": Object not as expected" ) |
| 6464 | return None |
| 6465 | except pexpect.EOF: |
| 6466 | main.log.error( self.name + ": EOF exception found" ) |
| 6467 | main.log.error( self.name + ": " + self.handle.before ) |
| 6468 | main.cleanAndExit() |
| 6469 | except Exception: |
| 6470 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6471 | main.cleanAndExit() |
| 6472 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6473 | def mcastSinkDelete( self, sAddr, gAddr, sink=None ): |
| 6474 | """ |
| 6475 | Delete multicast sink(s) by calling 'mcast-sink-delete' command |
| 6476 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6477 | gAddr: specifies multicast group address |
| 6478 | host: HostId of the sink e.g. "00:AA:00:00:01:05/40", |
| 6479 | will delete the route if not specified |
| 6480 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6481 | """ |
| 6482 | try: |
| 6483 | cmdStr = "mcast-sink-delete" |
| 6484 | cmdStr += " -sAddr " + str( sAddr ) |
| 6485 | cmdStr += " -gAddr " + str( gAddr ) |
| 6486 | if sink: |
| 6487 | cmdStr += " -s " + str( sink ) |
| 6488 | handle = self.sendline( cmdStr ) |
| 6489 | assert handle is not None, "Error in sendline" |
| 6490 | assert "Command not found:" not in handle, handle |
| 6491 | assert "Unsupported command:" not in handle, handle |
| 6492 | assert "Error executing command" not in handle, handle |
| 6493 | if "Updated the mcast route" in handle: |
| 6494 | return main.TRUE |
| 6495 | elif "Deleted the mcast route" in handle: |
| 6496 | return main.TRUE |
| 6497 | else: |
| 6498 | return main.FALSE |
| 6499 | except AssertionError: |
| 6500 | main.log.exception( "" ) |
| 6501 | return None |
| 6502 | except TypeError: |
| 6503 | main.log.exception( self.name + ": Object not as expected" ) |
| 6504 | return None |
| 6505 | except pexpect.EOF: |
| 6506 | main.log.error( self.name + ": EOF exception found" ) |
| 6507 | main.log.error( self.name + ": " + self.handle.before ) |
| 6508 | main.cleanAndExit() |
| 6509 | except Exception: |
| 6510 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6511 | main.cleanAndExit() |
| 6512 | |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6513 | def mcastSourceDelete( self, sAddr, gAddr, srcs=None ): |
| 6514 | """ |
| 6515 | Delete multicast src(s) by calling 'mcast-source-delete' command |
| 6516 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6517 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6518 | srcs: a list of host IDs of the sources e.g. ["00:AA:00:00:01:05/40"], |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6519 | will delete the route if not specified |
| 6520 | Returns main.TRUE if mcast sink is deleted; Otherwise main.FALSE |
| 6521 | """ |
| 6522 | try: |
| 6523 | cmdStr = "mcast-source-delete" |
| 6524 | cmdStr += " -sAddr " + str( sAddr ) |
| 6525 | cmdStr += " -gAddr " + str( gAddr ) |
| 6526 | if srcs: |
| 6527 | assert isinstance( srcs, list ) |
| 6528 | for src in srcs: |
| 6529 | cmdStr += " -src " + str( src ) |
| 6530 | handle = self.sendline( cmdStr ) |
| 6531 | assert handle is not None, "Error in sendline" |
| 6532 | assert "Command not found:" not in handle, handle |
| 6533 | assert "Unsupported command:" not in handle, handle |
| 6534 | assert "Error executing command" not in handle, handle |
| 6535 | if "Updated the mcast route" in handle: |
| 6536 | return main.TRUE |
| 6537 | elif "Deleted the mcast route" in handle: |
| 6538 | return main.TRUE |
| 6539 | else: |
| 6540 | return main.FALSE |
| 6541 | except AssertionError: |
| 6542 | main.log.exception( "" ) |
| 6543 | return None |
| 6544 | except TypeError: |
| 6545 | main.log.exception( self.name + ": Object not as expected" ) |
| 6546 | return None |
| 6547 | except pexpect.EOF: |
| 6548 | main.log.error( self.name + ": EOF exception found" ) |
| 6549 | main.log.error( self.name + ": " + self.handle.before ) |
| 6550 | main.cleanAndExit() |
| 6551 | except Exception: |
| 6552 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6553 | main.cleanAndExit() |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6554 | |
| 6555 | def netcfg( self, jsonFormat=True, args="" ): |
| 6556 | """ |
| 6557 | Run netcfg cli command with given args |
| 6558 | """ |
| 6559 | try: |
| 6560 | cmdStr = "netcfg" |
| 6561 | if jsonFormat: |
| 6562 | cmdStr = cmdStr + " -j" |
| 6563 | if args: |
| 6564 | cmdStr = cmdStr + " " + str( args ) |
| 6565 | handle = self.sendline( cmdStr ) |
| 6566 | assert handle is not None, "Error in sendline" |
| 6567 | assert "Command not found:" not in handle, handle |
| 6568 | assert "Unsupported command:" not in handle, handle |
| 6569 | assert "Error executing command" not in handle, handle |
| 6570 | return handle |
| 6571 | except AssertionError: |
| 6572 | main.log.exception( "" ) |
| 6573 | return None |
| 6574 | except TypeError: |
| 6575 | main.log.exception( self.name + ": Object not as expected" ) |
| 6576 | return None |
| 6577 | except pexpect.EOF: |
| 6578 | main.log.error( self.name + ": EOF exception found" ) |
| 6579 | main.log.error( self.name + ": " + self.handle.before ) |
| 6580 | main.cleanAndExit() |
| 6581 | except Exception: |
| 6582 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6583 | main.cleanAndExit() |
| 6584 | |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6585 | def composeT3Command( self, sAddr, dAddr, ipv6=False, verbose=True, simple=False ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6586 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6587 | Compose and return a list of t3-troubleshoot cli commands for given source and destination addresses |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6588 | Options: |
| 6589 | sAddr: IP address of the source host |
| 6590 | dAddr: IP address of the destination host |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6591 | ipv6: True if hosts are IPv6 |
| 6592 | verbose: return verbose t3 output if True |
| 6593 | simple: compose command for t3-troubleshoot-simple if True |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6594 | """ |
| 6595 | try: |
| 6596 | # Collect information of both hosts from onos |
| 6597 | hosts = self.hosts() |
| 6598 | hosts = json.loads( hosts ) |
| 6599 | sHost = None |
| 6600 | dHost = None |
| 6601 | for host in hosts: |
| 6602 | if sAddr in host[ "ipAddresses" ]: |
| 6603 | sHost = host |
| 6604 | elif dAddr in host[ "ipAddresses" ]: |
| 6605 | dHost = host |
| 6606 | if sHost and dHost: |
| 6607 | break |
| 6608 | assert sHost, "Not able to find host with IP {}".format( sAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6609 | cmdList = [] |
You Wang | 5d9527b | 2018-05-29 17:08:54 -0700 | [diff] [blame] | 6610 | if simple: |
| 6611 | assert dHost, "Not able to find host with IP {}".format( dAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6612 | cmdStr = "t3-troubleshoot-simple" |
| 6613 | if verbose: |
| 6614 | cmdStr += " -vv" |
| 6615 | if ipv6: |
| 6616 | cmdStr += " -et ipv6" |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6617 | cmdStr += " {}/{} {}/{}".format( sHost[ "mac" ], sHost[ "vlan" ], dHost[ "mac" ], dHost[ "vlan" ] ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6618 | cmdList.append( cmdStr ) |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6619 | else: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6620 | for location in sHost[ "locations" ]: |
| 6621 | cmdStr = "t3-troubleshoot" |
| 6622 | if verbose: |
| 6623 | cmdStr += " -vv" |
| 6624 | if ipv6: |
| 6625 | cmdStr += " -et ipv6" |
| 6626 | cmdStr += " -s " + str( sAddr ) |
| 6627 | cmdStr += " -sp " + str( location[ "elementId" ] ) + "/" + str( location[ "port" ] ) |
| 6628 | cmdStr += " -sm " + str( sHost[ "mac" ] ) |
| 6629 | if sHost[ "vlan" ] != "None": |
| 6630 | cmdStr += " -vid " + sHost[ "vlan" ] |
| 6631 | cmdStr += " -d " + str( dAddr ) |
| 6632 | netcfg = self.netcfg( args="devices {}".format( location[ "elementId" ] ) ) |
| 6633 | netcfg = json.loads( netcfg ) |
| 6634 | assert netcfg, "Failed to get netcfg" |
| 6635 | cmdStr += " -dm " + str( netcfg[ "segmentrouting" ][ "routerMac" ] ) |
| 6636 | cmdList.append( cmdStr ) |
| 6637 | return cmdList |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6638 | except AssertionError: |
| 6639 | main.log.exception( "" ) |
| 6640 | return None |
| 6641 | except ( KeyError, TypeError ): |
| 6642 | main.log.exception( self.name + ": Object not as expected" ) |
| 6643 | return None |
| 6644 | except Exception: |
| 6645 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6646 | main.cleanAndExit() |
| 6647 | |
| 6648 | def t3( self, sAddr, dAddr, ipv6=False ): |
| 6649 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6650 | Run t3-troubleshoot cli commands for all posible routes given source and destination addresses |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6651 | Options: |
| 6652 | sAddr: IP address of the source host |
| 6653 | dAddr: IP address of the destination host |
| 6654 | """ |
| 6655 | try: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6656 | cmdList = self.composeT3Command( sAddr, dAddr, ipv6 ) |
| 6657 | assert cmdList is not None, "composeT3Command returned None" |
| 6658 | t3Output = "" |
| 6659 | for cmdStr in cmdList: |
| 6660 | handle = self.sendline( cmdStr ) |
| 6661 | assert handle is not None, "Error in sendline" |
| 6662 | assert "Command not found:" not in handle, handle |
| 6663 | assert "Unsupported command:" not in handle, handle |
| 6664 | assert "Error executing command" not in handle, handle |
| 6665 | assert "Tracing packet" in handle |
| 6666 | t3Output += handle |
| 6667 | return t3Output |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6668 | except AssertionError: |
| 6669 | main.log.exception( "" ) |
| 6670 | return None |
| 6671 | except pexpect.EOF: |
| 6672 | main.log.error( self.name + ": EOF exception found" ) |
| 6673 | main.log.error( self.name + ": " + self.handle.before ) |
| 6674 | main.cleanAndExit() |
| 6675 | except Exception: |
| 6676 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6677 | main.cleanAndExit() |