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 |
steven30801 | e42f1fb | 2019-01-17 11:31:45 +0800 | [diff] [blame] | 199 | elif i == 2: # Timeout |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 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 | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 525 | def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True, expectJson=False ): |
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 | cf31d0f | 2018-12-13 11:18:48 -0800 | [diff] [blame] | 561 | karafEscape = re.compile( r"('(0|1)~\'|\r\r\r\n\x1b\[A\x1b\[79C(x|\s)?|\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 |
Jon Hall | cf31d0f | 2018-12-13 11:18:48 -0800 | [diff] [blame] | 574 | # NOTE: karaf is sometimes adding a single character then two |
| 575 | # backspaces and sometimes adding 2 characters with 2 backspaces?? |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 576 | backspaceEscape = re.compile( r'((..\x08\x08)|(.|\s)\x08)' ) |
| 577 | response = backspaceEscape.sub( '', response ) |
| 578 | if debug: |
| 579 | main.log.debug( self.name + ": backspaceEscape output" ) |
| 580 | main.log.debug( self.name + ": " + repr( response ) ) |
| 581 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 582 | # Remove extra return chars that get added |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 583 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 584 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 585 | main.log.debug( self.name + ": Removed extra returns " + |
| 586 | "from output" ) |
| 587 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 588 | |
| 589 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 590 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 591 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 592 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 593 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 594 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 595 | # parse for just the output, remove the cmd from response |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 596 | cmdPattern = cmdStr.strip() |
| 597 | main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) + |
| 598 | "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 599 | if relaxedRegex: |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 600 | cmdPattern = cmdPattern.split( '|' )[ -1 ].strip() |
| 601 | main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) + |
| 602 | "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 603 | # This was added because karaf 4.2 is stripping some characters from the command echo |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 604 | output = response.split( cmdPattern, 1 ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 605 | if expectJson: |
| 606 | main.log.warn( "Relaxed Regex: Searching for a json string amongst the output" ) |
| 607 | jsonPattern = r'\{.*\}' |
| 608 | match = re.search( jsonPattern, output[ 0 ] ) |
| 609 | if match: |
| 610 | output = [ '' , match.group( 0 ) ] # We expect a list with the second element to be the output |
Jon Hall | 39e3ffe | 2018-12-05 11:40:29 -0800 | [diff] [blame] | 611 | if len( output ) < 2: |
| 612 | main.log.warn( "Relaxing regex match to last 5 characters of the sent command" ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 613 | cmdPattern = cmdPattern[ -5: ] |
| 614 | main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) + |
| 615 | "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) ) |
| 616 | output = response.split( cmdPattern, 1 ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 617 | else: |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 618 | output = response.split( cmdPattern, 1 ) |
| 619 | if len( output ) < 2: # TODO: Should we do this without the relaxedRegex flag? |
Jon Hall | 8c9dd1c | 2018-11-14 15:40:39 -0800 | [diff] [blame] | 620 | main.log.warn( "Relaxing regex match to last 5 characters of the sent command" ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 621 | output = response.split( cmdPattern[ -5: ], 1 ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 622 | if output: |
| 623 | if debug: |
| 624 | main.log.debug( self.name + ": split output" ) |
| 625 | for r in output: |
| 626 | main.log.debug( self.name + ": " + repr( r ) ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 627 | if len( output ) == 1: |
| 628 | main.log.error( "Could not remove sent command echo from output" ) |
| 629 | return output |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 630 | output = output[ 1 ].strip() |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 631 | if showResponse: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 632 | main.log.info( "Response from ONOS: {}".format( output ) ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 633 | self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 634 | return output |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 635 | except pexpect.TIMEOUT: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 636 | main.log.error( self.name + ": ONOS timeout" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 637 | if debug: |
| 638 | main.log.debug( self.handle.before ) |
You Wang | 6b5e5ba | 2019-01-31 15:32:40 -0800 | [diff] [blame] | 639 | self.exitFromCmd( self.karafPrompt, 100 ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 640 | return None |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 641 | except IndexError: |
| 642 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 643 | main.log.debug( "response: {}".format( repr( response ) ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 644 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 645 | except TypeError: |
| 646 | main.log.exception( self.name + ": Object not as expected" ) |
| 647 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 648 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 649 | main.log.error( self.name + ": EOF exception found" ) |
| 650 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 651 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 652 | return None |
| 653 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 654 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 655 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 656 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 657 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 658 | return None |
| 659 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 660 | main.cleanAndExit() |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 661 | |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 662 | def lineCount( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True ): |
| 663 | """ |
| 664 | A wrapper around sendline(). Will return the number of lines returned or None on error |
| 665 | |
| 666 | Required Arguments: |
| 667 | cmdStr - String to send to the pexpect session |
| 668 | |
| 669 | Optional Arguments: |
| 670 | showResponse - Defaults to False. If True will log the response. |
| 671 | debug - Defaults to False. If True, will enable debug logging. |
| 672 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 673 | before a timeout. |
| 674 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
| 675 | closed channel, but instead return None |
| 676 | 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. |
| 677 | |
| 678 | Warning: There are no sanity checking to commands sent using this method. |
| 679 | |
| 680 | """ |
| 681 | try: |
| 682 | numLines = self.sendline( cmdStr, showResponse, debug, timeout, noExit, relaxedRegex ) |
You Wang | 0ce8e0c | 2019-02-22 12:22:26 -0800 | [diff] [blame] | 683 | parsed = re.search( "(\d+)", numLines ) |
Jon Hall | 8c9dd1c | 2018-11-14 15:40:39 -0800 | [diff] [blame] | 684 | if not parsed: |
| 685 | main.log.error( "Warning, output of karaf's wc may have changed" ) |
| 686 | return None |
| 687 | return parsed.group( 1 ) |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 688 | except IndexError: |
| 689 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 690 | main.log.debug( "response: {}".format( repr( numLines ) ) ) |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 691 | return None |
| 692 | except TypeError: |
| 693 | main.log.exception( self.name + ": Object not as expected" ) |
| 694 | return None |
| 695 | except Exception: |
| 696 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 697 | if noExit: |
| 698 | return None |
| 699 | else: |
| 700 | main.cleanAndExit() |
| 701 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 702 | # IMPORTANT NOTE: |
| 703 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 704 | # the cli command changing 'a:b' with 'aB'. |
| 705 | # Ex ) onos:topology > onosTopology |
| 706 | # onos:links > onosLinks |
| 707 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 708 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 709 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 710 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 711 | Adds a new cluster node by ID and address information. |
| 712 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 713 | * nodeId |
| 714 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 715 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 716 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 717 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 718 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 719 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 720 | str( ONOSIp ) + " " + str( tcpPort ) |
| 721 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 722 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 723 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 724 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 725 | main.log.error( self.name + ": Error in adding node" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 726 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 727 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 728 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 729 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 730 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 731 | except AssertionError: |
| 732 | main.log.exception( "" ) |
| 733 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 734 | except TypeError: |
| 735 | main.log.exception( self.name + ": Object not as expected" ) |
| 736 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 737 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 738 | main.log.error( self.name + ": EOF exception found" ) |
| 739 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 740 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 741 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 742 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 743 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 744 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 745 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 746 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 747 | Removes a cluster by ID |
| 748 | Issues command: 'remove-node [<node-id>]' |
| 749 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 750 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 751 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 752 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 753 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 754 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 755 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 756 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 757 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 758 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 759 | main.log.error( self.name + ": Error in removing node" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 760 | main.log.error( handle ) |
| 761 | return main.FALSE |
| 762 | else: |
| 763 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 764 | except AssertionError: |
| 765 | main.log.exception( "" ) |
| 766 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 767 | except TypeError: |
| 768 | main.log.exception( self.name + ": Object not as expected" ) |
| 769 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 770 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 771 | main.log.error( self.name + ": EOF exception found" ) |
| 772 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 773 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 774 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 775 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 776 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 777 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 778 | def nodes( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 779 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 780 | List the nodes currently visible |
| 781 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 782 | Optional argument: |
| 783 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 784 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 785 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 786 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 787 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 788 | cmdStr += " -j" |
| 789 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 790 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 791 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 792 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 793 | except AssertionError: |
| 794 | main.log.exception( "" ) |
| 795 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 796 | except TypeError: |
| 797 | main.log.exception( self.name + ": Object not as expected" ) |
| 798 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 799 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 800 | main.log.error( self.name + ": EOF exception found" ) |
| 801 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 802 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 803 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 804 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 805 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 806 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 807 | def topology( self ): |
| 808 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 809 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 810 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 811 | Return: |
| 812 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 813 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 814 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 815 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 816 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 817 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 818 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 819 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 820 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 821 | except AssertionError: |
| 822 | main.log.exception( "" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 823 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 824 | except TypeError: |
| 825 | main.log.exception( self.name + ": Object not as expected" ) |
| 826 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 827 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 828 | main.log.error( self.name + ": EOF exception found" ) |
| 829 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 830 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 831 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 832 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 833 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 834 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 835 | def deviceRemove( self, deviceId ): |
| 836 | """ |
| 837 | Removes particular device from storage |
| 838 | |
| 839 | TODO: refactor this function |
| 840 | """ |
| 841 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 842 | cmdStr = "device-remove " + str( deviceId ) |
| 843 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 844 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 845 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 846 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 847 | main.log.error( self.name + ": Error in removing device" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 848 | main.log.error( handle ) |
| 849 | return main.FALSE |
| 850 | else: |
| 851 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 852 | except AssertionError: |
| 853 | main.log.exception( "" ) |
| 854 | return None |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 855 | except TypeError: |
| 856 | main.log.exception( self.name + ": Object not as expected" ) |
| 857 | return None |
| 858 | except pexpect.EOF: |
| 859 | main.log.error( self.name + ": EOF exception found" ) |
| 860 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 861 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 862 | except Exception: |
| 863 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 864 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 865 | |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 866 | def devices( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 867 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 868 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 869 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 870 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 871 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 872 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 873 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 874 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 875 | cmdStr += " -j" |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 876 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 877 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 878 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 879 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 880 | except AssertionError: |
| 881 | main.log.exception( "" ) |
| 882 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 883 | except TypeError: |
| 884 | main.log.exception( self.name + ": Object not as expected" ) |
| 885 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 886 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 887 | main.log.error( self.name + ": EOF exception found" ) |
| 888 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 889 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 890 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 891 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 892 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 893 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 894 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 895 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 896 | This balances the devices across all controllers |
| 897 | by issuing command: 'onos> onos:balance-masters' |
| 898 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 899 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 900 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 901 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 902 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 903 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 904 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 905 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 906 | main.log.error( self.name + ": Error in balancing masters" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 907 | main.log.error( handle ) |
| 908 | return main.FALSE |
| 909 | else: |
| 910 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 911 | except AssertionError: |
| 912 | main.log.exception( "" ) |
| 913 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 914 | except TypeError: |
| 915 | main.log.exception( self.name + ": Object not as expected" ) |
| 916 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 917 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 918 | main.log.error( self.name + ": EOF exception found" ) |
| 919 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 920 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 921 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 922 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 923 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 924 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 925 | def checkMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 926 | """ |
| 927 | Returns the output of the masters command. |
| 928 | Optional argument: |
| 929 | * jsonFormat - boolean indicating if you want output in json |
| 930 | """ |
| 931 | try: |
| 932 | cmdStr = "onos:masters" |
| 933 | if jsonFormat: |
| 934 | cmdStr += " -j" |
| 935 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 936 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 937 | assert "Command not found:" not in output, output |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 938 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 939 | except AssertionError: |
| 940 | main.log.exception( "" ) |
| 941 | return None |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 942 | except TypeError: |
| 943 | main.log.exception( self.name + ": Object not as expected" ) |
| 944 | return None |
| 945 | except pexpect.EOF: |
| 946 | main.log.error( self.name + ": EOF exception found" ) |
| 947 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 948 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 949 | except Exception: |
| 950 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 951 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 952 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 953 | def checkBalanceMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 954 | """ |
| 955 | Uses the master command to check that the devices' leadership |
| 956 | is evenly divided |
| 957 | |
| 958 | Dependencies: checkMasters() and summary() |
| 959 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 960 | Returns main.TRUE if the devices are balanced |
| 961 | Returns main.FALSE if the devices are unbalanced |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 962 | Exits on Exception |
| 963 | Returns None on TypeError |
| 964 | """ |
| 965 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 966 | summaryOutput = self.summary() |
| 967 | totalDevices = json.loads( summaryOutput )[ "devices" ] |
| 968 | except ( TypeError, ValueError ): |
| 969 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) ) |
| 970 | return None |
| 971 | try: |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 972 | totalOwnedDevices = 0 |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 973 | mastersOutput = self.checkMasters() |
| 974 | masters = json.loads( mastersOutput ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 975 | first = masters[ 0 ][ "size" ] |
| 976 | for master in masters: |
| 977 | totalOwnedDevices += master[ "size" ] |
| 978 | if master[ "size" ] > first + 1 or master[ "size" ] < first - 1: |
| 979 | main.log.error( "Mastership not balanced" ) |
| 980 | main.log.info( "\n" + self.checkMasters( False ) ) |
| 981 | return main.FALSE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 982 | main.log.info( "Mastership balanced between " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 983 | str( len( masters ) ) + " masters" ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 984 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 985 | except ( TypeError, ValueError ): |
| 986 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 987 | return None |
| 988 | except pexpect.EOF: |
| 989 | main.log.error( self.name + ": EOF exception found" ) |
| 990 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 991 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 992 | except Exception: |
| 993 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 994 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 995 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 996 | def links( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 997 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 998 | Lists all core links |
| 999 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1000 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1001 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1002 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1003 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1004 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1005 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1006 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1007 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1008 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1009 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1010 | except AssertionError: |
| 1011 | main.log.exception( "" ) |
| 1012 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1013 | except TypeError: |
| 1014 | main.log.exception( self.name + ": Object not as expected" ) |
| 1015 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1016 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1017 | main.log.error( self.name + ": EOF exception found" ) |
| 1018 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1019 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1020 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1021 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1022 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1023 | |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 1024 | def ports( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1025 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1026 | Lists all ports |
| 1027 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1028 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1029 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1030 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1031 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1032 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1033 | cmdStr += " -j" |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 1034 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1035 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1036 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1037 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1038 | except AssertionError: |
| 1039 | main.log.exception( "" ) |
| 1040 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1041 | except TypeError: |
| 1042 | main.log.exception( self.name + ": Object not as expected" ) |
| 1043 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1044 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1045 | main.log.error( self.name + ": EOF exception found" ) |
| 1046 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1047 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1048 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1049 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1050 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1051 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1052 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1053 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1054 | Lists all devices and the controllers with roles assigned to them |
| 1055 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1056 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1057 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1058 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1059 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1060 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1061 | cmdStr += " -j" |
| 1062 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1063 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1064 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1065 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1066 | except AssertionError: |
| 1067 | main.log.exception( "" ) |
| 1068 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1069 | except TypeError: |
| 1070 | main.log.exception( self.name + ": Object not as expected" ) |
| 1071 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1072 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1073 | main.log.error( self.name + ": EOF exception found" ) |
| 1074 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1075 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1076 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1077 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1078 | main.cleanAndExit() |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1079 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1080 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1081 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1082 | Given the a string containing the json representation of the "roles" |
| 1083 | cli command and a partial or whole device id, returns a json object |
| 1084 | containing the roles output for the first device whose id contains |
| 1085 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1086 | |
| 1087 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1088 | A dict of the role assignments for the given device or |
| 1089 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1090 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1091 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1092 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1093 | return None |
| 1094 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1095 | rawRoles = self.roles() |
| 1096 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1097 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1098 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1099 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1100 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1101 | return device |
| 1102 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1103 | except ( TypeError, ValueError ): |
| 1104 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1105 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 1106 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1107 | main.log.error( self.name + ": EOF exception found" ) |
| 1108 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1109 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1110 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1111 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1112 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1113 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1114 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1115 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1116 | Iterates through each device and checks if there is a master assigned |
| 1117 | Returns: main.TRUE if each device has a master |
| 1118 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1119 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1120 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1121 | rawRoles = self.roles() |
| 1122 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1123 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1124 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1125 | # print device |
| 1126 | if device[ 'master' ] == "none": |
| 1127 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1128 | return main.FALSE |
| 1129 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1130 | except ( TypeError, ValueError ): |
| 1131 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1132 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1133 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1134 | main.log.error( self.name + ": EOF exception found" ) |
| 1135 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1136 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1137 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1138 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1139 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1140 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1141 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1142 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1143 | Returns string of paths, and the cost. |
| 1144 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1145 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1146 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1147 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 1148 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1149 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1150 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1151 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1152 | main.log.error( self.name + ": Error in getting paths" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1153 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1154 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1155 | path = handle.split( ";" )[ 0 ] |
| 1156 | cost = handle.split( ";" )[ 1 ] |
| 1157 | return ( path, cost ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1158 | except AssertionError: |
| 1159 | main.log.exception( "" ) |
| 1160 | return ( handle, "Error" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1161 | except TypeError: |
| 1162 | main.log.exception( self.name + ": Object not as expected" ) |
| 1163 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1164 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1165 | main.log.error( self.name + ": EOF exception found" ) |
| 1166 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1167 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1168 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1169 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1170 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1171 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1172 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1173 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1174 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1175 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1176 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1177 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1178 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1179 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1180 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1181 | cmdStr += " -j" |
| 1182 | handle = self.sendline( cmdStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1183 | if handle: |
| 1184 | assert "Command not found:" not in handle, handle |
Jon Hall | baf5316 | 2015-12-17 17:04:34 -0800 | [diff] [blame] | 1185 | # TODO: Maybe make this less hardcoded |
| 1186 | # ConsistentMap Exceptions |
| 1187 | assert "org.onosproject.store.service" not in handle |
| 1188 | # Node not leader |
| 1189 | assert "java.lang.IllegalStateException" not in handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1190 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1191 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1192 | main.log.exception( self.name + ": Error in processing '" + cmdStr + "' " + |
Jeremy Songster | 6949cea | 2016-04-19 18:13:18 -0700 | [diff] [blame] | 1193 | "command: " + str( handle ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1194 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1195 | except TypeError: |
| 1196 | main.log.exception( self.name + ": Object not as expected" ) |
| 1197 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1198 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1199 | main.log.error( self.name + ": EOF exception found" ) |
| 1200 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1201 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1202 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1203 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1204 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1205 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1206 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1207 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1208 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1209 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1210 | 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] | 1211 | partial mac address |
| 1212 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1213 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1214 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1215 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1216 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1217 | return None |
| 1218 | else: |
| 1219 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1220 | rawHosts = self.hosts() |
| 1221 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1222 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1223 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1224 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1225 | if not host: |
| 1226 | pass |
| 1227 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1228 | return host |
| 1229 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1230 | except ( TypeError, ValueError ): |
| 1231 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1232 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1233 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1234 | main.log.error( self.name + ": EOF exception found" ) |
| 1235 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1236 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1237 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1238 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1239 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1240 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1241 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1242 | """ |
| 1243 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1244 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1245 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1246 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1247 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1248 | IMPORTANT: |
| 1249 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1250 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1251 | Furthermore, it assumes that value of VLAN is '-1' |
| 1252 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1253 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1254 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1255 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1256 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1257 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1258 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1259 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1260 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1261 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 1262 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 1263 | i = iter( str( hostHex ) ) |
| 1264 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 1265 | hostHex = hostHex + "/-1" |
| 1266 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1267 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1268 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1269 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1270 | except TypeError: |
| 1271 | main.log.exception( self.name + ": Object not as expected" ) |
| 1272 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1273 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1274 | main.log.error( self.name + ": EOF exception found" ) |
| 1275 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1276 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1277 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1278 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1279 | main.cleanAndExit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1280 | |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1281 | def verifyHostLocation( self, hostIp, location ): |
| 1282 | """ |
| 1283 | Description: |
| 1284 | Verify the host given is discovered in all locations expected |
| 1285 | Required: |
| 1286 | hostIp: IP address of the host |
| 1287 | location: expected location(s) of the given host. ex. "of:0000000000000005/8" |
| 1288 | Could be a string or list |
| 1289 | Returns: |
| 1290 | main.TRUE if host is discovered on all locations provided |
| 1291 | main.FALSE otherwise |
| 1292 | """ |
| 1293 | import json |
| 1294 | locations = [ location ] if isinstance( location, str ) else location |
| 1295 | assert isinstance( locations, list ), "Wrong type of location: {}".format( type( location ) ) |
| 1296 | try: |
| 1297 | hosts = self.hosts() |
| 1298 | hosts = json.loads( hosts ) |
| 1299 | targetHost = None |
| 1300 | for host in hosts: |
| 1301 | if hostIp in host[ "ipAddresses" ]: |
| 1302 | targetHost = host |
You Wang | fd80ab4 | 2018-05-10 17:21:53 -0700 | [diff] [blame] | 1303 | assert targetHost, "Not able to find host with IP {}".format( hostIp ) |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1304 | result = main.TRUE |
| 1305 | locationsDiscovered = [ loc[ "elementId" ] + "/" + loc[ "port" ] for loc in targetHost[ "locations" ] ] |
| 1306 | for loc in locations: |
| 1307 | discovered = False |
| 1308 | for locDiscovered in locationsDiscovered: |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1309 | locToMatch = locDiscovered if "/" in loc else locDiscovered.split( "/" )[0] |
| 1310 | if loc == locToMatch: |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1311 | main.log.debug( "Host {} discovered with location {}".format( hostIp, loc ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1312 | discovered = True |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1313 | break |
| 1314 | if discovered: |
| 1315 | locationsDiscovered.remove( locDiscovered ) |
| 1316 | else: |
| 1317 | main.log.warn( "Host {} not discovered with location {}".format( hostIp, loc ) ) |
| 1318 | result = main.FALSE |
| 1319 | if locationsDiscovered: |
| 1320 | main.log.warn( "Host {} is also discovered with location {}".format( hostIp, locationsDiscovered ) ) |
| 1321 | result = main.FALSE |
| 1322 | return result |
| 1323 | except KeyError: |
| 1324 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1325 | return None |
| 1326 | except pexpect.EOF: |
| 1327 | main.log.error( self.name + ": EOF exception found" ) |
| 1328 | main.log.error( self.name + ": " + self.handle.before ) |
| 1329 | main.cleanAndExit() |
| 1330 | except Exception: |
| 1331 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1332 | return None |
| 1333 | |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1334 | def verifyHostIp( self, hostList=[], prefix="" ): |
| 1335 | """ |
| 1336 | Description: |
| 1337 | Verify that all hosts have IP address assigned to them |
| 1338 | Optional: |
| 1339 | hostList: If specified, verifications only happen to the hosts |
| 1340 | in hostList |
| 1341 | prefix: at least one of the ip address assigned to the host |
| 1342 | needs to have the specified prefix |
| 1343 | Returns: |
| 1344 | main.TRUE if all hosts have specific IP address assigned; |
| 1345 | main.FALSE otherwise |
| 1346 | """ |
| 1347 | import json |
| 1348 | try: |
| 1349 | hosts = self.hosts() |
| 1350 | hosts = json.loads( hosts ) |
| 1351 | if not hostList: |
| 1352 | hostList = [ host[ "id" ] for host in hosts ] |
| 1353 | for host in hosts: |
| 1354 | hostId = host[ "id" ] |
| 1355 | if hostId not in hostList: |
| 1356 | continue |
| 1357 | ipList = host[ "ipAddresses" ] |
| 1358 | main.log.debug( self.name + ": IP list on host " + str( hostId ) + ": " + str( ipList ) ) |
| 1359 | if not ipList: |
| 1360 | main.log.warn( self.name + ": Failed to discover any IP addresses on host " + str( hostId ) ) |
| 1361 | else: |
| 1362 | if not any( ip.startswith( str( prefix ) ) for ip in ipList ): |
| 1363 | main.log.warn( self.name + ": None of the IPs on host " + str( hostId ) + " has prefix " + str( prefix ) ) |
| 1364 | else: |
| 1365 | main.log.debug( self.name + ": Found matching IP on host " + str( hostId ) ) |
| 1366 | hostList.remove( hostId ) |
| 1367 | if hostList: |
| 1368 | main.log.warn( self.name + ": failed to verify IP on following hosts: " + str( hostList) ) |
| 1369 | return main.FALSE |
| 1370 | else: |
| 1371 | return main.TRUE |
| 1372 | except KeyError: |
| 1373 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1374 | return None |
| 1375 | except pexpect.EOF: |
| 1376 | main.log.error( self.name + ": EOF exception found" ) |
| 1377 | main.log.error( self.name + ": " + self.handle.before ) |
| 1378 | main.cleanAndExit() |
| 1379 | except Exception: |
| 1380 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1381 | return None |
| 1382 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1383 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1384 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1385 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1386 | * hostIdOne: ONOS host id for host1 |
| 1387 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1388 | Optional: |
| 1389 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1390 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1391 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1392 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1393 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1394 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1395 | Returns: |
| 1396 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1397 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1398 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1399 | cmdStr = "add-host-intent " |
| 1400 | if vlanId: |
| 1401 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1402 | if setVlan: |
| 1403 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1404 | if encap: |
| 1405 | cmdStr += "--encapsulation " + str( encap ) + " " |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1406 | if bandwidth: |
| 1407 | cmdStr += "-b " + str( bandwidth ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1408 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1409 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1410 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1411 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1412 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1413 | main.log.error( self.name + ": Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1414 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1415 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1416 | else: |
| 1417 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1418 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1419 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1420 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1421 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1422 | else: |
| 1423 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1424 | main.log.debug( "Response from ONOS was: " + |
| 1425 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1426 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1427 | except AssertionError: |
| 1428 | main.log.exception( "" ) |
| 1429 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1430 | except TypeError: |
| 1431 | main.log.exception( self.name + ": Object not as expected" ) |
| 1432 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1433 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1434 | main.log.error( self.name + ": EOF exception found" ) |
| 1435 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1436 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1437 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1438 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1439 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1440 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1441 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1442 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1443 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1444 | * ingressDevice: device id of ingress device |
| 1445 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1446 | Optional: |
| 1447 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1448 | Description: |
| 1449 | Adds an optical intent by specifying an ingress and egress device |
| 1450 | Returns: |
| 1451 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1452 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1453 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1454 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1455 | " " + str( egressDevice ) |
| 1456 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1457 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1458 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1459 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1460 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1461 | main.log.error( self.name + ": Error in adding Optical intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1462 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1463 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1464 | main.log.info( "Optical intent installed between " + |
| 1465 | str( ingressDevice ) + " and " + |
| 1466 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1467 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1468 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1469 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1470 | else: |
| 1471 | main.log.error( "Error, intent ID not found" ) |
| 1472 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1473 | except AssertionError: |
| 1474 | main.log.exception( "" ) |
| 1475 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1476 | except TypeError: |
| 1477 | main.log.exception( self.name + ": Object not as expected" ) |
| 1478 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1479 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1480 | main.log.error( self.name + ": EOF exception found" ) |
| 1481 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1482 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1483 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1484 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1485 | main.cleanAndExit() |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1486 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1487 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1488 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1489 | ingressDevice, |
| 1490 | egressDevice, |
| 1491 | portIngress="", |
| 1492 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1493 | ethType="", |
| 1494 | ethSrc="", |
| 1495 | ethDst="", |
| 1496 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1497 | lambdaAlloc=False, |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1498 | protected=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1499 | ipProto="", |
| 1500 | ipSrc="", |
| 1501 | ipDst="", |
| 1502 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1503 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1504 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1505 | setVlan="", |
| 1506 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1507 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1508 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1509 | * ingressDevice: device id of ingress device |
| 1510 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1511 | Optional: |
| 1512 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1513 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1514 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1515 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1516 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1517 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1518 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1519 | * ipSrc: specify ip source address |
| 1520 | * ipDst: specify ip destination address |
| 1521 | * tcpSrc: specify tcp source port |
| 1522 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1523 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1524 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1525 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1526 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1527 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1528 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1529 | Returns: |
| 1530 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1531 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1532 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1533 | options developers provide for point-to-point |
| 1534 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1535 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1536 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1537 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1538 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1539 | if ethType: |
| 1540 | cmd += " --ethType " + str( ethType ) |
| 1541 | if ethSrc: |
| 1542 | cmd += " --ethSrc " + str( ethSrc ) |
| 1543 | if ethDst: |
| 1544 | cmd += " --ethDst " + str( ethDst ) |
| 1545 | if bandwidth: |
| 1546 | cmd += " --bandwidth " + str( bandwidth ) |
| 1547 | if lambdaAlloc: |
| 1548 | cmd += " --lambda " |
| 1549 | if ipProto: |
| 1550 | cmd += " --ipProto " + str( ipProto ) |
| 1551 | if ipSrc: |
| 1552 | cmd += " --ipSrc " + str( ipSrc ) |
| 1553 | if ipDst: |
| 1554 | cmd += " --ipDst " + str( ipDst ) |
| 1555 | if tcpSrc: |
| 1556 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1557 | if tcpDst: |
| 1558 | cmd += " --tcpDst " + str( tcpDst ) |
| 1559 | if vlanId: |
| 1560 | cmd += " -v " + str( vlanId ) |
| 1561 | if setVlan: |
| 1562 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1563 | if encap: |
| 1564 | cmd += " --encapsulation " + str( encap ) |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1565 | if protected: |
| 1566 | cmd += " --protect " |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1567 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1568 | # Check whether the user appended the port |
| 1569 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1570 | if "/" in ingressDevice: |
| 1571 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1572 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1573 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1574 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1575 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1576 | # Would it make sense to throw an exception and exit |
| 1577 | # the test? |
| 1578 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1579 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1580 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1581 | str( ingressDevice ) + "/" +\ |
| 1582 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1583 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1584 | if "/" in egressDevice: |
| 1585 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1586 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1587 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1588 | main.log.error( "You must specify the egress port" ) |
| 1589 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1590 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1591 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1592 | str( egressDevice ) + "/" +\ |
| 1593 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1594 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1595 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1596 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1597 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1598 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1599 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1600 | main.log.error( self.name + ": Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1601 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1602 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1603 | # TODO: print out all the options in this message? |
| 1604 | main.log.info( "Point-to-point intent installed between " + |
| 1605 | str( ingressDevice ) + " and " + |
| 1606 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1607 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1608 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1609 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1610 | else: |
| 1611 | main.log.error( "Error, intent ID not found" ) |
| 1612 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1613 | except AssertionError: |
| 1614 | main.log.exception( "" ) |
| 1615 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1616 | except TypeError: |
| 1617 | main.log.exception( self.name + ": Object not as expected" ) |
| 1618 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1619 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1620 | main.log.error( self.name + ": EOF exception found" ) |
| 1621 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1622 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1623 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1624 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1625 | main.cleanAndExit() |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1626 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1627 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1628 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1629 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1630 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1631 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1632 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1633 | ethType="", |
| 1634 | ethSrc="", |
| 1635 | ethDst="", |
| 1636 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1637 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1638 | ipProto="", |
| 1639 | ipSrc="", |
| 1640 | ipDst="", |
| 1641 | tcpSrc="", |
| 1642 | tcpDst="", |
| 1643 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1644 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1645 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1646 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1647 | partial=False, |
| 1648 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1649 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1650 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1651 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1652 | is same. That is, all ingress devices include port numbers |
| 1653 | with a "/" or all ingress devices could specify device |
| 1654 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1655 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1656 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1657 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1658 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1659 | Optional: |
| 1660 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1661 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1662 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1663 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1664 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1665 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1666 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1667 | * ipSrc: specify ip source address |
| 1668 | * ipDst: specify ip destination address |
| 1669 | * tcpSrc: specify tcp source port |
| 1670 | * tcpDst: specify tcp destination port |
| 1671 | * setEthSrc: action to Rewrite Source MAC Address |
| 1672 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1673 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1674 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1675 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1676 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1677 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1678 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1679 | Returns: |
| 1680 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1681 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1682 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1683 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1684 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1685 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1686 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1687 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1688 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1689 | if ethType: |
| 1690 | cmd += " --ethType " + str( ethType ) |
| 1691 | if ethSrc: |
| 1692 | cmd += " --ethSrc " + str( ethSrc ) |
| 1693 | if ethDst: |
| 1694 | cmd += " --ethDst " + str( ethDst ) |
| 1695 | if bandwidth: |
| 1696 | cmd += " --bandwidth " + str( bandwidth ) |
| 1697 | if lambdaAlloc: |
| 1698 | cmd += " --lambda " |
| 1699 | if ipProto: |
| 1700 | cmd += " --ipProto " + str( ipProto ) |
| 1701 | if ipSrc: |
| 1702 | cmd += " --ipSrc " + str( ipSrc ) |
| 1703 | if ipDst: |
| 1704 | cmd += " --ipDst " + str( ipDst ) |
| 1705 | if tcpSrc: |
| 1706 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1707 | if tcpDst: |
| 1708 | cmd += " --tcpDst " + str( tcpDst ) |
| 1709 | if setEthSrc: |
| 1710 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1711 | if setEthDst: |
| 1712 | cmd += " --setEthDst " + str( setEthDst ) |
| 1713 | if vlanId: |
| 1714 | cmd += " -v " + str( vlanId ) |
| 1715 | if setVlan: |
| 1716 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1717 | if partial: |
| 1718 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1719 | if encap: |
| 1720 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1721 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1722 | # Check whether the user appended the port |
| 1723 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1724 | |
| 1725 | if portIngressList is None: |
| 1726 | for ingressDevice in ingressDeviceList: |
| 1727 | if "/" in ingressDevice: |
| 1728 | cmd += " " + str( ingressDevice ) |
| 1729 | else: |
| 1730 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1731 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1732 | # TODO: perhaps more meaningful return |
| 1733 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1734 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1735 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1736 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1737 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1738 | cmd += " " + \ |
| 1739 | str( ingressDevice ) + "/" +\ |
| 1740 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1741 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1742 | main.log.error( "Device list and port list does not " + |
| 1743 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1744 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1745 | if "/" in egressDevice: |
| 1746 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1747 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1748 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1749 | main.log.error( "You must specify " + |
| 1750 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1751 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1752 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1753 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1754 | str( egressDevice ) + "/" +\ |
| 1755 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1756 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1757 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1758 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1759 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1760 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1761 | main.log.error( self.name + ": Error in adding multipoint-to-singlepoint " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1762 | "intent" ) |
| 1763 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1764 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1765 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1766 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1767 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1768 | else: |
| 1769 | main.log.error( "Error, intent ID not found" ) |
| 1770 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1771 | except AssertionError: |
| 1772 | main.log.exception( "" ) |
| 1773 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1774 | except TypeError: |
| 1775 | main.log.exception( self.name + ": Object not as expected" ) |
| 1776 | return None |
| 1777 | except pexpect.EOF: |
| 1778 | main.log.error( self.name + ": EOF exception found" ) |
| 1779 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1780 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1781 | except Exception: |
| 1782 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1783 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1784 | |
| 1785 | def addSinglepointToMultipointIntent( |
| 1786 | self, |
| 1787 | ingressDevice, |
| 1788 | egressDeviceList, |
| 1789 | portIngress="", |
| 1790 | portEgressList=None, |
| 1791 | ethType="", |
| 1792 | ethSrc="", |
| 1793 | ethDst="", |
| 1794 | bandwidth="", |
| 1795 | lambdaAlloc=False, |
| 1796 | ipProto="", |
| 1797 | ipSrc="", |
| 1798 | ipDst="", |
| 1799 | tcpSrc="", |
| 1800 | tcpDst="", |
| 1801 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1802 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1803 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1804 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1805 | partial=False, |
| 1806 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1807 | """ |
| 1808 | Note: |
| 1809 | This function assumes the format of all egress devices |
| 1810 | is same. That is, all egress devices include port numbers |
| 1811 | with a "/" or all egress devices could specify device |
| 1812 | ids and port numbers seperately. |
| 1813 | Required: |
| 1814 | * EgressDeviceList: List of device ids of egress device |
| 1815 | ( Atleast 2 eress devices required in the list ) |
| 1816 | * ingressDevice: device id of ingress device |
| 1817 | Optional: |
| 1818 | * ethType: specify ethType |
| 1819 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1820 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1821 | * bandwidth: specify bandwidth capacity of link |
| 1822 | * lambdaAlloc: if True, intent will allocate lambda |
| 1823 | for the specified intent |
| 1824 | * ipProto: specify ip protocol |
| 1825 | * ipSrc: specify ip source address |
| 1826 | * ipDst: specify ip destination address |
| 1827 | * tcpSrc: specify tcp source port |
| 1828 | * tcpDst: specify tcp destination port |
| 1829 | * setEthSrc: action to Rewrite Source MAC Address |
| 1830 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1831 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1832 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1833 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1834 | Description: |
| 1835 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1836 | specifying device id's and optional fields |
| 1837 | Returns: |
| 1838 | A string of the intent id or None on error |
| 1839 | |
| 1840 | NOTE: This function may change depending on the |
| 1841 | options developers provide for singlepoint-to-multipoint |
| 1842 | intent via cli |
| 1843 | """ |
| 1844 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1845 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1846 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1847 | if ethType: |
| 1848 | cmd += " --ethType " + str( ethType ) |
| 1849 | if ethSrc: |
| 1850 | cmd += " --ethSrc " + str( ethSrc ) |
| 1851 | if ethDst: |
| 1852 | cmd += " --ethDst " + str( ethDst ) |
| 1853 | if bandwidth: |
| 1854 | cmd += " --bandwidth " + str( bandwidth ) |
| 1855 | if lambdaAlloc: |
| 1856 | cmd += " --lambda " |
| 1857 | if ipProto: |
| 1858 | cmd += " --ipProto " + str( ipProto ) |
| 1859 | if ipSrc: |
| 1860 | cmd += " --ipSrc " + str( ipSrc ) |
| 1861 | if ipDst: |
| 1862 | cmd += " --ipDst " + str( ipDst ) |
| 1863 | if tcpSrc: |
| 1864 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1865 | if tcpDst: |
| 1866 | cmd += " --tcpDst " + str( tcpDst ) |
| 1867 | if setEthSrc: |
| 1868 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1869 | if setEthDst: |
| 1870 | cmd += " --setEthDst " + str( setEthDst ) |
| 1871 | if vlanId: |
| 1872 | cmd += " -v " + str( vlanId ) |
| 1873 | if setVlan: |
| 1874 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1875 | if partial: |
| 1876 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1877 | if encap: |
| 1878 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1879 | |
| 1880 | # Check whether the user appended the port |
| 1881 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1882 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1883 | if "/" in ingressDevice: |
| 1884 | cmd += " " + str( ingressDevice ) |
| 1885 | else: |
| 1886 | if not portIngress: |
| 1887 | main.log.error( "You must specify " + |
| 1888 | "the Ingress port" ) |
| 1889 | return main.FALSE |
| 1890 | |
| 1891 | cmd += " " +\ |
| 1892 | str( ingressDevice ) + "/" +\ |
| 1893 | str( portIngress ) |
| 1894 | |
| 1895 | if portEgressList is None: |
| 1896 | for egressDevice in egressDeviceList: |
| 1897 | if "/" in egressDevice: |
| 1898 | cmd += " " + str( egressDevice ) |
| 1899 | else: |
| 1900 | main.log.error( "You must specify " + |
| 1901 | "the egress port" ) |
| 1902 | # TODO: perhaps more meaningful return |
| 1903 | return main.FALSE |
| 1904 | else: |
| 1905 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1906 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1907 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1908 | cmd += " " + \ |
| 1909 | str( egressDevice ) + "/" +\ |
| 1910 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1911 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1912 | main.log.error( "Device list and port list does not " + |
| 1913 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1914 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1915 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1916 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1917 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1918 | # If error, return error message |
| 1919 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1920 | main.log.error( self.name + ": Error in adding singlepoint-to-multipoint " + |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1921 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1922 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1923 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1924 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1925 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1926 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1927 | else: |
| 1928 | main.log.error( "Error, intent ID not found" ) |
| 1929 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1930 | except AssertionError: |
| 1931 | main.log.exception( "" ) |
| 1932 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1933 | except TypeError: |
| 1934 | main.log.exception( self.name + ": Object not as expected" ) |
| 1935 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1936 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1937 | main.log.error( self.name + ": EOF exception found" ) |
| 1938 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1939 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1940 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1941 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1942 | main.cleanAndExit() |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1943 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1944 | def addMplsIntent( |
| 1945 | self, |
| 1946 | ingressDevice, |
| 1947 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1948 | ingressPort="", |
| 1949 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1950 | ethType="", |
| 1951 | ethSrc="", |
| 1952 | ethDst="", |
| 1953 | bandwidth="", |
| 1954 | lambdaAlloc=False, |
| 1955 | ipProto="", |
| 1956 | ipSrc="", |
| 1957 | ipDst="", |
| 1958 | tcpSrc="", |
| 1959 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1960 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1961 | egressLabel="", |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1962 | priority="" ): |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1963 | """ |
| 1964 | Required: |
| 1965 | * ingressDevice: device id of ingress device |
| 1966 | * egressDevice: device id of egress device |
| 1967 | Optional: |
| 1968 | * ethType: specify ethType |
| 1969 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1970 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1971 | * bandwidth: specify bandwidth capacity of link |
| 1972 | * lambdaAlloc: if True, intent will allocate lambda |
| 1973 | for the specified intent |
| 1974 | * ipProto: specify ip protocol |
| 1975 | * ipSrc: specify ip source address |
| 1976 | * ipDst: specify ip destination address |
| 1977 | * tcpSrc: specify tcp source port |
| 1978 | * tcpDst: specify tcp destination port |
| 1979 | * ingressLabel: Ingress MPLS label |
| 1980 | * egressLabel: Egress MPLS label |
| 1981 | Description: |
| 1982 | Adds MPLS intent by |
| 1983 | specifying device id's and optional fields |
| 1984 | Returns: |
| 1985 | A string of the intent id or None on error |
| 1986 | |
| 1987 | NOTE: This function may change depending on the |
| 1988 | options developers provide for MPLS |
| 1989 | intent via cli |
| 1990 | """ |
| 1991 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1992 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1993 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1994 | if ethType: |
| 1995 | cmd += " --ethType " + str( ethType ) |
| 1996 | if ethSrc: |
| 1997 | cmd += " --ethSrc " + str( ethSrc ) |
| 1998 | if ethDst: |
| 1999 | cmd += " --ethDst " + str( ethDst ) |
| 2000 | if bandwidth: |
| 2001 | cmd += " --bandwidth " + str( bandwidth ) |
| 2002 | if lambdaAlloc: |
| 2003 | cmd += " --lambda " |
| 2004 | if ipProto: |
| 2005 | cmd += " --ipProto " + str( ipProto ) |
| 2006 | if ipSrc: |
| 2007 | cmd += " --ipSrc " + str( ipSrc ) |
| 2008 | if ipDst: |
| 2009 | cmd += " --ipDst " + str( ipDst ) |
| 2010 | if tcpSrc: |
| 2011 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 2012 | if tcpDst: |
| 2013 | cmd += " --tcpDst " + str( tcpDst ) |
| 2014 | if ingressLabel: |
| 2015 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 2016 | if egressLabel: |
| 2017 | cmd += " --egressLabel " + str( egressLabel ) |
| 2018 | if priority: |
| 2019 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2020 | |
| 2021 | # Check whether the user appended the port |
| 2022 | # or provided it as an input |
| 2023 | if "/" in ingressDevice: |
| 2024 | cmd += " " + str( ingressDevice ) |
| 2025 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2026 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2027 | main.log.error( "You must specify the ingress port" ) |
| 2028 | return None |
| 2029 | |
| 2030 | cmd += " " + \ |
| 2031 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2032 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2033 | |
| 2034 | if "/" in egressDevice: |
| 2035 | cmd += " " + str( egressDevice ) |
| 2036 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2037 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2038 | main.log.error( "You must specify the egress port" ) |
| 2039 | return None |
| 2040 | |
| 2041 | cmd += " " +\ |
| 2042 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2043 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2044 | |
| 2045 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2046 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2047 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2048 | # If error, return error message |
| 2049 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2050 | main.log.error( self.name + ": Error in adding mpls intent" ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2051 | return None |
| 2052 | else: |
| 2053 | # TODO: print out all the options in this message? |
| 2054 | main.log.info( "MPLS intent installed between " + |
| 2055 | str( ingressDevice ) + " and " + |
| 2056 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2057 | match = re.search( 'id=0x([\da-f]+),', handle ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2058 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2059 | return match.group()[ 3:-1 ] |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2060 | else: |
| 2061 | main.log.error( "Error, intent ID not found" ) |
| 2062 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2063 | except AssertionError: |
| 2064 | main.log.exception( "" ) |
| 2065 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2066 | except TypeError: |
| 2067 | main.log.exception( self.name + ": Object not as expected" ) |
| 2068 | return None |
| 2069 | except pexpect.EOF: |
| 2070 | main.log.error( self.name + ": EOF exception found" ) |
| 2071 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2072 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2073 | except Exception: |
| 2074 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2075 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2076 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2077 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 2078 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2079 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2080 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2081 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2082 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2083 | -p or --purge: Purge the intent from the store after removal |
| 2084 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2085 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 2086 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2087 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2088 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2089 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2090 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2091 | if purge: |
| 2092 | cmdStr += " -p" |
| 2093 | if sync: |
| 2094 | cmdStr += " -s" |
| 2095 | |
| 2096 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2097 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2098 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2099 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2100 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2101 | main.log.error( self.name + ": Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2102 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2103 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2104 | # TODO: Should this be main.TRUE |
| 2105 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2106 | except AssertionError: |
| 2107 | main.log.exception( "" ) |
| 2108 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2109 | except TypeError: |
| 2110 | main.log.exception( self.name + ": Object not as expected" ) |
| 2111 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2112 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2113 | main.log.error( self.name + ": EOF exception found" ) |
| 2114 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2115 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2116 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2117 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2118 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2119 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2120 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2121 | """ |
| 2122 | Description: |
| 2123 | Remove all the intents |
| 2124 | Optional args:- |
| 2125 | -s or --sync: Waits for the removal before returning |
| 2126 | -p or --purge: Purge the intent from the store after removal |
| 2127 | Returns: |
| 2128 | Returns main.TRUE if all intents are removed, otherwise returns |
| 2129 | main.FALSE; Returns None for exception |
| 2130 | """ |
| 2131 | try: |
| 2132 | cmdStr = "remove-intent" |
| 2133 | if purge: |
| 2134 | cmdStr += " -p" |
| 2135 | if sync: |
| 2136 | cmdStr += " -s" |
| 2137 | |
| 2138 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2139 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2140 | assert handle is not None, "Error in sendline" |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2141 | assert "Command not found:" not in handle, handle |
| 2142 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2143 | main.log.error( self.name + ": Error in removing intent" ) |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2144 | return main.FALSE |
| 2145 | else: |
| 2146 | return main.TRUE |
| 2147 | except AssertionError: |
| 2148 | main.log.exception( "" ) |
| 2149 | return None |
| 2150 | except TypeError: |
| 2151 | main.log.exception( self.name + ": Object not as expected" ) |
| 2152 | return None |
| 2153 | except pexpect.EOF: |
| 2154 | main.log.error( self.name + ": EOF exception found" ) |
| 2155 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2156 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2157 | except Exception: |
| 2158 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2159 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2160 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 2161 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2162 | """ |
| 2163 | Purges all WITHDRAWN Intents |
| 2164 | """ |
| 2165 | try: |
| 2166 | cmdStr = "purge-intents" |
| 2167 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2168 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2169 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2170 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2171 | main.log.error( self.name + ": Error in purging intents" ) |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2172 | return main.FALSE |
| 2173 | else: |
| 2174 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2175 | except AssertionError: |
| 2176 | main.log.exception( "" ) |
| 2177 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2178 | except TypeError: |
| 2179 | main.log.exception( self.name + ": Object not as expected" ) |
| 2180 | return None |
| 2181 | except pexpect.EOF: |
| 2182 | main.log.error( self.name + ": EOF exception found" ) |
| 2183 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2184 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2185 | except Exception: |
| 2186 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2187 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2188 | |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 2189 | def wipeout( self ): |
| 2190 | """ |
| 2191 | Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS. |
| 2192 | """ |
| 2193 | try: |
| 2194 | cmdStr = "wipe-out please" |
| 2195 | handle = self.sendline( cmdStr, timeout=60 ) |
| 2196 | assert handle is not None, "Error in sendline" |
| 2197 | assert "Command not found:" not in handle, handle |
| 2198 | return main.TRUE |
| 2199 | except AssertionError: |
| 2200 | main.log.exception( "" ) |
| 2201 | return None |
| 2202 | except TypeError: |
| 2203 | main.log.exception( self.name + ": Object not as expected" ) |
| 2204 | return None |
| 2205 | except pexpect.EOF: |
| 2206 | main.log.error( self.name + ": EOF exception found" ) |
| 2207 | main.log.error( self.name + ": " + self.handle.before ) |
| 2208 | main.cleanAndExit() |
| 2209 | except Exception: |
| 2210 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2211 | main.cleanAndExit() |
| 2212 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2213 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2214 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2215 | NOTE: This method should be used after installing application: |
| 2216 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2217 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2218 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2219 | Description: |
| 2220 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2221 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2222 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2223 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2224 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2225 | cmdStr += " -j" |
| 2226 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2227 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2228 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2229 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2230 | except AssertionError: |
| 2231 | main.log.exception( "" ) |
| 2232 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2233 | except TypeError: |
| 2234 | main.log.exception( self.name + ": Object not as expected" ) |
| 2235 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2236 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2237 | main.log.error( self.name + ": EOF exception found" ) |
| 2238 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2239 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2240 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2241 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2242 | main.cleanAndExit() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2243 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2244 | def ipv4RouteNumber( self ): |
| 2245 | """ |
| 2246 | NOTE: This method should be used after installing application: |
| 2247 | onos-app-sdnip |
| 2248 | Description: |
| 2249 | Obtain the total IPv4 routes number in the system |
| 2250 | """ |
| 2251 | try: |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2252 | cmdStr = "routes -j" |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2253 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2254 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2255 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2256 | jsonResult = json.loads( handle ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2257 | return len( jsonResult[ 'routes4' ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2258 | except AssertionError: |
| 2259 | main.log.exception( "" ) |
| 2260 | return None |
| 2261 | except ( TypeError, ValueError ): |
| 2262 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2263 | return None |
| 2264 | except pexpect.EOF: |
| 2265 | main.log.error( self.name + ": EOF exception found" ) |
| 2266 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2267 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2268 | except Exception: |
| 2269 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2270 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2271 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2272 | # =============Function to check Bandwidth allocation======== |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2273 | def allocations( self, jsonFormat = True ): |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2274 | """ |
| 2275 | Description: |
| 2276 | Obtain Bandwidth Allocation Information from ONOS cli. |
| 2277 | """ |
| 2278 | try: |
| 2279 | cmdStr = "allocations" |
| 2280 | if jsonFormat: |
| 2281 | cmdStr += " -j" |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2282 | handle = self.sendline( cmdStr, timeout=300 ) |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2283 | assert handle is not None, "Error in sendline" |
| 2284 | assert "Command not found:" not in handle, handle |
| 2285 | return handle |
| 2286 | except AssertionError: |
| 2287 | main.log.exception( "" ) |
| 2288 | return None |
| 2289 | except ( TypeError, ValueError ): |
| 2290 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
| 2291 | return None |
| 2292 | except pexpect.EOF: |
| 2293 | main.log.error( self.name + ": EOF exception found" ) |
| 2294 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2295 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2296 | except Exception: |
| 2297 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2298 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2299 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2300 | def intents( self, jsonFormat = True, summary = False, **intentargs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2301 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2302 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2303 | Obtain intents from the ONOS cli. |
| 2304 | Optional: |
| 2305 | * jsonFormat: Enable output formatting in json, default to True |
| 2306 | * summary: Whether only output the intent summary, defaults to False |
| 2307 | * type: Only output a certain type of intent. This options is valid |
| 2308 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2309 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2310 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2311 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2312 | if summary: |
| 2313 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2314 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2315 | cmdStr += " -j" |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2316 | handle = self.sendline( cmdStr, timeout=300 ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2317 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2318 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2319 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2320 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2321 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2322 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2323 | intentType = "" |
| 2324 | # IF we want the summary of a specific intent type |
| 2325 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2326 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2327 | if intentType in jsonResult.keys(): |
| 2328 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2329 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2330 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2331 | return handle |
| 2332 | else: |
| 2333 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2334 | except AssertionError: |
| 2335 | main.log.exception( "" ) |
| 2336 | return None |
| 2337 | except ( TypeError, ValueError ): |
| 2338 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2339 | return None |
| 2340 | except pexpect.EOF: |
| 2341 | main.log.error( self.name + ": EOF exception found" ) |
| 2342 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2343 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2344 | except Exception: |
| 2345 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2346 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2347 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2348 | def getIntentState( self, intentsId, intentsJson=None ): |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2349 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2350 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2351 | Gets intent state. Accepts a single intent ID (string type) or a |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2352 | list of intent IDs. |
| 2353 | Parameters: |
| 2354 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2355 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2356 | Returns: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2357 | 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] | 2358 | accepted. |
| 2359 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2360 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2361 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2362 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2363 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2364 | try: |
| 2365 | state = "State is Undefined" |
| 2366 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2367 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2368 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2369 | rawJson = intentsJson |
| 2370 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2371 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2372 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2373 | if intentsId == intent[ 'id' ]: |
| 2374 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2375 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2376 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2377 | " in the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2378 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2379 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2380 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2381 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2382 | stateDict = {} |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2383 | for intent in parsedIntentsJson: |
| 2384 | if intentsId[ i ] == intent[ 'id' ]: |
| 2385 | stateDict[ 'state' ] = intent[ 'state' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2386 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2387 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2388 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2389 | if len( intentsId ) != len( dictList ): |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2390 | main.log.warn( "Could not find all intents in ONOS output" ) |
| 2391 | main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2392 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2393 | else: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2394 | main.log.info( "Invalid type for intentsId argument" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2395 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2396 | except ( TypeError, ValueError ): |
| 2397 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2398 | return None |
| 2399 | except pexpect.EOF: |
| 2400 | main.log.error( self.name + ": EOF exception found" ) |
| 2401 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2402 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2403 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2404 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2405 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2406 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2407 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2408 | """ |
| 2409 | Description: |
| 2410 | Check intents state |
| 2411 | Required: |
| 2412 | intentsId - List of intents ID to be checked |
| 2413 | Optional: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2414 | expectedState - Check the expected state(s) of each intents |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2415 | state in the list. |
| 2416 | *NOTE: You can pass in a list of expected state, |
| 2417 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2418 | Return: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2419 | Returns main.TRUE only if all intent are the same as expected states, |
| 2420 | otherwise returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2421 | """ |
| 2422 | try: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2423 | returnValue = main.TRUE |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2424 | # Generating a dictionary: intent id as a key and state as value |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2425 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2426 | # intentsDict = self.getIntentState( intentsId ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2427 | intentsDict = [] |
| 2428 | for intent in json.loads( self.intents() ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2429 | if isinstance( intentsId, types.StringType ) \ |
| 2430 | and intent.get( 'id' ) == intentsId: |
| 2431 | intentsDict.append( intent ) |
| 2432 | elif isinstance( intentsId, types.ListType ) \ |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2433 | and any( intent.get( 'id' ) == ids for ids in intentsId ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2434 | intentsDict.append( intent ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2435 | |
| 2436 | if not intentsDict: |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2437 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2438 | "getting intents state" ) |
| 2439 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2440 | |
| 2441 | if isinstance( expectedState, types.StringType ): |
| 2442 | for intents in intentsDict: |
| 2443 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2444 | main.log.debug( self.name + " : Intent ID - " + |
| 2445 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2446 | " actual state = " + |
| 2447 | intents.get( 'state' ) |
| 2448 | + " does not equal expected state = " |
| 2449 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2450 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2451 | elif isinstance( expectedState, types.ListType ): |
| 2452 | for intents in intentsDict: |
| 2453 | if not any( state == intents.get( 'state' ) for state in |
| 2454 | expectedState ): |
| 2455 | main.log.debug( self.name + " : Intent ID - " + |
| 2456 | intents.get( 'id' ) + |
| 2457 | " actual state = " + |
| 2458 | intents.get( 'state' ) + |
| 2459 | " does not equal expected states = " |
| 2460 | + str( expectedState ) ) |
| 2461 | returnValue = main.FALSE |
| 2462 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2463 | if returnValue == main.TRUE: |
| 2464 | main.log.info( self.name + ": All " + |
| 2465 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2466 | " intents are in " + str( expectedState ) + |
| 2467 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2468 | return returnValue |
| 2469 | except TypeError: |
| 2470 | main.log.exception( self.name + ": Object not as expected" ) |
| 2471 | return None |
| 2472 | except pexpect.EOF: |
| 2473 | main.log.error( self.name + ": EOF exception found" ) |
| 2474 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2475 | main.cleanAndExit() |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2476 | except Exception: |
| 2477 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2478 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2479 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2480 | def compareBandwidthAllocations( self, expectedAllocations ): |
| 2481 | """ |
| 2482 | Description: |
| 2483 | Compare the allocated bandwidth with the given allocations |
| 2484 | Required: |
| 2485 | expectedAllocations - The expected ONOS output of the allocations command |
| 2486 | Return: |
| 2487 | Returns main.TRUE only if all intent are the same as expected states, |
| 2488 | otherwise returns main.FALSE. |
| 2489 | """ |
| 2490 | # FIXME: Convert these string comparisons to object comparisons |
| 2491 | try: |
| 2492 | returnValue = main.TRUE |
| 2493 | bandwidthFailed = False |
| 2494 | rawAlloc = self.allocations() |
| 2495 | expectedFormat = StringIO( expectedAllocations ) |
| 2496 | ONOSOutput = StringIO( rawAlloc ) |
| 2497 | main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ), |
| 2498 | str( expectedFormat ) ) ) |
| 2499 | |
| 2500 | for actual, expected in izip( ONOSOutput, expectedFormat ): |
| 2501 | actual = actual.rstrip() |
| 2502 | expected = expected.rstrip() |
| 2503 | main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) ) |
| 2504 | if actual != expected and 'allocated' in actual and 'allocated' in expected: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2505 | marker1 = actual.find( 'allocated' ) |
| 2506 | m1 = actual[ :marker1 ] |
| 2507 | marker2 = expected.find( 'allocated' ) |
| 2508 | m2 = expected[ :marker2 ] |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2509 | if m1 != m2: |
| 2510 | bandwidthFailed = True |
| 2511 | elif actual != expected and 'allocated' not in actual and 'allocated' not in expected: |
| 2512 | bandwidthFailed = True |
| 2513 | expectedFormat.close() |
| 2514 | ONOSOutput.close() |
| 2515 | |
| 2516 | if bandwidthFailed: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2517 | main.log.error( "Bandwidth not allocated correctly using Intents!!" ) |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2518 | returnValue = main.FALSE |
| 2519 | return returnValue |
| 2520 | except TypeError: |
| 2521 | main.log.exception( self.name + ": Object not as expected" ) |
| 2522 | return None |
| 2523 | except pexpect.EOF: |
| 2524 | main.log.error( self.name + ": EOF exception found" ) |
| 2525 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2526 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2527 | except Exception: |
| 2528 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2529 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2530 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2531 | def compareIntent( self, intentDict ): |
| 2532 | """ |
| 2533 | Description: |
| 2534 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2535 | Return: |
| 2536 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2537 | Arguments: |
| 2538 | intentDict: a dictionary which maps intent ids to intent states |
| 2539 | """ |
| 2540 | try: |
| 2541 | intentsRaw = self.intents() |
| 2542 | intentsJson = json.loads( intentsRaw ) |
| 2543 | intentDictONOS = {} |
| 2544 | for intent in intentsJson: |
| 2545 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2546 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2547 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2548 | 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] | 2549 | str( len( intentDict ) ) + " expected and " + |
| 2550 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2551 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2552 | for intentID in intentDict.keys(): |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2553 | if intentID not in intentDictONOS.keys(): |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2554 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2555 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2556 | else: |
| 2557 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2558 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2559 | " expected state is " + intentDict[ intentID ] + |
| 2560 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2561 | returnValue = main.FALSE |
| 2562 | intentDictONOS.pop( intentID ) |
| 2563 | if len( intentDictONOS ) > 0: |
| 2564 | returnValue = main.FALSE |
| 2565 | for intentID in intentDictONOS.keys(): |
| 2566 | 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] | 2567 | if returnValue == main.TRUE: |
| 2568 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2569 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2570 | except KeyError: |
| 2571 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2572 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2573 | except ( TypeError, ValueError ): |
| 2574 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2575 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2576 | except pexpect.EOF: |
| 2577 | main.log.error( self.name + ": EOF exception found" ) |
| 2578 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2579 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2580 | except Exception: |
| 2581 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2582 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2583 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2584 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2585 | """ |
| 2586 | Description: |
| 2587 | Check the number of installed intents. |
| 2588 | Optional: |
| 2589 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2590 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2591 | Return: |
| 2592 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2593 | , otherwise, returns main.FALSE. |
| 2594 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2595 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2596 | try: |
| 2597 | cmd = "intents -s -j" |
| 2598 | |
| 2599 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2600 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2601 | if response is None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2602 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2603 | response = json.loads( response ) |
| 2604 | |
| 2605 | # get total and installed number, see if they are match |
| 2606 | allState = response.get( 'all' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2607 | if allState.get( 'total' ) == allState.get( 'installed' ): |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2608 | main.log.info( 'Total Intents: {} Installed Intents: {}'.format( |
| 2609 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2610 | return main.TRUE |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2611 | main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format( |
| 2612 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2613 | return main.FALSE |
| 2614 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2615 | except ( TypeError, ValueError ): |
| 2616 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2617 | return None |
| 2618 | except pexpect.EOF: |
| 2619 | main.log.error( self.name + ": EOF exception found" ) |
| 2620 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2621 | if noExit: |
| 2622 | return main.FALSE |
| 2623 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2624 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2625 | except pexpect.TIMEOUT: |
| 2626 | main.log.error( self.name + ": ONOS timeout" ) |
| 2627 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2628 | except Exception: |
| 2629 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2630 | if noExit: |
| 2631 | return main.FALSE |
| 2632 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2633 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2634 | |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2635 | 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] | 2636 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2637 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2638 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2639 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2640 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2641 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2642 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2643 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2644 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2645 | if jsonFormat: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2646 | cmdStr += " -j" |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2647 | if noCore: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2648 | cmdStr += " -n" |
| 2649 | cmdStr += " " + state |
| 2650 | cmdStr += " " + device |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2651 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2652 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2653 | assert "Command not found:" not in handle, handle |
| 2654 | if re.search( "Error:", handle ): |
| 2655 | main.log.error( self.name + ": flows() response: " + |
| 2656 | str( handle ) ) |
| 2657 | return handle |
| 2658 | except AssertionError: |
| 2659 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2660 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2661 | except TypeError: |
| 2662 | main.log.exception( self.name + ": Object not as expected" ) |
| 2663 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2664 | except pexpect.TIMEOUT: |
| 2665 | main.log.error( self.name + ": ONOS timeout" ) |
| 2666 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2667 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2668 | main.log.error( self.name + ": EOF exception found" ) |
| 2669 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2670 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2671 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2672 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2673 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2674 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2675 | def checkFlowCount( self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2676 | count = self.getTotalFlowsNum( timeout=timeout ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2677 | count = int( count ) if count else 0 |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 2678 | main.log.debug( "found {} flows".format( count ) ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2679 | return count if ( count > min ) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2680 | |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2681 | def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2682 | """ |
| 2683 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2684 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2685 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2686 | if the count of those states is 0, which means all current flows |
| 2687 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2688 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2689 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2690 | Return: |
| 2691 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2692 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2693 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2694 | """ |
| 2695 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2696 | states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2697 | checkedStates = [] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2698 | statesCount = [ 0, 0, 0, 0 ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2699 | for s in states: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2700 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2701 | if rawFlows: |
| 2702 | # if we didn't get flows or flows function return None, we should return |
| 2703 | # main.Flase |
| 2704 | checkedStates.append( json.loads( rawFlows ) ) |
| 2705 | else: |
| 2706 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2707 | for i in range( len( states ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2708 | for c in checkedStates[ i ]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2709 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2710 | statesCount[ i ] += int( c.get( "flowCount" ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2711 | except TypeError: |
| 2712 | main.log.exception( "Json object not as expected" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2713 | main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2714 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2715 | # We want to count PENDING_ADD if isPENDING is true |
| 2716 | if isPENDING: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2717 | if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2718 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2719 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2720 | if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2721 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2722 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2723 | except ( TypeError, ValueError ): |
| 2724 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2725 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2726 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2727 | except AssertionError: |
| 2728 | main.log.exception( "" ) |
| 2729 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2730 | except pexpect.TIMEOUT: |
| 2731 | main.log.error( self.name + ": ONOS timeout" ) |
| 2732 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2733 | except pexpect.EOF: |
| 2734 | main.log.error( self.name + ": EOF exception found" ) |
| 2735 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2736 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2737 | except Exception: |
| 2738 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2739 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2740 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2741 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2742 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2743 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2744 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2745 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2746 | a specific point-to-point intent definition |
| 2747 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2748 | * ingress: specify source dpid |
| 2749 | * egress: specify destination dpid |
| 2750 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2751 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2752 | * offset: the keyOffset is where the next batch of intents |
| 2753 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2754 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2755 | * getResponse: If set to True, function will return ONOS response. |
| 2756 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2757 | Returns: If failed to push test intents, it will returen None, |
| 2758 | if successful, return true. |
| 2759 | Timeout expection will return None, |
| 2760 | TypeError will return false |
| 2761 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2762 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2763 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2764 | if background: |
| 2765 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2766 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2767 | back = "" |
| 2768 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2769 | ingress, |
| 2770 | egress, |
| 2771 | batchSize, |
| 2772 | offset, |
| 2773 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2774 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2775 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2776 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2777 | main.log.info( response ) |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2778 | if getResponse: |
| 2779 | return response |
| 2780 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2781 | # TODO: We should handle if there is failure in installation |
| 2782 | return main.TRUE |
| 2783 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2784 | except AssertionError: |
| 2785 | main.log.exception( "" ) |
| 2786 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2787 | except pexpect.TIMEOUT: |
| 2788 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2789 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2790 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2791 | main.log.error( self.name + ": EOF exception found" ) |
| 2792 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2793 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2794 | except TypeError: |
| 2795 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2796 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2797 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2798 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2799 | main.cleanAndExit() |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2800 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2801 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2802 | """ |
| 2803 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2804 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2805 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2806 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2807 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2808 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2809 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2810 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2811 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2812 | cmd = "flows -c added" |
| 2813 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2814 | if rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2815 | rawFlows = rawFlows.split( "\n" ) |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2816 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2817 | for l in rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2818 | totalFlows += int( l.split( "Count=" )[ 1 ] ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2819 | else: |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 2820 | main.log.warn( "Response not as expected!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2821 | return None |
| 2822 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2823 | |
You Wang | d3097f7 | 2018-12-12 11:56:03 -0800 | [diff] [blame] | 2824 | except IndexError: |
| 2825 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
| 2826 | main.log.debug( "rawFlows: {}".format( rawFlows ) ) |
| 2827 | return None |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2828 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2829 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2830 | return None |
| 2831 | except pexpect.EOF: |
| 2832 | main.log.error( self.name + ": EOF exception found" ) |
| 2833 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2834 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2835 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2836 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2837 | except pexpect.TIMEOUT: |
| 2838 | main.log.error( self.name + ": ONOS timeout" ) |
| 2839 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2840 | except Exception: |
| 2841 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2842 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2843 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2844 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2845 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2846 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2847 | """ |
| 2848 | Description: |
| 2849 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2850 | Optional: |
| 2851 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2852 | Return: |
| 2853 | The number of intents |
| 2854 | """ |
| 2855 | try: |
| 2856 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2857 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2858 | if response is None: |
| 2859 | return -1 |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2860 | response = json.loads( response ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2861 | return int( response.get( "intents" ) ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2862 | except ( TypeError, ValueError ): |
| 2863 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2864 | return None |
| 2865 | except pexpect.EOF: |
| 2866 | main.log.error( self.name + ": EOF exception found" ) |
| 2867 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2868 | if noExit: |
| 2869 | return -1 |
| 2870 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2871 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2872 | except Exception: |
| 2873 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2874 | if noExit: |
| 2875 | return -1 |
| 2876 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2877 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2878 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2879 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2880 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2881 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2882 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2883 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2884 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2885 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2886 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2887 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2888 | cmdStr += " -j" |
| 2889 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2890 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2891 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2892 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2893 | except AssertionError: |
| 2894 | main.log.exception( "" ) |
| 2895 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2896 | except TypeError: |
| 2897 | main.log.exception( self.name + ": Object not as expected" ) |
| 2898 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2899 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2900 | main.log.error( self.name + ": EOF exception found" ) |
| 2901 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2902 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2903 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2904 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2905 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2906 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2907 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2908 | """ |
| 2909 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2910 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2911 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2912 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2913 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2914 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2915 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2916 | cmdStr += " -j" |
| 2917 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2918 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2919 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2920 | if handle: |
| 2921 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2922 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2923 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2924 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2925 | else: |
| 2926 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2927 | except AssertionError: |
| 2928 | main.log.exception( "" ) |
| 2929 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2930 | except TypeError: |
| 2931 | main.log.exception( self.name + ": Object not as expected" ) |
| 2932 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2933 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2934 | main.log.error( self.name + ": EOF exception found" ) |
| 2935 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2936 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2937 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2938 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2939 | main.cleanAndExit() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2940 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2941 | # Wrapper functions **************** |
| 2942 | # Wrapper functions use existing driver |
| 2943 | # functions and extends their use case. |
| 2944 | # For example, we may use the output of |
| 2945 | # a normal driver function, and parse it |
| 2946 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2947 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2948 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2949 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2950 | Description: |
| 2951 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2952 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2953 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2954 | # Obtain output of intents function |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2955 | intentsStr = self.intents( jsonFormat=True ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 2956 | if intentsStr is None: |
| 2957 | raise TypeError |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2958 | # Convert to a dictionary |
| 2959 | intents = json.loads( intentsStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2960 | intentIdList = [] |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2961 | for intent in intents: |
| 2962 | intentIdList.append( intent[ 'id' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2963 | return intentIdList |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2964 | except TypeError: |
| 2965 | main.log.exception( self.name + ": Object not as expected" ) |
| 2966 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2967 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2968 | main.log.error( self.name + ": EOF exception found" ) |
| 2969 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2970 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2971 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2972 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2973 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2974 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2975 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2976 | """ |
| 2977 | Determine the number of flow rules for the given device id that are |
| 2978 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2979 | Params: |
| 2980 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2981 | """ |
| 2982 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2983 | if core: |
| 2984 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2985 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2986 | else: |
| 2987 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2988 | "grep 'state=ADDED' | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 2989 | handle = self.lineCount( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2990 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2991 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2992 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2993 | except AssertionError: |
| 2994 | main.log.exception( "" ) |
| 2995 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2996 | except pexpect.EOF: |
| 2997 | main.log.error( self.name + ": EOF exception found" ) |
| 2998 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2999 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3000 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 3001 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3002 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 3003 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3004 | def groupAddedCount( self, deviceId, core=False ): |
| 3005 | """ |
| 3006 | Determine the number of group rules for the given device id that are |
| 3007 | in the added state |
| 3008 | Params: |
| 3009 | core: if True, only return the number of core groups added |
| 3010 | """ |
| 3011 | try: |
| 3012 | if core: |
| 3013 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 3014 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 3015 | else: |
| 3016 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 3017 | "grep 'state=ADDED' | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3018 | handle = self.lineCount( cmdStr ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3019 | assert handle is not None, "Error in sendline" |
| 3020 | assert "Command not found:" not in handle, handle |
| 3021 | return handle |
| 3022 | except AssertionError: |
| 3023 | main.log.exception( "" ) |
| 3024 | return None |
| 3025 | except pexpect.EOF: |
| 3026 | main.log.error( self.name + ": EOF exception found" ) |
| 3027 | main.log.error( self.name + ": " + self.handle.before ) |
| 3028 | main.cleanAndExit() |
| 3029 | except Exception: |
| 3030 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3031 | main.cleanAndExit() |
| 3032 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 3033 | def addStaticRoute( self, subnet, intf): |
| 3034 | """ |
| 3035 | Adds a static route to onos. |
| 3036 | Params: |
| 3037 | subnet: The subnet reaching through this route |
| 3038 | intf: The interface this route is reachable through |
| 3039 | """ |
| 3040 | try: |
| 3041 | cmdStr = "route-add " + subnet + " " + intf |
| 3042 | handle = self.sendline( cmdStr ) |
| 3043 | assert handle is not None, "Error in sendline" |
| 3044 | assert "Command not found:" not in handle, handle |
| 3045 | return handle |
| 3046 | except AssertionError: |
| 3047 | main.log.exception( "" ) |
| 3048 | return None |
| 3049 | except pexpect.EOF: |
| 3050 | main.log.error( self.name + ": EOF exception found" ) |
| 3051 | main.log.error( self.name + ": " + self.handle.before ) |
| 3052 | main.cleanAndExit() |
| 3053 | except Exception: |
| 3054 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3055 | main.cleanAndExit() |
| 3056 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3057 | def checkGroupAddedCount( self, deviceId, expectedGroupCount=0, core=False, comparison=0): |
| 3058 | """ |
| 3059 | Description: |
| 3060 | Check whether the number of groups for the given device id that |
| 3061 | are in ADDED state is bigger than minGroupCount. |
| 3062 | Required: |
| 3063 | * deviceId: device id to check the number of added group rules |
| 3064 | Optional: |
| 3065 | * minGroupCount: the number of groups to compare |
| 3066 | * core: if True, only check the number of core groups added |
| 3067 | * comparison: if 0, compare with greater than minFlowCount |
| 3068 | * if 1, compare with equal to minFlowCount |
| 3069 | Return: |
| 3070 | Returns the number of groups if it is bigger than minGroupCount, |
| 3071 | returns main.FALSE otherwise. |
| 3072 | """ |
| 3073 | count = self.groupAddedCount( deviceId, core ) |
| 3074 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 3075 | main.log.debug( "found {} groups".format( count ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3076 | return count if ((count > expectedGroupCount) if (comparison == 0) else (count == expectedGroupCount)) else main.FALSE |
| 3077 | |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3078 | def getGroups( self, deviceId, groupType="any" ): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3079 | """ |
| 3080 | Retrieve groups from a specific device. |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3081 | deviceId: Id of the device from which we retrieve groups |
| 3082 | groupType: Type of group |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3083 | """ |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3084 | try: |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3085 | groupCmd = "groups -t {0} any {1}".format( groupType, deviceId ) |
| 3086 | handle = self.sendline( groupCmd ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3087 | assert handle is not None, "Error in sendline" |
| 3088 | assert "Command not found:" not in handle, handle |
| 3089 | return handle |
| 3090 | except AssertionError: |
| 3091 | main.log.exception( "" ) |
| 3092 | return None |
| 3093 | except TypeError: |
| 3094 | main.log.exception( self.name + ": Object not as expected" ) |
| 3095 | return None |
| 3096 | except pexpect.EOF: |
| 3097 | main.log.error( self.name + ": EOF exception found" ) |
| 3098 | main.log.error( self.name + ": " + self.handle.before ) |
| 3099 | main.cleanAndExit() |
| 3100 | except Exception: |
| 3101 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3102 | main.cleanAndExit() |
| 3103 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3104 | def checkFlowAddedCount( self, deviceId, expectedFlowCount=0, core=False, comparison=0): |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3105 | """ |
| 3106 | Description: |
| 3107 | Check whether the number of flow rules for the given device id that |
| 3108 | are in ADDED state is bigger than minFlowCount. |
| 3109 | Required: |
| 3110 | * deviceId: device id to check the number of added flow rules |
| 3111 | Optional: |
| 3112 | * minFlowCount: the number of flow rules to compare |
| 3113 | * core: if True, only check the number of core flows added |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3114 | * comparison: if 0, compare with greater than minFlowCount |
| 3115 | * if 1, compare with equal to minFlowCount |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3116 | Return: |
| 3117 | Returns the number of flow rules if it is bigger than minFlowCount, |
| 3118 | returns main.FALSE otherwise. |
| 3119 | """ |
| 3120 | count = self.flowAddedCount( deviceId, core ) |
| 3121 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 3122 | main.log.debug( "found {} flows".format( count ) ) |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 3123 | 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] | 3124 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3125 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3126 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3127 | Use 'devices' function to obtain list of all devices |
| 3128 | and parse the result to obtain a list of all device |
| 3129 | id's. Returns this list. Returns empty list if no |
| 3130 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3131 | List is ordered sequentially |
| 3132 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3133 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3134 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3135 | the ids. By obtaining the list of device ids on the fly, |
| 3136 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3137 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3138 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3139 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3140 | devicesStr = self.devices( jsonFormat=False ) |
| 3141 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3142 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3143 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3144 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3145 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3146 | |
| 3147 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3148 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3149 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3150 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3151 | # Split list further into arguments before and after string |
| 3152 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3153 | # append to idList |
| 3154 | for arg in tempList: |
| 3155 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 3156 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3157 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3158 | except TypeError: |
| 3159 | main.log.exception( self.name + ": Object not as expected" ) |
| 3160 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3161 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3162 | main.log.error( self.name + ": EOF exception found" ) |
| 3163 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3164 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3165 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3166 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3167 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3168 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3169 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3170 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3171 | Uses 'nodes' function to obtain list of all nodes |
| 3172 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3173 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3174 | Returns: |
| 3175 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3176 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3177 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3178 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3179 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3180 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 3181 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3182 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3183 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3184 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3185 | nodesJson = json.loads( nodesStr ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3186 | idList = [ node.get( 'id' ) for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3187 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3188 | except ( TypeError, ValueError ): |
| 3189 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3190 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3191 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3192 | main.log.error( self.name + ": EOF exception found" ) |
| 3193 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3194 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3195 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3196 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3197 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3198 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3199 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3200 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3201 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 3202 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3203 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3204 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3205 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3206 | return None |
| 3207 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3208 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3209 | rawDevices = self.devices() |
| 3210 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3211 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3212 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3213 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 3214 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3215 | return device |
| 3216 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3217 | except ( TypeError, ValueError ): |
| 3218 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3219 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3220 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3221 | main.log.error( self.name + ": EOF exception found" ) |
| 3222 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3223 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3224 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3225 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3226 | main.cleanAndExit() |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3227 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3228 | def getTopology( self, topologyOutput ): |
| 3229 | """ |
| 3230 | Definition: |
| 3231 | Loads a json topology output |
| 3232 | Return: |
| 3233 | topology = current ONOS topology |
| 3234 | """ |
| 3235 | import json |
| 3236 | try: |
| 3237 | # either onos:topology or 'topology' will work in CLI |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3238 | topology = json.loads( topologyOutput ) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 3239 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3240 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 3241 | except ( TypeError, ValueError ): |
| 3242 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 3243 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3244 | except pexpect.EOF: |
| 3245 | main.log.error( self.name + ": EOF exception found" ) |
| 3246 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3247 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3248 | except Exception: |
| 3249 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3250 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3251 | |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3252 | def checkStatus( self, numoswitch, numolink = -1, numoctrl = -1, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3253 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3254 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3255 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3256 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3257 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3258 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3259 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3260 | numoctrl = expected number of controllers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3261 | logLevel = level to log to. |
| 3262 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3263 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3264 | Returns: main.TRUE if the number of switches and links are correct, |
| 3265 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3266 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3267 | """ |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3268 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3269 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 3270 | summary = self.summary() |
| 3271 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 3272 | except ( TypeError, ValueError ): |
| 3273 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 3274 | return main.ERROR |
| 3275 | try: |
| 3276 | topology = self.getTopology( self.topology() ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 3277 | if topology == {} or topology is None or summary == {} or summary is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3278 | return main.ERROR |
| 3279 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3280 | # Is the number of switches is what we expected |
| 3281 | devices = topology.get( 'devices', False ) |
| 3282 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3283 | nodes = summary.get( 'nodes', False ) |
| 3284 | if devices is False or links is False or nodes is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3285 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3286 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3287 | # Is the number of links is what we expected |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3288 | linkCheck = ( int( links ) == int( numolink ) ) or int( numolink ) == -1 |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3289 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
| 3290 | if switchCheck and linkCheck and nodeCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3291 | # We expected the correct numbers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3292 | output = output + "The number of links and switches match "\ |
| 3293 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3294 | result = main.TRUE |
| 3295 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3296 | output = output + \ |
| 3297 | "The number of links and switches does not match " + \ |
| 3298 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3299 | result = main.FALSE |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3300 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 3301 | output = output + " (%i expected) " % int( numoswitch ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3302 | if int( numolink ) > 0: |
| 3303 | output = output + "and %i links " % int( links ) |
| 3304 | output = output + "(%i expected)" % int( numolink ) |
YPZhang | d7e4b6e | 2016-06-17 16:07:55 -0700 | [diff] [blame] | 3305 | if int( numoctrl ) > 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3306 | output = output + "and %i controllers " % int( nodes ) |
| 3307 | output = output + "(%i expected)" % int( numoctrl ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3308 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3309 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3310 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3311 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3312 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3313 | main.log.info( output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3314 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3315 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3316 | main.log.error( self.name + ": EOF exception found" ) |
| 3317 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3318 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3319 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3320 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3321 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3322 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3323 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3324 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3325 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3326 | deviceId must be the id of a device as seen in the onos devices command |
| 3327 | 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] | 3328 | role must be either master, standby, or none |
| 3329 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3330 | Returns: |
| 3331 | main.TRUE or main.FALSE based on argument verification and |
| 3332 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3333 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3334 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3335 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3336 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3337 | cmdStr = "device-role " +\ |
| 3338 | str( deviceId ) + " " +\ |
| 3339 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3340 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3341 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3342 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3343 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3344 | if re.search( "Error", handle ): |
| 3345 | # end color output to escape any colours |
| 3346 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3347 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3348 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3349 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3350 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3351 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3352 | main.log.error( "Invalid 'role' given to device_role(). " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3353 | "Value was '" + str( role ) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3354 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3355 | except AssertionError: |
| 3356 | main.log.exception( "" ) |
| 3357 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3358 | except TypeError: |
| 3359 | main.log.exception( self.name + ": Object not as expected" ) |
| 3360 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3361 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3362 | main.log.error( self.name + ": EOF exception found" ) |
| 3363 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3364 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3365 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3366 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3367 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3368 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3369 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3370 | """ |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3371 | Lists all topology clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 3372 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3373 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3374 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3375 | try: |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3376 | cmdStr = "topo-clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3377 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3378 | cmdStr += " -j" |
| 3379 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3380 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3381 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3382 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3383 | except AssertionError: |
| 3384 | main.log.exception( "" ) |
| 3385 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3386 | except TypeError: |
| 3387 | main.log.exception( self.name + ": Object not as expected" ) |
| 3388 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3389 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3390 | main.log.error( self.name + ": EOF exception found" ) |
| 3391 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3392 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3393 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3394 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3395 | main.cleanAndExit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3396 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3397 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3398 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3399 | CLI command to get the current leader for the Election test application |
| 3400 | NOTE: Requires installation of the onos-app-election feature |
| 3401 | Returns: Node IP of the leader if one exists |
| 3402 | None if none exists |
| 3403 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3404 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3405 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3406 | cmdStr = "election-test-leader" |
| 3407 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3408 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3409 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3410 | # Leader |
| 3411 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3412 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3413 | nodeSearch = re.search( leaderPattern, response ) |
| 3414 | if nodeSearch: |
| 3415 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3416 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3417 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3418 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3419 | # no leader |
| 3420 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3421 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3422 | nullSearch = re.search( nullPattern, response ) |
| 3423 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3424 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3425 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3426 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3427 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3428 | main.log.error( self.name + ": Error in electionTestLeader on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3429 | ": " + "unexpected response" ) |
| 3430 | main.log.error( repr( response ) ) |
| 3431 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3432 | except AssertionError: |
| 3433 | main.log.exception( "" ) |
| 3434 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3435 | except TypeError: |
| 3436 | main.log.exception( self.name + ": Object not as expected" ) |
| 3437 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3438 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3439 | main.log.error( self.name + ": EOF exception found" ) |
| 3440 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3441 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3442 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3443 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3444 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3445 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3446 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3447 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3448 | CLI command to run for leadership of the Election test application. |
| 3449 | NOTE: Requires installation of the onos-app-election feature |
| 3450 | Returns: Main.TRUE on success |
| 3451 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3452 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3453 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3454 | cmdStr = "election-test-run" |
| 3455 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3456 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3457 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3458 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3459 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3460 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3461 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3462 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3463 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3464 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3465 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3466 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3467 | main.log.error( self.name + ": Error in electionTestRun on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3468 | ": " + "unexpected response" ) |
| 3469 | main.log.error( repr( response ) ) |
| 3470 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3471 | except AssertionError: |
| 3472 | main.log.exception( "" ) |
| 3473 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3474 | except TypeError: |
| 3475 | main.log.exception( self.name + ": Object not as expected" ) |
| 3476 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3477 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3478 | main.log.error( self.name + ": EOF exception found" ) |
| 3479 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3480 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3481 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3482 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3483 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3484 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3485 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3486 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3487 | * CLI command to withdraw the local node from leadership election for |
| 3488 | * the Election test application. |
| 3489 | #NOTE: Requires installation of the onos-app-election feature |
| 3490 | Returns: Main.TRUE on success |
| 3491 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3492 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3493 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3494 | cmdStr = "election-test-withdraw" |
| 3495 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3496 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3497 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3498 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3499 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3500 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3501 | if re.search( successPattern, response ): |
| 3502 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3503 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3504 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3505 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3506 | main.log.error( self.name + ": Error in electionTestWithdraw on " + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3507 | self.name + ": " + "unexpected response" ) |
| 3508 | main.log.error( repr( response ) ) |
| 3509 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3510 | except AssertionError: |
| 3511 | main.log.exception( "" ) |
| 3512 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3513 | except TypeError: |
| 3514 | main.log.exception( self.name + ": Object not as expected" ) |
| 3515 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3516 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3517 | main.log.error( self.name + ": EOF exception found" ) |
| 3518 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3519 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3520 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3521 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3522 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3523 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3524 | def getDevicePortsEnabledCount( self, dpid ): |
| 3525 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3526 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3527 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3528 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3529 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3530 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3531 | output = self.lineCount( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3532 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3533 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3534 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3535 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3536 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3537 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3538 | except AssertionError: |
| 3539 | main.log.exception( "" ) |
| 3540 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3541 | except TypeError: |
| 3542 | main.log.exception( self.name + ": Object not as expected" ) |
| 3543 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3544 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3545 | main.log.error( self.name + ": EOF exception found" ) |
| 3546 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3547 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3548 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3549 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3550 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3551 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3552 | def getDeviceLinksActiveCount( self, dpid ): |
| 3553 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3554 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3555 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3556 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3557 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3558 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3559 | output = self.lineCount( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3560 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3561 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3562 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3563 | main.log.error( self.name + ": Error in getting ports " ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3564 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3565 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3566 | except AssertionError: |
| 3567 | main.log.exception( "" ) |
| 3568 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3569 | except TypeError: |
| 3570 | main.log.exception( self.name + ": Object not as expected" ) |
| 3571 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3572 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3573 | main.log.error( self.name + ": EOF exception found" ) |
| 3574 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3575 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3576 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3577 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3578 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3579 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3580 | def getAllIntentIds( self ): |
| 3581 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3582 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3583 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3584 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3585 | cmdStr = "onos:intents | grep id=" |
| 3586 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3587 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3588 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3589 | if re.search( "Error", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3590 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3591 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3592 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3593 | except AssertionError: |
| 3594 | main.log.exception( "" ) |
| 3595 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3596 | except TypeError: |
| 3597 | main.log.exception( self.name + ": Object not as expected" ) |
| 3598 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3599 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 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 | d4d4b37 | 2015-01-28 16:02:41 -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 | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3606 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3607 | def intentSummary( self ): |
| 3608 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3609 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3610 | """ |
| 3611 | try: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3612 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3613 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3614 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3615 | states.append( intent.get( 'state', None ) ) |
| 3616 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3617 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3618 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3619 | except ( TypeError, ValueError ): |
| 3620 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3621 | return None |
| 3622 | except pexpect.EOF: |
| 3623 | main.log.error( self.name + ": EOF exception found" ) |
| 3624 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3625 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3626 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3627 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3628 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3629 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3630 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3631 | """ |
| 3632 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3633 | Optional argument: |
| 3634 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3635 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3636 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3637 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3638 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3639 | cmdStr += " -j" |
| 3640 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3641 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3642 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3643 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3644 | except AssertionError: |
| 3645 | main.log.exception( "" ) |
| 3646 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3647 | except TypeError: |
| 3648 | main.log.exception( self.name + ": Object not as expected" ) |
| 3649 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3650 | except pexpect.EOF: |
| 3651 | main.log.error( self.name + ": EOF exception found" ) |
| 3652 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3653 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3654 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3655 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3656 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3657 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3658 | def leaderCandidates( self, jsonFormat=True ): |
| 3659 | """ |
| 3660 | Returns the output of the leaders -c command. |
| 3661 | Optional argument: |
| 3662 | * jsonFormat - boolean indicating if you want output in json |
| 3663 | """ |
| 3664 | try: |
| 3665 | cmdStr = "onos:leaders -c" |
| 3666 | if jsonFormat: |
| 3667 | cmdStr += " -j" |
| 3668 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3669 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3670 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3671 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3672 | except AssertionError: |
| 3673 | main.log.exception( "" ) |
| 3674 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3675 | except TypeError: |
| 3676 | main.log.exception( self.name + ": Object not as expected" ) |
| 3677 | return None |
| 3678 | except pexpect.EOF: |
| 3679 | main.log.error( self.name + ": EOF exception found" ) |
| 3680 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3681 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3682 | except Exception: |
| 3683 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3684 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3685 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3686 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3687 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3688 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3689 | topic parameter and an empty list if the topic doesn't exist |
| 3690 | If no leader is elected leader in the returned list will be "none" |
| 3691 | Returns None if there is a type error processing the json object |
| 3692 | """ |
| 3693 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3694 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3695 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3696 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3697 | assert "Command not found:" not in rawOutput, rawOutput |
| 3698 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3699 | results = [] |
| 3700 | for dict in output: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3701 | if dict[ "topic" ] == topic: |
| 3702 | leader = dict[ "leader" ] |
| 3703 | candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3704 | results.append( leader ) |
| 3705 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3706 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3707 | except AssertionError: |
| 3708 | main.log.exception( "" ) |
| 3709 | return None |
| 3710 | except ( TypeError, ValueError ): |
| 3711 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3712 | return None |
| 3713 | except pexpect.EOF: |
| 3714 | main.log.error( self.name + ": EOF exception found" ) |
| 3715 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3716 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3717 | except Exception: |
| 3718 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3719 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3720 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3721 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3722 | """ |
| 3723 | Returns the output of the intent Pending map. |
| 3724 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3725 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3726 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3727 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3728 | cmdStr += " -j" |
| 3729 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3730 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3731 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3732 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3733 | except AssertionError: |
| 3734 | main.log.exception( "" ) |
| 3735 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3736 | except TypeError: |
| 3737 | main.log.exception( self.name + ": Object not as expected" ) |
| 3738 | return None |
| 3739 | except pexpect.EOF: |
| 3740 | main.log.error( self.name + ": EOF exception found" ) |
| 3741 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3742 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3743 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3744 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3745 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3746 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3747 | def partitions( self, candidates=False, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3748 | """ |
| 3749 | Returns the output of the raft partitions command for ONOS. |
| 3750 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3751 | # Sample JSON |
| 3752 | # { |
| 3753 | # "leader": "tcp://10.128.30.11:7238", |
| 3754 | # "members": [ |
| 3755 | # "tcp://10.128.30.11:7238", |
| 3756 | # "tcp://10.128.30.17:7238", |
| 3757 | # "tcp://10.128.30.13:7238", |
| 3758 | # ], |
| 3759 | # "name": "p1", |
| 3760 | # "term": 3 |
| 3761 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3762 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3763 | cmdStr = "onos:partitions" |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3764 | if candidates: |
| 3765 | cmdStr += " -c" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3766 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3767 | cmdStr += " -j" |
| 3768 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3769 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3770 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3771 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3772 | except AssertionError: |
| 3773 | main.log.exception( "" ) |
| 3774 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3775 | except TypeError: |
| 3776 | main.log.exception( self.name + ": Object not as expected" ) |
| 3777 | return None |
| 3778 | except pexpect.EOF: |
| 3779 | main.log.error( self.name + ": EOF exception found" ) |
| 3780 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3781 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3782 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3783 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3784 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3785 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3786 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3787 | """ |
| 3788 | Returns the output of the apps command for ONOS. This command lists |
| 3789 | information about installed ONOS applications |
| 3790 | """ |
| 3791 | # Sample JSON object |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3792 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3793 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3794 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3795 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3796 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3797 | cmdStr = "onos:apps" |
Jon Hall | f03ae76 | 2019-01-22 13:25:27 -0800 | [diff] [blame] | 3798 | expectJson = False |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3799 | if summary: |
| 3800 | cmdStr += " -s" |
| 3801 | if active: |
| 3802 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3803 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3804 | cmdStr += " -j" |
Jon Hall | f03ae76 | 2019-01-22 13:25:27 -0800 | [diff] [blame] | 3805 | expectJson = True |
| 3806 | output = self.sendline( cmdStr, expectJson=expectJson ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3807 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3808 | assert "Command not found:" not in output, output |
| 3809 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3810 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3811 | # FIXME: look at specific exceptions/Errors |
| 3812 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3813 | main.log.exception( self.name + ": Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3814 | return None |
| 3815 | except TypeError: |
| 3816 | main.log.exception( self.name + ": Object not as expected" ) |
| 3817 | return None |
| 3818 | except pexpect.EOF: |
| 3819 | main.log.error( self.name + ": EOF exception found" ) |
| 3820 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3821 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3822 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3823 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3824 | main.cleanAndExit() |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3825 | |
You Wang | cdc51fe | 2018-08-12 17:14:56 -0700 | [diff] [blame] | 3826 | def appStatus( self, appName ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3827 | """ |
| 3828 | Uses the onos:apps cli command to return the status of an application. |
| 3829 | Returns: |
| 3830 | "ACTIVE" - If app is installed and activated |
| 3831 | "INSTALLED" - If app is installed and deactivated |
| 3832 | "UNINSTALLED" - If app is not installed |
| 3833 | None - on error |
| 3834 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3835 | try: |
| 3836 | if not isinstance( appName, types.StringType ): |
| 3837 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3838 | " a string" ) |
| 3839 | return None |
| 3840 | output = self.apps( jsonFormat=True ) |
| 3841 | appsJson = json.loads( output ) |
| 3842 | state = None |
| 3843 | for app in appsJson: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3844 | if appName == app.get( 'name' ): |
| 3845 | state = app.get( 'state' ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3846 | break |
| 3847 | if state == "ACTIVE" or state == "INSTALLED": |
| 3848 | return state |
| 3849 | elif state is None: |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 3850 | main.log.warn( "{} app not found".format( appName ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3851 | return "UNINSTALLED" |
| 3852 | elif state: |
| 3853 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3854 | str( state ) ) |
| 3855 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3856 | except ( TypeError, ValueError ): |
| 3857 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3858 | return None |
| 3859 | except pexpect.EOF: |
| 3860 | main.log.error( self.name + ": EOF exception found" ) |
| 3861 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3862 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3863 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3864 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3865 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3866 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3867 | def app( self, appName, option ): |
| 3868 | """ |
| 3869 | Interacts with the app command for ONOS. This command manages |
| 3870 | application inventory. |
| 3871 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3872 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3873 | # Validate argument types |
| 3874 | valid = True |
| 3875 | if not isinstance( appName, types.StringType ): |
| 3876 | main.log.error( self.name + ".app(): appName must be a " + |
| 3877 | "string" ) |
| 3878 | valid = False |
| 3879 | if not isinstance( option, types.StringType ): |
| 3880 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3881 | valid = False |
| 3882 | if not valid: |
| 3883 | return main.FALSE |
| 3884 | # Validate Option |
| 3885 | option = option.lower() |
| 3886 | # NOTE: Install may become a valid option |
| 3887 | if option == "activate": |
| 3888 | pass |
| 3889 | elif option == "deactivate": |
| 3890 | pass |
| 3891 | elif option == "uninstall": |
| 3892 | pass |
| 3893 | else: |
| 3894 | # Invalid option |
| 3895 | main.log.error( "The ONOS app command argument only takes " + |
| 3896 | "the values: (activate|deactivate|uninstall)" + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3897 | "; was given '" + option + "'" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3898 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3899 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3900 | output = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3901 | assert output is not None, "Error in sendline" |
| 3902 | assert "Command not found:" not in output, output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3903 | if "Error executing command" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3904 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3905 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3906 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3907 | elif "No such application" in output: |
| 3908 | main.log.error( "The application '" + appName + |
| 3909 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3910 | return main.FALSE |
| 3911 | elif "Command not found:" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3912 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3913 | str( output ) ) |
| 3914 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3915 | elif "Unsupported command:" in output: |
| 3916 | main.log.error( "Incorrect command given to 'app': " + |
| 3917 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3918 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3919 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3920 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3921 | return main.TRUE |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3922 | except AssertionError: |
| 3923 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 3924 | return main.ERROR |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3925 | except TypeError: |
| 3926 | main.log.exception( self.name + ": Object not as expected" ) |
| 3927 | return main.ERROR |
| 3928 | except pexpect.EOF: |
| 3929 | main.log.error( self.name + ": EOF exception found" ) |
| 3930 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3931 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3932 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3933 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3934 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3935 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3936 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3937 | """ |
| 3938 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3939 | appName is the hierarchical app name, not the feature name |
| 3940 | If check is True, method will check the status of the app after the |
| 3941 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3942 | Returns main.TRUE if the command was successfully sent |
| 3943 | main.FALSE if the cli responded with an error or given |
| 3944 | incorrect input |
| 3945 | """ |
| 3946 | try: |
| 3947 | if not isinstance( appName, types.StringType ): |
| 3948 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3949 | " a string" ) |
| 3950 | return main.FALSE |
| 3951 | status = self.appStatus( appName ) |
| 3952 | if status == "INSTALLED": |
| 3953 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3954 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3955 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3956 | status = self.appStatus( appName ) |
| 3957 | if status == "ACTIVE": |
| 3958 | return main.TRUE |
| 3959 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3960 | main.log.debug( "The state of application " + |
| 3961 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3962 | time.sleep( 1 ) |
| 3963 | return main.FALSE |
| 3964 | else: # not 'check' or command didn't succeed |
| 3965 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3966 | elif status == "ACTIVE": |
| 3967 | return main.TRUE |
| 3968 | elif status == "UNINSTALLED": |
| 3969 | main.log.error( self.name + ": Tried to activate the " + |
| 3970 | "application '" + appName + "' which is not " + |
| 3971 | "installed." ) |
| 3972 | else: |
| 3973 | main.log.error( "Unexpected return value from appStatus: " + |
| 3974 | str( status ) ) |
| 3975 | return main.ERROR |
| 3976 | except TypeError: |
| 3977 | main.log.exception( self.name + ": Object not as expected" ) |
| 3978 | return main.ERROR |
| 3979 | except pexpect.EOF: |
| 3980 | main.log.error( self.name + ": EOF exception found" ) |
| 3981 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3982 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3983 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3984 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3985 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3986 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3987 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3988 | """ |
| 3989 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3990 | appName is the hierarchical app name, not the feature name |
| 3991 | If check is True, method will check the status of the app after the |
| 3992 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3993 | Returns main.TRUE if the command was successfully sent |
| 3994 | main.FALSE if the cli responded with an error or given |
| 3995 | incorrect input |
| 3996 | """ |
| 3997 | try: |
| 3998 | if not isinstance( appName, types.StringType ): |
| 3999 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 4000 | "be a string" ) |
| 4001 | return main.FALSE |
| 4002 | status = self.appStatus( appName ) |
| 4003 | if status == "INSTALLED": |
| 4004 | return main.TRUE |
| 4005 | elif status == "ACTIVE": |
| 4006 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4007 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4008 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4009 | status = self.appStatus( appName ) |
| 4010 | if status == "INSTALLED": |
| 4011 | return main.TRUE |
| 4012 | else: |
| 4013 | time.sleep( 1 ) |
| 4014 | return main.FALSE |
| 4015 | else: # not check or command didn't succeed |
| 4016 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4017 | elif status == "UNINSTALLED": |
| 4018 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 4019 | "application '" + appName + "' which is not " + |
| 4020 | "installed." ) |
| 4021 | return main.TRUE |
| 4022 | else: |
| 4023 | main.log.error( "Unexpected return value from appStatus: " + |
| 4024 | str( status ) ) |
| 4025 | return main.ERROR |
| 4026 | except TypeError: |
| 4027 | main.log.exception( self.name + ": Object not as expected" ) |
| 4028 | return main.ERROR |
| 4029 | except pexpect.EOF: |
| 4030 | main.log.error( self.name + ": EOF exception found" ) |
| 4031 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4032 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4033 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4034 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4035 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4036 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4037 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4038 | """ |
| 4039 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4040 | appName is the hierarchical app name, not the feature name |
| 4041 | If check is True, method will check the status of the app after the |
| 4042 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4043 | Returns main.TRUE if the command was successfully sent |
| 4044 | main.FALSE if the cli responded with an error or given |
| 4045 | incorrect input |
| 4046 | """ |
| 4047 | # TODO: check with Thomas about the state machine for apps |
| 4048 | try: |
| 4049 | if not isinstance( appName, types.StringType ): |
| 4050 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 4051 | "be a string" ) |
| 4052 | return main.FALSE |
| 4053 | status = self.appStatus( appName ) |
| 4054 | if status == "INSTALLED": |
| 4055 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4056 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4057 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4058 | status = self.appStatus( appName ) |
| 4059 | if status == "UNINSTALLED": |
| 4060 | return main.TRUE |
| 4061 | else: |
| 4062 | time.sleep( 1 ) |
| 4063 | return main.FALSE |
| 4064 | else: # not check or command didn't succeed |
| 4065 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4066 | elif status == "ACTIVE": |
| 4067 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 4068 | "application '" + appName + "' which is " + |
| 4069 | "currently active." ) |
| 4070 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4071 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4072 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4073 | status = self.appStatus( appName ) |
| 4074 | if status == "UNINSTALLED": |
| 4075 | return main.TRUE |
| 4076 | else: |
| 4077 | time.sleep( 1 ) |
| 4078 | return main.FALSE |
| 4079 | else: # not check or command didn't succeed |
| 4080 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4081 | elif status == "UNINSTALLED": |
| 4082 | return main.TRUE |
| 4083 | else: |
| 4084 | main.log.error( "Unexpected return value from appStatus: " + |
| 4085 | str( status ) ) |
| 4086 | return main.ERROR |
| 4087 | except TypeError: |
| 4088 | main.log.exception( self.name + ": Object not as expected" ) |
| 4089 | return main.ERROR |
| 4090 | except pexpect.EOF: |
| 4091 | main.log.error( self.name + ": EOF exception found" ) |
| 4092 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4093 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4094 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4095 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4096 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4097 | |
| 4098 | def appIDs( self, jsonFormat=True ): |
| 4099 | """ |
| 4100 | Show the mappings between app id and app names given by the 'app-ids' |
| 4101 | cli command |
| 4102 | """ |
| 4103 | try: |
| 4104 | cmdStr = "app-ids" |
| 4105 | if jsonFormat: |
| 4106 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4107 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4108 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4109 | assert "Command not found:" not in output, output |
| 4110 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4111 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4112 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4113 | main.log.exception( self.name + ": Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4114 | return None |
| 4115 | except TypeError: |
| 4116 | main.log.exception( self.name + ": Object not as expected" ) |
| 4117 | return None |
| 4118 | except pexpect.EOF: |
| 4119 | main.log.error( self.name + ": EOF exception found" ) |
| 4120 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4121 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4122 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4123 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4124 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4125 | |
| 4126 | def appToIDCheck( self ): |
| 4127 | """ |
| 4128 | This method will check that each application's ID listed in 'apps' is |
| 4129 | the same as the ID listed in 'app-ids'. The check will also check that |
| 4130 | there are no duplicate IDs issued. Note that an app ID should be |
| 4131 | a globaly unique numerical identifier for app/app-like features. Once |
| 4132 | an ID is registered, the ID is never freed up so that if an app is |
| 4133 | reinstalled it will have the same ID. |
| 4134 | |
| 4135 | Returns: main.TRUE if the check passes and |
| 4136 | main.FALSE if the check fails or |
| 4137 | main.ERROR if there is some error in processing the test |
| 4138 | """ |
| 4139 | try: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4140 | # Grab IDs |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4141 | rawJson = self.appIDs( jsonFormat=True ) |
| 4142 | if rawJson: |
| 4143 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4144 | else: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4145 | main.log.error( "app-ids returned nothing: " + repr( rawJson ) ) |
| 4146 | return main.FALSE |
| 4147 | |
| 4148 | # Grab Apps |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4149 | rawJson = self.apps( jsonFormat=True ) |
| 4150 | if rawJson: |
| 4151 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4152 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4153 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4154 | return main.FALSE |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4155 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4156 | result = main.TRUE |
| 4157 | for app in apps: |
| 4158 | appID = app.get( 'id' ) |
| 4159 | if appID is None: |
| 4160 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4161 | result = main.FALSE |
| 4162 | appName = app.get( 'name' ) |
| 4163 | if appName is None: |
| 4164 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4165 | result = main.FALSE |
| 4166 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4167 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4168 | if not current: # if ids doesn't have this id |
| 4169 | result = main.FALSE |
| 4170 | main.log.error( "'app-ids' does not have the ID for " + |
| 4171 | str( appName ) + " that apps does." ) |
Jon Hall | b9d381e | 2018-02-05 12:02:10 -0800 | [diff] [blame] | 4172 | main.log.debug( "apps command returned: " + str( app ) + |
| 4173 | "; app-ids has: " + str( ids ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4174 | elif len( current ) > 1: |
| 4175 | # there is more than one app with this ID |
| 4176 | result = main.FALSE |
| 4177 | # We will log this later in the method |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4178 | elif not current[ 0 ][ 'name' ] == appName: |
| 4179 | currentName = current[ 0 ][ 'name' ] |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4180 | result = main.FALSE |
| 4181 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 4182 | " registered under id:" + str( appID ) + |
| 4183 | " but 'apps' has " + str( appName ) ) |
| 4184 | else: |
| 4185 | pass # id and name match! |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4186 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4187 | # now make sure that app-ids has no duplicates |
| 4188 | idsList = [] |
| 4189 | namesList = [] |
| 4190 | for item in ids: |
| 4191 | idsList.append( item[ 'id' ] ) |
| 4192 | namesList.append( item[ 'name' ] ) |
| 4193 | if len( idsList ) != len( set( idsList ) ) or\ |
| 4194 | len( namesList ) != len( set( namesList ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4195 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 4196 | + json.dumps( ids, |
| 4197 | sort_keys=True, |
| 4198 | indent=4, |
| 4199 | separators=( ',', ': ' ) ) ) |
| 4200 | result = main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4201 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4202 | except ( TypeError, ValueError ): |
| 4203 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4204 | return main.ERROR |
| 4205 | except pexpect.EOF: |
| 4206 | main.log.error( self.name + ": EOF exception found" ) |
| 4207 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4208 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4209 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4210 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4211 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4212 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4213 | def getCfg( self, component=None, propName=None, short=False, |
| 4214 | jsonFormat=True ): |
| 4215 | """ |
| 4216 | Get configuration settings from onos cli |
| 4217 | Optional arguments: |
| 4218 | component - Optionally only list configurations for a specific |
| 4219 | component. If None, all components with configurations |
| 4220 | are displayed. Case Sensitive string. |
| 4221 | propName - If component is specified, propName option will show |
| 4222 | only this specific configuration from that component. |
| 4223 | Case Sensitive string. |
| 4224 | jsonFormat - Returns output as json. Note that this will override |
| 4225 | the short option |
| 4226 | short - Short, less verbose, version of configurations. |
| 4227 | This is overridden by the json option |
| 4228 | returns: |
| 4229 | Output from cli as a string or None on error |
| 4230 | """ |
| 4231 | try: |
| 4232 | baseStr = "cfg" |
| 4233 | cmdStr = " get" |
| 4234 | componentStr = "" |
| 4235 | if component: |
| 4236 | componentStr += " " + component |
| 4237 | if propName: |
| 4238 | componentStr += " " + propName |
| 4239 | if jsonFormat: |
| 4240 | baseStr += " -j" |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4241 | expectJson = True |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4242 | elif short: |
| 4243 | baseStr += " -s" |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4244 | expectJson = False |
| 4245 | output = self.sendline( baseStr + cmdStr + componentStr, expectJson=expectJson ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4246 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4247 | assert "Command not found:" not in output, output |
| 4248 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4249 | return output |
| 4250 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4251 | main.log.exception( self.name + ": Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4252 | return None |
| 4253 | except TypeError: |
| 4254 | main.log.exception( self.name + ": Object not as expected" ) |
| 4255 | return None |
| 4256 | except pexpect.EOF: |
| 4257 | main.log.error( self.name + ": EOF exception found" ) |
| 4258 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4259 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4260 | except Exception: |
| 4261 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4262 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4263 | |
| 4264 | def setCfg( self, component, propName, value=None, check=True ): |
| 4265 | """ |
| 4266 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4267 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4268 | component - The case sensitive name of the component whose |
| 4269 | property is to be set |
| 4270 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4271 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4272 | 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] | 4273 | property and revert it to it's default value(if applicable) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4274 | check - Boolean, Check whether the option was successfully set this |
| 4275 | only applies when a value is given. |
| 4276 | returns: |
| 4277 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 4278 | will return main.TRUE unless there is an error |
| 4279 | """ |
| 4280 | try: |
| 4281 | baseStr = "cfg" |
| 4282 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 4283 | if value is not None: |
| 4284 | cmdStr += " " + str( value ) |
| 4285 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4286 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4287 | assert "Command not found:" not in output, output |
| 4288 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4289 | if value and check: |
| 4290 | results = self.getCfg( component=str( component ), |
| 4291 | propName=str( propName ), |
| 4292 | jsonFormat=True ) |
| 4293 | # Check if current value is what we just set |
| 4294 | try: |
| 4295 | jsonOutput = json.loads( results ) |
| 4296 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4297 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4298 | main.log.exception( "Error parsing cfg output" ) |
| 4299 | main.log.error( "output:" + repr( results ) ) |
| 4300 | return main.FALSE |
| 4301 | if current == str( value ): |
| 4302 | return main.TRUE |
| 4303 | return main.FALSE |
| 4304 | return main.TRUE |
| 4305 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4306 | main.log.exception( self.name + ": Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4307 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4308 | except ( TypeError, ValueError ): |
| 4309 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4310 | return main.FALSE |
| 4311 | except pexpect.EOF: |
| 4312 | main.log.error( self.name + ": EOF exception found" ) |
| 4313 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4314 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4315 | except Exception: |
| 4316 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4317 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4318 | |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4319 | def distPrimitivesSend( self, cmd ): |
| 4320 | """ |
| 4321 | Function to handle sending cli commands for the distributed primitives test app |
| 4322 | |
| 4323 | This command will catch some exceptions and retry the command on some |
| 4324 | specific store exceptions. |
| 4325 | |
| 4326 | Required arguments: |
| 4327 | cmd - The command to send to the cli |
| 4328 | returns: |
| 4329 | string containing the cli output |
| 4330 | None on Error |
| 4331 | """ |
| 4332 | try: |
| 4333 | output = self.sendline( cmd ) |
| 4334 | try: |
| 4335 | assert output is not None, "Error in sendline" |
| 4336 | # TODO: Maybe make this less hardcoded |
| 4337 | # ConsistentMap Exceptions |
| 4338 | assert "org.onosproject.store.service" not in output |
| 4339 | # Node not leader |
| 4340 | assert "java.lang.IllegalStateException" not in output |
| 4341 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4342 | main.log.error( self.name + ": Error in processing '" + cmd + "' " + |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4343 | "command: " + str( output ) ) |
| 4344 | retryTime = 30 # Conservative time, given by Madan |
| 4345 | main.log.info( "Waiting " + str( retryTime ) + |
| 4346 | "seconds before retrying." ) |
| 4347 | time.sleep( retryTime ) # Due to change in mastership |
| 4348 | output = self.sendline( cmd ) |
| 4349 | assert output is not None, "Error in sendline" |
| 4350 | assert "Command not found:" not in output, output |
| 4351 | assert "Error executing command" not in output, output |
| 4352 | main.log.info( self.name + ": " + output ) |
| 4353 | return output |
| 4354 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4355 | main.log.exception( self.name + ": Error in processing '" + cmd + "' command." ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4356 | return None |
| 4357 | except TypeError: |
| 4358 | main.log.exception( self.name + ": Object not as expected" ) |
| 4359 | return None |
| 4360 | except pexpect.EOF: |
| 4361 | main.log.error( self.name + ": EOF exception found" ) |
| 4362 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4363 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4364 | except Exception: |
| 4365 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4366 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4367 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4368 | def setTestAdd( self, setName, values ): |
| 4369 | """ |
| 4370 | CLI command to add elements to a distributed set. |
| 4371 | Arguments: |
| 4372 | setName - The name of the set to add to. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4373 | values - The value(s) to add to the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4374 | Example usages: |
| 4375 | setTestAdd( "set1", "a b c" ) |
| 4376 | setTestAdd( "set2", "1" ) |
| 4377 | returns: |
| 4378 | main.TRUE on success OR |
| 4379 | main.FALSE if elements were already in the set OR |
| 4380 | main.ERROR on error |
| 4381 | """ |
| 4382 | try: |
| 4383 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4384 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4385 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 4386 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4387 | if re.search( positiveMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4388 | return main.TRUE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4389 | elif re.search( negativeMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4390 | return main.FALSE |
| 4391 | else: |
| 4392 | main.log.error( self.name + ": setTestAdd did not" + |
| 4393 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4394 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4395 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4396 | except TypeError: |
| 4397 | main.log.exception( self.name + ": Object not as expected" ) |
| 4398 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4399 | except Exception: |
| 4400 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4401 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4402 | |
| 4403 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 4404 | """ |
| 4405 | CLI command to remove elements from a distributed set. |
| 4406 | Required arguments: |
| 4407 | setName - The name of the set to remove from. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4408 | values - The value(s) to remove from the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4409 | Optional arguments: |
| 4410 | clear - Clear all elements from the set |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4411 | retain - Retain only the given values. (intersection of the |
| 4412 | original set and the given set) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4413 | returns: |
| 4414 | main.TRUE on success OR |
| 4415 | main.FALSE if the set was not changed OR |
| 4416 | main.ERROR on error |
| 4417 | """ |
| 4418 | try: |
| 4419 | cmdStr = "set-test-remove " |
| 4420 | if clear: |
| 4421 | cmdStr += "-c " + str( setName ) |
| 4422 | elif retain: |
| 4423 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4424 | else: |
| 4425 | cmdStr += str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4426 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4427 | if clear: |
| 4428 | pattern = "Set " + str( setName ) + " cleared" |
| 4429 | if re.search( pattern, output ): |
| 4430 | return main.TRUE |
| 4431 | elif retain: |
| 4432 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4433 | "only elements of set \[(.*)\]" |
| 4434 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4435 | "retaining only elements of the set " +\ |
| 4436 | "\[(.*)\]" |
| 4437 | if re.search( positivePattern, output ): |
| 4438 | return main.TRUE |
| 4439 | elif re.search( negativePattern, output ): |
| 4440 | return main.FALSE |
| 4441 | else: |
| 4442 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4443 | str( setName ) |
| 4444 | if ( len( values.split() ) == 1 ): |
| 4445 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4446 | str( setName ) |
| 4447 | else: |
| 4448 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4449 | str( setName ) |
| 4450 | if re.search( positivePattern, output ): |
| 4451 | return main.TRUE |
| 4452 | elif re.search( negativePattern, output ): |
| 4453 | return main.FALSE |
| 4454 | main.log.error( self.name + ": setTestRemove did not" + |
| 4455 | " match expected output" ) |
| 4456 | main.log.debug( self.name + " expected: " + pattern ) |
| 4457 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4458 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4459 | except TypeError: |
| 4460 | main.log.exception( self.name + ": Object not as expected" ) |
| 4461 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4462 | except Exception: |
| 4463 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4464 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4465 | |
| 4466 | def setTestGet( self, setName, values="" ): |
| 4467 | """ |
| 4468 | CLI command to get the elements in a distributed set. |
| 4469 | Required arguments: |
| 4470 | setName - The name of the set to remove from. |
| 4471 | Optional arguments: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4472 | values - The value(s) to check if in the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4473 | returns: |
| 4474 | main.ERROR on error OR |
| 4475 | A list of elements in the set if no optional arguments are |
| 4476 | supplied OR |
| 4477 | A tuple containing the list then: |
| 4478 | main.FALSE if the given values are not in the set OR |
| 4479 | main.TRUE if the given values are in the set OR |
| 4480 | """ |
| 4481 | try: |
| 4482 | values = str( values ).strip() |
| 4483 | setName = str( setName ).strip() |
| 4484 | length = len( values.split() ) |
| 4485 | containsCheck = None |
| 4486 | # Patterns to match |
| 4487 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4488 | pattern = "Items in set " + setName + ":\r\n" + setPattern |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4489 | containsTrue = "Set " + setName + " contains the value " + values |
| 4490 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4491 | values |
| 4492 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4493 | setPattern |
| 4494 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4495 | " subset " + setPattern |
| 4496 | |
| 4497 | cmdStr = "set-test-get " |
| 4498 | cmdStr += setName + " " + values |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4499 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4500 | if length == 0: |
| 4501 | match = re.search( pattern, output ) |
| 4502 | else: # if given values |
| 4503 | if length == 1: # Contains output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4504 | patternTrue = pattern + "\r\n" + containsTrue |
| 4505 | patternFalse = pattern + "\r\n" + containsFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4506 | else: # ContainsAll output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4507 | patternTrue = pattern + "\r\n" + containsAllTrue |
| 4508 | patternFalse = pattern + "\r\n" + containsAllFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4509 | matchTrue = re.search( patternTrue, output ) |
| 4510 | matchFalse = re.search( patternFalse, output ) |
| 4511 | if matchTrue: |
| 4512 | containsCheck = main.TRUE |
| 4513 | match = matchTrue |
| 4514 | elif matchFalse: |
| 4515 | containsCheck = main.FALSE |
| 4516 | match = matchFalse |
| 4517 | else: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4518 | main.log.error( self.name + " setTestGet did not match " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4519 | "expected output" ) |
| 4520 | main.log.debug( self.name + " expected: " + pattern ) |
| 4521 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4522 | match = None |
| 4523 | if match: |
| 4524 | setMatch = match.group( 1 ) |
| 4525 | if setMatch == '': |
| 4526 | setList = [] |
| 4527 | else: |
| 4528 | setList = setMatch.split( ", " ) |
| 4529 | if length > 0: |
| 4530 | return ( setList, containsCheck ) |
| 4531 | else: |
| 4532 | return setList |
| 4533 | else: # no match |
| 4534 | main.log.error( self.name + ": setTestGet did not" + |
| 4535 | " match expected output" ) |
| 4536 | main.log.debug( self.name + " expected: " + pattern ) |
| 4537 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4538 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4539 | except TypeError: |
| 4540 | main.log.exception( self.name + ": Object not as expected" ) |
| 4541 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4542 | except Exception: |
| 4543 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4544 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4545 | |
| 4546 | def setTestSize( self, setName ): |
| 4547 | """ |
| 4548 | CLI command to get the elements in a distributed set. |
| 4549 | Required arguments: |
| 4550 | setName - The name of the set to remove from. |
| 4551 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4552 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4553 | None on error |
| 4554 | """ |
| 4555 | try: |
| 4556 | # TODO: Should this check against the number of elements returned |
| 4557 | # and then return true/false based on that? |
| 4558 | setName = str( setName ).strip() |
| 4559 | # Patterns to match |
| 4560 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4561 | pattern = "There are (\d+) items in set " + setName + ":\r\n" +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4562 | setPattern |
| 4563 | cmdStr = "set-test-get -s " |
| 4564 | cmdStr += setName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4565 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4566 | if output: |
| 4567 | match = re.search( pattern, output ) |
| 4568 | if match: |
| 4569 | setSize = int( match.group( 1 ) ) |
| 4570 | setMatch = match.group( 2 ) |
| 4571 | if len( setMatch.split() ) == setSize: |
| 4572 | main.log.info( "The size returned by " + self.name + |
| 4573 | " matches the number of elements in " + |
| 4574 | "the returned set" ) |
| 4575 | else: |
| 4576 | main.log.error( "The size returned by " + self.name + |
| 4577 | " does not match the number of " + |
| 4578 | "elements in the returned set." ) |
| 4579 | return setSize |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4580 | else: # no match |
| 4581 | main.log.error( self.name + ": setTestGet did not" + |
| 4582 | " match expected output" ) |
| 4583 | main.log.debug( self.name + " expected: " + pattern ) |
| 4584 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4585 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4586 | except TypeError: |
| 4587 | main.log.exception( self.name + ": Object not as expected" ) |
| 4588 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4589 | except Exception: |
| 4590 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4591 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4592 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4593 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4594 | """ |
| 4595 | Command to list the various counters in the system. |
| 4596 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4597 | if jsonFormat, a string of the json object returned by the cli |
| 4598 | command |
| 4599 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4600 | None on error |
| 4601 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4602 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4603 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4604 | if jsonFormat: |
| 4605 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4606 | output = self.sendline( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4607 | main.log.debug( self.name + ": Counters unparsed: " + output ) |
| 4608 | output = output.split( "\r\n" )[ -1 ] |
| 4609 | main.log.debug( self.name + ": Counters parsed: " + output ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4610 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4611 | assert "Command not found:" not in output, output |
| 4612 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4613 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4614 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4615 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4616 | main.log.exception( self.name + ": Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4617 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4618 | except TypeError: |
| 4619 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4620 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4621 | except pexpect.EOF: |
| 4622 | main.log.error( self.name + ": EOF exception found" ) |
| 4623 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4624 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4625 | except Exception: |
| 4626 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4627 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4628 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4629 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4630 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4631 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4632 | Required arguments: |
| 4633 | counter - The name of the counter to increment. |
| 4634 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4635 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4636 | returns: |
| 4637 | integer value of the counter or |
| 4638 | None on Error |
| 4639 | """ |
| 4640 | try: |
| 4641 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4642 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4643 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4644 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4645 | if delta != 1: |
| 4646 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4647 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4648 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4649 | match = re.search( pattern, output ) |
| 4650 | if match: |
| 4651 | return int( match.group( 1 ) ) |
| 4652 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4653 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4654 | " match expected output." ) |
| 4655 | main.log.debug( self.name + " expected: " + pattern ) |
| 4656 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4657 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4658 | except TypeError: |
| 4659 | main.log.exception( self.name + ": Object not as expected" ) |
| 4660 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4661 | except Exception: |
| 4662 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4663 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4664 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4665 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4666 | """ |
| 4667 | CLI command to get a distributed counter then add a delta to it. |
| 4668 | Required arguments: |
| 4669 | counter - The name of the counter to increment. |
| 4670 | Optional arguments: |
| 4671 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4672 | returns: |
| 4673 | integer value of the counter or |
| 4674 | None on Error |
| 4675 | """ |
| 4676 | try: |
| 4677 | counter = str( counter ) |
| 4678 | delta = int( delta ) |
| 4679 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4680 | cmdStr += counter |
| 4681 | if delta != 1: |
| 4682 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4683 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4684 | pattern = counter + " was updated to (-?\d+)" |
| 4685 | match = re.search( pattern, output ) |
| 4686 | if match: |
| 4687 | return int( match.group( 1 ) ) |
| 4688 | else: |
| 4689 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4690 | " match expected output." ) |
| 4691 | main.log.debug( self.name + " expected: " + pattern ) |
| 4692 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4693 | return None |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4694 | except TypeError: |
| 4695 | main.log.exception( self.name + ": Object not as expected" ) |
| 4696 | return None |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4697 | except Exception: |
| 4698 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4699 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4700 | |
| 4701 | def valueTestGet( self, valueName ): |
| 4702 | """ |
| 4703 | CLI command to get the value of an atomic value. |
| 4704 | Required arguments: |
| 4705 | valueName - The name of the value to get. |
| 4706 | returns: |
| 4707 | string value of the value or |
| 4708 | None on Error |
| 4709 | """ |
| 4710 | try: |
| 4711 | valueName = str( valueName ) |
| 4712 | cmdStr = "value-test " |
| 4713 | operation = "get" |
| 4714 | cmdStr = "value-test {} {}".format( valueName, |
| 4715 | operation ) |
| 4716 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4717 | main.log.debug( self.name + ": value test unparsed: " + output ) |
| 4718 | output = output.split( "\r\n" )[ -1 ] |
| 4719 | main.log.debug( self.name + ": value test parsed: " + output ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4720 | pattern = "(\w+)" |
| 4721 | match = re.search( pattern, output ) |
| 4722 | if match: |
| 4723 | return match.group( 1 ) |
| 4724 | else: |
| 4725 | main.log.error( self.name + ": valueTestGet did not" + |
| 4726 | " match expected output." ) |
| 4727 | main.log.debug( self.name + " expected: " + pattern ) |
| 4728 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4729 | return None |
| 4730 | except TypeError: |
| 4731 | main.log.exception( self.name + ": Object not as expected" ) |
| 4732 | return None |
| 4733 | except Exception: |
| 4734 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4735 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4736 | |
| 4737 | def valueTestSet( self, valueName, newValue ): |
| 4738 | """ |
| 4739 | CLI command to set the value of an atomic value. |
| 4740 | Required arguments: |
| 4741 | valueName - The name of the value to set. |
| 4742 | newValue - The value to assign to the given value. |
| 4743 | returns: |
| 4744 | main.TRUE on success or |
| 4745 | main.ERROR on Error |
| 4746 | """ |
| 4747 | try: |
| 4748 | valueName = str( valueName ) |
| 4749 | newValue = str( newValue ) |
| 4750 | operation = "set" |
| 4751 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4752 | operation, |
| 4753 | newValue ) |
| 4754 | output = self.distPrimitivesSend( cmdStr ) |
| 4755 | if output is not None: |
| 4756 | return main.TRUE |
| 4757 | else: |
| 4758 | return main.ERROR |
| 4759 | except TypeError: |
| 4760 | main.log.exception( self.name + ": Object not as expected" ) |
| 4761 | return main.ERROR |
| 4762 | except Exception: |
| 4763 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4764 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4765 | |
| 4766 | def valueTestCompareAndSet( self, valueName, oldValue, newValue ): |
| 4767 | """ |
| 4768 | CLI command to compareAndSet the value of an atomic value. |
| 4769 | Required arguments: |
| 4770 | valueName - The name of the value. |
| 4771 | oldValue - Compare the current value of the atomic value to this |
| 4772 | newValue - If the value equals oldValue, set the value to newValue |
| 4773 | returns: |
| 4774 | main.TRUE on success or |
| 4775 | main.FALSE on failure or |
| 4776 | main.ERROR on Error |
| 4777 | """ |
| 4778 | try: |
| 4779 | valueName = str( valueName ) |
| 4780 | oldValue = str( oldValue ) |
| 4781 | newValue = str( newValue ) |
| 4782 | operation = "compareAndSet" |
| 4783 | cmdStr = "value-test {} {} {} {}".format( valueName, |
| 4784 | operation, |
| 4785 | oldValue, |
| 4786 | newValue ) |
| 4787 | output = self.distPrimitivesSend( cmdStr ) |
| 4788 | pattern = "(\w+)" |
| 4789 | match = re.search( pattern, output ) |
| 4790 | if match: |
| 4791 | result = match.group( 1 ) |
| 4792 | if result == "true": |
| 4793 | return main.TRUE |
| 4794 | elif result == "false": |
| 4795 | return main.FALSE |
| 4796 | else: |
| 4797 | main.log.error( self.name + ": valueTestCompareAndSet did not" + |
| 4798 | " match expected output." ) |
| 4799 | main.log.debug( self.name + " expected: " + pattern ) |
| 4800 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4801 | return main.ERROR |
| 4802 | except TypeError: |
| 4803 | main.log.exception( self.name + ": Object not as expected" ) |
| 4804 | return main.ERROR |
| 4805 | except Exception: |
| 4806 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4807 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4808 | |
| 4809 | def valueTestGetAndSet( self, valueName, newValue ): |
| 4810 | """ |
| 4811 | CLI command to getAndSet the value of an atomic value. |
| 4812 | Required arguments: |
| 4813 | valueName - The name of the value to get. |
| 4814 | newValue - The value to assign to the given value |
| 4815 | returns: |
| 4816 | string value of the value or |
| 4817 | None on Error |
| 4818 | """ |
| 4819 | try: |
| 4820 | valueName = str( valueName ) |
| 4821 | cmdStr = "value-test " |
| 4822 | operation = "getAndSet" |
| 4823 | cmdStr += valueName + " " + operation |
| 4824 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4825 | operation, |
| 4826 | newValue ) |
| 4827 | output = self.distPrimitivesSend( cmdStr ) |
| 4828 | pattern = "(\w+)" |
| 4829 | match = re.search( pattern, output ) |
| 4830 | if match: |
| 4831 | return match.group( 1 ) |
| 4832 | else: |
| 4833 | main.log.error( self.name + ": valueTestGetAndSet did not" + |
| 4834 | " match expected output." ) |
| 4835 | main.log.debug( self.name + " expected: " + pattern ) |
| 4836 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4837 | return None |
| 4838 | except TypeError: |
| 4839 | main.log.exception( self.name + ": Object not as expected" ) |
| 4840 | return None |
| 4841 | except Exception: |
| 4842 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4843 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4844 | |
| 4845 | def valueTestDestroy( self, valueName ): |
| 4846 | """ |
| 4847 | CLI command to destroy an atomic value. |
| 4848 | Required arguments: |
| 4849 | valueName - The name of the value to destroy. |
| 4850 | returns: |
| 4851 | main.TRUE on success or |
| 4852 | main.ERROR on Error |
| 4853 | """ |
| 4854 | try: |
| 4855 | valueName = str( valueName ) |
| 4856 | cmdStr = "value-test " |
| 4857 | operation = "destroy" |
| 4858 | cmdStr += valueName + " " + operation |
| 4859 | output = self.distPrimitivesSend( cmdStr ) |
| 4860 | if output is not None: |
| 4861 | return main.TRUE |
| 4862 | else: |
| 4863 | return main.ERROR |
| 4864 | except TypeError: |
| 4865 | main.log.exception( self.name + ": Object not as expected" ) |
| 4866 | return main.ERROR |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4867 | except Exception: |
| 4868 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4869 | main.cleanAndExit() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4870 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4871 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4872 | """ |
| 4873 | Description: Execute summary command in onos |
| 4874 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4875 | no output |
| 4876 | |
| 4877 | """ |
| 4878 | try: |
| 4879 | cmdStr = "summary" |
| 4880 | if jsonFormat: |
| 4881 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4882 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4883 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4884 | assert "Command not found:" not in handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4885 | assert "Error:" not in handle, handle |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 4886 | assert "Error executing" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4887 | if not handle: |
| 4888 | main.log.error( self.name + ": There is no output in " + |
| 4889 | "summary command" ) |
| 4890 | return main.FALSE |
| 4891 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4892 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4893 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4894 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4895 | except TypeError: |
| 4896 | main.log.exception( self.name + ": Object not as expected" ) |
| 4897 | return None |
| 4898 | except pexpect.EOF: |
| 4899 | main.log.error( self.name + ": EOF exception found" ) |
| 4900 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4901 | main.cleanAndExit() |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4902 | except Exception: |
| 4903 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4904 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4905 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4906 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4907 | """ |
| 4908 | CLI command to get the value of a key in a consistent map using |
| 4909 | transactions. This a test function and can only get keys from the |
| 4910 | test map hard coded into the cli command |
| 4911 | Required arguments: |
| 4912 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4913 | returns: |
| 4914 | The string value of the key or |
| 4915 | None on Error |
| 4916 | """ |
| 4917 | try: |
| 4918 | keyName = str( keyName ) |
| 4919 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4920 | cmdStr += keyName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4921 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4922 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4923 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4924 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4925 | return None |
| 4926 | else: |
| 4927 | match = re.search( pattern, output ) |
| 4928 | if match: |
| 4929 | return match.groupdict()[ 'value' ] |
| 4930 | else: |
| 4931 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4932 | " match expected output." ) |
| 4933 | main.log.debug( self.name + " expected: " + pattern ) |
| 4934 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4935 | return None |
| 4936 | except TypeError: |
| 4937 | main.log.exception( self.name + ": Object not as expected" ) |
| 4938 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4939 | except Exception: |
| 4940 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4941 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4942 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4943 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4944 | """ |
| 4945 | CLI command to put a value into 'numKeys' number of keys in a |
| 4946 | consistent map using transactions. This a test function and can only |
| 4947 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4948 | Required arguments: |
| 4949 | numKeys - Number of keys to add the value to |
| 4950 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4951 | returns: |
| 4952 | A dictionary whose keys are the name of the keys put into the map |
| 4953 | and the values of the keys are dictionaries whose key-values are |
| 4954 | 'value': value put into map and optionaly |
| 4955 | 'oldValue': Previous value in the key or |
| 4956 | None on Error |
| 4957 | |
| 4958 | Example output |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4959 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4960 | 'Key2': {'value': 'Testing'} } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4961 | """ |
| 4962 | try: |
| 4963 | numKeys = str( numKeys ) |
| 4964 | value = str( value ) |
| 4965 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4966 | cmdStr += numKeys + " " + value |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4967 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4968 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4969 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4970 | results = {} |
| 4971 | for line in output.splitlines(): |
| 4972 | new = re.search( newPattern, line ) |
| 4973 | updated = re.search( updatedPattern, line ) |
| 4974 | if new: |
| 4975 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 4976 | elif updated: |
| 4977 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4978 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4979 | else: |
| 4980 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4981 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4982 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 4983 | newPattern, |
| 4984 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4985 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4986 | return results |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4987 | except ( TypeError, AttributeError ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4988 | main.log.exception( self.name + ": Object not as expected" ) |
| 4989 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4990 | except Exception: |
| 4991 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4992 | main.cleanAndExit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4993 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4994 | def maps( self, jsonFormat=True ): |
| 4995 | """ |
| 4996 | Description: Returns result of onos:maps |
| 4997 | Optional: |
| 4998 | * jsonFormat: enable json formatting of output |
| 4999 | """ |
| 5000 | try: |
| 5001 | cmdStr = "maps" |
| 5002 | if jsonFormat: |
| 5003 | cmdStr += " -j" |
| 5004 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5005 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5006 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 5007 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5008 | except AssertionError: |
| 5009 | main.log.exception( "" ) |
| 5010 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 5011 | except TypeError: |
| 5012 | main.log.exception( self.name + ": Object not as expected" ) |
| 5013 | return None |
| 5014 | except pexpect.EOF: |
| 5015 | main.log.error( self.name + ": EOF exception found" ) |
| 5016 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5017 | main.cleanAndExit() |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 5018 | except Exception: |
| 5019 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5020 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5021 | |
| 5022 | def getSwController( self, uri, jsonFormat=True ): |
| 5023 | """ |
| 5024 | Descrition: Gets the controller information from the device |
| 5025 | """ |
| 5026 | try: |
| 5027 | cmd = "device-controllers " |
| 5028 | if jsonFormat: |
| 5029 | cmd += "-j " |
| 5030 | response = self.sendline( cmd + uri ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5031 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5032 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5033 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5034 | except AssertionError: |
| 5035 | main.log.exception( "" ) |
| 5036 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5037 | except TypeError: |
| 5038 | main.log.exception( self.name + ": Object not as expected" ) |
| 5039 | return None |
| 5040 | except pexpect.EOF: |
| 5041 | main.log.error( self.name + ": EOF exception found" ) |
| 5042 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5043 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5044 | except Exception: |
| 5045 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5046 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5047 | |
| 5048 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 5049 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5050 | Descrition: sets the controller(s) for the specified device |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5051 | |
| 5052 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5053 | Required: uri - String: The uri of the device(switch). |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5054 | ip - String or List: The ip address of the controller. |
| 5055 | This parameter can be formed in a couple of different ways. |
| 5056 | VALID: |
| 5057 | 10.0.0.1 - just the ip address |
| 5058 | tcp:10.0.0.1 - the protocol and the ip address |
| 5059 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 5060 | so that you can add controllers with different |
| 5061 | protocols and ports |
| 5062 | INVALID: |
| 5063 | 10.0.0.1:6653 - this is not supported by ONOS |
| 5064 | |
| 5065 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 5066 | port - The port number. |
| 5067 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 5068 | |
| 5069 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 5070 | """ |
| 5071 | try: |
| 5072 | cmd = "device-setcontrollers" |
| 5073 | |
| 5074 | if jsonFormat: |
| 5075 | cmd += " -j" |
| 5076 | cmd += " " + uri |
| 5077 | if isinstance( ip, str ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5078 | ip = [ ip ] |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5079 | for item in ip: |
| 5080 | if ":" in item: |
| 5081 | sitem = item.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5082 | if len( sitem ) == 3: |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5083 | cmd += " " + item |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5084 | elif "." in sitem[ 1 ]: |
| 5085 | cmd += " {}:{}".format( item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5086 | else: |
| 5087 | main.log.error( "Malformed entry: " + item ) |
| 5088 | raise TypeError |
| 5089 | else: |
| 5090 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5091 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5092 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5093 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5094 | if "Error" in response: |
| 5095 | main.log.error( response ) |
| 5096 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5097 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5098 | except AssertionError: |
| 5099 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5100 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5101 | except TypeError: |
| 5102 | main.log.exception( self.name + ": Object not as expected" ) |
| 5103 | return main.FALSE |
| 5104 | except pexpect.EOF: |
| 5105 | main.log.error( self.name + ": EOF exception found" ) |
| 5106 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5107 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5108 | except Exception: |
| 5109 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5110 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5111 | |
| 5112 | def removeDevice( self, device ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5113 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5114 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5115 | Remove a device from ONOS by passing the uri of the device(s). |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5116 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5117 | 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] | 5118 | Returns: |
| 5119 | Returns main.FALSE if an exception is thrown or an error is present |
| 5120 | in the response. Otherwise, returns main.TRUE. |
| 5121 | NOTE: |
| 5122 | 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] | 5123 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5124 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5125 | if isinstance( device, str ): |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 5126 | deviceStr = device |
| 5127 | device = [] |
| 5128 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5129 | |
| 5130 | for d in device: |
| 5131 | time.sleep( 1 ) |
| 5132 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5133 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5134 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5135 | if "Error" in response: |
| 5136 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 5137 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5138 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5139 | except AssertionError: |
| 5140 | main.log.exception( "" ) |
| 5141 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5142 | except TypeError: |
| 5143 | main.log.exception( self.name + ": Object not as expected" ) |
| 5144 | return main.FALSE |
| 5145 | except pexpect.EOF: |
| 5146 | main.log.error( self.name + ": EOF exception found" ) |
| 5147 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5148 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5149 | except Exception: |
| 5150 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5151 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5152 | |
| 5153 | def removeHost( self, host ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5154 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5155 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5156 | Remove a host from ONOS by passing the id of the host(s) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5157 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5158 | 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] | 5159 | Returns: |
| 5160 | Returns main.FALSE if an exception is thrown or an error is present |
| 5161 | in the response. Otherwise, returns main.TRUE. |
| 5162 | NOTE: |
| 5163 | 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] | 5164 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5165 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5166 | if isinstance( host, str ): |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5167 | host = list( host ) |
| 5168 | |
| 5169 | for h in host: |
| 5170 | time.sleep( 1 ) |
| 5171 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5172 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5173 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5174 | if "Error" in response: |
| 5175 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 5176 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5177 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5178 | except AssertionError: |
| 5179 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5180 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5181 | except TypeError: |
| 5182 | main.log.exception( self.name + ": Object not as expected" ) |
| 5183 | return main.FALSE |
| 5184 | except pexpect.EOF: |
| 5185 | main.log.error( self.name + ": EOF exception found" ) |
| 5186 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5187 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5188 | except Exception: |
| 5189 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5190 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5191 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5192 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5193 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5194 | Description: |
| 5195 | Bring link down or up in the null-provider. |
| 5196 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5197 | begin - (string) One end of a device or switch. |
| 5198 | end - (string) the other end of the device or switch |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5199 | returns: |
| 5200 | main.TRUE if no exceptions were thrown and no Errors are |
| 5201 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5202 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5203 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5204 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5205 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5206 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5207 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5208 | if "Error" in response or "Failure" in response: |
| 5209 | main.log.error( response ) |
| 5210 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5211 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5212 | except AssertionError: |
| 5213 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5214 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5215 | except TypeError: |
| 5216 | main.log.exception( self.name + ": Object not as expected" ) |
| 5217 | return main.FALSE |
| 5218 | except pexpect.EOF: |
| 5219 | main.log.error( self.name + ": EOF exception found" ) |
| 5220 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5221 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5222 | except Exception: |
| 5223 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5224 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5225 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5226 | def portstate( self, dpid, port, state ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5227 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5228 | Description: |
| 5229 | Changes the state of port in an OF switch by means of the |
| 5230 | PORTSTATUS OF messages. |
| 5231 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5232 | dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102' |
| 5233 | port - (string) target port in the device. Ex: '2' |
| 5234 | state - (string) target state (enable or disable) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5235 | returns: |
| 5236 | main.TRUE if no exceptions were thrown and no Errors are |
| 5237 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5238 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5239 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5240 | state = state.lower() |
| 5241 | assert state == 'enable' or state == 'disable', "Unknown state" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5242 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5243 | response = self.sendline( cmd, showResponse=True ) |
| 5244 | assert response is not None, "Error in sendline" |
| 5245 | assert "Command not found:" not in response, response |
| 5246 | if "Error" in response or "Failure" in response: |
| 5247 | main.log.error( response ) |
| 5248 | return main.FALSE |
| 5249 | return main.TRUE |
| 5250 | except AssertionError: |
| 5251 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5252 | return main.FALSE |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5253 | except TypeError: |
| 5254 | main.log.exception( self.name + ": Object not as expected" ) |
| 5255 | return main.FALSE |
| 5256 | except pexpect.EOF: |
| 5257 | main.log.error( self.name + ": EOF exception found" ) |
| 5258 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5259 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5260 | except Exception: |
| 5261 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5262 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5263 | |
| 5264 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 5265 | """ |
| 5266 | Set the logging level to lvl for a specific app |
| 5267 | returns main.TRUE on success |
| 5268 | returns main.FALSE if Error occurred |
| 5269 | if noExit is True, TestON will not exit, but clean up |
| 5270 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 5271 | Level defaults to INFO |
| 5272 | """ |
| 5273 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5274 | self.handle.sendline( "log:set %s %s" % ( level, app ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 5275 | self.handle.expect( self.karafPrompt ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5276 | |
| 5277 | response = self.handle.before |
| 5278 | if re.search( "Error", response ): |
| 5279 | return main.FALSE |
| 5280 | return main.TRUE |
| 5281 | except pexpect.TIMEOUT: |
| 5282 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5283 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5284 | except pexpect.EOF: |
| 5285 | main.log.error( self.name + ": EOF exception found" ) |
| 5286 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5287 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5288 | except Exception: |
| 5289 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5290 | main.cleanAndExit() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5291 | |
| 5292 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 5293 | """ |
| 5294 | Return a dictionary which describes the latest network topology data as a |
| 5295 | graph. |
| 5296 | An example of the dictionary: |
| 5297 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 5298 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 5299 | Each vertex should at least have an 'edges' attribute which describes the |
| 5300 | adjacency information. The value of 'edges' attribute is also represented by |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5301 | 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] | 5302 | list of attributes. |
| 5303 | An example of the edges dictionary: |
| 5304 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 5305 | vertex3: { 'port': ..., 'weight': ... } } |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5306 | If includeHost == True, all hosts (and host-switch links) will be included |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5307 | in topology data. |
| 5308 | """ |
| 5309 | graphDict = {} |
| 5310 | try: |
| 5311 | links = self.links() |
| 5312 | links = json.loads( links ) |
| 5313 | devices = self.devices() |
| 5314 | devices = json.loads( devices ) |
| 5315 | idToDevice = {} |
| 5316 | for device in devices: |
| 5317 | idToDevice[ device[ 'id' ] ] = device |
| 5318 | if includeHost: |
| 5319 | hosts = self.hosts() |
| 5320 | # FIXME: support 'includeHost' argument |
| 5321 | for link in links: |
| 5322 | nodeA = link[ 'src' ][ 'device' ] |
| 5323 | nodeB = link[ 'dst' ][ 'device' ] |
| 5324 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5325 | if nodeA not in graphDict.keys(): |
| 5326 | graphDict[ nodeA ] = { 'edges': {}, |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5327 | 'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ], |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5328 | 'type': idToDevice[ nodeA ][ 'type' ], |
| 5329 | 'available': idToDevice[ nodeA ][ 'available' ], |
| 5330 | 'role': idToDevice[ nodeA ][ 'role' ], |
| 5331 | 'mfr': idToDevice[ nodeA ][ 'mfr' ], |
| 5332 | 'hw': idToDevice[ nodeA ][ 'hw' ], |
| 5333 | 'sw': idToDevice[ nodeA ][ 'sw' ], |
| 5334 | 'serial': idToDevice[ nodeA ][ 'serial' ], |
| 5335 | 'chassisId': idToDevice[ nodeA ][ 'chassisId' ], |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5336 | 'annotations': idToDevice[ nodeA ][ 'annotations' ]} |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5337 | else: |
| 5338 | # Assert nodeB is not connected to any current links of nodeA |
You Wang | 7d14d64 | 2019-01-23 15:10:08 -0800 | [diff] [blame] | 5339 | # assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
| 5340 | pass |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5341 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ], |
| 5342 | 'type': link[ 'type' ], |
| 5343 | 'state': link[ 'state' ] } |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5344 | return graphDict |
| 5345 | except ( TypeError, ValueError ): |
| 5346 | main.log.exception( self.name + ": Object not as expected" ) |
| 5347 | return None |
| 5348 | except KeyError: |
| 5349 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5350 | return None |
| 5351 | except AssertionError: |
| 5352 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5353 | return None |
| 5354 | except pexpect.EOF: |
| 5355 | main.log.error( self.name + ": EOF exception found" ) |
| 5356 | main.log.error( self.name + ": " + self.handle.before ) |
| 5357 | return None |
| 5358 | except Exception: |
| 5359 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5360 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5361 | |
| 5362 | def getIntentPerfSummary( self ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5363 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5364 | Send command to check intent-perf summary |
| 5365 | Returns: dictionary for intent-perf summary |
| 5366 | if something wrong, function will return None |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5367 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5368 | cmd = "intent-perf -s" |
| 5369 | respDic = {} |
| 5370 | resp = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 5371 | assert resp is not None, "Error in sendline" |
| 5372 | assert "Command not found:" not in resp, resp |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5373 | try: |
| 5374 | # Generate the dictionary to return |
| 5375 | for l in resp.split( "\n" ): |
| 5376 | # Delete any white space in line |
| 5377 | temp = re.sub( r'\s+', '', l ) |
| 5378 | temp = temp.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5379 | respDic[ temp[ 0 ] ] = temp[ 1 ] |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5380 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5381 | except ( TypeError, ValueError ): |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5382 | main.log.exception( self.name + ": Object not as expected" ) |
| 5383 | return None |
| 5384 | except KeyError: |
| 5385 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5386 | return None |
| 5387 | except AssertionError: |
| 5388 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5389 | return None |
| 5390 | except pexpect.EOF: |
| 5391 | main.log.error( self.name + ": EOF exception found" ) |
| 5392 | main.log.error( self.name + ": " + self.handle.before ) |
| 5393 | return None |
| 5394 | except Exception: |
| 5395 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5396 | return None |
| 5397 | return respDic |
| 5398 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5399 | def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ): |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5400 | """ |
| 5401 | Searches the latest ONOS log file for the given search term and |
| 5402 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5403 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5404 | Arguments: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5405 | searchTerm: |
| 5406 | The string to grep from the ONOS log. |
| 5407 | startLine: |
| 5408 | The term that decides which line is the start to search the searchTerm in |
| 5409 | the karaf log. For now, startTerm only works in 'first' mode. |
| 5410 | logNum: |
| 5411 | In some extreme cases, one karaf log is not big enough to contain all the |
| 5412 | information.Because of this, search mutiply logs is necessary to capture |
| 5413 | the right result. logNum is the number of karaf logs that we need to search |
| 5414 | the searchTerm. |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5415 | mode: |
| 5416 | all: return all the strings that contain the search term |
| 5417 | last: return the last string that contains the search term |
| 5418 | first: return the first string that contains the search term |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5419 | num: return the number of times that the searchTerm appears in the log |
| 5420 | total: return how many lines in karaf log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5421 | """ |
| 5422 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5423 | assert isinstance( searchTerm, str ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5424 | # Build the log paths string |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5425 | logPath = '/opt/onos/log/karaf.log.' |
| 5426 | logPaths = '/opt/onos/log/karaf.log' |
| 5427 | for i in range( 1, logNum ): |
| 5428 | logPaths = logPath + str( i ) + " " + logPaths |
| 5429 | cmd = "cat " + logPaths |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5430 | if startLine: |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5431 | # 100000000 is just a extreme large number to make sure this function can |
| 5432 | # grep all the lines after startLine |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5433 | cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'" |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5434 | if mode == 'all': |
| 5435 | cmd = cmd + " | grep \'" + searchTerm + "\'" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5436 | elif mode == 'last': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5437 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5438 | elif mode == 'first': |
| 5439 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1" |
| 5440 | elif mode == 'num': |
You Wang | d91a70f | 2019-01-03 15:28:10 -0800 | [diff] [blame] | 5441 | cmd = cmd + " | grep \'" + searchTerm + "\' | wc -l" |
| 5442 | num = self.lineCount( cmd ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5443 | return num |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5444 | elif mode == 'total': |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 5445 | totalLines = self.lineCount( "cat /opt/onos/log/karaf.log | wc -l" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5446 | return int( totalLines ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5447 | else: |
| 5448 | main.log.error( self.name + " unsupported mode" ) |
| 5449 | return main.ERROR |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5450 | before = self.sendline( cmd ) |
| 5451 | before = before.splitlines() |
| 5452 | # make sure the returned list only contains the search term |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5453 | returnLines = [ line for line in before if searchTerm in line ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5454 | return returnLines |
| 5455 | except AssertionError: |
| 5456 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5457 | return None |
| 5458 | except pexpect.EOF: |
| 5459 | main.log.error( self.name + ": EOF exception found" ) |
| 5460 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5461 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5462 | except pexpect.TIMEOUT: |
| 5463 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5464 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5465 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5466 | except Exception: |
| 5467 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5468 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5469 | |
| 5470 | def vplsShow( self, jsonFormat=True ): |
| 5471 | """ |
| 5472 | Description: Returns result of onos:vpls show, which should list the |
| 5473 | configured VPLS networks and the assigned interfaces. |
| 5474 | Optional: |
| 5475 | * jsonFormat: enable json formatting of output |
| 5476 | Returns: |
| 5477 | The output of the command or None on error. |
| 5478 | """ |
| 5479 | try: |
| 5480 | cmdStr = "vpls show" |
| 5481 | if jsonFormat: |
| 5482 | raise NotImplementedError |
| 5483 | cmdStr += " -j" |
| 5484 | handle = self.sendline( cmdStr ) |
| 5485 | assert handle is not None, "Error in sendline" |
| 5486 | assert "Command not found:" not in handle, handle |
| 5487 | return handle |
| 5488 | except AssertionError: |
| 5489 | main.log.exception( "" ) |
| 5490 | return None |
| 5491 | except TypeError: |
| 5492 | main.log.exception( self.name + ": Object not as expected" ) |
| 5493 | return None |
| 5494 | except pexpect.EOF: |
| 5495 | main.log.error( self.name + ": EOF exception found" ) |
| 5496 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5497 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5498 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5499 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5500 | return None |
| 5501 | except Exception: |
| 5502 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5503 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5504 | |
| 5505 | def parseVplsShow( self ): |
| 5506 | """ |
| 5507 | Parse the cli output of 'vpls show' into json output. This is required |
| 5508 | as there is currently no json output available. |
| 5509 | """ |
| 5510 | try: |
| 5511 | output = [] |
| 5512 | raw = self.vplsShow( jsonFormat=False ) |
| 5513 | namePat = "VPLS name: (?P<name>\w+)" |
| 5514 | interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]" |
| 5515 | encapPat = "Encapsulation: (?P<encap>\w+)" |
| 5516 | pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] ) |
| 5517 | mIter = re.finditer( pattern, raw ) |
| 5518 | for match in mIter: |
| 5519 | item = {} |
| 5520 | item[ 'name' ] = match.group( 'name' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5521 | ifaces = match.group( 'interfaces' ).split( ', ' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5522 | if ifaces == [ "" ]: |
| 5523 | ifaces = [] |
| 5524 | item[ 'interfaces' ] = ifaces |
| 5525 | encap = match.group( 'encap' ) |
| 5526 | if encap != 'NONE': |
| 5527 | item[ 'encapsulation' ] = encap.lower() |
| 5528 | output.append( item ) |
| 5529 | return output |
| 5530 | except Exception: |
| 5531 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5532 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5533 | |
| 5534 | def vplsList( self, jsonFormat=True ): |
| 5535 | """ |
| 5536 | Description: Returns result of onos:vpls list, which should list the |
| 5537 | configured VPLS networks. |
| 5538 | Optional: |
| 5539 | * jsonFormat: enable json formatting of output |
| 5540 | """ |
| 5541 | try: |
| 5542 | cmdStr = "vpls list" |
| 5543 | if jsonFormat: |
| 5544 | raise NotImplementedError |
| 5545 | cmdStr += " -j" |
| 5546 | handle = self.sendline( cmdStr ) |
| 5547 | assert handle is not None, "Error in sendline" |
| 5548 | assert "Command not found:" not in handle, handle |
| 5549 | return handle |
| 5550 | except AssertionError: |
| 5551 | main.log.exception( "" ) |
| 5552 | return None |
| 5553 | except TypeError: |
| 5554 | main.log.exception( self.name + ": Object not as expected" ) |
| 5555 | return None |
| 5556 | except pexpect.EOF: |
| 5557 | main.log.error( self.name + ": EOF exception found" ) |
| 5558 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5559 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5560 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5561 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5562 | return None |
| 5563 | except Exception: |
| 5564 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5565 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5566 | |
| 5567 | def vplsCreate( self, network ): |
| 5568 | """ |
| 5569 | CLI command to create a new VPLS network. |
| 5570 | Required arguments: |
| 5571 | network - String name of the network to create. |
| 5572 | returns: |
| 5573 | main.TRUE on success and main.FALSE on failure |
| 5574 | """ |
| 5575 | try: |
| 5576 | network = str( network ) |
| 5577 | cmdStr = "vpls create " |
| 5578 | cmdStr += network |
| 5579 | output = self.sendline( cmdStr ) |
| 5580 | assert output is not None, "Error in sendline" |
| 5581 | assert "Command not found:" not in output, output |
| 5582 | assert "Error executing command" not in output, output |
| 5583 | assert "VPLS already exists:" not in output, output |
| 5584 | return main.TRUE |
| 5585 | except AssertionError: |
| 5586 | main.log.exception( "" ) |
| 5587 | return main.FALSE |
| 5588 | except TypeError: |
| 5589 | main.log.exception( self.name + ": Object not as expected" ) |
| 5590 | return main.FALSE |
| 5591 | except pexpect.EOF: |
| 5592 | main.log.error( self.name + ": EOF exception found" ) |
| 5593 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5594 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5595 | except Exception: |
| 5596 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5597 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5598 | |
| 5599 | def vplsDelete( self, network ): |
| 5600 | """ |
| 5601 | CLI command to delete a VPLS network. |
| 5602 | Required arguments: |
| 5603 | network - Name of the network to delete. |
| 5604 | returns: |
| 5605 | main.TRUE on success and main.FALSE on failure |
| 5606 | """ |
| 5607 | try: |
| 5608 | network = str( network ) |
| 5609 | cmdStr = "vpls delete " |
| 5610 | cmdStr += network |
| 5611 | output = self.sendline( cmdStr ) |
| 5612 | assert output is not None, "Error in sendline" |
| 5613 | assert "Command not found:" not in output, output |
| 5614 | assert "Error executing command" not in output, output |
| 5615 | assert " not found" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5616 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5617 | return main.TRUE |
| 5618 | except AssertionError: |
| 5619 | main.log.exception( "" ) |
| 5620 | return main.FALSE |
| 5621 | except TypeError: |
| 5622 | main.log.exception( self.name + ": Object not as expected" ) |
| 5623 | return main.FALSE |
| 5624 | except pexpect.EOF: |
| 5625 | main.log.error( self.name + ": EOF exception found" ) |
| 5626 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5627 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5628 | except Exception: |
| 5629 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5630 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5631 | |
| 5632 | def vplsAddIface( self, network, iface ): |
| 5633 | """ |
| 5634 | CLI command to add an interface to a VPLS network. |
| 5635 | Required arguments: |
| 5636 | network - Name of the network to add the interface to. |
| 5637 | iface - The ONOS name for an interface. |
| 5638 | returns: |
| 5639 | main.TRUE on success and main.FALSE on failure |
| 5640 | """ |
| 5641 | try: |
| 5642 | network = str( network ) |
| 5643 | iface = str( iface ) |
| 5644 | cmdStr = "vpls add-if " |
| 5645 | cmdStr += network + " " + iface |
| 5646 | output = self.sendline( cmdStr ) |
| 5647 | assert output is not None, "Error in sendline" |
| 5648 | assert "Command not found:" not in output, output |
| 5649 | assert "Error executing command" not in output, output |
| 5650 | assert "already associated to network" not in output, output |
| 5651 | assert "Interface cannot be added." 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 vplsRemIface( self, network, iface ): |
| 5669 | """ |
| 5670 | CLI command to remove an interface from a VPLS network. |
| 5671 | Required arguments: |
| 5672 | network - Name of the network to remove the interface from. |
| 5673 | iface - Name of the interface to remove. |
| 5674 | returns: |
| 5675 | main.TRUE on success and main.FALSE on failure |
| 5676 | """ |
| 5677 | try: |
| 5678 | iface = str( iface ) |
| 5679 | cmdStr = "vpls rem-if " |
| 5680 | cmdStr += network + " " + iface |
| 5681 | output = self.sendline( cmdStr ) |
| 5682 | assert output is not None, "Error in sendline" |
| 5683 | assert "Command not found:" not in output, output |
| 5684 | assert "Error executing command" not in output, output |
| 5685 | assert "is not configured" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5686 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5687 | return main.TRUE |
| 5688 | except AssertionError: |
| 5689 | main.log.exception( "" ) |
| 5690 | return main.FALSE |
| 5691 | except TypeError: |
| 5692 | main.log.exception( self.name + ": Object not as expected" ) |
| 5693 | return main.FALSE |
| 5694 | except pexpect.EOF: |
| 5695 | main.log.error( self.name + ": EOF exception found" ) |
| 5696 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5697 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5698 | except Exception: |
| 5699 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5700 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5701 | |
| 5702 | def vplsClean( self ): |
| 5703 | """ |
| 5704 | Description: Clears the VPLS app configuration. |
| 5705 | Returns: main.TRUE on success and main.FALSE on failure |
| 5706 | """ |
| 5707 | try: |
| 5708 | cmdStr = "vpls clean" |
| 5709 | handle = self.sendline( cmdStr ) |
| 5710 | assert handle is not None, "Error in sendline" |
| 5711 | assert "Command not found:" not in handle, handle |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5712 | assert "still updating" not in handle, handle |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5713 | return handle |
| 5714 | except AssertionError: |
| 5715 | main.log.exception( "" ) |
| 5716 | return main.FALSE |
| 5717 | except TypeError: |
| 5718 | main.log.exception( self.name + ": Object not as expected" ) |
| 5719 | return main.FALSE |
| 5720 | except pexpect.EOF: |
| 5721 | main.log.error( self.name + ": EOF exception found" ) |
| 5722 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5723 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5724 | except Exception: |
| 5725 | main.log.exception( self.name + ": Uncaught exception!" ) |
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 | |
| 5728 | def vplsSetEncap( self, network, encapType ): |
| 5729 | """ |
| 5730 | CLI command to add an interface to a VPLS network. |
| 5731 | Required arguments: |
| 5732 | network - Name of the network to create. |
| 5733 | encapType - Type of encapsulation. |
| 5734 | returns: |
| 5735 | main.TRUE on success and main.FALSE on failure |
| 5736 | """ |
| 5737 | try: |
| 5738 | network = str( network ) |
| 5739 | encapType = str( encapType ).upper() |
| 5740 | assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type" |
| 5741 | cmdStr = "vpls set-encap " |
| 5742 | cmdStr += network + " " + encapType |
| 5743 | output = self.sendline( cmdStr ) |
| 5744 | assert output is not None, "Error in sendline" |
| 5745 | assert "Command not found:" not in output, output |
| 5746 | assert "Error executing command" not in output, output |
| 5747 | assert "already associated to network" not in output, output |
| 5748 | assert "Encapsulation type " not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5749 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5750 | return main.TRUE |
| 5751 | except AssertionError: |
| 5752 | main.log.exception( "" ) |
| 5753 | return main.FALSE |
| 5754 | except TypeError: |
| 5755 | main.log.exception( self.name + ": Object not as expected" ) |
| 5756 | return main.FALSE |
| 5757 | except pexpect.EOF: |
| 5758 | main.log.error( self.name + ": EOF exception found" ) |
| 5759 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5760 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 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() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5764 | |
| 5765 | def interfaces( self, jsonFormat=True ): |
| 5766 | """ |
| 5767 | Description: Returns result of interfaces command. |
| 5768 | Optional: |
| 5769 | * jsonFormat: enable json formatting of output |
| 5770 | Returns: |
| 5771 | The output of the command or None on error. |
| 5772 | """ |
| 5773 | try: |
| 5774 | cmdStr = "interfaces" |
| 5775 | if jsonFormat: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5776 | raise NotImplementedError |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5777 | cmdStr += " -j" |
| 5778 | handle = self.sendline( cmdStr ) |
| 5779 | assert handle is not None, "Error in sendline" |
| 5780 | assert "Command not found:" not in handle, handle |
| 5781 | return handle |
| 5782 | except AssertionError: |
| 5783 | main.log.exception( "" ) |
| 5784 | return None |
| 5785 | except TypeError: |
| 5786 | main.log.exception( self.name + ": Object not as expected" ) |
| 5787 | return None |
| 5788 | except pexpect.EOF: |
| 5789 | main.log.error( self.name + ": EOF exception found" ) |
| 5790 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5791 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5792 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5793 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5794 | return None |
| 5795 | except Exception: |
| 5796 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5797 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5798 | |
| 5799 | def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5800 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5801 | Get the timestamp of searchTerm from karaf log. |
| 5802 | |
| 5803 | Arguments: |
| 5804 | splitTerm_before and splitTerm_after: |
| 5805 | |
| 5806 | The terms that split the string that contains the timeStamp of |
| 5807 | searchTerm. For example, if that string is "xxxxxxxcreationTime = |
| 5808 | 1419510501xxxxxx", then the splitTerm_before is "CreationTime = " |
| 5809 | and the splitTerm_after is "x" |
| 5810 | |
| 5811 | others: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5812 | Please look at the "logsearch" Function in onosclidriver.py |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5813 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5814 | if logNum < 0: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5815 | main.log.error( "Get wrong log number ") |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5816 | return main.ERROR |
| 5817 | lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5818 | if len( lines ) == 0: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5819 | main.log.warn( "Captured timestamp string is empty" ) |
| 5820 | return main.ERROR |
| 5821 | lines = lines[ 0 ] |
| 5822 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5823 | assert isinstance( lines, str ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5824 | # get the target value |
| 5825 | line = lines.split( splitTerm_before ) |
| 5826 | key = line[ 1 ].split( splitTerm_after ) |
| 5827 | return int( key[ 0 ] ) |
| 5828 | except IndexError: |
| 5829 | main.log.warn( "Index Error!" ) |
| 5830 | return main.ERROR |
| 5831 | except AssertionError: |
| 5832 | main.log.warn( "Search Term Not Found " ) |
| 5833 | return main.ERROR |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5834 | |
| 5835 | def workQueueAdd( self, queueName, value ): |
| 5836 | """ |
| 5837 | CLI command to add a string to the specified Work Queue. |
| 5838 | This function uses the distributed primitives test app, which |
| 5839 | gives some cli access to distributed primitives for testing |
| 5840 | purposes only. |
| 5841 | |
| 5842 | Required arguments: |
| 5843 | queueName - The name of the queue to add to |
| 5844 | value - The 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 | value = str( value ) |
| 5852 | prefix = "work-queue-test" |
| 5853 | operation = "add" |
| 5854 | cmdStr = " ".join( [ prefix, queueName, operation, value ] ) |
| 5855 | output = self.distPrimitivesSend( cmdStr ) |
| 5856 | if "Invalid operation name" in output: |
| 5857 | main.log.warn( output ) |
| 5858 | return main.ERROR |
| 5859 | elif "Done" in output: |
| 5860 | return main.TRUE |
| 5861 | except TypeError: |
| 5862 | main.log.exception( self.name + ": Object not as expected" ) |
| 5863 | return main.ERROR |
| 5864 | except Exception: |
| 5865 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5866 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5867 | |
| 5868 | def workQueueAddMultiple( self, queueName, value1, value2 ): |
| 5869 | """ |
| 5870 | CLI command to add two strings to the specified Work Queue. |
| 5871 | This function uses the distributed primitives test app, which |
| 5872 | gives some cli access to distributed primitives for testing |
| 5873 | purposes only. |
| 5874 | |
| 5875 | Required arguments: |
| 5876 | queueName - The name of the queue to add to |
| 5877 | value1 - The first value to add to the queue |
| 5878 | value2 - The second value to add to the queue |
| 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 | value1 = str( value1 ) |
| 5886 | value2 = str( value2 ) |
| 5887 | prefix = "work-queue-test" |
| 5888 | operation = "addMultiple" |
| 5889 | cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] ) |
| 5890 | output = self.distPrimitivesSend( cmdStr ) |
| 5891 | if "Invalid operation name" in output: |
| 5892 | main.log.warn( output ) |
| 5893 | return main.ERROR |
| 5894 | elif "Done" in output: |
| 5895 | return main.TRUE |
| 5896 | except TypeError: |
| 5897 | main.log.exception( self.name + ": Object not as expected" ) |
| 5898 | return main.ERROR |
| 5899 | except Exception: |
| 5900 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5901 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5902 | |
| 5903 | def workQueueTakeAndComplete( self, queueName, number=1 ): |
| 5904 | """ |
| 5905 | CLI command to take a value from the specified Work Queue and compelte it. |
| 5906 | This function uses the distributed primitives test app, which |
| 5907 | gives some cli access to distributed primitives for testing |
| 5908 | purposes only. |
| 5909 | |
| 5910 | Required arguments: |
| 5911 | queueName - The name of the queue to add to |
| 5912 | number - The number of items to take and complete |
| 5913 | returns: |
| 5914 | main.TRUE on success, main.FALSE on failure and |
| 5915 | main.ERROR on error. |
| 5916 | """ |
| 5917 | try: |
| 5918 | queueName = str( queueName ) |
| 5919 | number = str( int( number ) ) |
| 5920 | prefix = "work-queue-test" |
| 5921 | operation = "takeAndComplete" |
| 5922 | cmdStr = " ".join( [ prefix, queueName, operation, number ] ) |
| 5923 | output = self.distPrimitivesSend( cmdStr ) |
| 5924 | if "Invalid operation name" in output: |
| 5925 | main.log.warn( output ) |
| 5926 | return main.ERROR |
| 5927 | elif "Done" in output: |
| 5928 | return main.TRUE |
| 5929 | except TypeError: |
| 5930 | main.log.exception( self.name + ": Object not as expected" ) |
| 5931 | return main.ERROR |
| 5932 | except Exception: |
| 5933 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5934 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5935 | |
| 5936 | def workQueueDestroy( self, queueName ): |
| 5937 | """ |
| 5938 | CLI command to destroy the specified Work Queue. |
| 5939 | This function uses the distributed primitives test app, which |
| 5940 | gives some cli access to distributed primitives for testing |
| 5941 | purposes only. |
| 5942 | |
| 5943 | Required arguments: |
| 5944 | queueName - The name of the queue to add to |
| 5945 | returns: |
| 5946 | main.TRUE on success, main.FALSE on failure and |
| 5947 | main.ERROR on error. |
| 5948 | """ |
| 5949 | try: |
| 5950 | queueName = str( queueName ) |
| 5951 | prefix = "work-queue-test" |
| 5952 | operation = "destroy" |
| 5953 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5954 | output = self.distPrimitivesSend( cmdStr ) |
| 5955 | if "Invalid operation name" in output: |
| 5956 | main.log.warn( output ) |
| 5957 | return main.ERROR |
| 5958 | return main.TRUE |
| 5959 | except TypeError: |
| 5960 | main.log.exception( self.name + ": Object not as expected" ) |
| 5961 | return main.ERROR |
| 5962 | except Exception: |
| 5963 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5964 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5965 | |
| 5966 | def workQueueTotalPending( self, queueName ): |
| 5967 | """ |
| 5968 | CLI command to get the Total Pending items of the specified Work Queue. |
| 5969 | This function uses the distributed primitives test app, which |
| 5970 | gives some cli access to distributed primitives for testing |
| 5971 | purposes only. |
| 5972 | |
| 5973 | Required arguments: |
| 5974 | queueName - The name of the queue to add to |
| 5975 | returns: |
| 5976 | The number of Pending items in the specified work queue or |
| 5977 | None on error |
| 5978 | """ |
| 5979 | try: |
| 5980 | queueName = str( queueName ) |
| 5981 | prefix = "work-queue-test" |
| 5982 | operation = "totalPending" |
| 5983 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5984 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 5985 | main.log.debug( self.name + ": work queue unparsed: " + output ) |
| 5986 | output = output.split( "\r\n" )[ -1 ] |
| 5987 | main.log.debug( self.name + ": work queue parsed: " + output ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5988 | pattern = r'\d+' |
| 5989 | if "Invalid operation name" in output: |
| 5990 | main.log.warn( output ) |
| 5991 | return None |
| 5992 | else: |
| 5993 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5994 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5995 | except ( AttributeError, TypeError ): |
| 5996 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5997 | return None |
| 5998 | except Exception: |
| 5999 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 6000 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6001 | |
| 6002 | def workQueueTotalCompleted( self, queueName ): |
| 6003 | """ |
| 6004 | CLI command to get the Total Completed items of the specified Work Queue. |
| 6005 | This function uses the distributed primitives test app, which |
| 6006 | gives some cli access to distributed primitives for testing |
| 6007 | purposes only. |
| 6008 | |
| 6009 | Required arguments: |
| 6010 | queueName - The name of the queue to add to |
| 6011 | returns: |
| 6012 | The number of complete items in the specified work queue or |
| 6013 | None on error |
| 6014 | """ |
| 6015 | try: |
| 6016 | queueName = str( queueName ) |
| 6017 | prefix = "work-queue-test" |
| 6018 | operation = "totalCompleted" |
| 6019 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 6020 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 6021 | main.log.debug( self.name + ": work queue unparsed: " + output ) |
| 6022 | output = output.split( "\r\n" )[ -1 ] |
| 6023 | main.log.debug( self.name + ": work queue parsed: " + output ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6024 | pattern = r'\d+' |
| 6025 | if "Invalid operation name" in output: |
| 6026 | main.log.warn( output ) |
| 6027 | return None |
| 6028 | else: |
| 6029 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 6030 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6031 | except ( AttributeError, TypeError ): |
| 6032 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 6033 | return None |
| 6034 | except Exception: |
| 6035 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 6036 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6037 | |
| 6038 | def workQueueTotalInProgress( self, queueName ): |
| 6039 | """ |
| 6040 | CLI command to get the Total In Progress items of the specified Work Queue. |
| 6041 | This function uses the distributed primitives test app, which |
| 6042 | gives some cli access to distributed primitives for testing |
| 6043 | purposes only. |
| 6044 | |
| 6045 | Required arguments: |
| 6046 | queueName - The name of the queue to add to |
| 6047 | returns: |
| 6048 | The number of In Progress items in the specified work queue or |
| 6049 | None on error |
| 6050 | """ |
| 6051 | try: |
| 6052 | queueName = str( queueName ) |
| 6053 | prefix = "work-queue-test" |
| 6054 | operation = "totalInProgress" |
| 6055 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 6056 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 6057 | main.log.debug( self.name + ": work queue unparsed: " + output ) |
| 6058 | output = output.split( "\r\n" )[ -1 ] |
| 6059 | main.log.debug( self.name + ": work queue parsed: " + output ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6060 | pattern = r'\d+' |
| 6061 | if "Invalid operation name" in output: |
| 6062 | main.log.warn( output ) |
| 6063 | return None |
| 6064 | else: |
| 6065 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 6066 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6067 | except ( AttributeError, TypeError ): |
| 6068 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 6069 | return None |
| 6070 | except Exception: |
| 6071 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 6072 | main.cleanAndExit() |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 6073 | |
| 6074 | def events( self, args='-a' ): |
| 6075 | """ |
| 6076 | Description: Returns events -a command output |
| 6077 | Optional: |
| 6078 | add other arguments |
| 6079 | """ |
| 6080 | try: |
| 6081 | cmdStr = "events" |
| 6082 | if args: |
| 6083 | cmdStr += " " + args |
| 6084 | handle = self.sendline( cmdStr ) |
| 6085 | assert handle is not None, "Error in sendline" |
| 6086 | assert "Command not found:" not in handle, handle |
| 6087 | return handle |
| 6088 | except AssertionError: |
| 6089 | main.log.exception( "" ) |
| 6090 | return None |
| 6091 | except TypeError: |
| 6092 | main.log.exception( self.name + ": Object not as expected" ) |
| 6093 | return None |
| 6094 | except pexpect.EOF: |
| 6095 | main.log.error( self.name + ": EOF exception found" ) |
| 6096 | main.log.error( self.name + ": " + self.handle.before ) |
| 6097 | main.cleanAndExit() |
| 6098 | except Exception: |
| 6099 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6100 | main.cleanAndExit() |
| 6101 | |
| 6102 | def getMaster( self, deviceID ): |
| 6103 | """ |
| 6104 | Description: Obtains current master using "roles" command for a specific deviceID |
| 6105 | """ |
| 6106 | try: |
| 6107 | return str( self.getRole( deviceID )[ 'master' ] ) |
| 6108 | except AssertionError: |
| 6109 | main.log.exception( "" ) |
| 6110 | return None |
| 6111 | except TypeError: |
| 6112 | main.log.exception( self.name + ": Object not as expected" ) |
| 6113 | return None |
| 6114 | except pexpect.EOF: |
| 6115 | main.log.error( self.name + ": EOF exception found" ) |
| 6116 | main.log.error( self.name + ": " + self.handle.before ) |
| 6117 | main.cleanAndExit() |
| 6118 | except Exception: |
| 6119 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 6120 | main.cleanAndExit() |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 6121 | |
| 6122 | def issu( self ): |
| 6123 | """ |
| 6124 | Short summary of In-Service Software Upgrade status |
| 6125 | |
| 6126 | Returns the output of the cli command or None on Error |
| 6127 | """ |
| 6128 | try: |
| 6129 | cmdStr = "issu" |
| 6130 | handle = self.sendline( cmdStr ) |
| 6131 | assert handle is not None, "Error in sendline" |
| 6132 | assert "Command not found:" not in handle, handle |
| 6133 | assert "Unsupported command:" not in handle, handle |
| 6134 | return handle |
| 6135 | except AssertionError: |
| 6136 | main.log.exception( "" ) |
| 6137 | return None |
| 6138 | except TypeError: |
| 6139 | main.log.exception( self.name + ": Object not as expected" ) |
| 6140 | return None |
| 6141 | except pexpect.EOF: |
| 6142 | main.log.error( self.name + ": EOF exception found" ) |
| 6143 | main.log.error( self.name + ": " + self.handle.before ) |
| 6144 | main.cleanAndExit() |
| 6145 | except Exception: |
| 6146 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6147 | main.cleanAndExit() |
| 6148 | |
| 6149 | def issuInit( self ): |
| 6150 | """ |
| 6151 | Initiates an In-Service Software Upgrade |
| 6152 | |
| 6153 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6154 | """ |
| 6155 | try: |
| 6156 | cmdStr = "issu init" |
| 6157 | handle = self.sendline( cmdStr ) |
| 6158 | assert handle is not None, "Error in sendline" |
| 6159 | assert "Command not found:" not in handle, handle |
| 6160 | assert "Unsupported command:" not in handle, handle |
| 6161 | if "Initialized" in handle: |
| 6162 | return main.TRUE |
| 6163 | else: |
| 6164 | return main.FALSE |
| 6165 | except AssertionError: |
| 6166 | main.log.exception( "" ) |
| 6167 | return main.ERROR |
| 6168 | except TypeError: |
| 6169 | main.log.exception( self.name + ": Object not as expected" ) |
| 6170 | return main.ERROR |
| 6171 | except pexpect.EOF: |
| 6172 | main.log.error( self.name + ": EOF exception found" ) |
| 6173 | main.log.error( self.name + ": " + self.handle.before ) |
| 6174 | main.cleanAndExit() |
| 6175 | except Exception: |
| 6176 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6177 | main.cleanAndExit() |
| 6178 | |
| 6179 | def issuUpgrade( self ): |
| 6180 | """ |
| 6181 | Transitions stores to upgraded nodes |
| 6182 | |
| 6183 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6184 | """ |
| 6185 | try: |
| 6186 | cmdStr = "issu upgrade" |
| 6187 | handle = self.sendline( cmdStr ) |
| 6188 | assert handle is not None, "Error in sendline" |
| 6189 | assert "Command not found:" not in handle, handle |
| 6190 | assert "Unsupported command:" not in handle, handle |
| 6191 | if "Upgraded" in handle: |
| 6192 | return main.TRUE |
| 6193 | else: |
| 6194 | return main.FALSE |
| 6195 | except AssertionError: |
| 6196 | main.log.exception( "" ) |
| 6197 | return main.ERROR |
| 6198 | except TypeError: |
| 6199 | main.log.exception( self.name + ": Object not as expected" ) |
| 6200 | return main.ERROR |
| 6201 | except pexpect.EOF: |
| 6202 | main.log.error( self.name + ": EOF exception found" ) |
| 6203 | main.log.error( self.name + ": " + self.handle.before ) |
| 6204 | main.cleanAndExit() |
| 6205 | except Exception: |
| 6206 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6207 | main.cleanAndExit() |
| 6208 | |
| 6209 | def issuCommit( self ): |
| 6210 | """ |
| 6211 | Finalizes an In-Service Software Upgrade |
| 6212 | |
| 6213 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6214 | """ |
| 6215 | try: |
| 6216 | cmdStr = "issu commit" |
| 6217 | handle = self.sendline( cmdStr ) |
| 6218 | assert handle is not None, "Error in sendline" |
| 6219 | assert "Command not found:" not in handle, handle |
| 6220 | assert "Unsupported command:" not in handle, handle |
| 6221 | # TODO: Check the version returned by this command |
| 6222 | if "Committed version" in handle: |
| 6223 | return main.TRUE |
| 6224 | else: |
| 6225 | return main.FALSE |
| 6226 | except AssertionError: |
| 6227 | main.log.exception( "" ) |
| 6228 | return main.ERROR |
| 6229 | except TypeError: |
| 6230 | main.log.exception( self.name + ": Object not as expected" ) |
| 6231 | return main.ERROR |
| 6232 | except pexpect.EOF: |
| 6233 | main.log.error( self.name + ": EOF exception found" ) |
| 6234 | main.log.error( self.name + ": " + self.handle.before ) |
| 6235 | main.cleanAndExit() |
| 6236 | except Exception: |
| 6237 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6238 | main.cleanAndExit() |
| 6239 | |
| 6240 | def issuRollback( self ): |
| 6241 | """ |
| 6242 | Rolls back an In-Service Software Upgrade |
| 6243 | |
| 6244 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6245 | """ |
| 6246 | try: |
| 6247 | cmdStr = "issu rollback" |
| 6248 | handle = self.sendline( cmdStr ) |
| 6249 | assert handle is not None, "Error in sendline" |
| 6250 | assert "Command not found:" not in handle, handle |
| 6251 | assert "Unsupported command:" not in handle, handle |
| 6252 | # TODO: Check the version returned by this command |
| 6253 | if "Rolled back to version" in handle: |
| 6254 | return main.TRUE |
| 6255 | else: |
| 6256 | return main.FALSE |
| 6257 | except AssertionError: |
| 6258 | main.log.exception( "" ) |
| 6259 | return main.ERROR |
| 6260 | except TypeError: |
| 6261 | main.log.exception( self.name + ": Object not as expected" ) |
| 6262 | return main.ERROR |
| 6263 | except pexpect.EOF: |
| 6264 | main.log.error( self.name + ": EOF exception found" ) |
| 6265 | main.log.error( self.name + ": " + self.handle.before ) |
| 6266 | main.cleanAndExit() |
| 6267 | except Exception: |
| 6268 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6269 | main.cleanAndExit() |
| 6270 | |
| 6271 | def issuReset( self ): |
| 6272 | """ |
| 6273 | Resets the In-Service Software Upgrade status after a rollback |
| 6274 | |
| 6275 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6276 | """ |
| 6277 | try: |
| 6278 | cmdStr = "issu reset" |
| 6279 | handle = self.sendline( cmdStr ) |
| 6280 | assert handle is not None, "Error in sendline" |
| 6281 | assert "Command not found:" not in handle, handle |
| 6282 | assert "Unsupported command:" not in handle, handle |
| 6283 | # TODO: Check the version returned by this command |
| 6284 | if "Reset version" in handle: |
| 6285 | return main.TRUE |
| 6286 | else: |
| 6287 | return main.FALSE |
| 6288 | except AssertionError: |
| 6289 | main.log.exception( "" ) |
| 6290 | return main.ERROR |
| 6291 | except TypeError: |
| 6292 | main.log.exception( self.name + ": Object not as expected" ) |
| 6293 | return main.ERROR |
| 6294 | except pexpect.EOF: |
| 6295 | main.log.error( self.name + ": EOF exception found" ) |
| 6296 | main.log.error( self.name + ": " + self.handle.before ) |
| 6297 | main.cleanAndExit() |
| 6298 | except Exception: |
| 6299 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6300 | main.cleanAndExit() |
| 6301 | |
| 6302 | def issuStatus( self ): |
| 6303 | """ |
| 6304 | Status of an In-Service Software Upgrade |
| 6305 | |
| 6306 | Returns the output of the cli command or None on Error |
| 6307 | """ |
| 6308 | try: |
| 6309 | cmdStr = "issu status" |
| 6310 | handle = self.sendline( cmdStr ) |
| 6311 | assert handle is not None, "Error in sendline" |
| 6312 | assert "Command not found:" not in handle, handle |
| 6313 | assert "Unsupported command:" not in handle, handle |
| 6314 | return handle |
| 6315 | except AssertionError: |
| 6316 | main.log.exception( "" ) |
| 6317 | return None |
| 6318 | except TypeError: |
| 6319 | main.log.exception( self.name + ": Object not as expected" ) |
| 6320 | return None |
| 6321 | except pexpect.EOF: |
| 6322 | main.log.error( self.name + ": EOF exception found" ) |
| 6323 | main.log.error( self.name + ": " + self.handle.before ) |
| 6324 | main.cleanAndExit() |
| 6325 | except Exception: |
| 6326 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6327 | main.cleanAndExit() |
| 6328 | |
| 6329 | def issuVersion( self ): |
| 6330 | """ |
| 6331 | Get the version of an In-Service Software Upgrade |
| 6332 | |
| 6333 | Returns the output of the cli command or None on Error |
| 6334 | """ |
| 6335 | try: |
| 6336 | cmdStr = "issu version" |
| 6337 | handle = self.sendline( cmdStr ) |
| 6338 | assert handle is not None, "Error in sendline" |
| 6339 | assert "Command not found:" not in handle, handle |
| 6340 | assert "Unsupported command:" not in handle, handle |
| 6341 | return handle |
| 6342 | except AssertionError: |
| 6343 | main.log.exception( "" ) |
| 6344 | return None |
| 6345 | except TypeError: |
| 6346 | main.log.exception( self.name + ": Object not as expected" ) |
| 6347 | return None |
| 6348 | except pexpect.EOF: |
| 6349 | main.log.error( self.name + ": EOF exception found" ) |
| 6350 | main.log.error( self.name + ": " + self.handle.before ) |
| 6351 | main.cleanAndExit() |
| 6352 | except Exception: |
| 6353 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6354 | main.cleanAndExit() |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6355 | |
| 6356 | def mcastJoin( self, sIP, groupIP, sPort, dPorts ): |
| 6357 | """ |
| 6358 | Create a multicast route by calling 'mcast-join' command |
| 6359 | sIP: source IP of the multicast route |
| 6360 | groupIP: group IP of the multicast route |
| 6361 | sPort: source port (e.g. of:0000000000000001/3 ) of the multicast route |
| 6362 | dPorts: a list of destination ports of the multicast route |
| 6363 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6364 | """ |
| 6365 | try: |
| 6366 | cmdStr = "mcast-join" |
| 6367 | cmdStr += " " + str( sIP ) |
| 6368 | cmdStr += " " + str( groupIP ) |
| 6369 | cmdStr += " " + str( sPort ) |
| 6370 | assert isinstance( dPorts, list ) |
| 6371 | for dPort in dPorts: |
| 6372 | cmdStr += " " + str( dPort ) |
| 6373 | handle = self.sendline( cmdStr ) |
| 6374 | assert handle is not None, "Error in sendline" |
| 6375 | assert "Command not found:" not in handle, handle |
| 6376 | assert "Unsupported command:" not in handle, handle |
| 6377 | assert "Error executing command" not in handle, handle |
| 6378 | if "Added the mcast route" in handle: |
| 6379 | return main.TRUE |
| 6380 | else: |
| 6381 | return main.FALSE |
| 6382 | except AssertionError: |
| 6383 | main.log.exception( "" ) |
| 6384 | return None |
| 6385 | except TypeError: |
| 6386 | main.log.exception( self.name + ": Object not as expected" ) |
| 6387 | return None |
| 6388 | except pexpect.EOF: |
| 6389 | main.log.error( self.name + ": EOF exception found" ) |
| 6390 | main.log.error( self.name + ": " + self.handle.before ) |
| 6391 | main.cleanAndExit() |
| 6392 | except Exception: |
| 6393 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6394 | main.cleanAndExit() |
| 6395 | |
| 6396 | def mcastDelete( self, sIP, groupIP, dPorts ): |
| 6397 | """ |
| 6398 | Delete a multicast route by calling 'mcast-delete' command |
| 6399 | sIP: source IP of the multicast route |
| 6400 | groupIP: group IP of the multicast route |
| 6401 | dPorts: a list of destination ports of the multicast route |
| 6402 | Returns main.TRUE if mcast route is deleted; Otherwise main.FALSE |
| 6403 | """ |
| 6404 | try: |
| 6405 | cmdStr = "mcast-delete" |
| 6406 | cmdStr += " " + str( sIP ) |
| 6407 | cmdStr += " " + str( groupIP ) |
| 6408 | assert isinstance( dPorts, list ) |
| 6409 | for dPort in dPorts: |
| 6410 | cmdStr += " " + str( dPort ) |
| 6411 | handle = self.sendline( cmdStr ) |
| 6412 | assert handle is not None, "Error in sendline" |
| 6413 | assert "Command not found:" not in handle, handle |
| 6414 | assert "Unsupported command:" not in handle, handle |
| 6415 | assert "Error executing command" not in handle, handle |
| 6416 | if "Updated the mcast route" in handle: |
| 6417 | return main.TRUE |
| 6418 | else: |
| 6419 | return main.FALSE |
| 6420 | except AssertionError: |
| 6421 | main.log.exception( "" ) |
| 6422 | return None |
| 6423 | except TypeError: |
| 6424 | main.log.exception( self.name + ": Object not as expected" ) |
| 6425 | return None |
| 6426 | except pexpect.EOF: |
| 6427 | main.log.error( self.name + ": EOF exception found" ) |
| 6428 | main.log.error( self.name + ": " + self.handle.before ) |
| 6429 | main.cleanAndExit() |
| 6430 | except Exception: |
| 6431 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6432 | main.cleanAndExit() |
| 6433 | |
| 6434 | def mcastHostJoin( self, sAddr, gAddr, srcs, sinks ): |
| 6435 | """ |
| 6436 | Create a multicast route by calling 'mcast-host-join' command |
| 6437 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6438 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6439 | 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] | 6440 | sinks: a list of HostId of the sinks e.g. ["00:AA:00:00:01:05/40"] |
| 6441 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6442 | """ |
| 6443 | try: |
| 6444 | cmdStr = "mcast-host-join" |
| 6445 | cmdStr += " -sAddr " + str( sAddr ) |
| 6446 | cmdStr += " -gAddr " + str( gAddr ) |
| 6447 | assert isinstance( srcs, list ) |
| 6448 | for src in srcs: |
| 6449 | cmdStr += " -srcs " + str( src ) |
| 6450 | assert isinstance( sinks, list ) |
| 6451 | for sink in sinks: |
| 6452 | cmdStr += " -sinks " + str( sink ) |
| 6453 | handle = self.sendline( cmdStr ) |
| 6454 | assert handle is not None, "Error in sendline" |
| 6455 | assert "Command not found:" not in handle, handle |
| 6456 | assert "Unsupported command:" not in handle, handle |
| 6457 | assert "Error executing command" not in handle, handle |
| 6458 | if "Added the mcast route" in handle: |
| 6459 | return main.TRUE |
| 6460 | else: |
| 6461 | return main.FALSE |
| 6462 | except AssertionError: |
| 6463 | main.log.exception( "" ) |
| 6464 | return None |
| 6465 | except TypeError: |
| 6466 | main.log.exception( self.name + ": Object not as expected" ) |
| 6467 | return None |
| 6468 | except pexpect.EOF: |
| 6469 | main.log.error( self.name + ": EOF exception found" ) |
| 6470 | main.log.error( self.name + ": " + self.handle.before ) |
| 6471 | main.cleanAndExit() |
| 6472 | except Exception: |
| 6473 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6474 | main.cleanAndExit() |
| 6475 | |
| 6476 | def mcastHostDelete( self, sAddr, gAddr, host=None ): |
| 6477 | """ |
| 6478 | Delete multicast sink(s) by calling 'mcast-host-delete' command |
| 6479 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6480 | gAddr: specifies multicast group address |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 6481 | 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] | 6482 | will delete the route if not specified |
| 6483 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6484 | """ |
| 6485 | try: |
| 6486 | cmdStr = "mcast-host-delete" |
| 6487 | cmdStr += " -sAddr " + str( sAddr ) |
| 6488 | cmdStr += " -gAddr " + str( gAddr ) |
| 6489 | if host: |
| 6490 | cmdStr += " -h " + str( host ) |
| 6491 | handle = self.sendline( cmdStr ) |
| 6492 | assert handle is not None, "Error in sendline" |
| 6493 | assert "Command not found:" not in handle, handle |
| 6494 | assert "Unsupported command:" not in handle, handle |
| 6495 | assert "Error executing command" not in handle, handle |
| 6496 | if "Updated the mcast route" in handle: |
| 6497 | return main.TRUE |
| 6498 | elif "Deleted the mcast route" in handle: |
| 6499 | return main.TRUE |
| 6500 | else: |
| 6501 | return main.FALSE |
| 6502 | except AssertionError: |
| 6503 | main.log.exception( "" ) |
| 6504 | return None |
| 6505 | except TypeError: |
| 6506 | main.log.exception( self.name + ": Object not as expected" ) |
| 6507 | return None |
| 6508 | except pexpect.EOF: |
| 6509 | main.log.error( self.name + ": EOF exception found" ) |
| 6510 | main.log.error( self.name + ": " + self.handle.before ) |
| 6511 | main.cleanAndExit() |
| 6512 | except Exception: |
| 6513 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6514 | main.cleanAndExit() |
| 6515 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6516 | def mcastSinkDelete( self, sAddr, gAddr, sink=None ): |
| 6517 | """ |
| 6518 | Delete multicast sink(s) by calling 'mcast-sink-delete' command |
| 6519 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6520 | gAddr: specifies multicast group address |
| 6521 | host: HostId of the sink e.g. "00:AA:00:00:01:05/40", |
| 6522 | will delete the route if not specified |
| 6523 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6524 | """ |
| 6525 | try: |
| 6526 | cmdStr = "mcast-sink-delete" |
| 6527 | cmdStr += " -sAddr " + str( sAddr ) |
| 6528 | cmdStr += " -gAddr " + str( gAddr ) |
| 6529 | if sink: |
| 6530 | cmdStr += " -s " + str( sink ) |
| 6531 | handle = self.sendline( cmdStr ) |
| 6532 | assert handle is not None, "Error in sendline" |
| 6533 | assert "Command not found:" not in handle, handle |
| 6534 | assert "Unsupported command:" not in handle, handle |
| 6535 | assert "Error executing command" not in handle, handle |
| 6536 | if "Updated the mcast route" in handle: |
| 6537 | return main.TRUE |
| 6538 | elif "Deleted the mcast route" in handle: |
| 6539 | return main.TRUE |
| 6540 | else: |
| 6541 | return main.FALSE |
| 6542 | except AssertionError: |
| 6543 | main.log.exception( "" ) |
| 6544 | return None |
| 6545 | except TypeError: |
| 6546 | main.log.exception( self.name + ": Object not as expected" ) |
| 6547 | return None |
| 6548 | except pexpect.EOF: |
| 6549 | main.log.error( self.name + ": EOF exception found" ) |
| 6550 | main.log.error( self.name + ": " + self.handle.before ) |
| 6551 | main.cleanAndExit() |
| 6552 | except Exception: |
| 6553 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6554 | main.cleanAndExit() |
| 6555 | |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6556 | def mcastSourceDelete( self, sAddr, gAddr, srcs=None ): |
| 6557 | """ |
| 6558 | Delete multicast src(s) by calling 'mcast-source-delete' command |
| 6559 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6560 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6561 | 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] | 6562 | will delete the route if not specified |
| 6563 | Returns main.TRUE if mcast sink is deleted; Otherwise main.FALSE |
| 6564 | """ |
| 6565 | try: |
| 6566 | cmdStr = "mcast-source-delete" |
| 6567 | cmdStr += " -sAddr " + str( sAddr ) |
| 6568 | cmdStr += " -gAddr " + str( gAddr ) |
| 6569 | if srcs: |
| 6570 | assert isinstance( srcs, list ) |
| 6571 | for src in srcs: |
| 6572 | cmdStr += " -src " + str( src ) |
| 6573 | handle = self.sendline( cmdStr ) |
| 6574 | assert handle is not None, "Error in sendline" |
| 6575 | assert "Command not found:" not in handle, handle |
| 6576 | assert "Unsupported command:" not in handle, handle |
| 6577 | assert "Error executing command" not in handle, handle |
| 6578 | if "Updated the mcast route" in handle: |
| 6579 | return main.TRUE |
| 6580 | elif "Deleted the mcast route" in handle: |
| 6581 | return main.TRUE |
| 6582 | else: |
| 6583 | return main.FALSE |
| 6584 | except AssertionError: |
| 6585 | main.log.exception( "" ) |
| 6586 | return None |
| 6587 | except TypeError: |
| 6588 | main.log.exception( self.name + ": Object not as expected" ) |
| 6589 | return None |
| 6590 | except pexpect.EOF: |
| 6591 | main.log.error( self.name + ": EOF exception found" ) |
| 6592 | main.log.error( self.name + ": " + self.handle.before ) |
| 6593 | main.cleanAndExit() |
| 6594 | except Exception: |
| 6595 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6596 | main.cleanAndExit() |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6597 | |
| 6598 | def netcfg( self, jsonFormat=True, args="" ): |
| 6599 | """ |
| 6600 | Run netcfg cli command with given args |
| 6601 | """ |
| 6602 | try: |
| 6603 | cmdStr = "netcfg" |
| 6604 | if jsonFormat: |
| 6605 | cmdStr = cmdStr + " -j" |
| 6606 | if args: |
| 6607 | cmdStr = cmdStr + " " + str( args ) |
| 6608 | handle = self.sendline( cmdStr ) |
| 6609 | assert handle is not None, "Error in sendline" |
| 6610 | assert "Command not found:" not in handle, handle |
| 6611 | assert "Unsupported command:" not in handle, handle |
| 6612 | assert "Error executing command" not in handle, handle |
| 6613 | return handle |
| 6614 | except AssertionError: |
| 6615 | main.log.exception( "" ) |
| 6616 | return None |
| 6617 | except TypeError: |
| 6618 | main.log.exception( self.name + ": Object not as expected" ) |
| 6619 | return None |
| 6620 | except pexpect.EOF: |
| 6621 | main.log.error( self.name + ": EOF exception found" ) |
| 6622 | main.log.error( self.name + ": " + self.handle.before ) |
| 6623 | main.cleanAndExit() |
| 6624 | except Exception: |
| 6625 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6626 | main.cleanAndExit() |
| 6627 | |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6628 | def composeT3Command( self, sAddr, dAddr, ipv6=False, verbose=True, simple=False ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6629 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6630 | 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] | 6631 | Options: |
| 6632 | sAddr: IP address of the source host |
| 6633 | dAddr: IP address of the destination host |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6634 | ipv6: True if hosts are IPv6 |
| 6635 | verbose: return verbose t3 output if True |
| 6636 | simple: compose command for t3-troubleshoot-simple if True |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6637 | """ |
| 6638 | try: |
| 6639 | # Collect information of both hosts from onos |
| 6640 | hosts = self.hosts() |
| 6641 | hosts = json.loads( hosts ) |
| 6642 | sHost = None |
| 6643 | dHost = None |
| 6644 | for host in hosts: |
| 6645 | if sAddr in host[ "ipAddresses" ]: |
| 6646 | sHost = host |
| 6647 | elif dAddr in host[ "ipAddresses" ]: |
| 6648 | dHost = host |
| 6649 | if sHost and dHost: |
| 6650 | break |
| 6651 | assert sHost, "Not able to find host with IP {}".format( sAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6652 | cmdList = [] |
You Wang | 5d9527b | 2018-05-29 17:08:54 -0700 | [diff] [blame] | 6653 | if simple: |
| 6654 | assert dHost, "Not able to find host with IP {}".format( dAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6655 | cmdStr = "t3-troubleshoot-simple" |
| 6656 | if verbose: |
| 6657 | cmdStr += " -vv" |
| 6658 | if ipv6: |
| 6659 | cmdStr += " -et ipv6" |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6660 | cmdStr += " {}/{} {}/{}".format( sHost[ "mac" ], sHost[ "vlan" ], dHost[ "mac" ], dHost[ "vlan" ] ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6661 | cmdList.append( cmdStr ) |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6662 | else: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6663 | for location in sHost[ "locations" ]: |
| 6664 | cmdStr = "t3-troubleshoot" |
| 6665 | if verbose: |
| 6666 | cmdStr += " -vv" |
| 6667 | if ipv6: |
| 6668 | cmdStr += " -et ipv6" |
| 6669 | cmdStr += " -s " + str( sAddr ) |
| 6670 | cmdStr += " -sp " + str( location[ "elementId" ] ) + "/" + str( location[ "port" ] ) |
| 6671 | cmdStr += " -sm " + str( sHost[ "mac" ] ) |
| 6672 | if sHost[ "vlan" ] != "None": |
| 6673 | cmdStr += " -vid " + sHost[ "vlan" ] |
| 6674 | cmdStr += " -d " + str( dAddr ) |
| 6675 | netcfg = self.netcfg( args="devices {}".format( location[ "elementId" ] ) ) |
| 6676 | netcfg = json.loads( netcfg ) |
| 6677 | assert netcfg, "Failed to get netcfg" |
| 6678 | cmdStr += " -dm " + str( netcfg[ "segmentrouting" ][ "routerMac" ] ) |
| 6679 | cmdList.append( cmdStr ) |
| 6680 | return cmdList |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6681 | except AssertionError: |
| 6682 | main.log.exception( "" ) |
| 6683 | return None |
| 6684 | except ( KeyError, TypeError ): |
| 6685 | main.log.exception( self.name + ": Object not as expected" ) |
| 6686 | return None |
| 6687 | except Exception: |
| 6688 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6689 | main.cleanAndExit() |
| 6690 | |
| 6691 | def t3( self, sAddr, dAddr, ipv6=False ): |
| 6692 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6693 | 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] | 6694 | Options: |
| 6695 | sAddr: IP address of the source host |
| 6696 | dAddr: IP address of the destination host |
| 6697 | """ |
| 6698 | try: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6699 | cmdList = self.composeT3Command( sAddr, dAddr, ipv6 ) |
| 6700 | assert cmdList is not None, "composeT3Command returned None" |
| 6701 | t3Output = "" |
| 6702 | for cmdStr in cmdList: |
| 6703 | handle = self.sendline( cmdStr ) |
| 6704 | assert handle is not None, "Error in sendline" |
| 6705 | assert "Command not found:" not in handle, handle |
| 6706 | assert "Unsupported command:" not in handle, handle |
| 6707 | assert "Error executing command" not in handle, handle |
| 6708 | assert "Tracing packet" in handle |
| 6709 | t3Output += handle |
| 6710 | return t3Output |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6711 | except AssertionError: |
| 6712 | main.log.exception( "" ) |
| 6713 | return None |
| 6714 | except pexpect.EOF: |
| 6715 | main.log.error( self.name + ": EOF exception found" ) |
| 6716 | main.log.error( self.name + ": " + self.handle.before ) |
| 6717 | main.cleanAndExit() |
| 6718 | except Exception: |
| 6719 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6720 | main.cleanAndExit() |