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 |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 61 | self.graph = Graph() |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 62 | super( OnosCliDriver, self ).__init__() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 63 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 64 | def checkOptions( self, var, defaultVar ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 65 | if var is None or var == "": |
| 66 | return defaultVar |
| 67 | return var |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 68 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 69 | def connect( self, **connectargs ): |
| 70 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 71 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 72 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 73 | try: |
| 74 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 75 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 658ec01 | 2015-03-11 15:13:09 -0700 | [diff] [blame] | 76 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 77 | for key in self.options: |
| 78 | if key == "home": |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 79 | self.home = self.options[ key ] |
| 80 | elif key == "karaf_username": |
| 81 | self.karafUser = self.options[ key ] |
| 82 | elif key == "karaf_password": |
| 83 | self.karafPass = self.options[ key ] |
| 84 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 85 | self.home = self.checkOptions( self.home, "~/onos" ) |
| 86 | self.karafUser = self.checkOptions( self.karafUser, self.user_name ) |
| 87 | self.karafPass = self.checkOptions( self.karafPass, self.pwd ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 88 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 89 | for key in self.options: |
| 90 | if key == 'onosIp': |
| 91 | self.onosIp = self.options[ 'onosIp' ] |
| 92 | break |
| 93 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 94 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 95 | |
| 96 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 97 | if os.getenv( str( self.ip_address ) ) is not None: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 98 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 99 | else: |
| 100 | main.log.info( self.name + |
| 101 | ": Trying to connect to " + |
| 102 | self.ip_address ) |
| 103 | |
| 104 | except KeyError: |
| 105 | main.log.info( "Invalid host name," + |
| 106 | " connecting to local host instead" ) |
| 107 | self.ip_address = 'localhost' |
| 108 | except Exception as inst: |
| 109 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 110 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 111 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 112 | user_name=self.user_name, |
| 113 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 114 | port=self.port, |
| 115 | pwd=self.pwd, |
| 116 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 117 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 118 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 119 | self.handle.expect( self.prompt ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 120 | if self.handle: |
| 121 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 122 | else: |
| 123 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 124 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 125 | except TypeError: |
| 126 | main.log.exception( self.name + ": Object not as expected" ) |
| 127 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 128 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 129 | main.log.error( self.name + ": EOF exception found" ) |
| 130 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 131 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 132 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 133 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 134 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 135 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 136 | def disconnect( self ): |
| 137 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 138 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 139 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 140 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 141 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 142 | if self.handle: |
| 143 | i = self.logout() |
| 144 | if i == main.TRUE: |
| 145 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 146 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 147 | self.handle.sendline( "exit" ) |
| 148 | self.handle.expect( "closed" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 149 | except TypeError: |
| 150 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 151 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 152 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 153 | main.log.error( self.name + ": EOF exception found" ) |
| 154 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 155 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 156 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 157 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 158 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 159 | main.log.exception( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 160 | response = main.FALSE |
| 161 | return response |
| 162 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 163 | def logout( self ): |
| 164 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 165 | Sends 'logout' command to ONOS cli |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 166 | Returns main.TRUE if exited CLI and |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 167 | main.FALSE on timeout (not guranteed you are disconnected) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 168 | None on TypeError |
| 169 | Exits test on unknown error or pexpect exits unexpectedly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 170 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 171 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 172 | if self.handle: |
| 173 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 174 | i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ], |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 175 | timeout=10 ) |
| 176 | if i == 0: # In ONOS CLI |
| 177 | self.handle.sendline( "logout" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 178 | j = self.handle.expect( [ self.prompt, |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 179 | "Command not found:", |
| 180 | pexpect.TIMEOUT ] ) |
| 181 | if j == 0: # Successfully logged out |
| 182 | return main.TRUE |
| 183 | elif j == 1 or j == 2: |
| 184 | # ONOS didn't fully load, and logout command isn't working |
| 185 | # or the command timed out |
| 186 | self.handle.send( "\x04" ) # send ctrl-d |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 187 | try: |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 188 | self.handle.expect( self.prompt ) |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 189 | except pexpect.TIMEOUT: |
| 190 | main.log.error( "ONOS did not respond to 'logout' or CTRL-d" ) |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 191 | return main.TRUE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 192 | else: # some other output |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 193 | main.log.warn( "Unknown repsonse to logout command: '{}'", |
| 194 | repr( self.handle.before ) ) |
| 195 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 196 | elif i == 1: # not in CLI |
| 197 | return main.TRUE |
| 198 | elif i == 3: # Timeout |
| 199 | return main.FALSE |
| 200 | else: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 201 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 202 | except TypeError: |
| 203 | main.log.exception( self.name + ": Object not as expected" ) |
| 204 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 205 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 206 | main.log.error( self.name + ": eof exception found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 207 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 208 | main.cleanAndExit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 209 | except ValueError: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 210 | main.log.error( self.name + |
| 211 | "ValueError exception in logout method" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 212 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 213 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 214 | main.cleanAndExit() |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 215 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 216 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 217 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 218 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 219 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 220 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 221 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 222 | try: |
| 223 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 224 | main.log.error( "Must define cellname" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 225 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 226 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 227 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 228 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 229 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 230 | # and that this driver will have to change accordingly |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 231 | self.handle.expect( str( cellname ) ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 232 | handleBefore = self.handle.before |
| 233 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 234 | # Get the rest of the handle |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 235 | self.handle.sendline( "" ) |
| 236 | self.handle.expect( self.prompt ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 237 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 238 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 239 | main.log.info( "Cell call returned: " + handleBefore + |
| 240 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 241 | |
| 242 | return main.TRUE |
| 243 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 244 | except TypeError: |
| 245 | main.log.exception( self.name + ": Object not as expected" ) |
| 246 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 247 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 248 | main.log.error( self.name + ": eof exception found" ) |
| 249 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 250 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 251 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 252 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 253 | main.cleanAndExit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 254 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 255 | def startOnosCli( self, ONOSIp, karafTimeout="", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 256 | commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 257 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 258 | karafTimeout is an optional argument. karafTimeout value passed |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 259 | by user would be used to set the current karaf shell idle timeout. |
| 260 | 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] | 261 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 262 | Below is an example to start a session with 60 seconds idle timeout |
| 263 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 264 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 265 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 266 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 267 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 268 | Note: karafTimeout is left as str so that this could be read |
| 269 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 270 | """ |
You Wang | f69ab39 | 2016-01-26 16:34:38 -0800 | [diff] [blame] | 271 | self.onosIp = ONOSIp |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 272 | try: |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 273 | # Check if we are already in the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 274 | self.handle.sendline( "" ) |
| 275 | x = self.handle.expect( [ |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 276 | self.prompt, "onos>" ], commandlineTimeout ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 277 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 278 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 279 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 280 | |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 281 | # Not in CLI so login |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 282 | if waitForStart: |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 283 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
| 284 | startCliCommand = "onos-wait-for-start " |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 285 | else: |
| 286 | startCliCommand = "onos " |
| 287 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 288 | i = self.handle.expect( [ |
| 289 | "onos>", |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 290 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 291 | |
| 292 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 293 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 294 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 295 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 296 | "config:property-set -p org.apache.karaf.shell\ |
| 297 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 298 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 299 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 300 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 301 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 302 | return main.TRUE |
| 303 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 304 | # If failed, send ctrl+c to process and try again |
| 305 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 306 | self.handle.send( "\x03" ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 307 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 308 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 309 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 310 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 311 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 312 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 313 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 314 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 315 | "config:property-set -p org.apache.karaf.shell\ |
| 316 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 317 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 318 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 319 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 320 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 321 | return main.TRUE |
| 322 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 323 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 324 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 325 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 326 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 327 | except TypeError: |
| 328 | main.log.exception( self.name + ": Object not as expected" ) |
| 329 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 330 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 331 | main.log.error( self.name + ": EOF exception found" ) |
| 332 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 333 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 334 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 335 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 336 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 337 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 338 | def startCellCli( self, karafTimeout="", |
| 339 | commandlineTimeout=10, onosStartTimeout=60 ): |
| 340 | """ |
| 341 | Start CLI on onos ecll handle. |
| 342 | |
| 343 | karafTimeout is an optional argument. karafTimeout value passed |
| 344 | by user would be used to set the current karaf shell idle timeout. |
| 345 | Note that when ever this property is modified the shell will exit and |
| 346 | the subsequent login would reflect new idle timeout. |
| 347 | Below is an example to start a session with 60 seconds idle timeout |
| 348 | ( input value is in milliseconds ): |
| 349 | |
| 350 | tValue = "60000" |
| 351 | |
| 352 | Note: karafTimeout is left as str so that this could be read |
| 353 | and passed to startOnosCli from PARAMS file as str. |
| 354 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 355 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 356 | try: |
| 357 | self.handle.sendline( "" ) |
| 358 | x = self.handle.expect( [ |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 359 | self.prompt, "onos>" ], commandlineTimeout ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 360 | |
| 361 | if x == 1: |
| 362 | main.log.info( "ONOS cli is already running" ) |
| 363 | return main.TRUE |
| 364 | |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 365 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 366 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 367 | i = self.handle.expect( [ |
| 368 | "onos>", |
| 369 | pexpect.TIMEOUT ], onosStartTimeout ) |
| 370 | |
| 371 | if i == 0: |
| 372 | main.log.info( self.name + " CLI Started successfully" ) |
| 373 | if karafTimeout: |
| 374 | self.handle.sendline( |
| 375 | "config:property-set -p org.apache.karaf.shell\ |
| 376 | sshIdleTimeout " + |
| 377 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 378 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 379 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 380 | self.handle.expect( "onos>" ) |
| 381 | return main.TRUE |
| 382 | else: |
| 383 | # If failed, send ctrl+c to process and try again |
| 384 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 385 | self.handle.send( "\x03" ) |
| 386 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 387 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 388 | timeout=30 ) |
| 389 | if i == 0: |
| 390 | main.log.info( self.name + " CLI Started " + |
| 391 | "successfully after retry attempt" ) |
| 392 | if karafTimeout: |
| 393 | self.handle.sendline( |
| 394 | "config:property-set -p org.apache.karaf.shell\ |
| 395 | sshIdleTimeout " + |
| 396 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 397 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 398 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 399 | self.handle.expect( "onos>" ) |
| 400 | return main.TRUE |
| 401 | else: |
| 402 | main.log.error( "Connection to CLI " + |
| 403 | self.name + " timeout" ) |
| 404 | return main.FALSE |
| 405 | |
| 406 | except TypeError: |
| 407 | main.log.exception( self.name + ": Object not as expected" ) |
| 408 | return None |
| 409 | except pexpect.EOF: |
| 410 | main.log.error( self.name + ": EOF exception found" ) |
| 411 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 412 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 413 | except Exception: |
| 414 | main.log.exception( self.name + ": Uncaught exception!" ) |
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 | |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 417 | def log( self, cmdStr, level="", noExit=False ): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 418 | """ |
| 419 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 420 | returns main.TRUE on success |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 421 | returns main.FALSE if Error occurred |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 422 | if noExit is True, TestON will not exit, but clean up |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 423 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 424 | Level defaults to INFO |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 425 | if cmdStr has spaces then put quotes in the passed string |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 426 | """ |
| 427 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 428 | lvlStr = "" |
| 429 | if level: |
| 430 | lvlStr = "--level=" + level |
| 431 | |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 432 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 433 | self.handle.expect( "log:log" ) |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 434 | self.handle.expect( "onos>" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 435 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 436 | response = self.handle.before |
| 437 | if re.search( "Error", response ): |
| 438 | return main.FALSE |
| 439 | return main.TRUE |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 440 | except pexpect.TIMEOUT: |
| 441 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 442 | if noExit: |
| 443 | main.cleanup() |
| 444 | return None |
| 445 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 446 | main.cleanAndExit() |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 447 | except pexpect.EOF: |
| 448 | main.log.error( self.name + ": EOF exception found" ) |
| 449 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 450 | if noExit: |
| 451 | main.cleanup() |
| 452 | return None |
| 453 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 454 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 455 | except Exception: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 456 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 457 | if noExit: |
| 458 | main.cleanup() |
| 459 | return None |
| 460 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 461 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 462 | |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 463 | def clearBuffer( self, debug=False, timeout=10, noExit=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 464 | """ |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 465 | Test cli connection and clear any left over output in the buffer |
| 466 | Optional Arguments: |
| 467 | debug - Defaults to False. If True, will enable debug logging. |
| 468 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 469 | before a timeout. |
| 470 | 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] | 471 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 472 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 473 | # Try to reconnect if disconnected from cli |
| 474 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 475 | i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ] ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 476 | response = self.handle.before |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 477 | if i == 1: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 478 | main.log.error( self.name + ": onos cli session closed. " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 479 | if self.onosIp: |
| 480 | main.log.warn( "Trying to reconnect " + self.onosIp ) |
| 481 | reconnectResult = self.startOnosCli( self.onosIp ) |
| 482 | if reconnectResult: |
| 483 | main.log.info( self.name + ": onos cli session reconnected." ) |
| 484 | else: |
| 485 | main.log.error( self.name + ": reconnection failed." ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 486 | if noExit: |
| 487 | return None |
| 488 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 489 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 490 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 491 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 492 | if i == 2: |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 493 | main.log.warn( "Timeout when testing cli responsiveness" ) |
| 494 | main.log.debug( self.handle.before ) |
| 495 | self.handle.send( "\x03" ) # Send ctrl-c to clear previous output |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 496 | self.handle.expect( "onos>" ) |
| 497 | |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 498 | response += self.handle.before |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 499 | if debug: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 500 | main.log.debug( self.name + ": Raw output from sending ''" ) |
| 501 | main.log.debug( self.name + ": " + repr( response ) ) |
| 502 | except pexpect.TIMEOUT: |
| 503 | main.log.error( self.name + ": ONOS timeout" ) |
| 504 | main.log.debug( self.handle.before ) |
You Wang | 141b43b | 2018-06-26 16:50:18 -0700 | [diff] [blame] | 505 | self.handle.send( "\x03" ) |
| 506 | self.handle.expect( "onos>" ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 507 | return None |
| 508 | except pexpect.EOF: |
| 509 | main.log.error( self.name + ": EOF exception found" ) |
| 510 | main.log.error( self.name + ": " + self.handle.before ) |
| 511 | if noExit: |
| 512 | return None |
| 513 | else: |
| 514 | main.cleanAndExit() |
| 515 | except Exception: |
| 516 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 517 | if noExit: |
| 518 | return None |
| 519 | else: |
| 520 | main.cleanAndExit() |
| 521 | |
| 522 | def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False ): |
| 523 | """ |
| 524 | A wrapper around pexpect's sendline/expect. Will return all the output from a given command |
| 525 | |
| 526 | Required Arguments: |
| 527 | cmdStr - String to send to the pexpect session |
| 528 | |
| 529 | Optional Arguments: |
| 530 | showResponse - Defaults to False. If True will log the response. |
| 531 | debug - Defaults to False. If True, will enable debug logging. |
| 532 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 533 | before a timeout. |
| 534 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
| 535 | closed channel, but instead return None |
| 536 | |
| 537 | Warning: There are no sanity checking to commands sent using this method. |
| 538 | |
| 539 | """ |
| 540 | try: |
| 541 | # Try to reconnect if disconnected from cli |
| 542 | self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit ) |
| 543 | if debug: |
| 544 | # NOTE: This adds an average of .4 seconds per call |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 545 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 546 | self.log( logStr, noExit=noExit ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 547 | self.handle.sendline( cmdStr ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 548 | i = self.handle.expect( "onos>", timeout ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 549 | response = self.handle.before |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 550 | # TODO: do something with i |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 551 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 552 | + self.name + "." ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 553 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 554 | main.log.debug( self.name + ": Raw output" ) |
| 555 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 556 | |
| 557 | # Remove ANSI color control strings from output |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 558 | ansiEscape = re.compile( r'\x1b[^m]*m' ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 559 | response = ansiEscape.sub( '', response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 560 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 561 | main.log.debug( self.name + ": ansiEscape output" ) |
| 562 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 563 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 564 | # Remove extra return chars that get added |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 565 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 566 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 567 | main.log.debug( self.name + ": Removed extra returns " + |
| 568 | "from output" ) |
| 569 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 570 | |
| 571 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 572 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 573 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 574 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 575 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 576 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 577 | # parse for just the output, remove the cmd from response |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 578 | output = response.split( cmdStr.strip(), 1 ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 579 | if output: |
| 580 | if debug: |
| 581 | main.log.debug( self.name + ": split output" ) |
| 582 | for r in output: |
| 583 | main.log.debug( self.name + ": " + repr( r ) ) |
| 584 | output = output[ 1 ].strip() |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 585 | if showResponse: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 586 | main.log.info( "Response from ONOS: {}".format( output ) ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 587 | self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 588 | return output |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 589 | except pexpect.TIMEOUT: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 590 | main.log.error( self.name + ": ONOS timeout" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 591 | if debug: |
| 592 | main.log.debug( self.handle.before ) |
You Wang | 141b43b | 2018-06-26 16:50:18 -0700 | [diff] [blame] | 593 | self.handle.send( "\x03" ) |
| 594 | self.handle.expect( "onos>" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 595 | return None |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 596 | except IndexError: |
| 597 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 598 | main.log.debug( "response: {}".format( repr( response ) ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 599 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 600 | except TypeError: |
| 601 | main.log.exception( self.name + ": Object not as expected" ) |
| 602 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 603 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 604 | main.log.error( self.name + ": EOF exception found" ) |
| 605 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 606 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 607 | return None |
| 608 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 609 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 610 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 611 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 612 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 613 | return None |
| 614 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 615 | main.cleanAndExit() |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 616 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 617 | # IMPORTANT NOTE: |
| 618 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 619 | # the cli command changing 'a:b' with 'aB'. |
| 620 | # Ex ) onos:topology > onosTopology |
| 621 | # onos:links > onosLinks |
| 622 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 623 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 624 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 625 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 626 | Adds a new cluster node by ID and address information. |
| 627 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 628 | * nodeId |
| 629 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 630 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 631 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 632 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 633 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 634 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 635 | str( ONOSIp ) + " " + str( tcpPort ) |
| 636 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 637 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 638 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 639 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 640 | main.log.error( self.name + ": Error in adding node" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 641 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 642 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 643 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 644 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 645 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 646 | except AssertionError: |
| 647 | main.log.exception( "" ) |
| 648 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 649 | except TypeError: |
| 650 | main.log.exception( self.name + ": Object not as expected" ) |
| 651 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 652 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 653 | main.log.error( self.name + ": EOF exception found" ) |
| 654 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 655 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 656 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 657 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 658 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 659 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 660 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 661 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 662 | Removes a cluster by ID |
| 663 | Issues command: 'remove-node [<node-id>]' |
| 664 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 665 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 666 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 667 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 668 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 669 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 670 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 671 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 672 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 673 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 674 | main.log.error( self.name + ": Error in removing node" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 675 | main.log.error( handle ) |
| 676 | return main.FALSE |
| 677 | else: |
| 678 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 679 | except AssertionError: |
| 680 | main.log.exception( "" ) |
| 681 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 682 | except TypeError: |
| 683 | main.log.exception( self.name + ": Object not as expected" ) |
| 684 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 685 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 686 | main.log.error( self.name + ": EOF exception found" ) |
| 687 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 688 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 689 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 690 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 691 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 692 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 693 | def nodes( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 694 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 695 | List the nodes currently visible |
| 696 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 697 | Optional argument: |
| 698 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 699 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 700 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 701 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 702 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 703 | cmdStr += " -j" |
| 704 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 705 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 706 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 707 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 708 | except AssertionError: |
| 709 | main.log.exception( "" ) |
| 710 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 711 | except TypeError: |
| 712 | main.log.exception( self.name + ": Object not as expected" ) |
| 713 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 714 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 715 | main.log.error( self.name + ": EOF exception found" ) |
| 716 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 717 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 718 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 719 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 720 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 721 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 722 | def topology( self ): |
| 723 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 724 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 725 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 726 | Return: |
| 727 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 728 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 729 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 730 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 731 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 732 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 733 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 734 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 735 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 736 | except AssertionError: |
| 737 | main.log.exception( "" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 738 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 739 | except TypeError: |
| 740 | main.log.exception( self.name + ": Object not as expected" ) |
| 741 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 742 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 743 | main.log.error( self.name + ": EOF exception found" ) |
| 744 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 745 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 746 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 747 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 748 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 749 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 750 | def deviceRemove( self, deviceId ): |
| 751 | """ |
| 752 | Removes particular device from storage |
| 753 | |
| 754 | TODO: refactor this function |
| 755 | """ |
| 756 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 757 | cmdStr = "device-remove " + str( deviceId ) |
| 758 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 759 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 760 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 761 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 762 | main.log.error( self.name + ": Error in removing device" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 763 | main.log.error( handle ) |
| 764 | return main.FALSE |
| 765 | else: |
| 766 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 767 | except AssertionError: |
| 768 | main.log.exception( "" ) |
| 769 | return None |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 770 | except TypeError: |
| 771 | main.log.exception( self.name + ": Object not as expected" ) |
| 772 | return None |
| 773 | except pexpect.EOF: |
| 774 | main.log.error( self.name + ": EOF exception found" ) |
| 775 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 776 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 777 | except Exception: |
| 778 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 779 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 780 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 781 | def devices( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 782 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 783 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 784 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 785 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 786 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 787 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 788 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 789 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 790 | cmdStr += " -j" |
| 791 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 792 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 793 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 794 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 795 | except AssertionError: |
| 796 | main.log.exception( "" ) |
| 797 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 798 | except TypeError: |
| 799 | main.log.exception( self.name + ": Object not as expected" ) |
| 800 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 801 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 802 | main.log.error( self.name + ": EOF exception found" ) |
| 803 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 804 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 805 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 806 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 807 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 808 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 809 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 810 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 811 | This balances the devices across all controllers |
| 812 | by issuing command: 'onos> onos:balance-masters' |
| 813 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 814 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 815 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 816 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 817 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 818 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 819 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 820 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 821 | main.log.error( self.name + ": Error in balancing masters" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 822 | main.log.error( handle ) |
| 823 | return main.FALSE |
| 824 | else: |
| 825 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 826 | except AssertionError: |
| 827 | main.log.exception( "" ) |
| 828 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 829 | except TypeError: |
| 830 | main.log.exception( self.name + ": Object not as expected" ) |
| 831 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 832 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 833 | main.log.error( self.name + ": EOF exception found" ) |
| 834 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 835 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 836 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 837 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 838 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 839 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 840 | def checkMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 841 | """ |
| 842 | Returns the output of the masters command. |
| 843 | Optional argument: |
| 844 | * jsonFormat - boolean indicating if you want output in json |
| 845 | """ |
| 846 | try: |
| 847 | cmdStr = "onos:masters" |
| 848 | if jsonFormat: |
| 849 | cmdStr += " -j" |
| 850 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 851 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 852 | assert "Command not found:" not in output, output |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 853 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 854 | except AssertionError: |
| 855 | main.log.exception( "" ) |
| 856 | return None |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 857 | except TypeError: |
| 858 | main.log.exception( self.name + ": Object not as expected" ) |
| 859 | return None |
| 860 | except pexpect.EOF: |
| 861 | main.log.error( self.name + ": EOF exception found" ) |
| 862 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 863 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 864 | except Exception: |
| 865 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 866 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 867 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 868 | def checkBalanceMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 869 | """ |
| 870 | Uses the master command to check that the devices' leadership |
| 871 | is evenly divided |
| 872 | |
| 873 | Dependencies: checkMasters() and summary() |
| 874 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 875 | Returns main.TRUE if the devices are balanced |
| 876 | Returns main.FALSE if the devices are unbalanced |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 877 | Exits on Exception |
| 878 | Returns None on TypeError |
| 879 | """ |
| 880 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 881 | summaryOutput = self.summary() |
| 882 | totalDevices = json.loads( summaryOutput )[ "devices" ] |
| 883 | except ( TypeError, ValueError ): |
| 884 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) ) |
| 885 | return None |
| 886 | try: |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 887 | totalOwnedDevices = 0 |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 888 | mastersOutput = self.checkMasters() |
| 889 | masters = json.loads( mastersOutput ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 890 | first = masters[ 0 ][ "size" ] |
| 891 | for master in masters: |
| 892 | totalOwnedDevices += master[ "size" ] |
| 893 | if master[ "size" ] > first + 1 or master[ "size" ] < first - 1: |
| 894 | main.log.error( "Mastership not balanced" ) |
| 895 | main.log.info( "\n" + self.checkMasters( False ) ) |
| 896 | return main.FALSE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 897 | main.log.info( "Mastership balanced between " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 898 | str( len( masters ) ) + " masters" ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 899 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 900 | except ( TypeError, ValueError ): |
| 901 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 902 | return None |
| 903 | except pexpect.EOF: |
| 904 | main.log.error( self.name + ": EOF exception found" ) |
| 905 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 906 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 907 | except Exception: |
| 908 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 909 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 910 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 911 | def links( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 912 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 913 | Lists all core links |
| 914 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 915 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 916 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 917 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 918 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 919 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 920 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 921 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 922 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 923 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 924 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 925 | except AssertionError: |
| 926 | main.log.exception( "" ) |
| 927 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 928 | except TypeError: |
| 929 | main.log.exception( self.name + ": Object not as expected" ) |
| 930 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 931 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 932 | main.log.error( self.name + ": EOF exception found" ) |
| 933 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 934 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 935 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 936 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 937 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 938 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 939 | def ports( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 940 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 941 | Lists all ports |
| 942 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 943 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 944 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 945 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 946 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 947 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 948 | cmdStr += " -j" |
| 949 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 950 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 951 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 952 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 953 | except AssertionError: |
| 954 | main.log.exception( "" ) |
| 955 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 956 | except TypeError: |
| 957 | main.log.exception( self.name + ": Object not as expected" ) |
| 958 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 959 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 960 | main.log.error( self.name + ": EOF exception found" ) |
| 961 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 962 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 963 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 964 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 965 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 966 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 967 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 968 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 969 | Lists all devices and the controllers with roles assigned to them |
| 970 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 971 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 972 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 973 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 974 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 975 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 976 | cmdStr += " -j" |
| 977 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 978 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 979 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 980 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 981 | except AssertionError: |
| 982 | main.log.exception( "" ) |
| 983 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 984 | except TypeError: |
| 985 | main.log.exception( self.name + ": Object not as expected" ) |
| 986 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 987 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 988 | main.log.error( self.name + ": EOF exception found" ) |
| 989 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 990 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 991 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 992 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 993 | main.cleanAndExit() |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 994 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 995 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 996 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 997 | Given the a string containing the json representation of the "roles" |
| 998 | cli command and a partial or whole device id, returns a json object |
| 999 | containing the roles output for the first device whose id contains |
| 1000 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1001 | |
| 1002 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1003 | A dict of the role assignments for the given device or |
| 1004 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1005 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1006 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1007 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1008 | return None |
| 1009 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1010 | rawRoles = self.roles() |
| 1011 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1012 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1013 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1014 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1015 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1016 | return device |
| 1017 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1018 | except ( TypeError, ValueError ): |
| 1019 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1020 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 1021 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1022 | main.log.error( self.name + ": EOF exception found" ) |
| 1023 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1024 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1025 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1026 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1027 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1028 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1029 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1030 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1031 | Iterates through each device and checks if there is a master assigned |
| 1032 | Returns: main.TRUE if each device has a master |
| 1033 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1034 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1035 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1036 | rawRoles = self.roles() |
| 1037 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1038 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1039 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1040 | # print device |
| 1041 | if device[ 'master' ] == "none": |
| 1042 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1043 | return main.FALSE |
| 1044 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1045 | except ( TypeError, ValueError ): |
| 1046 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1047 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1048 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1049 | main.log.error( self.name + ": EOF exception found" ) |
| 1050 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1051 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1052 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1053 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1054 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1055 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1056 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1057 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1058 | Returns string of paths, and the cost. |
| 1059 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1060 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1061 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1062 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 1063 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1064 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1065 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1066 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1067 | main.log.error( self.name + ": Error in getting paths" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1068 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1069 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1070 | path = handle.split( ";" )[ 0 ] |
| 1071 | cost = handle.split( ";" )[ 1 ] |
| 1072 | return ( path, cost ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1073 | except AssertionError: |
| 1074 | main.log.exception( "" ) |
| 1075 | return ( handle, "Error" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1076 | except TypeError: |
| 1077 | main.log.exception( self.name + ": Object not as expected" ) |
| 1078 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1079 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1080 | main.log.error( self.name + ": EOF exception found" ) |
| 1081 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1082 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1083 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1084 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1085 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1086 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1087 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1088 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1089 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1090 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1091 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1092 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1093 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1094 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1095 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1096 | cmdStr += " -j" |
| 1097 | handle = self.sendline( cmdStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1098 | if handle: |
| 1099 | assert "Command not found:" not in handle, handle |
Jon Hall | baf5316 | 2015-12-17 17:04:34 -0800 | [diff] [blame] | 1100 | # TODO: Maybe make this less hardcoded |
| 1101 | # ConsistentMap Exceptions |
| 1102 | assert "org.onosproject.store.service" not in handle |
| 1103 | # Node not leader |
| 1104 | assert "java.lang.IllegalStateException" not in handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1105 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1106 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1107 | main.log.exception( self.name + ": Error in processing '" + cmdStr + "' " + |
Jeremy Songster | 6949cea | 2016-04-19 18:13:18 -0700 | [diff] [blame] | 1108 | "command: " + str( handle ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1109 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1110 | except TypeError: |
| 1111 | main.log.exception( self.name + ": Object not as expected" ) |
| 1112 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1113 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1114 | main.log.error( self.name + ": EOF exception found" ) |
| 1115 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1116 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1117 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1118 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1119 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1120 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1121 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1122 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1123 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1124 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1125 | 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] | 1126 | partial mac address |
| 1127 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1128 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1129 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1130 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1131 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1132 | return None |
| 1133 | else: |
| 1134 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1135 | rawHosts = self.hosts() |
| 1136 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1137 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1138 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1139 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1140 | if not host: |
| 1141 | pass |
| 1142 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1143 | return host |
| 1144 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1145 | except ( TypeError, ValueError ): |
| 1146 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1147 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1148 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1149 | main.log.error( self.name + ": EOF exception found" ) |
| 1150 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1151 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1152 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1153 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1154 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1155 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1156 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1157 | """ |
| 1158 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1159 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1160 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1161 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1162 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1163 | IMPORTANT: |
| 1164 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1165 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1166 | Furthermore, it assumes that value of VLAN is '-1' |
| 1167 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1168 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1169 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1170 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1171 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1172 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1173 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1174 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1175 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1176 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 1177 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 1178 | i = iter( str( hostHex ) ) |
| 1179 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 1180 | hostHex = hostHex + "/-1" |
| 1181 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1182 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1183 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1184 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1185 | except TypeError: |
| 1186 | main.log.exception( self.name + ": Object not as expected" ) |
| 1187 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1188 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1189 | main.log.error( self.name + ": EOF exception found" ) |
| 1190 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1191 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1192 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1193 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1194 | main.cleanAndExit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1195 | |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1196 | def verifyHostLocation( self, hostIp, location ): |
| 1197 | """ |
| 1198 | Description: |
| 1199 | Verify the host given is discovered in all locations expected |
| 1200 | Required: |
| 1201 | hostIp: IP address of the host |
| 1202 | location: expected location(s) of the given host. ex. "of:0000000000000005/8" |
| 1203 | Could be a string or list |
| 1204 | Returns: |
| 1205 | main.TRUE if host is discovered on all locations provided |
| 1206 | main.FALSE otherwise |
| 1207 | """ |
| 1208 | import json |
| 1209 | locations = [ location ] if isinstance( location, str ) else location |
| 1210 | assert isinstance( locations, list ), "Wrong type of location: {}".format( type( location ) ) |
| 1211 | try: |
| 1212 | hosts = self.hosts() |
| 1213 | hosts = json.loads( hosts ) |
| 1214 | targetHost = None |
| 1215 | for host in hosts: |
| 1216 | if hostIp in host[ "ipAddresses" ]: |
| 1217 | targetHost = host |
You Wang | fd80ab4 | 2018-05-10 17:21:53 -0700 | [diff] [blame] | 1218 | assert targetHost, "Not able to find host with IP {}".format( hostIp ) |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1219 | result = main.TRUE |
| 1220 | locationsDiscovered = [ loc[ "elementId" ] + "/" + loc[ "port" ] for loc in targetHost[ "locations" ] ] |
| 1221 | for loc in locations: |
| 1222 | discovered = False |
| 1223 | for locDiscovered in locationsDiscovered: |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1224 | locToMatch = locDiscovered if "/" in loc else locDiscovered.split( "/" )[0] |
| 1225 | if loc == locToMatch: |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1226 | main.log.debug( "Host {} discovered with location {}".format( hostIp, loc ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1227 | discovered = True |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1228 | break |
| 1229 | if discovered: |
| 1230 | locationsDiscovered.remove( locDiscovered ) |
| 1231 | else: |
| 1232 | main.log.warn( "Host {} not discovered with location {}".format( hostIp, loc ) ) |
| 1233 | result = main.FALSE |
| 1234 | if locationsDiscovered: |
| 1235 | main.log.warn( "Host {} is also discovered with location {}".format( hostIp, locationsDiscovered ) ) |
| 1236 | result = main.FALSE |
| 1237 | return result |
| 1238 | except KeyError: |
| 1239 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1240 | return None |
| 1241 | except pexpect.EOF: |
| 1242 | main.log.error( self.name + ": EOF exception found" ) |
| 1243 | main.log.error( self.name + ": " + self.handle.before ) |
| 1244 | main.cleanAndExit() |
| 1245 | except Exception: |
| 1246 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1247 | return None |
| 1248 | |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1249 | def verifyHostIp( self, hostList=[], prefix="" ): |
| 1250 | """ |
| 1251 | Description: |
| 1252 | Verify that all hosts have IP address assigned to them |
| 1253 | Optional: |
| 1254 | hostList: If specified, verifications only happen to the hosts |
| 1255 | in hostList |
| 1256 | prefix: at least one of the ip address assigned to the host |
| 1257 | needs to have the specified prefix |
| 1258 | Returns: |
| 1259 | main.TRUE if all hosts have specific IP address assigned; |
| 1260 | main.FALSE otherwise |
| 1261 | """ |
| 1262 | import json |
| 1263 | try: |
| 1264 | hosts = self.hosts() |
| 1265 | hosts = json.loads( hosts ) |
| 1266 | if not hostList: |
| 1267 | hostList = [ host[ "id" ] for host in hosts ] |
| 1268 | for host in hosts: |
| 1269 | hostId = host[ "id" ] |
| 1270 | if hostId not in hostList: |
| 1271 | continue |
| 1272 | ipList = host[ "ipAddresses" ] |
| 1273 | main.log.debug( self.name + ": IP list on host " + str( hostId ) + ": " + str( ipList ) ) |
| 1274 | if not ipList: |
| 1275 | main.log.warn( self.name + ": Failed to discover any IP addresses on host " + str( hostId ) ) |
| 1276 | else: |
| 1277 | if not any( ip.startswith( str( prefix ) ) for ip in ipList ): |
| 1278 | main.log.warn( self.name + ": None of the IPs on host " + str( hostId ) + " has prefix " + str( prefix ) ) |
| 1279 | else: |
| 1280 | main.log.debug( self.name + ": Found matching IP on host " + str( hostId ) ) |
| 1281 | hostList.remove( hostId ) |
| 1282 | if hostList: |
| 1283 | main.log.warn( self.name + ": failed to verify IP on following hosts: " + str( hostList) ) |
| 1284 | return main.FALSE |
| 1285 | else: |
| 1286 | return main.TRUE |
| 1287 | except KeyError: |
| 1288 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1289 | return None |
| 1290 | except pexpect.EOF: |
| 1291 | main.log.error( self.name + ": EOF exception found" ) |
| 1292 | main.log.error( self.name + ": " + self.handle.before ) |
| 1293 | main.cleanAndExit() |
| 1294 | except Exception: |
| 1295 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1296 | return None |
| 1297 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1298 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1299 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1300 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1301 | * hostIdOne: ONOS host id for host1 |
| 1302 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1303 | Optional: |
| 1304 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1305 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1306 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1307 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1308 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1309 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1310 | Returns: |
| 1311 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1312 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1313 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1314 | cmdStr = "add-host-intent " |
| 1315 | if vlanId: |
| 1316 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1317 | if setVlan: |
| 1318 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1319 | if encap: |
| 1320 | cmdStr += "--encapsulation " + str( encap ) + " " |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1321 | if bandwidth: |
| 1322 | cmdStr += "-b " + str( bandwidth ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1323 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1324 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1325 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1326 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1327 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1328 | main.log.error( self.name + ": Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1329 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1330 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1331 | else: |
| 1332 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1333 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1334 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1335 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1336 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1337 | else: |
| 1338 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1339 | main.log.debug( "Response from ONOS was: " + |
| 1340 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1341 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1342 | except AssertionError: |
| 1343 | main.log.exception( "" ) |
| 1344 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1345 | except TypeError: |
| 1346 | main.log.exception( self.name + ": Object not as expected" ) |
| 1347 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1348 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1349 | main.log.error( self.name + ": EOF exception found" ) |
| 1350 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1351 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1352 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1353 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1354 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1355 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1356 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1357 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1358 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1359 | * ingressDevice: device id of ingress device |
| 1360 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1361 | Optional: |
| 1362 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1363 | Description: |
| 1364 | Adds an optical intent by specifying an ingress and egress device |
| 1365 | Returns: |
| 1366 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1367 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1368 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1369 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1370 | " " + str( egressDevice ) |
| 1371 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1372 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1373 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1374 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1375 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1376 | main.log.error( self.name + ": Error in adding Optical intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1377 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1378 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1379 | main.log.info( "Optical intent installed between " + |
| 1380 | str( ingressDevice ) + " and " + |
| 1381 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1382 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1383 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1384 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1385 | else: |
| 1386 | main.log.error( "Error, intent ID not found" ) |
| 1387 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1388 | except AssertionError: |
| 1389 | main.log.exception( "" ) |
| 1390 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1391 | except TypeError: |
| 1392 | main.log.exception( self.name + ": Object not as expected" ) |
| 1393 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1394 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1395 | main.log.error( self.name + ": EOF exception found" ) |
| 1396 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1397 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1398 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1399 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1400 | main.cleanAndExit() |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1401 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1402 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1403 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1404 | ingressDevice, |
| 1405 | egressDevice, |
| 1406 | portIngress="", |
| 1407 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1408 | ethType="", |
| 1409 | ethSrc="", |
| 1410 | ethDst="", |
| 1411 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1412 | lambdaAlloc=False, |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1413 | protected=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1414 | ipProto="", |
| 1415 | ipSrc="", |
| 1416 | ipDst="", |
| 1417 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1418 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1419 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1420 | setVlan="", |
| 1421 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1422 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1423 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1424 | * ingressDevice: device id of ingress device |
| 1425 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1426 | Optional: |
| 1427 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1428 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1429 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1430 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1431 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1432 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1433 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1434 | * ipSrc: specify ip source address |
| 1435 | * ipDst: specify ip destination address |
| 1436 | * tcpSrc: specify tcp source port |
| 1437 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1438 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1439 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1440 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1441 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1442 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1443 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1444 | Returns: |
| 1445 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1446 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1447 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1448 | options developers provide for point-to-point |
| 1449 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1450 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1451 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1452 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1453 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1454 | if ethType: |
| 1455 | cmd += " --ethType " + str( ethType ) |
| 1456 | if ethSrc: |
| 1457 | cmd += " --ethSrc " + str( ethSrc ) |
| 1458 | if ethDst: |
| 1459 | cmd += " --ethDst " + str( ethDst ) |
| 1460 | if bandwidth: |
| 1461 | cmd += " --bandwidth " + str( bandwidth ) |
| 1462 | if lambdaAlloc: |
| 1463 | cmd += " --lambda " |
| 1464 | if ipProto: |
| 1465 | cmd += " --ipProto " + str( ipProto ) |
| 1466 | if ipSrc: |
| 1467 | cmd += " --ipSrc " + str( ipSrc ) |
| 1468 | if ipDst: |
| 1469 | cmd += " --ipDst " + str( ipDst ) |
| 1470 | if tcpSrc: |
| 1471 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1472 | if tcpDst: |
| 1473 | cmd += " --tcpDst " + str( tcpDst ) |
| 1474 | if vlanId: |
| 1475 | cmd += " -v " + str( vlanId ) |
| 1476 | if setVlan: |
| 1477 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1478 | if encap: |
| 1479 | cmd += " --encapsulation " + str( encap ) |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1480 | if protected: |
| 1481 | cmd += " --protect " |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1482 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1483 | # Check whether the user appended the port |
| 1484 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1485 | if "/" in ingressDevice: |
| 1486 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1487 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1488 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1489 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1490 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1491 | # Would it make sense to throw an exception and exit |
| 1492 | # the test? |
| 1493 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1494 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1495 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1496 | str( ingressDevice ) + "/" +\ |
| 1497 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1498 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1499 | if "/" in egressDevice: |
| 1500 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1501 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1502 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1503 | main.log.error( "You must specify the egress port" ) |
| 1504 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1505 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1506 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1507 | str( egressDevice ) + "/" +\ |
| 1508 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1509 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1510 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1511 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1512 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1513 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1514 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1515 | main.log.error( self.name + ": Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1516 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1517 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1518 | # TODO: print out all the options in this message? |
| 1519 | main.log.info( "Point-to-point intent installed between " + |
| 1520 | str( ingressDevice ) + " and " + |
| 1521 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1522 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1523 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1524 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1525 | else: |
| 1526 | main.log.error( "Error, intent ID not found" ) |
| 1527 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1528 | except AssertionError: |
| 1529 | main.log.exception( "" ) |
| 1530 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1531 | except TypeError: |
| 1532 | main.log.exception( self.name + ": Object not as expected" ) |
| 1533 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1534 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1535 | main.log.error( self.name + ": EOF exception found" ) |
| 1536 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1537 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1538 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1539 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1540 | main.cleanAndExit() |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1541 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1542 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1543 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1544 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1545 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1546 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1547 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1548 | ethType="", |
| 1549 | ethSrc="", |
| 1550 | ethDst="", |
| 1551 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1552 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1553 | ipProto="", |
| 1554 | ipSrc="", |
| 1555 | ipDst="", |
| 1556 | tcpSrc="", |
| 1557 | tcpDst="", |
| 1558 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1559 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1560 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1561 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1562 | partial=False, |
| 1563 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1564 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1565 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1566 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1567 | is same. That is, all ingress devices include port numbers |
| 1568 | with a "/" or all ingress devices could specify device |
| 1569 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1570 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1571 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1572 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1573 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1574 | Optional: |
| 1575 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1576 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1577 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1578 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1579 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1580 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1581 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1582 | * ipSrc: specify ip source address |
| 1583 | * ipDst: specify ip destination address |
| 1584 | * tcpSrc: specify tcp source port |
| 1585 | * tcpDst: specify tcp destination port |
| 1586 | * setEthSrc: action to Rewrite Source MAC Address |
| 1587 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1588 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1589 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1590 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1591 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1592 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1593 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1594 | Returns: |
| 1595 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1596 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1597 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1598 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1599 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1600 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1601 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1602 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1603 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1604 | if ethType: |
| 1605 | cmd += " --ethType " + str( ethType ) |
| 1606 | if ethSrc: |
| 1607 | cmd += " --ethSrc " + str( ethSrc ) |
| 1608 | if ethDst: |
| 1609 | cmd += " --ethDst " + str( ethDst ) |
| 1610 | if bandwidth: |
| 1611 | cmd += " --bandwidth " + str( bandwidth ) |
| 1612 | if lambdaAlloc: |
| 1613 | cmd += " --lambda " |
| 1614 | if ipProto: |
| 1615 | cmd += " --ipProto " + str( ipProto ) |
| 1616 | if ipSrc: |
| 1617 | cmd += " --ipSrc " + str( ipSrc ) |
| 1618 | if ipDst: |
| 1619 | cmd += " --ipDst " + str( ipDst ) |
| 1620 | if tcpSrc: |
| 1621 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1622 | if tcpDst: |
| 1623 | cmd += " --tcpDst " + str( tcpDst ) |
| 1624 | if setEthSrc: |
| 1625 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1626 | if setEthDst: |
| 1627 | cmd += " --setEthDst " + str( setEthDst ) |
| 1628 | if vlanId: |
| 1629 | cmd += " -v " + str( vlanId ) |
| 1630 | if setVlan: |
| 1631 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1632 | if partial: |
| 1633 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1634 | if encap: |
| 1635 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1636 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1637 | # Check whether the user appended the port |
| 1638 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1639 | |
| 1640 | if portIngressList is None: |
| 1641 | for ingressDevice in ingressDeviceList: |
| 1642 | if "/" in ingressDevice: |
| 1643 | cmd += " " + str( ingressDevice ) |
| 1644 | else: |
| 1645 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1646 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1647 | # TODO: perhaps more meaningful return |
| 1648 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1649 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1650 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1651 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1652 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1653 | cmd += " " + \ |
| 1654 | str( ingressDevice ) + "/" +\ |
| 1655 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1656 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1657 | main.log.error( "Device list and port list does not " + |
| 1658 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1659 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1660 | if "/" in egressDevice: |
| 1661 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1662 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1663 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1664 | main.log.error( "You must specify " + |
| 1665 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1666 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1667 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1668 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1669 | str( egressDevice ) + "/" +\ |
| 1670 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1671 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1672 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1673 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1674 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1675 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1676 | main.log.error( self.name + ": Error in adding multipoint-to-singlepoint " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1677 | "intent" ) |
| 1678 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1679 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1680 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1681 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1682 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1683 | else: |
| 1684 | main.log.error( "Error, intent ID not found" ) |
| 1685 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1686 | except AssertionError: |
| 1687 | main.log.exception( "" ) |
| 1688 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1689 | except TypeError: |
| 1690 | main.log.exception( self.name + ": Object not as expected" ) |
| 1691 | return None |
| 1692 | except pexpect.EOF: |
| 1693 | main.log.error( self.name + ": EOF exception found" ) |
| 1694 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1695 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1696 | except Exception: |
| 1697 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1698 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1699 | |
| 1700 | def addSinglepointToMultipointIntent( |
| 1701 | self, |
| 1702 | ingressDevice, |
| 1703 | egressDeviceList, |
| 1704 | portIngress="", |
| 1705 | portEgressList=None, |
| 1706 | ethType="", |
| 1707 | ethSrc="", |
| 1708 | ethDst="", |
| 1709 | bandwidth="", |
| 1710 | lambdaAlloc=False, |
| 1711 | ipProto="", |
| 1712 | ipSrc="", |
| 1713 | ipDst="", |
| 1714 | tcpSrc="", |
| 1715 | tcpDst="", |
| 1716 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1717 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1718 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1719 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1720 | partial=False, |
| 1721 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1722 | """ |
| 1723 | Note: |
| 1724 | This function assumes the format of all egress devices |
| 1725 | is same. That is, all egress devices include port numbers |
| 1726 | with a "/" or all egress devices could specify device |
| 1727 | ids and port numbers seperately. |
| 1728 | Required: |
| 1729 | * EgressDeviceList: List of device ids of egress device |
| 1730 | ( Atleast 2 eress devices required in the list ) |
| 1731 | * ingressDevice: device id of ingress device |
| 1732 | Optional: |
| 1733 | * ethType: specify ethType |
| 1734 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1735 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1736 | * bandwidth: specify bandwidth capacity of link |
| 1737 | * lambdaAlloc: if True, intent will allocate lambda |
| 1738 | for the specified intent |
| 1739 | * ipProto: specify ip protocol |
| 1740 | * ipSrc: specify ip source address |
| 1741 | * ipDst: specify ip destination address |
| 1742 | * tcpSrc: specify tcp source port |
| 1743 | * tcpDst: specify tcp destination port |
| 1744 | * setEthSrc: action to Rewrite Source MAC Address |
| 1745 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1746 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1747 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1748 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1749 | Description: |
| 1750 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1751 | specifying device id's and optional fields |
| 1752 | Returns: |
| 1753 | A string of the intent id or None on error |
| 1754 | |
| 1755 | NOTE: This function may change depending on the |
| 1756 | options developers provide for singlepoint-to-multipoint |
| 1757 | intent via cli |
| 1758 | """ |
| 1759 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1760 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1761 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1762 | if ethType: |
| 1763 | cmd += " --ethType " + str( ethType ) |
| 1764 | if ethSrc: |
| 1765 | cmd += " --ethSrc " + str( ethSrc ) |
| 1766 | if ethDst: |
| 1767 | cmd += " --ethDst " + str( ethDst ) |
| 1768 | if bandwidth: |
| 1769 | cmd += " --bandwidth " + str( bandwidth ) |
| 1770 | if lambdaAlloc: |
| 1771 | cmd += " --lambda " |
| 1772 | if ipProto: |
| 1773 | cmd += " --ipProto " + str( ipProto ) |
| 1774 | if ipSrc: |
| 1775 | cmd += " --ipSrc " + str( ipSrc ) |
| 1776 | if ipDst: |
| 1777 | cmd += " --ipDst " + str( ipDst ) |
| 1778 | if tcpSrc: |
| 1779 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1780 | if tcpDst: |
| 1781 | cmd += " --tcpDst " + str( tcpDst ) |
| 1782 | if setEthSrc: |
| 1783 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1784 | if setEthDst: |
| 1785 | cmd += " --setEthDst " + str( setEthDst ) |
| 1786 | if vlanId: |
| 1787 | cmd += " -v " + str( vlanId ) |
| 1788 | if setVlan: |
| 1789 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1790 | if partial: |
| 1791 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1792 | if encap: |
| 1793 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1794 | |
| 1795 | # Check whether the user appended the port |
| 1796 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1797 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1798 | if "/" in ingressDevice: |
| 1799 | cmd += " " + str( ingressDevice ) |
| 1800 | else: |
| 1801 | if not portIngress: |
| 1802 | main.log.error( "You must specify " + |
| 1803 | "the Ingress port" ) |
| 1804 | return main.FALSE |
| 1805 | |
| 1806 | cmd += " " +\ |
| 1807 | str( ingressDevice ) + "/" +\ |
| 1808 | str( portIngress ) |
| 1809 | |
| 1810 | if portEgressList is None: |
| 1811 | for egressDevice in egressDeviceList: |
| 1812 | if "/" in egressDevice: |
| 1813 | cmd += " " + str( egressDevice ) |
| 1814 | else: |
| 1815 | main.log.error( "You must specify " + |
| 1816 | "the egress port" ) |
| 1817 | # TODO: perhaps more meaningful return |
| 1818 | return main.FALSE |
| 1819 | else: |
| 1820 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1821 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1822 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1823 | cmd += " " + \ |
| 1824 | str( egressDevice ) + "/" +\ |
| 1825 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1826 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1827 | main.log.error( "Device list and port list does not " + |
| 1828 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1829 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1830 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1831 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1832 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1833 | # If error, return error message |
| 1834 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1835 | main.log.error( self.name + ": Error in adding singlepoint-to-multipoint " + |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1836 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1837 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1838 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1839 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1840 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1841 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1842 | else: |
| 1843 | main.log.error( "Error, intent ID not found" ) |
| 1844 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1845 | except AssertionError: |
| 1846 | main.log.exception( "" ) |
| 1847 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1848 | except TypeError: |
| 1849 | main.log.exception( self.name + ": Object not as expected" ) |
| 1850 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1851 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1852 | main.log.error( self.name + ": EOF exception found" ) |
| 1853 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1854 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1855 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1856 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1857 | main.cleanAndExit() |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1858 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1859 | def addMplsIntent( |
| 1860 | self, |
| 1861 | ingressDevice, |
| 1862 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1863 | ingressPort="", |
| 1864 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1865 | ethType="", |
| 1866 | ethSrc="", |
| 1867 | ethDst="", |
| 1868 | bandwidth="", |
| 1869 | lambdaAlloc=False, |
| 1870 | ipProto="", |
| 1871 | ipSrc="", |
| 1872 | ipDst="", |
| 1873 | tcpSrc="", |
| 1874 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1875 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1876 | egressLabel="", |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1877 | priority="" ): |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1878 | """ |
| 1879 | Required: |
| 1880 | * ingressDevice: device id of ingress device |
| 1881 | * egressDevice: device id of egress device |
| 1882 | Optional: |
| 1883 | * ethType: specify ethType |
| 1884 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1885 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1886 | * bandwidth: specify bandwidth capacity of link |
| 1887 | * lambdaAlloc: if True, intent will allocate lambda |
| 1888 | for the specified intent |
| 1889 | * ipProto: specify ip protocol |
| 1890 | * ipSrc: specify ip source address |
| 1891 | * ipDst: specify ip destination address |
| 1892 | * tcpSrc: specify tcp source port |
| 1893 | * tcpDst: specify tcp destination port |
| 1894 | * ingressLabel: Ingress MPLS label |
| 1895 | * egressLabel: Egress MPLS label |
| 1896 | Description: |
| 1897 | Adds MPLS intent by |
| 1898 | specifying device id's and optional fields |
| 1899 | Returns: |
| 1900 | A string of the intent id or None on error |
| 1901 | |
| 1902 | NOTE: This function may change depending on the |
| 1903 | options developers provide for MPLS |
| 1904 | intent via cli |
| 1905 | """ |
| 1906 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1907 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1908 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1909 | if ethType: |
| 1910 | cmd += " --ethType " + str( ethType ) |
| 1911 | if ethSrc: |
| 1912 | cmd += " --ethSrc " + str( ethSrc ) |
| 1913 | if ethDst: |
| 1914 | cmd += " --ethDst " + str( ethDst ) |
| 1915 | if bandwidth: |
| 1916 | cmd += " --bandwidth " + str( bandwidth ) |
| 1917 | if lambdaAlloc: |
| 1918 | cmd += " --lambda " |
| 1919 | if ipProto: |
| 1920 | cmd += " --ipProto " + str( ipProto ) |
| 1921 | if ipSrc: |
| 1922 | cmd += " --ipSrc " + str( ipSrc ) |
| 1923 | if ipDst: |
| 1924 | cmd += " --ipDst " + str( ipDst ) |
| 1925 | if tcpSrc: |
| 1926 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1927 | if tcpDst: |
| 1928 | cmd += " --tcpDst " + str( tcpDst ) |
| 1929 | if ingressLabel: |
| 1930 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 1931 | if egressLabel: |
| 1932 | cmd += " --egressLabel " + str( egressLabel ) |
| 1933 | if priority: |
| 1934 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1935 | |
| 1936 | # Check whether the user appended the port |
| 1937 | # or provided it as an input |
| 1938 | if "/" in ingressDevice: |
| 1939 | cmd += " " + str( ingressDevice ) |
| 1940 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1941 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1942 | main.log.error( "You must specify the ingress port" ) |
| 1943 | return None |
| 1944 | |
| 1945 | cmd += " " + \ |
| 1946 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1947 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1948 | |
| 1949 | if "/" in egressDevice: |
| 1950 | cmd += " " + str( egressDevice ) |
| 1951 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1952 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1953 | main.log.error( "You must specify the egress port" ) |
| 1954 | return None |
| 1955 | |
| 1956 | cmd += " " +\ |
| 1957 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1958 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1959 | |
| 1960 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1961 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1962 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1963 | # If error, return error message |
| 1964 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1965 | main.log.error( self.name + ": Error in adding mpls intent" ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1966 | return None |
| 1967 | else: |
| 1968 | # TODO: print out all the options in this message? |
| 1969 | main.log.info( "MPLS intent installed between " + |
| 1970 | str( ingressDevice ) + " and " + |
| 1971 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1972 | match = re.search( 'id=0x([\da-f]+),', handle ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1973 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1974 | return match.group()[ 3:-1 ] |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1975 | else: |
| 1976 | main.log.error( "Error, intent ID not found" ) |
| 1977 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1978 | except AssertionError: |
| 1979 | main.log.exception( "" ) |
| 1980 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1981 | except TypeError: |
| 1982 | main.log.exception( self.name + ": Object not as expected" ) |
| 1983 | return None |
| 1984 | except pexpect.EOF: |
| 1985 | main.log.error( self.name + ": EOF exception found" ) |
| 1986 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1987 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1988 | except Exception: |
| 1989 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1990 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1991 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1992 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 1993 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1994 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1995 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1996 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1997 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1998 | -p or --purge: Purge the intent from the store after removal |
| 1999 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2000 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 2001 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2002 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2003 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2004 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2005 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2006 | if purge: |
| 2007 | cmdStr += " -p" |
| 2008 | if sync: |
| 2009 | cmdStr += " -s" |
| 2010 | |
| 2011 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2012 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2013 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2014 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2015 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2016 | main.log.error( self.name + ": Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2017 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2018 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2019 | # TODO: Should this be main.TRUE |
| 2020 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2021 | except AssertionError: |
| 2022 | main.log.exception( "" ) |
| 2023 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2024 | except TypeError: |
| 2025 | main.log.exception( self.name + ": Object not as expected" ) |
| 2026 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2027 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2028 | main.log.error( self.name + ": EOF exception found" ) |
| 2029 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2030 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2031 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2032 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2033 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2034 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2035 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2036 | """ |
| 2037 | Description: |
| 2038 | Remove all the intents |
| 2039 | Optional args:- |
| 2040 | -s or --sync: Waits for the removal before returning |
| 2041 | -p or --purge: Purge the intent from the store after removal |
| 2042 | Returns: |
| 2043 | Returns main.TRUE if all intents are removed, otherwise returns |
| 2044 | main.FALSE; Returns None for exception |
| 2045 | """ |
| 2046 | try: |
| 2047 | cmdStr = "remove-intent" |
| 2048 | if purge: |
| 2049 | cmdStr += " -p" |
| 2050 | if sync: |
| 2051 | cmdStr += " -s" |
| 2052 | |
| 2053 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2054 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2055 | assert handle is not None, "Error in sendline" |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2056 | assert "Command not found:" not in handle, handle |
| 2057 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2058 | main.log.error( self.name + ": Error in removing intent" ) |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2059 | return main.FALSE |
| 2060 | else: |
| 2061 | return main.TRUE |
| 2062 | except AssertionError: |
| 2063 | main.log.exception( "" ) |
| 2064 | return None |
| 2065 | except TypeError: |
| 2066 | main.log.exception( self.name + ": Object not as expected" ) |
| 2067 | return None |
| 2068 | except pexpect.EOF: |
| 2069 | main.log.error( self.name + ": EOF exception found" ) |
| 2070 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2071 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2072 | except Exception: |
| 2073 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2074 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2075 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 2076 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2077 | """ |
| 2078 | Purges all WITHDRAWN Intents |
| 2079 | """ |
| 2080 | try: |
| 2081 | cmdStr = "purge-intents" |
| 2082 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2083 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2084 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2085 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2086 | main.log.error( self.name + ": Error in purging intents" ) |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2087 | return main.FALSE |
| 2088 | else: |
| 2089 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2090 | except AssertionError: |
| 2091 | main.log.exception( "" ) |
| 2092 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2093 | except TypeError: |
| 2094 | main.log.exception( self.name + ": Object not as expected" ) |
| 2095 | return None |
| 2096 | except pexpect.EOF: |
| 2097 | main.log.error( self.name + ": EOF exception found" ) |
| 2098 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2099 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2100 | except Exception: |
| 2101 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2102 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2103 | |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 2104 | def wipeout( self ): |
| 2105 | """ |
| 2106 | Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS. |
| 2107 | """ |
| 2108 | try: |
| 2109 | cmdStr = "wipe-out please" |
| 2110 | handle = self.sendline( cmdStr, timeout=60 ) |
| 2111 | assert handle is not None, "Error in sendline" |
| 2112 | assert "Command not found:" not in handle, handle |
| 2113 | return main.TRUE |
| 2114 | except AssertionError: |
| 2115 | main.log.exception( "" ) |
| 2116 | return None |
| 2117 | except TypeError: |
| 2118 | main.log.exception( self.name + ": Object not as expected" ) |
| 2119 | return None |
| 2120 | except pexpect.EOF: |
| 2121 | main.log.error( self.name + ": EOF exception found" ) |
| 2122 | main.log.error( self.name + ": " + self.handle.before ) |
| 2123 | main.cleanAndExit() |
| 2124 | except Exception: |
| 2125 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2126 | main.cleanAndExit() |
| 2127 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2128 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2129 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2130 | NOTE: This method should be used after installing application: |
| 2131 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2132 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2133 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2134 | Description: |
| 2135 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2136 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2137 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2138 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2139 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2140 | cmdStr += " -j" |
| 2141 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2142 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2143 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2144 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2145 | except AssertionError: |
| 2146 | main.log.exception( "" ) |
| 2147 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2148 | except TypeError: |
| 2149 | main.log.exception( self.name + ": Object not as expected" ) |
| 2150 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2151 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2152 | main.log.error( self.name + ": EOF exception found" ) |
| 2153 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2154 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2155 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2156 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2157 | main.cleanAndExit() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2158 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2159 | def ipv4RouteNumber( self ): |
| 2160 | """ |
| 2161 | NOTE: This method should be used after installing application: |
| 2162 | onos-app-sdnip |
| 2163 | Description: |
| 2164 | Obtain the total IPv4 routes number in the system |
| 2165 | """ |
| 2166 | try: |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2167 | cmdStr = "routes -j" |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2168 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2169 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2170 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2171 | jsonResult = json.loads( handle ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2172 | return len( jsonResult[ 'routes4' ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2173 | except AssertionError: |
| 2174 | main.log.exception( "" ) |
| 2175 | return None |
| 2176 | except ( TypeError, ValueError ): |
| 2177 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2178 | return None |
| 2179 | except pexpect.EOF: |
| 2180 | main.log.error( self.name + ": EOF exception found" ) |
| 2181 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2182 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2183 | except Exception: |
| 2184 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2185 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2186 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2187 | # =============Function to check Bandwidth allocation======== |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2188 | def allocations( self, jsonFormat = True ): |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2189 | """ |
| 2190 | Description: |
| 2191 | Obtain Bandwidth Allocation Information from ONOS cli. |
| 2192 | """ |
| 2193 | try: |
| 2194 | cmdStr = "allocations" |
| 2195 | if jsonFormat: |
| 2196 | cmdStr += " -j" |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2197 | handle = self.sendline( cmdStr, timeout=300 ) |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2198 | assert handle is not None, "Error in sendline" |
| 2199 | assert "Command not found:" not in handle, handle |
| 2200 | return handle |
| 2201 | except AssertionError: |
| 2202 | main.log.exception( "" ) |
| 2203 | return None |
| 2204 | except ( TypeError, ValueError ): |
| 2205 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
| 2206 | return None |
| 2207 | except pexpect.EOF: |
| 2208 | main.log.error( self.name + ": EOF exception found" ) |
| 2209 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2210 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2211 | except Exception: |
| 2212 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2213 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2214 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2215 | def intents( self, jsonFormat = True, summary = False, **intentargs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2216 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2217 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2218 | Obtain intents from the ONOS cli. |
| 2219 | Optional: |
| 2220 | * jsonFormat: Enable output formatting in json, default to True |
| 2221 | * summary: Whether only output the intent summary, defaults to False |
| 2222 | * type: Only output a certain type of intent. This options is valid |
| 2223 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2224 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2225 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2226 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2227 | if summary: |
| 2228 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2229 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2230 | cmdStr += " -j" |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2231 | handle = self.sendline( cmdStr, timeout=300 ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2232 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2233 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2234 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2235 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2236 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2237 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2238 | intentType = "" |
| 2239 | # IF we want the summary of a specific intent type |
| 2240 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2241 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2242 | if intentType in jsonResult.keys(): |
| 2243 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2244 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2245 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2246 | return handle |
| 2247 | else: |
| 2248 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2249 | except AssertionError: |
| 2250 | main.log.exception( "" ) |
| 2251 | return None |
| 2252 | except ( TypeError, ValueError ): |
| 2253 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2254 | return None |
| 2255 | except pexpect.EOF: |
| 2256 | main.log.error( self.name + ": EOF exception found" ) |
| 2257 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2258 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2259 | except Exception: |
| 2260 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2261 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2262 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2263 | def getIntentState( self, intentsId, intentsJson=None ): |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2264 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2265 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2266 | Gets intent state. Accepts a single intent ID (string type) or a |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2267 | list of intent IDs. |
| 2268 | Parameters: |
| 2269 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2270 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2271 | Returns: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2272 | 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] | 2273 | accepted. |
| 2274 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2275 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2276 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2277 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2278 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2279 | try: |
| 2280 | state = "State is Undefined" |
| 2281 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2282 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2283 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2284 | rawJson = intentsJson |
| 2285 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2286 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2287 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2288 | if intentsId == intent[ 'id' ]: |
| 2289 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2290 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2291 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2292 | " in the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2293 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2294 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2295 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2296 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2297 | stateDict = {} |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2298 | for intent in parsedIntentsJson: |
| 2299 | if intentsId[ i ] == intent[ 'id' ]: |
| 2300 | stateDict[ 'state' ] = intent[ 'state' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2301 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2302 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2303 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2304 | if len( intentsId ) != len( dictList ): |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2305 | main.log.warn( "Could not find all intents in ONOS output" ) |
| 2306 | main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2307 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2308 | else: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2309 | main.log.info( "Invalid type for intentsId argument" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2310 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2311 | except ( TypeError, ValueError ): |
| 2312 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2313 | return None |
| 2314 | except pexpect.EOF: |
| 2315 | main.log.error( self.name + ": EOF exception found" ) |
| 2316 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2317 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2318 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2319 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2320 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2321 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2322 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2323 | """ |
| 2324 | Description: |
| 2325 | Check intents state |
| 2326 | Required: |
| 2327 | intentsId - List of intents ID to be checked |
| 2328 | Optional: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2329 | expectedState - Check the expected state(s) of each intents |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2330 | state in the list. |
| 2331 | *NOTE: You can pass in a list of expected state, |
| 2332 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2333 | Return: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2334 | Returns main.TRUE only if all intent are the same as expected states, |
| 2335 | otherwise returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2336 | """ |
| 2337 | try: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2338 | returnValue = main.TRUE |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2339 | # Generating a dictionary: intent id as a key and state as value |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2340 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2341 | # intentsDict = self.getIntentState( intentsId ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2342 | intentsDict = [] |
| 2343 | for intent in json.loads( self.intents() ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2344 | if isinstance( intentsId, types.StringType ) \ |
| 2345 | and intent.get( 'id' ) == intentsId: |
| 2346 | intentsDict.append( intent ) |
| 2347 | elif isinstance( intentsId, types.ListType ) \ |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2348 | and any( intent.get( 'id' ) == ids for ids in intentsId ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2349 | intentsDict.append( intent ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2350 | |
| 2351 | if not intentsDict: |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2352 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2353 | "getting intents state" ) |
| 2354 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2355 | |
| 2356 | if isinstance( expectedState, types.StringType ): |
| 2357 | for intents in intentsDict: |
| 2358 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2359 | main.log.debug( self.name + " : Intent ID - " + |
| 2360 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2361 | " actual state = " + |
| 2362 | intents.get( 'state' ) |
| 2363 | + " does not equal expected state = " |
| 2364 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2365 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2366 | elif isinstance( expectedState, types.ListType ): |
| 2367 | for intents in intentsDict: |
| 2368 | if not any( state == intents.get( 'state' ) for state in |
| 2369 | expectedState ): |
| 2370 | main.log.debug( self.name + " : Intent ID - " + |
| 2371 | intents.get( 'id' ) + |
| 2372 | " actual state = " + |
| 2373 | intents.get( 'state' ) + |
| 2374 | " does not equal expected states = " |
| 2375 | + str( expectedState ) ) |
| 2376 | returnValue = main.FALSE |
| 2377 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2378 | if returnValue == main.TRUE: |
| 2379 | main.log.info( self.name + ": All " + |
| 2380 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2381 | " intents are in " + str( expectedState ) + |
| 2382 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2383 | return returnValue |
| 2384 | except TypeError: |
| 2385 | main.log.exception( self.name + ": Object not as expected" ) |
| 2386 | return None |
| 2387 | except pexpect.EOF: |
| 2388 | main.log.error( self.name + ": EOF exception found" ) |
| 2389 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2390 | main.cleanAndExit() |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2391 | except Exception: |
| 2392 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2393 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2394 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2395 | def compareBandwidthAllocations( self, expectedAllocations ): |
| 2396 | """ |
| 2397 | Description: |
| 2398 | Compare the allocated bandwidth with the given allocations |
| 2399 | Required: |
| 2400 | expectedAllocations - The expected ONOS output of the allocations command |
| 2401 | Return: |
| 2402 | Returns main.TRUE only if all intent are the same as expected states, |
| 2403 | otherwise returns main.FALSE. |
| 2404 | """ |
| 2405 | # FIXME: Convert these string comparisons to object comparisons |
| 2406 | try: |
| 2407 | returnValue = main.TRUE |
| 2408 | bandwidthFailed = False |
| 2409 | rawAlloc = self.allocations() |
| 2410 | expectedFormat = StringIO( expectedAllocations ) |
| 2411 | ONOSOutput = StringIO( rawAlloc ) |
| 2412 | main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ), |
| 2413 | str( expectedFormat ) ) ) |
| 2414 | |
| 2415 | for actual, expected in izip( ONOSOutput, expectedFormat ): |
| 2416 | actual = actual.rstrip() |
| 2417 | expected = expected.rstrip() |
| 2418 | main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) ) |
| 2419 | if actual != expected and 'allocated' in actual and 'allocated' in expected: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2420 | marker1 = actual.find( 'allocated' ) |
| 2421 | m1 = actual[ :marker1 ] |
| 2422 | marker2 = expected.find( 'allocated' ) |
| 2423 | m2 = expected[ :marker2 ] |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2424 | if m1 != m2: |
| 2425 | bandwidthFailed = True |
| 2426 | elif actual != expected and 'allocated' not in actual and 'allocated' not in expected: |
| 2427 | bandwidthFailed = True |
| 2428 | expectedFormat.close() |
| 2429 | ONOSOutput.close() |
| 2430 | |
| 2431 | if bandwidthFailed: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2432 | main.log.error( "Bandwidth not allocated correctly using Intents!!" ) |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2433 | returnValue = main.FALSE |
| 2434 | return returnValue |
| 2435 | except TypeError: |
| 2436 | main.log.exception( self.name + ": Object not as expected" ) |
| 2437 | return None |
| 2438 | except pexpect.EOF: |
| 2439 | main.log.error( self.name + ": EOF exception found" ) |
| 2440 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2441 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2442 | except Exception: |
| 2443 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2444 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2445 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2446 | def compareIntent( self, intentDict ): |
| 2447 | """ |
| 2448 | Description: |
| 2449 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2450 | Return: |
| 2451 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2452 | Arguments: |
| 2453 | intentDict: a dictionary which maps intent ids to intent states |
| 2454 | """ |
| 2455 | try: |
| 2456 | intentsRaw = self.intents() |
| 2457 | intentsJson = json.loads( intentsRaw ) |
| 2458 | intentDictONOS = {} |
| 2459 | for intent in intentsJson: |
| 2460 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2461 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2462 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2463 | 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] | 2464 | str( len( intentDict ) ) + " expected and " + |
| 2465 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2466 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2467 | for intentID in intentDict.keys(): |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2468 | if intentID not in intentDictONOS.keys(): |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2469 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2470 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2471 | else: |
| 2472 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2473 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2474 | " expected state is " + intentDict[ intentID ] + |
| 2475 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2476 | returnValue = main.FALSE |
| 2477 | intentDictONOS.pop( intentID ) |
| 2478 | if len( intentDictONOS ) > 0: |
| 2479 | returnValue = main.FALSE |
| 2480 | for intentID in intentDictONOS.keys(): |
| 2481 | 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] | 2482 | if returnValue == main.TRUE: |
| 2483 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2484 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2485 | except KeyError: |
| 2486 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2487 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2488 | except ( TypeError, ValueError ): |
| 2489 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2490 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2491 | except pexpect.EOF: |
| 2492 | main.log.error( self.name + ": EOF exception found" ) |
| 2493 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2494 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2495 | except Exception: |
| 2496 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2497 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2498 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2499 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2500 | """ |
| 2501 | Description: |
| 2502 | Check the number of installed intents. |
| 2503 | Optional: |
| 2504 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2505 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2506 | Return: |
| 2507 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2508 | , otherwise, returns main.FALSE. |
| 2509 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2510 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2511 | try: |
| 2512 | cmd = "intents -s -j" |
| 2513 | |
| 2514 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2515 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2516 | if response is None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2517 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2518 | response = json.loads( response ) |
| 2519 | |
| 2520 | # get total and installed number, see if they are match |
| 2521 | allState = response.get( 'all' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2522 | if allState.get( 'total' ) == allState.get( 'installed' ): |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2523 | main.log.info( 'Total Intents: {} Installed Intents: {}'.format( |
| 2524 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2525 | return main.TRUE |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2526 | main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format( |
| 2527 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2528 | return main.FALSE |
| 2529 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2530 | except ( TypeError, ValueError ): |
| 2531 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2532 | return None |
| 2533 | except pexpect.EOF: |
| 2534 | main.log.error( self.name + ": EOF exception found" ) |
| 2535 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2536 | if noExit: |
| 2537 | return main.FALSE |
| 2538 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2539 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2540 | except pexpect.TIMEOUT: |
| 2541 | main.log.error( self.name + ": ONOS timeout" ) |
| 2542 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2543 | except Exception: |
| 2544 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2545 | if noExit: |
| 2546 | return main.FALSE |
| 2547 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2548 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2549 | |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2550 | 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] | 2551 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2552 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2553 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2554 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2555 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2556 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2557 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2558 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2559 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2560 | if jsonFormat: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2561 | cmdStr += " -j" |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2562 | if noCore: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2563 | cmdStr += " -n" |
| 2564 | cmdStr += " " + state |
| 2565 | cmdStr += " " + device |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2566 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2567 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2568 | assert "Command not found:" not in handle, handle |
| 2569 | if re.search( "Error:", handle ): |
| 2570 | main.log.error( self.name + ": flows() response: " + |
| 2571 | str( handle ) ) |
| 2572 | return handle |
| 2573 | except AssertionError: |
| 2574 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2575 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2576 | except TypeError: |
| 2577 | main.log.exception( self.name + ": Object not as expected" ) |
| 2578 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2579 | except pexpect.TIMEOUT: |
| 2580 | main.log.error( self.name + ": ONOS timeout" ) |
| 2581 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2582 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2583 | main.log.error( self.name + ": EOF exception found" ) |
| 2584 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2585 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2586 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2587 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2588 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2589 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2590 | def checkFlowCount( self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2591 | count = self.getTotalFlowsNum( timeout=timeout ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2592 | count = int( count ) if count else 0 |
| 2593 | return count if ( count > min ) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2594 | |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2595 | def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2596 | """ |
| 2597 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2598 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2599 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2600 | if the count of those states is 0, which means all current flows |
| 2601 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2602 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2603 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2604 | Return: |
| 2605 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2606 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2607 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2608 | """ |
| 2609 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2610 | states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2611 | checkedStates = [] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2612 | statesCount = [ 0, 0, 0, 0 ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2613 | for s in states: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2614 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2615 | if rawFlows: |
| 2616 | # if we didn't get flows or flows function return None, we should return |
| 2617 | # main.Flase |
| 2618 | checkedStates.append( json.loads( rawFlows ) ) |
| 2619 | else: |
| 2620 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2621 | for i in range( len( states ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2622 | for c in checkedStates[ i ]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2623 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2624 | statesCount[ i ] += int( c.get( "flowCount" ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2625 | except TypeError: |
| 2626 | main.log.exception( "Json object not as expected" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2627 | main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2628 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2629 | # We want to count PENDING_ADD if isPENDING is true |
| 2630 | if isPENDING: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2631 | if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2632 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2633 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2634 | if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2635 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2636 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2637 | except ( TypeError, ValueError ): |
| 2638 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2639 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2640 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2641 | except AssertionError: |
| 2642 | main.log.exception( "" ) |
| 2643 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2644 | except pexpect.TIMEOUT: |
| 2645 | main.log.error( self.name + ": ONOS timeout" ) |
| 2646 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2647 | except pexpect.EOF: |
| 2648 | main.log.error( self.name + ": EOF exception found" ) |
| 2649 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2650 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2651 | except Exception: |
| 2652 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2653 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2654 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2655 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2656 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2657 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2658 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2659 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2660 | a specific point-to-point intent definition |
| 2661 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2662 | * ingress: specify source dpid |
| 2663 | * egress: specify destination dpid |
| 2664 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2665 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2666 | * offset: the keyOffset is where the next batch of intents |
| 2667 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2668 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2669 | * getResponse: If set to True, function will return ONOS response. |
| 2670 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2671 | Returns: If failed to push test intents, it will returen None, |
| 2672 | if successful, return true. |
| 2673 | Timeout expection will return None, |
| 2674 | TypeError will return false |
| 2675 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2676 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2677 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2678 | if background: |
| 2679 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2680 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2681 | back = "" |
| 2682 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2683 | ingress, |
| 2684 | egress, |
| 2685 | batchSize, |
| 2686 | offset, |
| 2687 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2688 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2689 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2690 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2691 | main.log.info( response ) |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2692 | if getResponse: |
| 2693 | return response |
| 2694 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2695 | # TODO: We should handle if there is failure in installation |
| 2696 | return main.TRUE |
| 2697 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2698 | except AssertionError: |
| 2699 | main.log.exception( "" ) |
| 2700 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2701 | except pexpect.TIMEOUT: |
| 2702 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2703 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2704 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2705 | main.log.error( self.name + ": EOF exception found" ) |
| 2706 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2707 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2708 | except TypeError: |
| 2709 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2710 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2711 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2712 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2713 | main.cleanAndExit() |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2714 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2715 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2716 | """ |
| 2717 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2718 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2719 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2720 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2721 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2722 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2723 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2724 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2725 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2726 | cmd = "flows -c added" |
| 2727 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2728 | if rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2729 | rawFlows = rawFlows.split( "\n" ) |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2730 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2731 | for l in rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2732 | totalFlows += int( l.split( "Count=" )[ 1 ] ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2733 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2734 | main.log.error( "Response not as expected!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2735 | return None |
| 2736 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2737 | |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2738 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2739 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2740 | return None |
| 2741 | except pexpect.EOF: |
| 2742 | main.log.error( self.name + ": EOF exception found" ) |
| 2743 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2744 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2745 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2746 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2747 | except pexpect.TIMEOUT: |
| 2748 | main.log.error( self.name + ": ONOS timeout" ) |
| 2749 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2750 | except Exception: |
| 2751 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2752 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2753 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2754 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2755 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2756 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2757 | """ |
| 2758 | Description: |
| 2759 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2760 | Optional: |
| 2761 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2762 | Return: |
| 2763 | The number of intents |
| 2764 | """ |
| 2765 | try: |
| 2766 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2767 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2768 | if response is None: |
| 2769 | return -1 |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2770 | response = json.loads( response ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2771 | return int( response.get( "intents" ) ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2772 | except ( TypeError, ValueError ): |
| 2773 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2774 | return None |
| 2775 | except pexpect.EOF: |
| 2776 | main.log.error( self.name + ": EOF exception found" ) |
| 2777 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2778 | if noExit: |
| 2779 | return -1 |
| 2780 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2781 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2782 | except Exception: |
| 2783 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2784 | if noExit: |
| 2785 | return -1 |
| 2786 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2787 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2788 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2789 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2790 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2791 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2792 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2793 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2794 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2795 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2796 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2797 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2798 | cmdStr += " -j" |
| 2799 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2800 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2801 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2802 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2803 | except AssertionError: |
| 2804 | main.log.exception( "" ) |
| 2805 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2806 | except TypeError: |
| 2807 | main.log.exception( self.name + ": Object not as expected" ) |
| 2808 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2809 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2810 | main.log.error( self.name + ": EOF exception found" ) |
| 2811 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2812 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2813 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2814 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2815 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2816 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2817 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2818 | """ |
| 2819 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2820 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2821 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2822 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2823 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2824 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2825 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2826 | cmdStr += " -j" |
| 2827 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2828 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2829 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2830 | if handle: |
| 2831 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2832 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2833 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2834 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2835 | else: |
| 2836 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2837 | except AssertionError: |
| 2838 | main.log.exception( "" ) |
| 2839 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2840 | except TypeError: |
| 2841 | main.log.exception( self.name + ": Object not as expected" ) |
| 2842 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2843 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2844 | main.log.error( self.name + ": EOF exception found" ) |
| 2845 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2846 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2847 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2848 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2849 | main.cleanAndExit() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2850 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2851 | # Wrapper functions **************** |
| 2852 | # Wrapper functions use existing driver |
| 2853 | # functions and extends their use case. |
| 2854 | # For example, we may use the output of |
| 2855 | # a normal driver function, and parse it |
| 2856 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2857 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2858 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2859 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2860 | Description: |
| 2861 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2862 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2863 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2864 | # Obtain output of intents function |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2865 | intentsStr = self.intents( jsonFormat=True ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 2866 | if intentsStr is None: |
| 2867 | raise TypeError |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2868 | # Convert to a dictionary |
| 2869 | intents = json.loads( intentsStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2870 | intentIdList = [] |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2871 | for intent in intents: |
| 2872 | intentIdList.append( intent[ 'id' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2873 | return intentIdList |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2874 | except TypeError: |
| 2875 | main.log.exception( self.name + ": Object not as expected" ) |
| 2876 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2877 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2878 | main.log.error( self.name + ": EOF exception found" ) |
| 2879 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2880 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2881 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2882 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2883 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2884 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2885 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2886 | """ |
| 2887 | Determine the number of flow rules for the given device id that are |
| 2888 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2889 | Params: |
| 2890 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2891 | """ |
| 2892 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2893 | if core: |
| 2894 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2895 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2896 | else: |
| 2897 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2898 | "grep 'state=ADDED' | wc -l" |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2899 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2900 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2901 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2902 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2903 | except AssertionError: |
| 2904 | main.log.exception( "" ) |
| 2905 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2906 | except pexpect.EOF: |
| 2907 | main.log.error( self.name + ": EOF exception found" ) |
| 2908 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2909 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2910 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2911 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2912 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2913 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2914 | def groupAddedCount( self, deviceId, core=False ): |
| 2915 | """ |
| 2916 | Determine the number of group rules for the given device id that are |
| 2917 | in the added state |
| 2918 | Params: |
| 2919 | core: if True, only return the number of core groups added |
| 2920 | """ |
| 2921 | try: |
| 2922 | if core: |
| 2923 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 2924 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2925 | else: |
| 2926 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 2927 | "grep 'state=ADDED' | wc -l" |
| 2928 | handle = self.sendline( cmdStr ) |
| 2929 | assert handle is not None, "Error in sendline" |
| 2930 | assert "Command not found:" not in handle, handle |
| 2931 | return handle |
| 2932 | except AssertionError: |
| 2933 | main.log.exception( "" ) |
| 2934 | return None |
| 2935 | except pexpect.EOF: |
| 2936 | main.log.error( self.name + ": EOF exception found" ) |
| 2937 | main.log.error( self.name + ": " + self.handle.before ) |
| 2938 | main.cleanAndExit() |
| 2939 | except Exception: |
| 2940 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2941 | main.cleanAndExit() |
| 2942 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 2943 | def addStaticRoute( self, subnet, intf): |
| 2944 | """ |
| 2945 | Adds a static route to onos. |
| 2946 | Params: |
| 2947 | subnet: The subnet reaching through this route |
| 2948 | intf: The interface this route is reachable through |
| 2949 | """ |
| 2950 | try: |
| 2951 | cmdStr = "route-add " + subnet + " " + intf |
| 2952 | handle = self.sendline( cmdStr ) |
| 2953 | assert handle is not None, "Error in sendline" |
| 2954 | assert "Command not found:" not in handle, handle |
| 2955 | return handle |
| 2956 | except AssertionError: |
| 2957 | main.log.exception( "" ) |
| 2958 | return None |
| 2959 | except pexpect.EOF: |
| 2960 | main.log.error( self.name + ": EOF exception found" ) |
| 2961 | main.log.error( self.name + ": " + self.handle.before ) |
| 2962 | main.cleanAndExit() |
| 2963 | except Exception: |
| 2964 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2965 | main.cleanAndExit() |
| 2966 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2967 | def checkGroupAddedCount( self, deviceId, expectedGroupCount=0, core=False, comparison=0): |
| 2968 | """ |
| 2969 | Description: |
| 2970 | Check whether the number of groups for the given device id that |
| 2971 | are in ADDED state is bigger than minGroupCount. |
| 2972 | Required: |
| 2973 | * deviceId: device id to check the number of added group rules |
| 2974 | Optional: |
| 2975 | * minGroupCount: the number of groups to compare |
| 2976 | * core: if True, only check the number of core groups added |
| 2977 | * comparison: if 0, compare with greater than minFlowCount |
| 2978 | * if 1, compare with equal to minFlowCount |
| 2979 | Return: |
| 2980 | Returns the number of groups if it is bigger than minGroupCount, |
| 2981 | returns main.FALSE otherwise. |
| 2982 | """ |
| 2983 | count = self.groupAddedCount( deviceId, core ) |
| 2984 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 2985 | main.log.debug( "found {} groups".format( count ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2986 | return count if ((count > expectedGroupCount) if (comparison == 0) else (count == expectedGroupCount)) else main.FALSE |
| 2987 | |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 2988 | def getGroups( self, deviceId, groupType="any" ): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2989 | """ |
| 2990 | Retrieve groups from a specific device. |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 2991 | deviceId: Id of the device from which we retrieve groups |
| 2992 | groupType: Type of group |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2993 | """ |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2994 | try: |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 2995 | groupCmd = "groups -t {0} any {1}".format( groupType, deviceId ) |
| 2996 | handle = self.sendline( groupCmd ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2997 | assert handle is not None, "Error in sendline" |
| 2998 | assert "Command not found:" not in handle, handle |
| 2999 | return handle |
| 3000 | except AssertionError: |
| 3001 | main.log.exception( "" ) |
| 3002 | return None |
| 3003 | except TypeError: |
| 3004 | main.log.exception( self.name + ": Object not as expected" ) |
| 3005 | return None |
| 3006 | except pexpect.EOF: |
| 3007 | main.log.error( self.name + ": EOF exception found" ) |
| 3008 | main.log.error( self.name + ": " + self.handle.before ) |
| 3009 | main.cleanAndExit() |
| 3010 | except Exception: |
| 3011 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3012 | main.cleanAndExit() |
| 3013 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3014 | def checkFlowAddedCount( self, deviceId, expectedFlowCount=0, core=False, comparison=0): |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3015 | """ |
| 3016 | Description: |
| 3017 | Check whether the number of flow rules for the given device id that |
| 3018 | are in ADDED state is bigger than minFlowCount. |
| 3019 | Required: |
| 3020 | * deviceId: device id to check the number of added flow rules |
| 3021 | Optional: |
| 3022 | * minFlowCount: the number of flow rules to compare |
| 3023 | * core: if True, only check the number of core flows added |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3024 | * comparison: if 0, compare with greater than minFlowCount |
| 3025 | * if 1, compare with equal to minFlowCount |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3026 | Return: |
| 3027 | Returns the number of flow rules if it is bigger than minFlowCount, |
| 3028 | returns main.FALSE otherwise. |
| 3029 | """ |
| 3030 | count = self.flowAddedCount( deviceId, core ) |
| 3031 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 3032 | main.log.debug( "found {} flows".format( count ) ) |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 3033 | 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] | 3034 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3035 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3036 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3037 | Use 'devices' function to obtain list of all devices |
| 3038 | and parse the result to obtain a list of all device |
| 3039 | id's. Returns this list. Returns empty list if no |
| 3040 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3041 | List is ordered sequentially |
| 3042 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3043 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3044 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3045 | the ids. By obtaining the list of device ids on the fly, |
| 3046 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3047 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3048 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3049 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3050 | devicesStr = self.devices( jsonFormat=False ) |
| 3051 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3052 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3053 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3054 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3055 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3056 | |
| 3057 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3058 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3059 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3060 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3061 | # Split list further into arguments before and after string |
| 3062 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3063 | # append to idList |
| 3064 | for arg in tempList: |
| 3065 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 3066 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3067 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3068 | except TypeError: |
| 3069 | main.log.exception( self.name + ": Object not as expected" ) |
| 3070 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3071 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3072 | main.log.error( self.name + ": EOF exception found" ) |
| 3073 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3074 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3075 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3076 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3077 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3078 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3079 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3080 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3081 | Uses 'nodes' function to obtain list of all nodes |
| 3082 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3083 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3084 | Returns: |
| 3085 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3086 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3087 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3088 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3089 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3090 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 3091 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3092 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3093 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3094 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3095 | nodesJson = json.loads( nodesStr ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3096 | idList = [ node.get( 'id' ) for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3097 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3098 | except ( TypeError, ValueError ): |
| 3099 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3100 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3101 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3102 | main.log.error( self.name + ": EOF exception found" ) |
| 3103 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3104 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3105 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3106 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3107 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3108 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3109 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3110 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3111 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 3112 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3113 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3114 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3115 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3116 | return None |
| 3117 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3118 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3119 | rawDevices = self.devices() |
| 3120 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3121 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3122 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3123 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 3124 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3125 | return device |
| 3126 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3127 | except ( TypeError, ValueError ): |
| 3128 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3129 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3130 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3131 | main.log.error( self.name + ": EOF exception found" ) |
| 3132 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3133 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3134 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3135 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3136 | main.cleanAndExit() |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3137 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3138 | def getTopology( self, topologyOutput ): |
| 3139 | """ |
| 3140 | Definition: |
| 3141 | Loads a json topology output |
| 3142 | Return: |
| 3143 | topology = current ONOS topology |
| 3144 | """ |
| 3145 | import json |
| 3146 | try: |
| 3147 | # either onos:topology or 'topology' will work in CLI |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3148 | topology = json.loads( topologyOutput ) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 3149 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3150 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 3151 | except ( TypeError, ValueError ): |
| 3152 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 3153 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3154 | except pexpect.EOF: |
| 3155 | main.log.error( self.name + ": EOF exception found" ) |
| 3156 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3157 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3158 | except Exception: |
| 3159 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3160 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3161 | |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3162 | def checkStatus( self, numoswitch, numolink = -1, numoctrl = -1, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3163 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3164 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3165 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3166 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3167 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3168 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3169 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3170 | numoctrl = expected number of controllers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3171 | logLevel = level to log to. |
| 3172 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3173 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3174 | Returns: main.TRUE if the number of switches and links are correct, |
| 3175 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3176 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3177 | """ |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3178 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3179 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 3180 | summary = self.summary() |
| 3181 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 3182 | except ( TypeError, ValueError ): |
| 3183 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 3184 | return main.ERROR |
| 3185 | try: |
| 3186 | topology = self.getTopology( self.topology() ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 3187 | if topology == {} or topology is None or summary == {} or summary is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3188 | return main.ERROR |
| 3189 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3190 | # Is the number of switches is what we expected |
| 3191 | devices = topology.get( 'devices', False ) |
| 3192 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3193 | nodes = summary.get( 'nodes', False ) |
| 3194 | if devices is False or links is False or nodes is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3195 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3196 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3197 | # Is the number of links is what we expected |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3198 | linkCheck = ( int( links ) == int( numolink ) ) or int( numolink ) == -1 |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3199 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
| 3200 | if switchCheck and linkCheck and nodeCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3201 | # We expected the correct numbers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3202 | output = output + "The number of links and switches match "\ |
| 3203 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3204 | result = main.TRUE |
| 3205 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3206 | output = output + \ |
| 3207 | "The number of links and switches does not match " + \ |
| 3208 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3209 | result = main.FALSE |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3210 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 3211 | output = output + " (%i expected) " % int( numoswitch ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3212 | if int( numolink ) > 0: |
| 3213 | output = output + "and %i links " % int( links ) |
| 3214 | output = output + "(%i expected)" % int( numolink ) |
YPZhang | d7e4b6e | 2016-06-17 16:07:55 -0700 | [diff] [blame] | 3215 | if int( numoctrl ) > 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3216 | output = output + "and %i controllers " % int( nodes ) |
| 3217 | output = output + "(%i expected)" % int( numoctrl ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3218 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3219 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3220 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3221 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3222 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3223 | main.log.info( output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3224 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3225 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3226 | main.log.error( self.name + ": EOF exception found" ) |
| 3227 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3228 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3229 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3230 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3231 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3232 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3233 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3234 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3235 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3236 | deviceId must be the id of a device as seen in the onos devices command |
| 3237 | 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] | 3238 | role must be either master, standby, or none |
| 3239 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3240 | Returns: |
| 3241 | main.TRUE or main.FALSE based on argument verification and |
| 3242 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3243 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3244 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3245 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3246 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3247 | cmdStr = "device-role " +\ |
| 3248 | str( deviceId ) + " " +\ |
| 3249 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3250 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3251 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3252 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3253 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3254 | if re.search( "Error", handle ): |
| 3255 | # end color output to escape any colours |
| 3256 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3257 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3258 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3259 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3260 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3261 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3262 | main.log.error( "Invalid 'role' given to device_role(). " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3263 | "Value was '" + str( role ) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3264 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3265 | except AssertionError: |
| 3266 | main.log.exception( "" ) |
| 3267 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3268 | except TypeError: |
| 3269 | main.log.exception( self.name + ": Object not as expected" ) |
| 3270 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3271 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3272 | main.log.error( self.name + ": EOF exception found" ) |
| 3273 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3274 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3275 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3276 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3277 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3278 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3279 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3280 | """ |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3281 | Lists all topology clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 3282 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3283 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3284 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3285 | try: |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3286 | cmdStr = "topo-clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3287 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3288 | cmdStr += " -j" |
| 3289 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3290 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3291 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3292 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3293 | except AssertionError: |
| 3294 | main.log.exception( "" ) |
| 3295 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3296 | except TypeError: |
| 3297 | main.log.exception( self.name + ": Object not as expected" ) |
| 3298 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3299 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3300 | main.log.error( self.name + ": EOF exception found" ) |
| 3301 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3302 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3303 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3304 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3305 | main.cleanAndExit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3306 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3307 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3308 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3309 | CLI command to get the current leader for the Election test application |
| 3310 | NOTE: Requires installation of the onos-app-election feature |
| 3311 | Returns: Node IP of the leader if one exists |
| 3312 | None if none exists |
| 3313 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3314 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3315 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3316 | cmdStr = "election-test-leader" |
| 3317 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3318 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3319 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3320 | # Leader |
| 3321 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3322 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3323 | nodeSearch = re.search( leaderPattern, response ) |
| 3324 | if nodeSearch: |
| 3325 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3326 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3327 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3328 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3329 | # no leader |
| 3330 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3331 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3332 | nullSearch = re.search( nullPattern, response ) |
| 3333 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3334 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3335 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3336 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3337 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3338 | main.log.error( self.name + ": Error in electionTestLeader on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3339 | ": " + "unexpected response" ) |
| 3340 | main.log.error( repr( response ) ) |
| 3341 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3342 | except AssertionError: |
| 3343 | main.log.exception( "" ) |
| 3344 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3345 | except TypeError: |
| 3346 | main.log.exception( self.name + ": Object not as expected" ) |
| 3347 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3348 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3349 | main.log.error( self.name + ": EOF exception found" ) |
| 3350 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3351 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3352 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3353 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3354 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3355 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3356 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3357 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3358 | CLI command to run for leadership of the Election test application. |
| 3359 | NOTE: Requires installation of the onos-app-election feature |
| 3360 | Returns: Main.TRUE on success |
| 3361 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3362 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3363 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3364 | cmdStr = "election-test-run" |
| 3365 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3366 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3367 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3368 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3369 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3370 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3371 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3372 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3373 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3374 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3375 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3376 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3377 | main.log.error( self.name + ": Error in electionTestRun on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3378 | ": " + "unexpected response" ) |
| 3379 | main.log.error( repr( response ) ) |
| 3380 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3381 | except AssertionError: |
| 3382 | main.log.exception( "" ) |
| 3383 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3384 | except TypeError: |
| 3385 | main.log.exception( self.name + ": Object not as expected" ) |
| 3386 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3387 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3388 | main.log.error( self.name + ": EOF exception found" ) |
| 3389 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3390 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3391 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3392 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3393 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3394 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3395 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3396 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3397 | * CLI command to withdraw the local node from leadership election for |
| 3398 | * the Election test application. |
| 3399 | #NOTE: Requires installation of the onos-app-election feature |
| 3400 | Returns: Main.TRUE on success |
| 3401 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3402 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3403 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3404 | cmdStr = "election-test-withdraw" |
| 3405 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3406 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3407 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3408 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3409 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3410 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3411 | if re.search( successPattern, response ): |
| 3412 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3413 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3414 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3415 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3416 | main.log.error( self.name + ": Error in electionTestWithdraw on " + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3417 | self.name + ": " + "unexpected response" ) |
| 3418 | main.log.error( repr( response ) ) |
| 3419 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3420 | except AssertionError: |
| 3421 | main.log.exception( "" ) |
| 3422 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3423 | except TypeError: |
| 3424 | main.log.exception( self.name + ": Object not as expected" ) |
| 3425 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3426 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3427 | main.log.error( self.name + ": EOF exception found" ) |
| 3428 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3429 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3430 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3431 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3432 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3433 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3434 | def getDevicePortsEnabledCount( self, dpid ): |
| 3435 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3436 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3437 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3438 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3439 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3440 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 3441 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3442 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3443 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3444 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3445 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3446 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3447 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3448 | except AssertionError: |
| 3449 | main.log.exception( "" ) |
| 3450 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3451 | except TypeError: |
| 3452 | main.log.exception( self.name + ": Object not as expected" ) |
| 3453 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3454 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3455 | main.log.error( self.name + ": EOF exception found" ) |
| 3456 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3457 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3458 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3459 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3460 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3461 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3462 | def getDeviceLinksActiveCount( self, dpid ): |
| 3463 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3464 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3465 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3466 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3467 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3468 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 3469 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3470 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3471 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3472 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3473 | main.log.error( self.name + ": Error in getting ports " ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3474 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3475 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3476 | except AssertionError: |
| 3477 | main.log.exception( "" ) |
| 3478 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3479 | except TypeError: |
| 3480 | main.log.exception( self.name + ": Object not as expected" ) |
| 3481 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3482 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3483 | main.log.error( self.name + ": EOF exception found" ) |
| 3484 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3485 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3486 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3487 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3488 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3489 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3490 | def getAllIntentIds( self ): |
| 3491 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3492 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3493 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3494 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3495 | cmdStr = "onos:intents | grep id=" |
| 3496 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3497 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3498 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3499 | if re.search( "Error", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3500 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3501 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3502 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3503 | except AssertionError: |
| 3504 | main.log.exception( "" ) |
| 3505 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3506 | except TypeError: |
| 3507 | main.log.exception( self.name + ": Object not as expected" ) |
| 3508 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3509 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3510 | main.log.error( self.name + ": EOF exception found" ) |
| 3511 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3512 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3513 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3514 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3515 | main.cleanAndExit() |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3516 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3517 | def intentSummary( self ): |
| 3518 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3519 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3520 | """ |
| 3521 | try: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3522 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3523 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3524 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3525 | states.append( intent.get( 'state', None ) ) |
| 3526 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3527 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3528 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3529 | except ( TypeError, ValueError ): |
| 3530 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3531 | return None |
| 3532 | except pexpect.EOF: |
| 3533 | main.log.error( self.name + ": EOF exception found" ) |
| 3534 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3535 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3536 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3537 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3538 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3539 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3540 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3541 | """ |
| 3542 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3543 | Optional argument: |
| 3544 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3545 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3546 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3547 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3548 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3549 | cmdStr += " -j" |
| 3550 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3551 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3552 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3553 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3554 | except AssertionError: |
| 3555 | main.log.exception( "" ) |
| 3556 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3557 | except TypeError: |
| 3558 | main.log.exception( self.name + ": Object not as expected" ) |
| 3559 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3560 | except pexpect.EOF: |
| 3561 | main.log.error( self.name + ": EOF exception found" ) |
| 3562 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3563 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3564 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3565 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3566 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3567 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3568 | def leaderCandidates( self, jsonFormat=True ): |
| 3569 | """ |
| 3570 | Returns the output of the leaders -c command. |
| 3571 | Optional argument: |
| 3572 | * jsonFormat - boolean indicating if you want output in json |
| 3573 | """ |
| 3574 | try: |
| 3575 | cmdStr = "onos:leaders -c" |
| 3576 | if jsonFormat: |
| 3577 | cmdStr += " -j" |
| 3578 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3579 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3580 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3581 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3582 | except AssertionError: |
| 3583 | main.log.exception( "" ) |
| 3584 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3585 | except TypeError: |
| 3586 | main.log.exception( self.name + ": Object not as expected" ) |
| 3587 | return None |
| 3588 | except pexpect.EOF: |
| 3589 | main.log.error( self.name + ": EOF exception found" ) |
| 3590 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3591 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3592 | except Exception: |
| 3593 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3594 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3595 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3596 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3597 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3598 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3599 | topic parameter and an empty list if the topic doesn't exist |
| 3600 | If no leader is elected leader in the returned list will be "none" |
| 3601 | Returns None if there is a type error processing the json object |
| 3602 | """ |
| 3603 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3604 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3605 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3606 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3607 | assert "Command not found:" not in rawOutput, rawOutput |
| 3608 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3609 | results = [] |
| 3610 | for dict in output: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3611 | if dict[ "topic" ] == topic: |
| 3612 | leader = dict[ "leader" ] |
| 3613 | candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3614 | results.append( leader ) |
| 3615 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3616 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3617 | except AssertionError: |
| 3618 | main.log.exception( "" ) |
| 3619 | return None |
| 3620 | except ( TypeError, ValueError ): |
| 3621 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3622 | return None |
| 3623 | except pexpect.EOF: |
| 3624 | main.log.error( self.name + ": EOF exception found" ) |
| 3625 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3626 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3627 | except Exception: |
| 3628 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3629 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3630 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3631 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3632 | """ |
| 3633 | Returns the output of the intent Pending map. |
| 3634 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3635 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3636 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3637 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3638 | cmdStr += " -j" |
| 3639 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3640 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3641 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3642 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3643 | except AssertionError: |
| 3644 | main.log.exception( "" ) |
| 3645 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3646 | except TypeError: |
| 3647 | main.log.exception( self.name + ": Object not as expected" ) |
| 3648 | return None |
| 3649 | except pexpect.EOF: |
| 3650 | main.log.error( self.name + ": EOF exception found" ) |
| 3651 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3652 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3653 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3654 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3655 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3656 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3657 | def partitions( self, candidates=False, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3658 | """ |
| 3659 | Returns the output of the raft partitions command for ONOS. |
| 3660 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3661 | # Sample JSON |
| 3662 | # { |
| 3663 | # "leader": "tcp://10.128.30.11:7238", |
| 3664 | # "members": [ |
| 3665 | # "tcp://10.128.30.11:7238", |
| 3666 | # "tcp://10.128.30.17:7238", |
| 3667 | # "tcp://10.128.30.13:7238", |
| 3668 | # ], |
| 3669 | # "name": "p1", |
| 3670 | # "term": 3 |
| 3671 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3672 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3673 | cmdStr = "onos:partitions" |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3674 | if candidates: |
| 3675 | cmdStr += " -c" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3676 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3677 | cmdStr += " -j" |
| 3678 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3679 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3680 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3681 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3682 | except AssertionError: |
| 3683 | main.log.exception( "" ) |
| 3684 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3685 | except TypeError: |
| 3686 | main.log.exception( self.name + ": Object not as expected" ) |
| 3687 | return None |
| 3688 | except pexpect.EOF: |
| 3689 | main.log.error( self.name + ": EOF exception found" ) |
| 3690 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3691 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3692 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3693 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3694 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3695 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3696 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3697 | """ |
| 3698 | Returns the output of the apps command for ONOS. This command lists |
| 3699 | information about installed ONOS applications |
| 3700 | """ |
| 3701 | # Sample JSON object |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3702 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3703 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3704 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3705 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3706 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3707 | cmdStr = "onos:apps" |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3708 | if summary: |
| 3709 | cmdStr += " -s" |
| 3710 | if active: |
| 3711 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3712 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3713 | cmdStr += " -j" |
| 3714 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3715 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3716 | assert "Command not found:" not in output, output |
| 3717 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3718 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3719 | # FIXME: look at specific exceptions/Errors |
| 3720 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3721 | main.log.exception( self.name + ": Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3722 | return None |
| 3723 | except TypeError: |
| 3724 | main.log.exception( self.name + ": Object not as expected" ) |
| 3725 | return None |
| 3726 | except pexpect.EOF: |
| 3727 | main.log.error( self.name + ": EOF exception found" ) |
| 3728 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3729 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3730 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3731 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3732 | main.cleanAndExit() |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3733 | |
You Wang | cdc51fe | 2018-08-12 17:14:56 -0700 | [diff] [blame] | 3734 | def appStatus( self, appName ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3735 | """ |
| 3736 | Uses the onos:apps cli command to return the status of an application. |
| 3737 | Returns: |
| 3738 | "ACTIVE" - If app is installed and activated |
| 3739 | "INSTALLED" - If app is installed and deactivated |
| 3740 | "UNINSTALLED" - If app is not installed |
| 3741 | None - on error |
| 3742 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3743 | try: |
| 3744 | if not isinstance( appName, types.StringType ): |
| 3745 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3746 | " a string" ) |
| 3747 | return None |
| 3748 | output = self.apps( jsonFormat=True ) |
| 3749 | appsJson = json.loads( output ) |
| 3750 | state = None |
| 3751 | for app in appsJson: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3752 | if appName == app.get( 'name' ): |
| 3753 | state = app.get( 'state' ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3754 | break |
| 3755 | if state == "ACTIVE" or state == "INSTALLED": |
| 3756 | return state |
| 3757 | elif state is None: |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 3758 | main.log.warn( "{} app not found".format( appName ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3759 | return "UNINSTALLED" |
| 3760 | elif state: |
| 3761 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3762 | str( state ) ) |
| 3763 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3764 | except ( TypeError, ValueError ): |
| 3765 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3766 | return None |
| 3767 | except pexpect.EOF: |
| 3768 | main.log.error( self.name + ": EOF exception found" ) |
| 3769 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3770 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3771 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3772 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3773 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3774 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3775 | def app( self, appName, option ): |
| 3776 | """ |
| 3777 | Interacts with the app command for ONOS. This command manages |
| 3778 | application inventory. |
| 3779 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3780 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3781 | # Validate argument types |
| 3782 | valid = True |
| 3783 | if not isinstance( appName, types.StringType ): |
| 3784 | main.log.error( self.name + ".app(): appName must be a " + |
| 3785 | "string" ) |
| 3786 | valid = False |
| 3787 | if not isinstance( option, types.StringType ): |
| 3788 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3789 | valid = False |
| 3790 | if not valid: |
| 3791 | return main.FALSE |
| 3792 | # Validate Option |
| 3793 | option = option.lower() |
| 3794 | # NOTE: Install may become a valid option |
| 3795 | if option == "activate": |
| 3796 | pass |
| 3797 | elif option == "deactivate": |
| 3798 | pass |
| 3799 | elif option == "uninstall": |
| 3800 | pass |
| 3801 | else: |
| 3802 | # Invalid option |
| 3803 | main.log.error( "The ONOS app command argument only takes " + |
| 3804 | "the values: (activate|deactivate|uninstall)" + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3805 | "; was given '" + option + "'" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3806 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3807 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3808 | output = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3809 | assert output is not None, "Error in sendline" |
| 3810 | assert "Command not found:" not in output, output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3811 | if "Error executing command" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3812 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3813 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3814 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3815 | elif "No such application" in output: |
| 3816 | main.log.error( "The application '" + appName + |
| 3817 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3818 | return main.FALSE |
| 3819 | elif "Command not found:" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3820 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3821 | str( output ) ) |
| 3822 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3823 | elif "Unsupported command:" in output: |
| 3824 | main.log.error( "Incorrect command given to 'app': " + |
| 3825 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3826 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3827 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3828 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3829 | return main.TRUE |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3830 | except AssertionError: |
| 3831 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 3832 | return main.ERROR |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3833 | except TypeError: |
| 3834 | main.log.exception( self.name + ": Object not as expected" ) |
| 3835 | return main.ERROR |
| 3836 | except pexpect.EOF: |
| 3837 | main.log.error( self.name + ": EOF exception found" ) |
| 3838 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3839 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3840 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3841 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3842 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3843 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3844 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3845 | """ |
| 3846 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3847 | appName is the hierarchical app name, not the feature name |
| 3848 | If check is True, method will check the status of the app after the |
| 3849 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3850 | Returns main.TRUE if the command was successfully sent |
| 3851 | main.FALSE if the cli responded with an error or given |
| 3852 | incorrect input |
| 3853 | """ |
| 3854 | try: |
| 3855 | if not isinstance( appName, types.StringType ): |
| 3856 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3857 | " a string" ) |
| 3858 | return main.FALSE |
| 3859 | status = self.appStatus( appName ) |
| 3860 | if status == "INSTALLED": |
| 3861 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3862 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3863 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3864 | status = self.appStatus( appName ) |
| 3865 | if status == "ACTIVE": |
| 3866 | return main.TRUE |
| 3867 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3868 | main.log.debug( "The state of application " + |
| 3869 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3870 | time.sleep( 1 ) |
| 3871 | return main.FALSE |
| 3872 | else: # not 'check' or command didn't succeed |
| 3873 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3874 | elif status == "ACTIVE": |
| 3875 | return main.TRUE |
| 3876 | elif status == "UNINSTALLED": |
| 3877 | main.log.error( self.name + ": Tried to activate the " + |
| 3878 | "application '" + appName + "' which is not " + |
| 3879 | "installed." ) |
| 3880 | else: |
| 3881 | main.log.error( "Unexpected return value from appStatus: " + |
| 3882 | str( status ) ) |
| 3883 | return main.ERROR |
| 3884 | except TypeError: |
| 3885 | main.log.exception( self.name + ": Object not as expected" ) |
| 3886 | return main.ERROR |
| 3887 | except pexpect.EOF: |
| 3888 | main.log.error( self.name + ": EOF exception found" ) |
| 3889 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3890 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3891 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3892 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3893 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3894 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3895 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3896 | """ |
| 3897 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3898 | appName is the hierarchical app name, not the feature name |
| 3899 | If check is True, method will check the status of the app after the |
| 3900 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3901 | Returns main.TRUE if the command was successfully sent |
| 3902 | main.FALSE if the cli responded with an error or given |
| 3903 | incorrect input |
| 3904 | """ |
| 3905 | try: |
| 3906 | if not isinstance( appName, types.StringType ): |
| 3907 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 3908 | "be a string" ) |
| 3909 | return main.FALSE |
| 3910 | status = self.appStatus( appName ) |
| 3911 | if status == "INSTALLED": |
| 3912 | return main.TRUE |
| 3913 | elif status == "ACTIVE": |
| 3914 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3915 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3916 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3917 | status = self.appStatus( appName ) |
| 3918 | if status == "INSTALLED": |
| 3919 | return main.TRUE |
| 3920 | else: |
| 3921 | time.sleep( 1 ) |
| 3922 | return main.FALSE |
| 3923 | else: # not check or command didn't succeed |
| 3924 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3925 | elif status == "UNINSTALLED": |
| 3926 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 3927 | "application '" + appName + "' which is not " + |
| 3928 | "installed." ) |
| 3929 | return main.TRUE |
| 3930 | else: |
| 3931 | main.log.error( "Unexpected return value from appStatus: " + |
| 3932 | str( status ) ) |
| 3933 | return main.ERROR |
| 3934 | except TypeError: |
| 3935 | main.log.exception( self.name + ": Object not as expected" ) |
| 3936 | return main.ERROR |
| 3937 | except pexpect.EOF: |
| 3938 | main.log.error( self.name + ": EOF exception found" ) |
| 3939 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3940 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3941 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3942 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3943 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3944 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3945 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3946 | """ |
| 3947 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3948 | appName is the hierarchical app name, not the feature name |
| 3949 | If check is True, method will check the status of the app after the |
| 3950 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3951 | Returns main.TRUE if the command was successfully sent |
| 3952 | main.FALSE if the cli responded with an error or given |
| 3953 | incorrect input |
| 3954 | """ |
| 3955 | # TODO: check with Thomas about the state machine for apps |
| 3956 | try: |
| 3957 | if not isinstance( appName, types.StringType ): |
| 3958 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 3959 | "be a string" ) |
| 3960 | return main.FALSE |
| 3961 | status = self.appStatus( appName ) |
| 3962 | if status == "INSTALLED": |
| 3963 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3964 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3965 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3966 | status = self.appStatus( appName ) |
| 3967 | if status == "UNINSTALLED": |
| 3968 | return main.TRUE |
| 3969 | else: |
| 3970 | time.sleep( 1 ) |
| 3971 | return main.FALSE |
| 3972 | else: # not check or command didn't succeed |
| 3973 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3974 | elif status == "ACTIVE": |
| 3975 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 3976 | "application '" + appName + "' which is " + |
| 3977 | "currently active." ) |
| 3978 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3979 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3980 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3981 | status = self.appStatus( appName ) |
| 3982 | if status == "UNINSTALLED": |
| 3983 | return main.TRUE |
| 3984 | else: |
| 3985 | time.sleep( 1 ) |
| 3986 | return main.FALSE |
| 3987 | else: # not check or command didn't succeed |
| 3988 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3989 | elif status == "UNINSTALLED": |
| 3990 | return main.TRUE |
| 3991 | else: |
| 3992 | main.log.error( "Unexpected return value from appStatus: " + |
| 3993 | str( status ) ) |
| 3994 | return main.ERROR |
| 3995 | except TypeError: |
| 3996 | main.log.exception( self.name + ": Object not as expected" ) |
| 3997 | return main.ERROR |
| 3998 | except pexpect.EOF: |
| 3999 | main.log.error( self.name + ": EOF exception found" ) |
| 4000 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4001 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4002 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4003 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4004 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4005 | |
| 4006 | def appIDs( self, jsonFormat=True ): |
| 4007 | """ |
| 4008 | Show the mappings between app id and app names given by the 'app-ids' |
| 4009 | cli command |
| 4010 | """ |
| 4011 | try: |
| 4012 | cmdStr = "app-ids" |
| 4013 | if jsonFormat: |
| 4014 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4015 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4016 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4017 | assert "Command not found:" not in output, output |
| 4018 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4019 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4020 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4021 | main.log.exception( self.name + ": Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4022 | return None |
| 4023 | except TypeError: |
| 4024 | main.log.exception( self.name + ": Object not as expected" ) |
| 4025 | return None |
| 4026 | except pexpect.EOF: |
| 4027 | main.log.error( self.name + ": EOF exception found" ) |
| 4028 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4029 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4030 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4031 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4032 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4033 | |
| 4034 | def appToIDCheck( self ): |
| 4035 | """ |
| 4036 | This method will check that each application's ID listed in 'apps' is |
| 4037 | the same as the ID listed in 'app-ids'. The check will also check that |
| 4038 | there are no duplicate IDs issued. Note that an app ID should be |
| 4039 | a globaly unique numerical identifier for app/app-like features. Once |
| 4040 | an ID is registered, the ID is never freed up so that if an app is |
| 4041 | reinstalled it will have the same ID. |
| 4042 | |
| 4043 | Returns: main.TRUE if the check passes and |
| 4044 | main.FALSE if the check fails or |
| 4045 | main.ERROR if there is some error in processing the test |
| 4046 | """ |
| 4047 | try: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4048 | # Grab IDs |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4049 | rawJson = self.appIDs( jsonFormat=True ) |
| 4050 | if rawJson: |
| 4051 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4052 | else: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4053 | main.log.error( "app-ids returned nothing: " + repr( rawJson ) ) |
| 4054 | return main.FALSE |
| 4055 | |
| 4056 | # Grab Apps |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4057 | rawJson = self.apps( jsonFormat=True ) |
| 4058 | if rawJson: |
| 4059 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4060 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4061 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4062 | return main.FALSE |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4063 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4064 | result = main.TRUE |
| 4065 | for app in apps: |
| 4066 | appID = app.get( 'id' ) |
| 4067 | if appID is None: |
| 4068 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4069 | result = main.FALSE |
| 4070 | appName = app.get( 'name' ) |
| 4071 | if appName is None: |
| 4072 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4073 | result = main.FALSE |
| 4074 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4075 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4076 | if not current: # if ids doesn't have this id |
| 4077 | result = main.FALSE |
| 4078 | main.log.error( "'app-ids' does not have the ID for " + |
| 4079 | str( appName ) + " that apps does." ) |
Jon Hall | b9d381e | 2018-02-05 12:02:10 -0800 | [diff] [blame] | 4080 | main.log.debug( "apps command returned: " + str( app ) + |
| 4081 | "; app-ids has: " + str( ids ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4082 | elif len( current ) > 1: |
| 4083 | # there is more than one app with this ID |
| 4084 | result = main.FALSE |
| 4085 | # We will log this later in the method |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4086 | elif not current[ 0 ][ 'name' ] == appName: |
| 4087 | currentName = current[ 0 ][ 'name' ] |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4088 | result = main.FALSE |
| 4089 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 4090 | " registered under id:" + str( appID ) + |
| 4091 | " but 'apps' has " + str( appName ) ) |
| 4092 | else: |
| 4093 | pass # id and name match! |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4094 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4095 | # now make sure that app-ids has no duplicates |
| 4096 | idsList = [] |
| 4097 | namesList = [] |
| 4098 | for item in ids: |
| 4099 | idsList.append( item[ 'id' ] ) |
| 4100 | namesList.append( item[ 'name' ] ) |
| 4101 | if len( idsList ) != len( set( idsList ) ) or\ |
| 4102 | len( namesList ) != len( set( namesList ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4103 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 4104 | + json.dumps( ids, |
| 4105 | sort_keys=True, |
| 4106 | indent=4, |
| 4107 | separators=( ',', ': ' ) ) ) |
| 4108 | result = main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4109 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4110 | except ( TypeError, ValueError ): |
| 4111 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4112 | return main.ERROR |
| 4113 | except pexpect.EOF: |
| 4114 | main.log.error( self.name + ": EOF exception found" ) |
| 4115 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4116 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4117 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4118 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4119 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4120 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4121 | def getCfg( self, component=None, propName=None, short=False, |
| 4122 | jsonFormat=True ): |
| 4123 | """ |
| 4124 | Get configuration settings from onos cli |
| 4125 | Optional arguments: |
| 4126 | component - Optionally only list configurations for a specific |
| 4127 | component. If None, all components with configurations |
| 4128 | are displayed. Case Sensitive string. |
| 4129 | propName - If component is specified, propName option will show |
| 4130 | only this specific configuration from that component. |
| 4131 | Case Sensitive string. |
| 4132 | jsonFormat - Returns output as json. Note that this will override |
| 4133 | the short option |
| 4134 | short - Short, less verbose, version of configurations. |
| 4135 | This is overridden by the json option |
| 4136 | returns: |
| 4137 | Output from cli as a string or None on error |
| 4138 | """ |
| 4139 | try: |
| 4140 | baseStr = "cfg" |
| 4141 | cmdStr = " get" |
| 4142 | componentStr = "" |
| 4143 | if component: |
| 4144 | componentStr += " " + component |
| 4145 | if propName: |
| 4146 | componentStr += " " + propName |
| 4147 | if jsonFormat: |
| 4148 | baseStr += " -j" |
| 4149 | elif short: |
| 4150 | baseStr += " -s" |
| 4151 | output = self.sendline( baseStr + cmdStr + componentStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4152 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4153 | assert "Command not found:" not in output, output |
| 4154 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4155 | return output |
| 4156 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4157 | main.log.exception( self.name + ": Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4158 | return None |
| 4159 | except TypeError: |
| 4160 | main.log.exception( self.name + ": Object not as expected" ) |
| 4161 | return None |
| 4162 | except pexpect.EOF: |
| 4163 | main.log.error( self.name + ": EOF exception found" ) |
| 4164 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4165 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4166 | except Exception: |
| 4167 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4168 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4169 | |
| 4170 | def setCfg( self, component, propName, value=None, check=True ): |
| 4171 | """ |
| 4172 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4173 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4174 | component - The case sensitive name of the component whose |
| 4175 | property is to be set |
| 4176 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4177 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4178 | 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] | 4179 | property and revert it to it's default value(if applicable) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4180 | check - Boolean, Check whether the option was successfully set this |
| 4181 | only applies when a value is given. |
| 4182 | returns: |
| 4183 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 4184 | will return main.TRUE unless there is an error |
| 4185 | """ |
| 4186 | try: |
| 4187 | baseStr = "cfg" |
| 4188 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 4189 | if value is not None: |
| 4190 | cmdStr += " " + str( value ) |
| 4191 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4192 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4193 | assert "Command not found:" not in output, output |
| 4194 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4195 | if value and check: |
| 4196 | results = self.getCfg( component=str( component ), |
| 4197 | propName=str( propName ), |
| 4198 | jsonFormat=True ) |
| 4199 | # Check if current value is what we just set |
| 4200 | try: |
| 4201 | jsonOutput = json.loads( results ) |
| 4202 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4203 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4204 | main.log.exception( "Error parsing cfg output" ) |
| 4205 | main.log.error( "output:" + repr( results ) ) |
| 4206 | return main.FALSE |
| 4207 | if current == str( value ): |
| 4208 | return main.TRUE |
| 4209 | return main.FALSE |
| 4210 | return main.TRUE |
| 4211 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4212 | main.log.exception( self.name + ": Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4213 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4214 | except ( TypeError, ValueError ): |
| 4215 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4216 | return main.FALSE |
| 4217 | except pexpect.EOF: |
| 4218 | main.log.error( self.name + ": EOF exception found" ) |
| 4219 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4220 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4221 | except Exception: |
| 4222 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4223 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4224 | |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4225 | def distPrimitivesSend( self, cmd ): |
| 4226 | """ |
| 4227 | Function to handle sending cli commands for the distributed primitives test app |
| 4228 | |
| 4229 | This command will catch some exceptions and retry the command on some |
| 4230 | specific store exceptions. |
| 4231 | |
| 4232 | Required arguments: |
| 4233 | cmd - The command to send to the cli |
| 4234 | returns: |
| 4235 | string containing the cli output |
| 4236 | None on Error |
| 4237 | """ |
| 4238 | try: |
| 4239 | output = self.sendline( cmd ) |
| 4240 | try: |
| 4241 | assert output is not None, "Error in sendline" |
| 4242 | # TODO: Maybe make this less hardcoded |
| 4243 | # ConsistentMap Exceptions |
| 4244 | assert "org.onosproject.store.service" not in output |
| 4245 | # Node not leader |
| 4246 | assert "java.lang.IllegalStateException" not in output |
| 4247 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4248 | main.log.error( self.name + ": Error in processing '" + cmd + "' " + |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4249 | "command: " + str( output ) ) |
| 4250 | retryTime = 30 # Conservative time, given by Madan |
| 4251 | main.log.info( "Waiting " + str( retryTime ) + |
| 4252 | "seconds before retrying." ) |
| 4253 | time.sleep( retryTime ) # Due to change in mastership |
| 4254 | output = self.sendline( cmd ) |
| 4255 | assert output is not None, "Error in sendline" |
| 4256 | assert "Command not found:" not in output, output |
| 4257 | assert "Error executing command" not in output, output |
| 4258 | main.log.info( self.name + ": " + output ) |
| 4259 | return output |
| 4260 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4261 | main.log.exception( self.name + ": Error in processing '" + cmd + "' command." ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4262 | return None |
| 4263 | except TypeError: |
| 4264 | main.log.exception( self.name + ": Object not as expected" ) |
| 4265 | return None |
| 4266 | except pexpect.EOF: |
| 4267 | main.log.error( self.name + ": EOF exception found" ) |
| 4268 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4269 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4270 | except Exception: |
| 4271 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4272 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4273 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4274 | def setTestAdd( self, setName, values ): |
| 4275 | """ |
| 4276 | CLI command to add elements to a distributed set. |
| 4277 | Arguments: |
| 4278 | setName - The name of the set to add to. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4279 | values - The value(s) to add to the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4280 | Example usages: |
| 4281 | setTestAdd( "set1", "a b c" ) |
| 4282 | setTestAdd( "set2", "1" ) |
| 4283 | returns: |
| 4284 | main.TRUE on success OR |
| 4285 | main.FALSE if elements were already in the set OR |
| 4286 | main.ERROR on error |
| 4287 | """ |
| 4288 | try: |
| 4289 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4290 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4291 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 4292 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4293 | if re.search( positiveMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4294 | return main.TRUE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4295 | elif re.search( negativeMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4296 | return main.FALSE |
| 4297 | else: |
| 4298 | main.log.error( self.name + ": setTestAdd did not" + |
| 4299 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4300 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4301 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4302 | except TypeError: |
| 4303 | main.log.exception( self.name + ": Object not as expected" ) |
| 4304 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4305 | except Exception: |
| 4306 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4307 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4308 | |
| 4309 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 4310 | """ |
| 4311 | CLI command to remove elements from a distributed set. |
| 4312 | Required arguments: |
| 4313 | setName - The name of the set to remove from. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4314 | values - The value(s) to remove from the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4315 | Optional arguments: |
| 4316 | clear - Clear all elements from the set |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4317 | retain - Retain only the given values. (intersection of the |
| 4318 | original set and the given set) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4319 | returns: |
| 4320 | main.TRUE on success OR |
| 4321 | main.FALSE if the set was not changed OR |
| 4322 | main.ERROR on error |
| 4323 | """ |
| 4324 | try: |
| 4325 | cmdStr = "set-test-remove " |
| 4326 | if clear: |
| 4327 | cmdStr += "-c " + str( setName ) |
| 4328 | elif retain: |
| 4329 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4330 | else: |
| 4331 | cmdStr += str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4332 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4333 | if clear: |
| 4334 | pattern = "Set " + str( setName ) + " cleared" |
| 4335 | if re.search( pattern, output ): |
| 4336 | return main.TRUE |
| 4337 | elif retain: |
| 4338 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4339 | "only elements of set \[(.*)\]" |
| 4340 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4341 | "retaining only elements of the set " +\ |
| 4342 | "\[(.*)\]" |
| 4343 | if re.search( positivePattern, output ): |
| 4344 | return main.TRUE |
| 4345 | elif re.search( negativePattern, output ): |
| 4346 | return main.FALSE |
| 4347 | else: |
| 4348 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4349 | str( setName ) |
| 4350 | if ( len( values.split() ) == 1 ): |
| 4351 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4352 | str( setName ) |
| 4353 | else: |
| 4354 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4355 | str( setName ) |
| 4356 | if re.search( positivePattern, output ): |
| 4357 | return main.TRUE |
| 4358 | elif re.search( negativePattern, output ): |
| 4359 | return main.FALSE |
| 4360 | main.log.error( self.name + ": setTestRemove did not" + |
| 4361 | " match expected output" ) |
| 4362 | main.log.debug( self.name + " expected: " + pattern ) |
| 4363 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4364 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4365 | except TypeError: |
| 4366 | main.log.exception( self.name + ": Object not as expected" ) |
| 4367 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4368 | except Exception: |
| 4369 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4370 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4371 | |
| 4372 | def setTestGet( self, setName, values="" ): |
| 4373 | """ |
| 4374 | CLI command to get the elements in a distributed set. |
| 4375 | Required arguments: |
| 4376 | setName - The name of the set to remove from. |
| 4377 | Optional arguments: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4378 | values - The value(s) to check if in the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4379 | returns: |
| 4380 | main.ERROR on error OR |
| 4381 | A list of elements in the set if no optional arguments are |
| 4382 | supplied OR |
| 4383 | A tuple containing the list then: |
| 4384 | main.FALSE if the given values are not in the set OR |
| 4385 | main.TRUE if the given values are in the set OR |
| 4386 | """ |
| 4387 | try: |
| 4388 | values = str( values ).strip() |
| 4389 | setName = str( setName ).strip() |
| 4390 | length = len( values.split() ) |
| 4391 | containsCheck = None |
| 4392 | # Patterns to match |
| 4393 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4394 | pattern = "Items in set " + setName + ":\r\n" + setPattern |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4395 | containsTrue = "Set " + setName + " contains the value " + values |
| 4396 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4397 | values |
| 4398 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4399 | setPattern |
| 4400 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4401 | " subset " + setPattern |
| 4402 | |
| 4403 | cmdStr = "set-test-get " |
| 4404 | cmdStr += setName + " " + values |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4405 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4406 | if length == 0: |
| 4407 | match = re.search( pattern, output ) |
| 4408 | else: # if given values |
| 4409 | if length == 1: # Contains output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4410 | patternTrue = pattern + "\r\n" + containsTrue |
| 4411 | patternFalse = pattern + "\r\n" + containsFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4412 | else: # ContainsAll output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4413 | patternTrue = pattern + "\r\n" + containsAllTrue |
| 4414 | patternFalse = pattern + "\r\n" + containsAllFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4415 | matchTrue = re.search( patternTrue, output ) |
| 4416 | matchFalse = re.search( patternFalse, output ) |
| 4417 | if matchTrue: |
| 4418 | containsCheck = main.TRUE |
| 4419 | match = matchTrue |
| 4420 | elif matchFalse: |
| 4421 | containsCheck = main.FALSE |
| 4422 | match = matchFalse |
| 4423 | else: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4424 | main.log.error( self.name + " setTestGet did not match " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4425 | "expected output" ) |
| 4426 | main.log.debug( self.name + " expected: " + pattern ) |
| 4427 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4428 | match = None |
| 4429 | if match: |
| 4430 | setMatch = match.group( 1 ) |
| 4431 | if setMatch == '': |
| 4432 | setList = [] |
| 4433 | else: |
| 4434 | setList = setMatch.split( ", " ) |
| 4435 | if length > 0: |
| 4436 | return ( setList, containsCheck ) |
| 4437 | else: |
| 4438 | return setList |
| 4439 | else: # no match |
| 4440 | main.log.error( self.name + ": setTestGet did not" + |
| 4441 | " match expected output" ) |
| 4442 | main.log.debug( self.name + " expected: " + pattern ) |
| 4443 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4444 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4445 | except TypeError: |
| 4446 | main.log.exception( self.name + ": Object not as expected" ) |
| 4447 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4448 | except Exception: |
| 4449 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4450 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4451 | |
| 4452 | def setTestSize( self, setName ): |
| 4453 | """ |
| 4454 | CLI command to get the elements in a distributed set. |
| 4455 | Required arguments: |
| 4456 | setName - The name of the set to remove from. |
| 4457 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4458 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4459 | None on error |
| 4460 | """ |
| 4461 | try: |
| 4462 | # TODO: Should this check against the number of elements returned |
| 4463 | # and then return true/false based on that? |
| 4464 | setName = str( setName ).strip() |
| 4465 | # Patterns to match |
| 4466 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4467 | pattern = "There are (\d+) items in set " + setName + ":\r\n" +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4468 | setPattern |
| 4469 | cmdStr = "set-test-get -s " |
| 4470 | cmdStr += setName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4471 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4472 | if output: |
| 4473 | match = re.search( pattern, output ) |
| 4474 | if match: |
| 4475 | setSize = int( match.group( 1 ) ) |
| 4476 | setMatch = match.group( 2 ) |
| 4477 | if len( setMatch.split() ) == setSize: |
| 4478 | main.log.info( "The size returned by " + self.name + |
| 4479 | " matches the number of elements in " + |
| 4480 | "the returned set" ) |
| 4481 | else: |
| 4482 | main.log.error( "The size returned by " + self.name + |
| 4483 | " does not match the number of " + |
| 4484 | "elements in the returned set." ) |
| 4485 | return setSize |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4486 | else: # no match |
| 4487 | main.log.error( self.name + ": setTestGet did not" + |
| 4488 | " match expected output" ) |
| 4489 | main.log.debug( self.name + " expected: " + pattern ) |
| 4490 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4491 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4492 | except TypeError: |
| 4493 | main.log.exception( self.name + ": Object not as expected" ) |
| 4494 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4495 | except Exception: |
| 4496 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4497 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4498 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4499 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4500 | """ |
| 4501 | Command to list the various counters in the system. |
| 4502 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4503 | if jsonFormat, a string of the json object returned by the cli |
| 4504 | command |
| 4505 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4506 | None on error |
| 4507 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4508 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4509 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4510 | if jsonFormat: |
| 4511 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4512 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4513 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4514 | assert "Command not found:" not in output, output |
| 4515 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4516 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4517 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4518 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4519 | main.log.exception( self.name + ": Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4520 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4521 | except TypeError: |
| 4522 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4523 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4524 | except pexpect.EOF: |
| 4525 | main.log.error( self.name + ": EOF exception found" ) |
| 4526 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4527 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4528 | except Exception: |
| 4529 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4530 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4531 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4532 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4533 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4534 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4535 | Required arguments: |
| 4536 | counter - The name of the counter to increment. |
| 4537 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4538 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4539 | returns: |
| 4540 | integer value of the counter or |
| 4541 | None on Error |
| 4542 | """ |
| 4543 | try: |
| 4544 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4545 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4546 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4547 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4548 | if delta != 1: |
| 4549 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4550 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4551 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4552 | match = re.search( pattern, output ) |
| 4553 | if match: |
| 4554 | return int( match.group( 1 ) ) |
| 4555 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4556 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4557 | " match expected output." ) |
| 4558 | main.log.debug( self.name + " expected: " + pattern ) |
| 4559 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4560 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4561 | except TypeError: |
| 4562 | main.log.exception( self.name + ": Object not as expected" ) |
| 4563 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4564 | except Exception: |
| 4565 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4566 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4567 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4568 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4569 | """ |
| 4570 | CLI command to get a distributed counter then add a delta to it. |
| 4571 | Required arguments: |
| 4572 | counter - The name of the counter to increment. |
| 4573 | Optional arguments: |
| 4574 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4575 | returns: |
| 4576 | integer value of the counter or |
| 4577 | None on Error |
| 4578 | """ |
| 4579 | try: |
| 4580 | counter = str( counter ) |
| 4581 | delta = int( delta ) |
| 4582 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4583 | cmdStr += counter |
| 4584 | if delta != 1: |
| 4585 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4586 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4587 | pattern = counter + " was updated to (-?\d+)" |
| 4588 | match = re.search( pattern, output ) |
| 4589 | if match: |
| 4590 | return int( match.group( 1 ) ) |
| 4591 | else: |
| 4592 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4593 | " match expected output." ) |
| 4594 | main.log.debug( self.name + " expected: " + pattern ) |
| 4595 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4596 | return None |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4597 | except TypeError: |
| 4598 | main.log.exception( self.name + ": Object not as expected" ) |
| 4599 | return None |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4600 | except Exception: |
| 4601 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4602 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4603 | |
| 4604 | def valueTestGet( self, valueName ): |
| 4605 | """ |
| 4606 | CLI command to get the value of an atomic value. |
| 4607 | Required arguments: |
| 4608 | valueName - The name of the value to get. |
| 4609 | returns: |
| 4610 | string value of the value or |
| 4611 | None on Error |
| 4612 | """ |
| 4613 | try: |
| 4614 | valueName = str( valueName ) |
| 4615 | cmdStr = "value-test " |
| 4616 | operation = "get" |
| 4617 | cmdStr = "value-test {} {}".format( valueName, |
| 4618 | operation ) |
| 4619 | output = self.distPrimitivesSend( cmdStr ) |
| 4620 | pattern = "(\w+)" |
| 4621 | match = re.search( pattern, output ) |
| 4622 | if match: |
| 4623 | return match.group( 1 ) |
| 4624 | else: |
| 4625 | main.log.error( self.name + ": valueTestGet did not" + |
| 4626 | " match expected output." ) |
| 4627 | main.log.debug( self.name + " expected: " + pattern ) |
| 4628 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4629 | return None |
| 4630 | except TypeError: |
| 4631 | main.log.exception( self.name + ": Object not as expected" ) |
| 4632 | return None |
| 4633 | except Exception: |
| 4634 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4635 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4636 | |
| 4637 | def valueTestSet( self, valueName, newValue ): |
| 4638 | """ |
| 4639 | CLI command to set the value of an atomic value. |
| 4640 | Required arguments: |
| 4641 | valueName - The name of the value to set. |
| 4642 | newValue - The value to assign to the given value. |
| 4643 | returns: |
| 4644 | main.TRUE on success or |
| 4645 | main.ERROR on Error |
| 4646 | """ |
| 4647 | try: |
| 4648 | valueName = str( valueName ) |
| 4649 | newValue = str( newValue ) |
| 4650 | operation = "set" |
| 4651 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4652 | operation, |
| 4653 | newValue ) |
| 4654 | output = self.distPrimitivesSend( cmdStr ) |
| 4655 | if output is not None: |
| 4656 | return main.TRUE |
| 4657 | else: |
| 4658 | return main.ERROR |
| 4659 | except TypeError: |
| 4660 | main.log.exception( self.name + ": Object not as expected" ) |
| 4661 | return main.ERROR |
| 4662 | except Exception: |
| 4663 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4664 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4665 | |
| 4666 | def valueTestCompareAndSet( self, valueName, oldValue, newValue ): |
| 4667 | """ |
| 4668 | CLI command to compareAndSet the value of an atomic value. |
| 4669 | Required arguments: |
| 4670 | valueName - The name of the value. |
| 4671 | oldValue - Compare the current value of the atomic value to this |
| 4672 | newValue - If the value equals oldValue, set the value to newValue |
| 4673 | returns: |
| 4674 | main.TRUE on success or |
| 4675 | main.FALSE on failure or |
| 4676 | main.ERROR on Error |
| 4677 | """ |
| 4678 | try: |
| 4679 | valueName = str( valueName ) |
| 4680 | oldValue = str( oldValue ) |
| 4681 | newValue = str( newValue ) |
| 4682 | operation = "compareAndSet" |
| 4683 | cmdStr = "value-test {} {} {} {}".format( valueName, |
| 4684 | operation, |
| 4685 | oldValue, |
| 4686 | newValue ) |
| 4687 | output = self.distPrimitivesSend( cmdStr ) |
| 4688 | pattern = "(\w+)" |
| 4689 | match = re.search( pattern, output ) |
| 4690 | if match: |
| 4691 | result = match.group( 1 ) |
| 4692 | if result == "true": |
| 4693 | return main.TRUE |
| 4694 | elif result == "false": |
| 4695 | return main.FALSE |
| 4696 | else: |
| 4697 | main.log.error( self.name + ": valueTestCompareAndSet did not" + |
| 4698 | " match expected output." ) |
| 4699 | main.log.debug( self.name + " expected: " + pattern ) |
| 4700 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4701 | return main.ERROR |
| 4702 | except TypeError: |
| 4703 | main.log.exception( self.name + ": Object not as expected" ) |
| 4704 | return main.ERROR |
| 4705 | except Exception: |
| 4706 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4707 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4708 | |
| 4709 | def valueTestGetAndSet( self, valueName, newValue ): |
| 4710 | """ |
| 4711 | CLI command to getAndSet the value of an atomic value. |
| 4712 | Required arguments: |
| 4713 | valueName - The name of the value to get. |
| 4714 | newValue - The value to assign to the given value |
| 4715 | returns: |
| 4716 | string value of the value or |
| 4717 | None on Error |
| 4718 | """ |
| 4719 | try: |
| 4720 | valueName = str( valueName ) |
| 4721 | cmdStr = "value-test " |
| 4722 | operation = "getAndSet" |
| 4723 | cmdStr += valueName + " " + operation |
| 4724 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4725 | operation, |
| 4726 | newValue ) |
| 4727 | output = self.distPrimitivesSend( cmdStr ) |
| 4728 | pattern = "(\w+)" |
| 4729 | match = re.search( pattern, output ) |
| 4730 | if match: |
| 4731 | return match.group( 1 ) |
| 4732 | else: |
| 4733 | main.log.error( self.name + ": valueTestGetAndSet did not" + |
| 4734 | " match expected output." ) |
| 4735 | main.log.debug( self.name + " expected: " + pattern ) |
| 4736 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4737 | return None |
| 4738 | except TypeError: |
| 4739 | main.log.exception( self.name + ": Object not as expected" ) |
| 4740 | return None |
| 4741 | except Exception: |
| 4742 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4743 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4744 | |
| 4745 | def valueTestDestroy( self, valueName ): |
| 4746 | """ |
| 4747 | CLI command to destroy an atomic value. |
| 4748 | Required arguments: |
| 4749 | valueName - The name of the value to destroy. |
| 4750 | returns: |
| 4751 | main.TRUE on success or |
| 4752 | main.ERROR on Error |
| 4753 | """ |
| 4754 | try: |
| 4755 | valueName = str( valueName ) |
| 4756 | cmdStr = "value-test " |
| 4757 | operation = "destroy" |
| 4758 | cmdStr += valueName + " " + operation |
| 4759 | output = self.distPrimitivesSend( cmdStr ) |
| 4760 | if output is not None: |
| 4761 | return main.TRUE |
| 4762 | else: |
| 4763 | return main.ERROR |
| 4764 | except TypeError: |
| 4765 | main.log.exception( self.name + ": Object not as expected" ) |
| 4766 | return main.ERROR |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4767 | except Exception: |
| 4768 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4769 | main.cleanAndExit() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4770 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4771 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4772 | """ |
| 4773 | Description: Execute summary command in onos |
| 4774 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4775 | no output |
| 4776 | |
| 4777 | """ |
| 4778 | try: |
| 4779 | cmdStr = "summary" |
| 4780 | if jsonFormat: |
| 4781 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4782 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4783 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4784 | assert "Command not found:" not in handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4785 | assert "Error:" not in handle, handle |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 4786 | assert "Error executing" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4787 | if not handle: |
| 4788 | main.log.error( self.name + ": There is no output in " + |
| 4789 | "summary command" ) |
| 4790 | return main.FALSE |
| 4791 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4792 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4793 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4794 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4795 | except TypeError: |
| 4796 | main.log.exception( self.name + ": Object not as expected" ) |
| 4797 | return None |
| 4798 | except pexpect.EOF: |
| 4799 | main.log.error( self.name + ": EOF exception found" ) |
| 4800 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4801 | main.cleanAndExit() |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4802 | except Exception: |
| 4803 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4804 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4805 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4806 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4807 | """ |
| 4808 | CLI command to get the value of a key in a consistent map using |
| 4809 | transactions. This a test function and can only get keys from the |
| 4810 | test map hard coded into the cli command |
| 4811 | Required arguments: |
| 4812 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4813 | returns: |
| 4814 | The string value of the key or |
| 4815 | None on Error |
| 4816 | """ |
| 4817 | try: |
| 4818 | keyName = str( keyName ) |
| 4819 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4820 | cmdStr += keyName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4821 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4822 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4823 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4824 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4825 | return None |
| 4826 | else: |
| 4827 | match = re.search( pattern, output ) |
| 4828 | if match: |
| 4829 | return match.groupdict()[ 'value' ] |
| 4830 | else: |
| 4831 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4832 | " match expected output." ) |
| 4833 | main.log.debug( self.name + " expected: " + pattern ) |
| 4834 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4835 | return None |
| 4836 | except TypeError: |
| 4837 | main.log.exception( self.name + ": Object not as expected" ) |
| 4838 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4839 | except Exception: |
| 4840 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4841 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4842 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4843 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4844 | """ |
| 4845 | CLI command to put a value into 'numKeys' number of keys in a |
| 4846 | consistent map using transactions. This a test function and can only |
| 4847 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4848 | Required arguments: |
| 4849 | numKeys - Number of keys to add the value to |
| 4850 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4851 | returns: |
| 4852 | A dictionary whose keys are the name of the keys put into the map |
| 4853 | and the values of the keys are dictionaries whose key-values are |
| 4854 | 'value': value put into map and optionaly |
| 4855 | 'oldValue': Previous value in the key or |
| 4856 | None on Error |
| 4857 | |
| 4858 | Example output |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4859 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4860 | 'Key2': {'value': 'Testing'} } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4861 | """ |
| 4862 | try: |
| 4863 | numKeys = str( numKeys ) |
| 4864 | value = str( value ) |
| 4865 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4866 | cmdStr += numKeys + " " + value |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4867 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4868 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4869 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4870 | results = {} |
| 4871 | for line in output.splitlines(): |
| 4872 | new = re.search( newPattern, line ) |
| 4873 | updated = re.search( updatedPattern, line ) |
| 4874 | if new: |
| 4875 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 4876 | elif updated: |
| 4877 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4878 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4879 | else: |
| 4880 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4881 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4882 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 4883 | newPattern, |
| 4884 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4885 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4886 | return results |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4887 | except ( TypeError, AttributeError ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4888 | main.log.exception( self.name + ": Object not as expected" ) |
| 4889 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4890 | except Exception: |
| 4891 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4892 | main.cleanAndExit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4893 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4894 | def maps( self, jsonFormat=True ): |
| 4895 | """ |
| 4896 | Description: Returns result of onos:maps |
| 4897 | Optional: |
| 4898 | * jsonFormat: enable json formatting of output |
| 4899 | """ |
| 4900 | try: |
| 4901 | cmdStr = "maps" |
| 4902 | if jsonFormat: |
| 4903 | cmdStr += " -j" |
| 4904 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4905 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4906 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4907 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4908 | except AssertionError: |
| 4909 | main.log.exception( "" ) |
| 4910 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4911 | except TypeError: |
| 4912 | main.log.exception( self.name + ": Object not as expected" ) |
| 4913 | return None |
| 4914 | except pexpect.EOF: |
| 4915 | main.log.error( self.name + ": EOF exception found" ) |
| 4916 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4917 | main.cleanAndExit() |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4918 | except Exception: |
| 4919 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4920 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4921 | |
| 4922 | def getSwController( self, uri, jsonFormat=True ): |
| 4923 | """ |
| 4924 | Descrition: Gets the controller information from the device |
| 4925 | """ |
| 4926 | try: |
| 4927 | cmd = "device-controllers " |
| 4928 | if jsonFormat: |
| 4929 | cmd += "-j " |
| 4930 | response = self.sendline( cmd + uri ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4931 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4932 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4933 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4934 | except AssertionError: |
| 4935 | main.log.exception( "" ) |
| 4936 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4937 | except TypeError: |
| 4938 | main.log.exception( self.name + ": Object not as expected" ) |
| 4939 | return None |
| 4940 | except pexpect.EOF: |
| 4941 | main.log.error( self.name + ": EOF exception found" ) |
| 4942 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4943 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4944 | except Exception: |
| 4945 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4946 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4947 | |
| 4948 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 4949 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4950 | Descrition: sets the controller(s) for the specified device |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4951 | |
| 4952 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4953 | Required: uri - String: The uri of the device(switch). |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4954 | ip - String or List: The ip address of the controller. |
| 4955 | This parameter can be formed in a couple of different ways. |
| 4956 | VALID: |
| 4957 | 10.0.0.1 - just the ip address |
| 4958 | tcp:10.0.0.1 - the protocol and the ip address |
| 4959 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 4960 | so that you can add controllers with different |
| 4961 | protocols and ports |
| 4962 | INVALID: |
| 4963 | 10.0.0.1:6653 - this is not supported by ONOS |
| 4964 | |
| 4965 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 4966 | port - The port number. |
| 4967 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 4968 | |
| 4969 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 4970 | """ |
| 4971 | try: |
| 4972 | cmd = "device-setcontrollers" |
| 4973 | |
| 4974 | if jsonFormat: |
| 4975 | cmd += " -j" |
| 4976 | cmd += " " + uri |
| 4977 | if isinstance( ip, str ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4978 | ip = [ ip ] |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4979 | for item in ip: |
| 4980 | if ":" in item: |
| 4981 | sitem = item.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4982 | if len( sitem ) == 3: |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4983 | cmd += " " + item |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4984 | elif "." in sitem[ 1 ]: |
| 4985 | cmd += " {}:{}".format( item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4986 | else: |
| 4987 | main.log.error( "Malformed entry: " + item ) |
| 4988 | raise TypeError |
| 4989 | else: |
| 4990 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4991 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4992 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4993 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4994 | if "Error" in response: |
| 4995 | main.log.error( response ) |
| 4996 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4997 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4998 | except AssertionError: |
| 4999 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5000 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5001 | except TypeError: |
| 5002 | main.log.exception( self.name + ": Object not as expected" ) |
| 5003 | return main.FALSE |
| 5004 | except pexpect.EOF: |
| 5005 | main.log.error( self.name + ": EOF exception found" ) |
| 5006 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5007 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5008 | except Exception: |
| 5009 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5010 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5011 | |
| 5012 | def removeDevice( self, device ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5013 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5014 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5015 | Remove a device from ONOS by passing the uri of the device(s). |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5016 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5017 | 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] | 5018 | Returns: |
| 5019 | Returns main.FALSE if an exception is thrown or an error is present |
| 5020 | in the response. Otherwise, returns main.TRUE. |
| 5021 | NOTE: |
| 5022 | 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] | 5023 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5024 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5025 | if isinstance( device, str ): |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 5026 | deviceStr = device |
| 5027 | device = [] |
| 5028 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5029 | |
| 5030 | for d in device: |
| 5031 | time.sleep( 1 ) |
| 5032 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5033 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5034 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5035 | if "Error" in response: |
| 5036 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 5037 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5038 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5039 | except AssertionError: |
| 5040 | main.log.exception( "" ) |
| 5041 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5042 | except TypeError: |
| 5043 | main.log.exception( self.name + ": Object not as expected" ) |
| 5044 | return main.FALSE |
| 5045 | except pexpect.EOF: |
| 5046 | main.log.error( self.name + ": EOF exception found" ) |
| 5047 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5048 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5049 | except Exception: |
| 5050 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5051 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5052 | |
| 5053 | def removeHost( self, host ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5054 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5055 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5056 | Remove a host from ONOS by passing the id of the host(s) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5057 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5058 | 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] | 5059 | Returns: |
| 5060 | Returns main.FALSE if an exception is thrown or an error is present |
| 5061 | in the response. Otherwise, returns main.TRUE. |
| 5062 | NOTE: |
| 5063 | 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] | 5064 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5065 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5066 | if isinstance( host, str ): |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5067 | host = list( host ) |
| 5068 | |
| 5069 | for h in host: |
| 5070 | time.sleep( 1 ) |
| 5071 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5072 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5073 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5074 | if "Error" in response: |
| 5075 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 5076 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5077 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5078 | except AssertionError: |
| 5079 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5080 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5081 | except TypeError: |
| 5082 | main.log.exception( self.name + ": Object not as expected" ) |
| 5083 | return main.FALSE |
| 5084 | except pexpect.EOF: |
| 5085 | main.log.error( self.name + ": EOF exception found" ) |
| 5086 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5087 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5088 | except Exception: |
| 5089 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5090 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5091 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5092 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5093 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5094 | Description: |
| 5095 | Bring link down or up in the null-provider. |
| 5096 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5097 | begin - (string) One end of a device or switch. |
| 5098 | end - (string) the other end of the device or switch |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5099 | returns: |
| 5100 | main.TRUE if no exceptions were thrown and no Errors are |
| 5101 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5102 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5103 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5104 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5105 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5106 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5107 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5108 | if "Error" in response or "Failure" in response: |
| 5109 | main.log.error( response ) |
| 5110 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5111 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5112 | except AssertionError: |
| 5113 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5114 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5115 | except TypeError: |
| 5116 | main.log.exception( self.name + ": Object not as expected" ) |
| 5117 | return main.FALSE |
| 5118 | except pexpect.EOF: |
| 5119 | main.log.error( self.name + ": EOF exception found" ) |
| 5120 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5121 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5122 | except Exception: |
| 5123 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5124 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5125 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5126 | def portstate( self, dpid, port, state ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5127 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5128 | Description: |
| 5129 | Changes the state of port in an OF switch by means of the |
| 5130 | PORTSTATUS OF messages. |
| 5131 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5132 | dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102' |
| 5133 | port - (string) target port in the device. Ex: '2' |
| 5134 | state - (string) target state (enable or disable) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5135 | returns: |
| 5136 | main.TRUE if no exceptions were thrown and no Errors are |
| 5137 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5138 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5139 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5140 | state = state.lower() |
| 5141 | assert state == 'enable' or state == 'disable', "Unknown state" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5142 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5143 | response = self.sendline( cmd, showResponse=True ) |
| 5144 | assert response is not None, "Error in sendline" |
| 5145 | assert "Command not found:" not in response, response |
| 5146 | if "Error" in response or "Failure" in response: |
| 5147 | main.log.error( response ) |
| 5148 | return main.FALSE |
| 5149 | return main.TRUE |
| 5150 | except AssertionError: |
| 5151 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5152 | return main.FALSE |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5153 | except TypeError: |
| 5154 | main.log.exception( self.name + ": Object not as expected" ) |
| 5155 | return main.FALSE |
| 5156 | except pexpect.EOF: |
| 5157 | main.log.error( self.name + ": EOF exception found" ) |
| 5158 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5159 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5160 | except Exception: |
| 5161 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5162 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5163 | |
| 5164 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 5165 | """ |
| 5166 | Set the logging level to lvl for a specific app |
| 5167 | returns main.TRUE on success |
| 5168 | returns main.FALSE if Error occurred |
| 5169 | if noExit is True, TestON will not exit, but clean up |
| 5170 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 5171 | Level defaults to INFO |
| 5172 | """ |
| 5173 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5174 | self.handle.sendline( "log:set %s %s" % ( level, app ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5175 | self.handle.expect( "onos>" ) |
| 5176 | |
| 5177 | response = self.handle.before |
| 5178 | if re.search( "Error", response ): |
| 5179 | return main.FALSE |
| 5180 | return main.TRUE |
| 5181 | except pexpect.TIMEOUT: |
| 5182 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5183 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 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() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [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() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5191 | |
| 5192 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 5193 | """ |
| 5194 | Return a dictionary which describes the latest network topology data as a |
| 5195 | graph. |
| 5196 | An example of the dictionary: |
| 5197 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 5198 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 5199 | Each vertex should at least have an 'edges' attribute which describes the |
| 5200 | adjacency information. The value of 'edges' attribute is also represented by |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5201 | 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] | 5202 | list of attributes. |
| 5203 | An example of the edges dictionary: |
| 5204 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 5205 | vertex3: { 'port': ..., 'weight': ... } } |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5206 | If includeHost == True, all hosts (and host-switch links) will be included |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5207 | in topology data. |
| 5208 | """ |
| 5209 | graphDict = {} |
| 5210 | try: |
| 5211 | links = self.links() |
| 5212 | links = json.loads( links ) |
| 5213 | devices = self.devices() |
| 5214 | devices = json.loads( devices ) |
| 5215 | idToDevice = {} |
| 5216 | for device in devices: |
| 5217 | idToDevice[ device[ 'id' ] ] = device |
| 5218 | if includeHost: |
| 5219 | hosts = self.hosts() |
| 5220 | # FIXME: support 'includeHost' argument |
| 5221 | for link in links: |
| 5222 | nodeA = link[ 'src' ][ 'device' ] |
| 5223 | nodeB = link[ 'dst' ][ 'device' ] |
| 5224 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5225 | if nodeA not in graphDict.keys(): |
| 5226 | graphDict[ nodeA ] = { 'edges': {}, |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5227 | 'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ], |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5228 | 'type': idToDevice[ nodeA ][ 'type' ], |
| 5229 | 'available': idToDevice[ nodeA ][ 'available' ], |
| 5230 | 'role': idToDevice[ nodeA ][ 'role' ], |
| 5231 | 'mfr': idToDevice[ nodeA ][ 'mfr' ], |
| 5232 | 'hw': idToDevice[ nodeA ][ 'hw' ], |
| 5233 | 'sw': idToDevice[ nodeA ][ 'sw' ], |
| 5234 | 'serial': idToDevice[ nodeA ][ 'serial' ], |
| 5235 | 'chassisId': idToDevice[ nodeA ][ 'chassisId' ], |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5236 | 'annotations': idToDevice[ nodeA ][ 'annotations' ]} |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5237 | else: |
| 5238 | # Assert nodeB is not connected to any current links of nodeA |
| 5239 | assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5240 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ], |
| 5241 | 'type': link[ 'type' ], |
| 5242 | 'state': link[ 'state' ] } |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5243 | return graphDict |
| 5244 | except ( TypeError, ValueError ): |
| 5245 | main.log.exception( self.name + ": Object not as expected" ) |
| 5246 | return None |
| 5247 | except KeyError: |
| 5248 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5249 | return None |
| 5250 | except AssertionError: |
| 5251 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5252 | return None |
| 5253 | except pexpect.EOF: |
| 5254 | main.log.error( self.name + ": EOF exception found" ) |
| 5255 | main.log.error( self.name + ": " + self.handle.before ) |
| 5256 | return None |
| 5257 | except Exception: |
| 5258 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5259 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5260 | |
| 5261 | def getIntentPerfSummary( self ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5262 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5263 | Send command to check intent-perf summary |
| 5264 | Returns: dictionary for intent-perf summary |
| 5265 | if something wrong, function will return None |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5266 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5267 | cmd = "intent-perf -s" |
| 5268 | respDic = {} |
| 5269 | resp = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 5270 | assert resp is not None, "Error in sendline" |
| 5271 | assert "Command not found:" not in resp, resp |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5272 | try: |
| 5273 | # Generate the dictionary to return |
| 5274 | for l in resp.split( "\n" ): |
| 5275 | # Delete any white space in line |
| 5276 | temp = re.sub( r'\s+', '', l ) |
| 5277 | temp = temp.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5278 | respDic[ temp[ 0 ] ] = temp[ 1 ] |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5279 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5280 | except ( TypeError, ValueError ): |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5281 | main.log.exception( self.name + ": Object not as expected" ) |
| 5282 | return None |
| 5283 | except KeyError: |
| 5284 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5285 | return None |
| 5286 | except AssertionError: |
| 5287 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5288 | return None |
| 5289 | except pexpect.EOF: |
| 5290 | main.log.error( self.name + ": EOF exception found" ) |
| 5291 | main.log.error( self.name + ": " + self.handle.before ) |
| 5292 | return None |
| 5293 | except Exception: |
| 5294 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5295 | return None |
| 5296 | return respDic |
| 5297 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5298 | def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ): |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5299 | """ |
| 5300 | Searches the latest ONOS log file for the given search term and |
| 5301 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5302 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5303 | Arguments: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5304 | searchTerm: |
| 5305 | The string to grep from the ONOS log. |
| 5306 | startLine: |
| 5307 | The term that decides which line is the start to search the searchTerm in |
| 5308 | the karaf log. For now, startTerm only works in 'first' mode. |
| 5309 | logNum: |
| 5310 | In some extreme cases, one karaf log is not big enough to contain all the |
| 5311 | information.Because of this, search mutiply logs is necessary to capture |
| 5312 | the right result. logNum is the number of karaf logs that we need to search |
| 5313 | the searchTerm. |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5314 | mode: |
| 5315 | all: return all the strings that contain the search term |
| 5316 | last: return the last string that contains the search term |
| 5317 | first: return the first string that contains the search term |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5318 | num: return the number of times that the searchTerm appears in the log |
| 5319 | total: return how many lines in karaf log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5320 | """ |
| 5321 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5322 | assert isinstance( searchTerm, str ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5323 | # Build the log paths string |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5324 | logPath = '/opt/onos/log/karaf.log.' |
| 5325 | logPaths = '/opt/onos/log/karaf.log' |
| 5326 | for i in range( 1, logNum ): |
| 5327 | logPaths = logPath + str( i ) + " " + logPaths |
| 5328 | cmd = "cat " + logPaths |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5329 | if startLine: |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5330 | # 100000000 is just a extreme large number to make sure this function can |
| 5331 | # grep all the lines after startLine |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5332 | cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'" |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5333 | if mode == 'all': |
| 5334 | cmd = cmd + " | grep \'" + searchTerm + "\'" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5335 | elif mode == 'last': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5336 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5337 | elif mode == 'first': |
| 5338 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1" |
| 5339 | elif mode == 'num': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5340 | cmd = cmd + " | grep -c \'" + searchTerm + "\'" |
You Wang | 118ba58 | 2017-01-02 17:14:43 -0800 | [diff] [blame] | 5341 | num = self.sendline( cmd ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5342 | return num |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5343 | elif mode == 'total': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5344 | totalLines = self.sendline( "cat /opt/onos/log/karaf.log | wc -l" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5345 | return int( totalLines ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5346 | else: |
| 5347 | main.log.error( self.name + " unsupported mode" ) |
| 5348 | return main.ERROR |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5349 | before = self.sendline( cmd ) |
| 5350 | before = before.splitlines() |
| 5351 | # make sure the returned list only contains the search term |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5352 | returnLines = [ line for line in before if searchTerm in line ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5353 | return returnLines |
| 5354 | except AssertionError: |
| 5355 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5356 | return None |
| 5357 | except pexpect.EOF: |
| 5358 | main.log.error( self.name + ": EOF exception found" ) |
| 5359 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5360 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5361 | except pexpect.TIMEOUT: |
| 5362 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5363 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5364 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5365 | except Exception: |
| 5366 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5367 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5368 | |
| 5369 | def vplsShow( self, jsonFormat=True ): |
| 5370 | """ |
| 5371 | Description: Returns result of onos:vpls show, which should list the |
| 5372 | configured VPLS networks and the assigned interfaces. |
| 5373 | Optional: |
| 5374 | * jsonFormat: enable json formatting of output |
| 5375 | Returns: |
| 5376 | The output of the command or None on error. |
| 5377 | """ |
| 5378 | try: |
| 5379 | cmdStr = "vpls show" |
| 5380 | if jsonFormat: |
| 5381 | raise NotImplementedError |
| 5382 | cmdStr += " -j" |
| 5383 | handle = self.sendline( cmdStr ) |
| 5384 | assert handle is not None, "Error in sendline" |
| 5385 | assert "Command not found:" not in handle, handle |
| 5386 | return handle |
| 5387 | except AssertionError: |
| 5388 | main.log.exception( "" ) |
| 5389 | return None |
| 5390 | except TypeError: |
| 5391 | main.log.exception( self.name + ": Object not as expected" ) |
| 5392 | return None |
| 5393 | except pexpect.EOF: |
| 5394 | main.log.error( self.name + ": EOF exception found" ) |
| 5395 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5396 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5397 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5398 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5399 | return None |
| 5400 | except Exception: |
| 5401 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5402 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5403 | |
| 5404 | def parseVplsShow( self ): |
| 5405 | """ |
| 5406 | Parse the cli output of 'vpls show' into json output. This is required |
| 5407 | as there is currently no json output available. |
| 5408 | """ |
| 5409 | try: |
| 5410 | output = [] |
| 5411 | raw = self.vplsShow( jsonFormat=False ) |
| 5412 | namePat = "VPLS name: (?P<name>\w+)" |
| 5413 | interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]" |
| 5414 | encapPat = "Encapsulation: (?P<encap>\w+)" |
| 5415 | pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] ) |
| 5416 | mIter = re.finditer( pattern, raw ) |
| 5417 | for match in mIter: |
| 5418 | item = {} |
| 5419 | item[ 'name' ] = match.group( 'name' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5420 | ifaces = match.group( 'interfaces' ).split( ', ' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5421 | if ifaces == [ "" ]: |
| 5422 | ifaces = [] |
| 5423 | item[ 'interfaces' ] = ifaces |
| 5424 | encap = match.group( 'encap' ) |
| 5425 | if encap != 'NONE': |
| 5426 | item[ 'encapsulation' ] = encap.lower() |
| 5427 | output.append( item ) |
| 5428 | return output |
| 5429 | except Exception: |
| 5430 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5431 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5432 | |
| 5433 | def vplsList( self, jsonFormat=True ): |
| 5434 | """ |
| 5435 | Description: Returns result of onos:vpls list, which should list the |
| 5436 | configured VPLS networks. |
| 5437 | Optional: |
| 5438 | * jsonFormat: enable json formatting of output |
| 5439 | """ |
| 5440 | try: |
| 5441 | cmdStr = "vpls list" |
| 5442 | if jsonFormat: |
| 5443 | raise NotImplementedError |
| 5444 | cmdStr += " -j" |
| 5445 | handle = self.sendline( cmdStr ) |
| 5446 | assert handle is not None, "Error in sendline" |
| 5447 | assert "Command not found:" not in handle, handle |
| 5448 | return handle |
| 5449 | except AssertionError: |
| 5450 | main.log.exception( "" ) |
| 5451 | return None |
| 5452 | except TypeError: |
| 5453 | main.log.exception( self.name + ": Object not as expected" ) |
| 5454 | return None |
| 5455 | except pexpect.EOF: |
| 5456 | main.log.error( self.name + ": EOF exception found" ) |
| 5457 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5458 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5459 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5460 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5461 | return None |
| 5462 | except Exception: |
| 5463 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5464 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5465 | |
| 5466 | def vplsCreate( self, network ): |
| 5467 | """ |
| 5468 | CLI command to create a new VPLS network. |
| 5469 | Required arguments: |
| 5470 | network - String name of the network to create. |
| 5471 | returns: |
| 5472 | main.TRUE on success and main.FALSE on failure |
| 5473 | """ |
| 5474 | try: |
| 5475 | network = str( network ) |
| 5476 | cmdStr = "vpls create " |
| 5477 | cmdStr += network |
| 5478 | output = self.sendline( cmdStr ) |
| 5479 | assert output is not None, "Error in sendline" |
| 5480 | assert "Command not found:" not in output, output |
| 5481 | assert "Error executing command" not in output, output |
| 5482 | assert "VPLS already exists:" not in output, output |
| 5483 | return main.TRUE |
| 5484 | except AssertionError: |
| 5485 | main.log.exception( "" ) |
| 5486 | return main.FALSE |
| 5487 | except TypeError: |
| 5488 | main.log.exception( self.name + ": Object not as expected" ) |
| 5489 | return main.FALSE |
| 5490 | except pexpect.EOF: |
| 5491 | main.log.error( self.name + ": EOF exception found" ) |
| 5492 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5493 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5494 | except Exception: |
| 5495 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5496 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5497 | |
| 5498 | def vplsDelete( self, network ): |
| 5499 | """ |
| 5500 | CLI command to delete a VPLS network. |
| 5501 | Required arguments: |
| 5502 | network - Name of the network to delete. |
| 5503 | returns: |
| 5504 | main.TRUE on success and main.FALSE on failure |
| 5505 | """ |
| 5506 | try: |
| 5507 | network = str( network ) |
| 5508 | cmdStr = "vpls delete " |
| 5509 | cmdStr += network |
| 5510 | output = self.sendline( cmdStr ) |
| 5511 | assert output is not None, "Error in sendline" |
| 5512 | assert "Command not found:" not in output, output |
| 5513 | assert "Error executing command" not in output, output |
| 5514 | assert " not found" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5515 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5516 | return main.TRUE |
| 5517 | except AssertionError: |
| 5518 | main.log.exception( "" ) |
| 5519 | return main.FALSE |
| 5520 | except TypeError: |
| 5521 | main.log.exception( self.name + ": Object not as expected" ) |
| 5522 | return main.FALSE |
| 5523 | except pexpect.EOF: |
| 5524 | main.log.error( self.name + ": EOF exception found" ) |
| 5525 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5526 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5527 | except Exception: |
| 5528 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5529 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5530 | |
| 5531 | def vplsAddIface( self, network, iface ): |
| 5532 | """ |
| 5533 | CLI command to add an interface to a VPLS network. |
| 5534 | Required arguments: |
| 5535 | network - Name of the network to add the interface to. |
| 5536 | iface - The ONOS name for an interface. |
| 5537 | returns: |
| 5538 | main.TRUE on success and main.FALSE on failure |
| 5539 | """ |
| 5540 | try: |
| 5541 | network = str( network ) |
| 5542 | iface = str( iface ) |
| 5543 | cmdStr = "vpls add-if " |
| 5544 | cmdStr += network + " " + iface |
| 5545 | output = self.sendline( cmdStr ) |
| 5546 | assert output is not None, "Error in sendline" |
| 5547 | assert "Command not found:" not in output, output |
| 5548 | assert "Error executing command" not in output, output |
| 5549 | assert "already associated to network" not in output, output |
| 5550 | assert "Interface cannot be added." not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5551 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5552 | return main.TRUE |
| 5553 | except AssertionError: |
| 5554 | main.log.exception( "" ) |
| 5555 | return main.FALSE |
| 5556 | except TypeError: |
| 5557 | main.log.exception( self.name + ": Object not as expected" ) |
| 5558 | return main.FALSE |
| 5559 | except pexpect.EOF: |
| 5560 | main.log.error( self.name + ": EOF exception found" ) |
| 5561 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5562 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 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 vplsRemIface( self, network, iface ): |
| 5568 | """ |
| 5569 | CLI command to remove an interface from a VPLS network. |
| 5570 | Required arguments: |
| 5571 | network - Name of the network to remove the interface from. |
| 5572 | iface - Name of the interface to remove. |
| 5573 | returns: |
| 5574 | main.TRUE on success and main.FALSE on failure |
| 5575 | """ |
| 5576 | try: |
| 5577 | iface = str( iface ) |
| 5578 | cmdStr = "vpls rem-if " |
| 5579 | cmdStr += network + " " + iface |
| 5580 | output = self.sendline( cmdStr ) |
| 5581 | assert output is not None, "Error in sendline" |
| 5582 | assert "Command not found:" not in output, output |
| 5583 | assert "Error executing command" not in output, output |
| 5584 | assert "is not configured" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5585 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5586 | return main.TRUE |
| 5587 | except AssertionError: |
| 5588 | main.log.exception( "" ) |
| 5589 | return main.FALSE |
| 5590 | except TypeError: |
| 5591 | main.log.exception( self.name + ": Object not as expected" ) |
| 5592 | return main.FALSE |
| 5593 | except pexpect.EOF: |
| 5594 | main.log.error( self.name + ": EOF exception found" ) |
| 5595 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5596 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5597 | except Exception: |
| 5598 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5599 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5600 | |
| 5601 | def vplsClean( self ): |
| 5602 | """ |
| 5603 | Description: Clears the VPLS app configuration. |
| 5604 | Returns: main.TRUE on success and main.FALSE on failure |
| 5605 | """ |
| 5606 | try: |
| 5607 | cmdStr = "vpls clean" |
| 5608 | handle = self.sendline( cmdStr ) |
| 5609 | assert handle is not None, "Error in sendline" |
| 5610 | assert "Command not found:" not in handle, handle |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5611 | assert "still updating" not in handle, handle |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5612 | return handle |
| 5613 | except AssertionError: |
| 5614 | main.log.exception( "" ) |
| 5615 | return main.FALSE |
| 5616 | except TypeError: |
| 5617 | main.log.exception( self.name + ": Object not as expected" ) |
| 5618 | return main.FALSE |
| 5619 | except pexpect.EOF: |
| 5620 | main.log.error( self.name + ": EOF exception found" ) |
| 5621 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5622 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5623 | except Exception: |
| 5624 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5625 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5626 | |
| 5627 | def vplsSetEncap( self, network, encapType ): |
| 5628 | """ |
| 5629 | CLI command to add an interface to a VPLS network. |
| 5630 | Required arguments: |
| 5631 | network - Name of the network to create. |
| 5632 | encapType - Type of encapsulation. |
| 5633 | returns: |
| 5634 | main.TRUE on success and main.FALSE on failure |
| 5635 | """ |
| 5636 | try: |
| 5637 | network = str( network ) |
| 5638 | encapType = str( encapType ).upper() |
| 5639 | assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type" |
| 5640 | cmdStr = "vpls set-encap " |
| 5641 | cmdStr += network + " " + encapType |
| 5642 | output = self.sendline( cmdStr ) |
| 5643 | assert output is not None, "Error in sendline" |
| 5644 | assert "Command not found:" not in output, output |
| 5645 | assert "Error executing command" not in output, output |
| 5646 | assert "already associated to network" not in output, output |
| 5647 | assert "Encapsulation type " not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5648 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5649 | return main.TRUE |
| 5650 | except AssertionError: |
| 5651 | main.log.exception( "" ) |
| 5652 | return main.FALSE |
| 5653 | except TypeError: |
| 5654 | main.log.exception( self.name + ": Object not as expected" ) |
| 5655 | return main.FALSE |
| 5656 | except pexpect.EOF: |
| 5657 | main.log.error( self.name + ": EOF exception found" ) |
| 5658 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5659 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5660 | except Exception: |
| 5661 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5662 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5663 | |
| 5664 | def interfaces( self, jsonFormat=True ): |
| 5665 | """ |
| 5666 | Description: Returns result of interfaces command. |
| 5667 | Optional: |
| 5668 | * jsonFormat: enable json formatting of output |
| 5669 | Returns: |
| 5670 | The output of the command or None on error. |
| 5671 | """ |
| 5672 | try: |
| 5673 | cmdStr = "interfaces" |
| 5674 | if jsonFormat: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5675 | raise NotImplementedError |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5676 | cmdStr += " -j" |
| 5677 | handle = self.sendline( cmdStr ) |
| 5678 | assert handle is not None, "Error in sendline" |
| 5679 | assert "Command not found:" not in handle, handle |
| 5680 | return handle |
| 5681 | except AssertionError: |
| 5682 | main.log.exception( "" ) |
| 5683 | return None |
| 5684 | except TypeError: |
| 5685 | main.log.exception( self.name + ": Object not as expected" ) |
| 5686 | return None |
| 5687 | except pexpect.EOF: |
| 5688 | main.log.error( self.name + ": EOF exception found" ) |
| 5689 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5690 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5691 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5692 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5693 | return None |
| 5694 | except Exception: |
| 5695 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5696 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5697 | |
| 5698 | def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5699 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5700 | Get the timestamp of searchTerm from karaf log. |
| 5701 | |
| 5702 | Arguments: |
| 5703 | splitTerm_before and splitTerm_after: |
| 5704 | |
| 5705 | The terms that split the string that contains the timeStamp of |
| 5706 | searchTerm. For example, if that string is "xxxxxxxcreationTime = |
| 5707 | 1419510501xxxxxx", then the splitTerm_before is "CreationTime = " |
| 5708 | and the splitTerm_after is "x" |
| 5709 | |
| 5710 | others: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5711 | Please look at the "logsearch" Function in onosclidriver.py |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5712 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5713 | if logNum < 0: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5714 | main.log.error( "Get wrong log number ") |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5715 | return main.ERROR |
| 5716 | lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5717 | if len( lines ) == 0: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5718 | main.log.warn( "Captured timestamp string is empty" ) |
| 5719 | return main.ERROR |
| 5720 | lines = lines[ 0 ] |
| 5721 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5722 | assert isinstance( lines, str ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5723 | # get the target value |
| 5724 | line = lines.split( splitTerm_before ) |
| 5725 | key = line[ 1 ].split( splitTerm_after ) |
| 5726 | return int( key[ 0 ] ) |
| 5727 | except IndexError: |
| 5728 | main.log.warn( "Index Error!" ) |
| 5729 | return main.ERROR |
| 5730 | except AssertionError: |
| 5731 | main.log.warn( "Search Term Not Found " ) |
| 5732 | return main.ERROR |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5733 | |
| 5734 | def workQueueAdd( self, queueName, value ): |
| 5735 | """ |
| 5736 | CLI command to add a string to the specified Work Queue. |
| 5737 | This function uses the distributed primitives test app, which |
| 5738 | gives some cli access to distributed primitives for testing |
| 5739 | purposes only. |
| 5740 | |
| 5741 | Required arguments: |
| 5742 | queueName - The name of the queue to add to |
| 5743 | value - The value to add to the queue |
| 5744 | returns: |
| 5745 | main.TRUE on success, main.FALSE on failure and |
| 5746 | main.ERROR on error. |
| 5747 | """ |
| 5748 | try: |
| 5749 | queueName = str( queueName ) |
| 5750 | value = str( value ) |
| 5751 | prefix = "work-queue-test" |
| 5752 | operation = "add" |
| 5753 | cmdStr = " ".join( [ prefix, queueName, operation, value ] ) |
| 5754 | output = self.distPrimitivesSend( cmdStr ) |
| 5755 | if "Invalid operation name" in output: |
| 5756 | main.log.warn( output ) |
| 5757 | return main.ERROR |
| 5758 | elif "Done" in output: |
| 5759 | return main.TRUE |
| 5760 | except TypeError: |
| 5761 | main.log.exception( self.name + ": Object not as expected" ) |
| 5762 | return main.ERROR |
| 5763 | except Exception: |
| 5764 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5765 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5766 | |
| 5767 | def workQueueAddMultiple( self, queueName, value1, value2 ): |
| 5768 | """ |
| 5769 | CLI command to add two strings to the specified Work Queue. |
| 5770 | This function uses the distributed primitives test app, which |
| 5771 | gives some cli access to distributed primitives for testing |
| 5772 | purposes only. |
| 5773 | |
| 5774 | Required arguments: |
| 5775 | queueName - The name of the queue to add to |
| 5776 | value1 - The first value to add to the queue |
| 5777 | value2 - The second value to add to the queue |
| 5778 | returns: |
| 5779 | main.TRUE on success, main.FALSE on failure and |
| 5780 | main.ERROR on error. |
| 5781 | """ |
| 5782 | try: |
| 5783 | queueName = str( queueName ) |
| 5784 | value1 = str( value1 ) |
| 5785 | value2 = str( value2 ) |
| 5786 | prefix = "work-queue-test" |
| 5787 | operation = "addMultiple" |
| 5788 | cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] ) |
| 5789 | output = self.distPrimitivesSend( cmdStr ) |
| 5790 | if "Invalid operation name" in output: |
| 5791 | main.log.warn( output ) |
| 5792 | return main.ERROR |
| 5793 | elif "Done" in output: |
| 5794 | return main.TRUE |
| 5795 | except TypeError: |
| 5796 | main.log.exception( self.name + ": Object not as expected" ) |
| 5797 | return main.ERROR |
| 5798 | except Exception: |
| 5799 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5800 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5801 | |
| 5802 | def workQueueTakeAndComplete( self, queueName, number=1 ): |
| 5803 | """ |
| 5804 | CLI command to take a value from the specified Work Queue and compelte it. |
| 5805 | This function uses the distributed primitives test app, which |
| 5806 | gives some cli access to distributed primitives for testing |
| 5807 | purposes only. |
| 5808 | |
| 5809 | Required arguments: |
| 5810 | queueName - The name of the queue to add to |
| 5811 | number - The number of items to take and complete |
| 5812 | returns: |
| 5813 | main.TRUE on success, main.FALSE on failure and |
| 5814 | main.ERROR on error. |
| 5815 | """ |
| 5816 | try: |
| 5817 | queueName = str( queueName ) |
| 5818 | number = str( int( number ) ) |
| 5819 | prefix = "work-queue-test" |
| 5820 | operation = "takeAndComplete" |
| 5821 | cmdStr = " ".join( [ prefix, queueName, operation, number ] ) |
| 5822 | output = self.distPrimitivesSend( cmdStr ) |
| 5823 | if "Invalid operation name" in output: |
| 5824 | main.log.warn( output ) |
| 5825 | return main.ERROR |
| 5826 | elif "Done" in output: |
| 5827 | return main.TRUE |
| 5828 | except TypeError: |
| 5829 | main.log.exception( self.name + ": Object not as expected" ) |
| 5830 | return main.ERROR |
| 5831 | except Exception: |
| 5832 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5833 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5834 | |
| 5835 | def workQueueDestroy( self, queueName ): |
| 5836 | """ |
| 5837 | CLI command to destroy 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 | returns: |
| 5845 | main.TRUE on success, main.FALSE on failure and |
| 5846 | main.ERROR on error. |
| 5847 | """ |
| 5848 | try: |
| 5849 | queueName = str( queueName ) |
| 5850 | prefix = "work-queue-test" |
| 5851 | operation = "destroy" |
| 5852 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5853 | output = self.distPrimitivesSend( cmdStr ) |
| 5854 | if "Invalid operation name" in output: |
| 5855 | main.log.warn( output ) |
| 5856 | return main.ERROR |
| 5857 | return main.TRUE |
| 5858 | except TypeError: |
| 5859 | main.log.exception( self.name + ": Object not as expected" ) |
| 5860 | return main.ERROR |
| 5861 | except Exception: |
| 5862 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5863 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5864 | |
| 5865 | def workQueueTotalPending( self, queueName ): |
| 5866 | """ |
| 5867 | CLI command to get the Total Pending items of the specified Work Queue. |
| 5868 | This function uses the distributed primitives test app, which |
| 5869 | gives some cli access to distributed primitives for testing |
| 5870 | purposes only. |
| 5871 | |
| 5872 | Required arguments: |
| 5873 | queueName - The name of the queue to add to |
| 5874 | returns: |
| 5875 | The number of Pending items in the specified work queue or |
| 5876 | None on error |
| 5877 | """ |
| 5878 | try: |
| 5879 | queueName = str( queueName ) |
| 5880 | prefix = "work-queue-test" |
| 5881 | operation = "totalPending" |
| 5882 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5883 | output = self.distPrimitivesSend( cmdStr ) |
| 5884 | pattern = r'\d+' |
| 5885 | if "Invalid operation name" in output: |
| 5886 | main.log.warn( output ) |
| 5887 | return None |
| 5888 | else: |
| 5889 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5890 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5891 | except ( AttributeError, TypeError ): |
| 5892 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5893 | return None |
| 5894 | except Exception: |
| 5895 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5896 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5897 | |
| 5898 | def workQueueTotalCompleted( self, queueName ): |
| 5899 | """ |
| 5900 | CLI command to get the Total Completed items of the specified Work Queue. |
| 5901 | This function uses the distributed primitives test app, which |
| 5902 | gives some cli access to distributed primitives for testing |
| 5903 | purposes only. |
| 5904 | |
| 5905 | Required arguments: |
| 5906 | queueName - The name of the queue to add to |
| 5907 | returns: |
| 5908 | The number of complete items in the specified work queue or |
| 5909 | None on error |
| 5910 | """ |
| 5911 | try: |
| 5912 | queueName = str( queueName ) |
| 5913 | prefix = "work-queue-test" |
| 5914 | operation = "totalCompleted" |
| 5915 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5916 | output = self.distPrimitivesSend( cmdStr ) |
| 5917 | pattern = r'\d+' |
| 5918 | if "Invalid operation name" in output: |
| 5919 | main.log.warn( output ) |
| 5920 | return None |
| 5921 | else: |
| 5922 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5923 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5924 | except ( AttributeError, TypeError ): |
| 5925 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5926 | return None |
| 5927 | except Exception: |
| 5928 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5929 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5930 | |
| 5931 | def workQueueTotalInProgress( self, queueName ): |
| 5932 | """ |
| 5933 | CLI command to get the Total In Progress items of the specified Work Queue. |
| 5934 | This function uses the distributed primitives test app, which |
| 5935 | gives some cli access to distributed primitives for testing |
| 5936 | purposes only. |
| 5937 | |
| 5938 | Required arguments: |
| 5939 | queueName - The name of the queue to add to |
| 5940 | returns: |
| 5941 | The number of In Progress items in the specified work queue or |
| 5942 | None on error |
| 5943 | """ |
| 5944 | try: |
| 5945 | queueName = str( queueName ) |
| 5946 | prefix = "work-queue-test" |
| 5947 | operation = "totalInProgress" |
| 5948 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5949 | output = self.distPrimitivesSend( cmdStr ) |
| 5950 | pattern = r'\d+' |
| 5951 | if "Invalid operation name" in output: |
| 5952 | main.log.warn( output ) |
| 5953 | return None |
| 5954 | else: |
| 5955 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5956 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5957 | except ( AttributeError, TypeError ): |
| 5958 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5959 | return None |
| 5960 | except Exception: |
| 5961 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5962 | main.cleanAndExit() |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 5963 | |
| 5964 | def events( self, args='-a' ): |
| 5965 | """ |
| 5966 | Description: Returns events -a command output |
| 5967 | Optional: |
| 5968 | add other arguments |
| 5969 | """ |
| 5970 | try: |
| 5971 | cmdStr = "events" |
| 5972 | if args: |
| 5973 | cmdStr += " " + args |
| 5974 | handle = self.sendline( cmdStr ) |
| 5975 | assert handle is not None, "Error in sendline" |
| 5976 | assert "Command not found:" not in handle, handle |
| 5977 | return handle |
| 5978 | except AssertionError: |
| 5979 | main.log.exception( "" ) |
| 5980 | return None |
| 5981 | except TypeError: |
| 5982 | main.log.exception( self.name + ": Object not as expected" ) |
| 5983 | return None |
| 5984 | except pexpect.EOF: |
| 5985 | main.log.error( self.name + ": EOF exception found" ) |
| 5986 | main.log.error( self.name + ": " + self.handle.before ) |
| 5987 | main.cleanAndExit() |
| 5988 | except Exception: |
| 5989 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5990 | main.cleanAndExit() |
| 5991 | |
| 5992 | def getMaster( self, deviceID ): |
| 5993 | """ |
| 5994 | Description: Obtains current master using "roles" command for a specific deviceID |
| 5995 | """ |
| 5996 | try: |
| 5997 | return str( self.getRole( deviceID )[ 'master' ] ) |
| 5998 | except AssertionError: |
| 5999 | main.log.exception( "" ) |
| 6000 | return None |
| 6001 | except TypeError: |
| 6002 | main.log.exception( self.name + ": Object not as expected" ) |
| 6003 | return None |
| 6004 | except pexpect.EOF: |
| 6005 | main.log.error( self.name + ": EOF exception found" ) |
| 6006 | main.log.error( self.name + ": " + self.handle.before ) |
| 6007 | main.cleanAndExit() |
| 6008 | except Exception: |
| 6009 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 6010 | main.cleanAndExit() |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 6011 | |
| 6012 | def issu( self ): |
| 6013 | """ |
| 6014 | Short summary of In-Service Software Upgrade status |
| 6015 | |
| 6016 | Returns the output of the cli command or None on Error |
| 6017 | """ |
| 6018 | try: |
| 6019 | cmdStr = "issu" |
| 6020 | handle = self.sendline( cmdStr ) |
| 6021 | assert handle is not None, "Error in sendline" |
| 6022 | assert "Command not found:" not in handle, handle |
| 6023 | assert "Unsupported command:" not in handle, handle |
| 6024 | return handle |
| 6025 | except AssertionError: |
| 6026 | main.log.exception( "" ) |
| 6027 | return None |
| 6028 | except TypeError: |
| 6029 | main.log.exception( self.name + ": Object not as expected" ) |
| 6030 | return None |
| 6031 | except pexpect.EOF: |
| 6032 | main.log.error( self.name + ": EOF exception found" ) |
| 6033 | main.log.error( self.name + ": " + self.handle.before ) |
| 6034 | main.cleanAndExit() |
| 6035 | except Exception: |
| 6036 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6037 | main.cleanAndExit() |
| 6038 | |
| 6039 | def issuInit( self ): |
| 6040 | """ |
| 6041 | Initiates an In-Service Software Upgrade |
| 6042 | |
| 6043 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6044 | """ |
| 6045 | try: |
| 6046 | cmdStr = "issu init" |
| 6047 | handle = self.sendline( cmdStr ) |
| 6048 | assert handle is not None, "Error in sendline" |
| 6049 | assert "Command not found:" not in handle, handle |
| 6050 | assert "Unsupported command:" not in handle, handle |
| 6051 | if "Initialized" in handle: |
| 6052 | return main.TRUE |
| 6053 | else: |
| 6054 | return main.FALSE |
| 6055 | except AssertionError: |
| 6056 | main.log.exception( "" ) |
| 6057 | return main.ERROR |
| 6058 | except TypeError: |
| 6059 | main.log.exception( self.name + ": Object not as expected" ) |
| 6060 | return main.ERROR |
| 6061 | except pexpect.EOF: |
| 6062 | main.log.error( self.name + ": EOF exception found" ) |
| 6063 | main.log.error( self.name + ": " + self.handle.before ) |
| 6064 | main.cleanAndExit() |
| 6065 | except Exception: |
| 6066 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6067 | main.cleanAndExit() |
| 6068 | |
| 6069 | def issuUpgrade( self ): |
| 6070 | """ |
| 6071 | Transitions stores to upgraded nodes |
| 6072 | |
| 6073 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6074 | """ |
| 6075 | try: |
| 6076 | cmdStr = "issu upgrade" |
| 6077 | handle = self.sendline( cmdStr ) |
| 6078 | assert handle is not None, "Error in sendline" |
| 6079 | assert "Command not found:" not in handle, handle |
| 6080 | assert "Unsupported command:" not in handle, handle |
| 6081 | if "Upgraded" in handle: |
| 6082 | return main.TRUE |
| 6083 | else: |
| 6084 | return main.FALSE |
| 6085 | except AssertionError: |
| 6086 | main.log.exception( "" ) |
| 6087 | return main.ERROR |
| 6088 | except TypeError: |
| 6089 | main.log.exception( self.name + ": Object not as expected" ) |
| 6090 | return main.ERROR |
| 6091 | except pexpect.EOF: |
| 6092 | main.log.error( self.name + ": EOF exception found" ) |
| 6093 | main.log.error( self.name + ": " + self.handle.before ) |
| 6094 | main.cleanAndExit() |
| 6095 | except Exception: |
| 6096 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6097 | main.cleanAndExit() |
| 6098 | |
| 6099 | def issuCommit( self ): |
| 6100 | """ |
| 6101 | Finalizes an In-Service Software Upgrade |
| 6102 | |
| 6103 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6104 | """ |
| 6105 | try: |
| 6106 | cmdStr = "issu commit" |
| 6107 | handle = self.sendline( cmdStr ) |
| 6108 | assert handle is not None, "Error in sendline" |
| 6109 | assert "Command not found:" not in handle, handle |
| 6110 | assert "Unsupported command:" not in handle, handle |
| 6111 | # TODO: Check the version returned by this command |
| 6112 | if "Committed version" in handle: |
| 6113 | return main.TRUE |
| 6114 | else: |
| 6115 | return main.FALSE |
| 6116 | except AssertionError: |
| 6117 | main.log.exception( "" ) |
| 6118 | return main.ERROR |
| 6119 | except TypeError: |
| 6120 | main.log.exception( self.name + ": Object not as expected" ) |
| 6121 | return main.ERROR |
| 6122 | except pexpect.EOF: |
| 6123 | main.log.error( self.name + ": EOF exception found" ) |
| 6124 | main.log.error( self.name + ": " + self.handle.before ) |
| 6125 | main.cleanAndExit() |
| 6126 | except Exception: |
| 6127 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6128 | main.cleanAndExit() |
| 6129 | |
| 6130 | def issuRollback( self ): |
| 6131 | """ |
| 6132 | Rolls back an In-Service Software Upgrade |
| 6133 | |
| 6134 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6135 | """ |
| 6136 | try: |
| 6137 | cmdStr = "issu rollback" |
| 6138 | handle = self.sendline( cmdStr ) |
| 6139 | assert handle is not None, "Error in sendline" |
| 6140 | assert "Command not found:" not in handle, handle |
| 6141 | assert "Unsupported command:" not in handle, handle |
| 6142 | # TODO: Check the version returned by this command |
| 6143 | if "Rolled back to version" in handle: |
| 6144 | return main.TRUE |
| 6145 | else: |
| 6146 | return main.FALSE |
| 6147 | except AssertionError: |
| 6148 | main.log.exception( "" ) |
| 6149 | return main.ERROR |
| 6150 | except TypeError: |
| 6151 | main.log.exception( self.name + ": Object not as expected" ) |
| 6152 | return main.ERROR |
| 6153 | except pexpect.EOF: |
| 6154 | main.log.error( self.name + ": EOF exception found" ) |
| 6155 | main.log.error( self.name + ": " + self.handle.before ) |
| 6156 | main.cleanAndExit() |
| 6157 | except Exception: |
| 6158 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6159 | main.cleanAndExit() |
| 6160 | |
| 6161 | def issuReset( self ): |
| 6162 | """ |
| 6163 | Resets the In-Service Software Upgrade status after a rollback |
| 6164 | |
| 6165 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6166 | """ |
| 6167 | try: |
| 6168 | cmdStr = "issu reset" |
| 6169 | handle = self.sendline( cmdStr ) |
| 6170 | assert handle is not None, "Error in sendline" |
| 6171 | assert "Command not found:" not in handle, handle |
| 6172 | assert "Unsupported command:" not in handle, handle |
| 6173 | # TODO: Check the version returned by this command |
| 6174 | if "Reset version" in handle: |
| 6175 | return main.TRUE |
| 6176 | else: |
| 6177 | return main.FALSE |
| 6178 | except AssertionError: |
| 6179 | main.log.exception( "" ) |
| 6180 | return main.ERROR |
| 6181 | except TypeError: |
| 6182 | main.log.exception( self.name + ": Object not as expected" ) |
| 6183 | return main.ERROR |
| 6184 | except pexpect.EOF: |
| 6185 | main.log.error( self.name + ": EOF exception found" ) |
| 6186 | main.log.error( self.name + ": " + self.handle.before ) |
| 6187 | main.cleanAndExit() |
| 6188 | except Exception: |
| 6189 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6190 | main.cleanAndExit() |
| 6191 | |
| 6192 | def issuStatus( self ): |
| 6193 | """ |
| 6194 | Status of an In-Service Software Upgrade |
| 6195 | |
| 6196 | Returns the output of the cli command or None on Error |
| 6197 | """ |
| 6198 | try: |
| 6199 | cmdStr = "issu status" |
| 6200 | handle = self.sendline( cmdStr ) |
| 6201 | assert handle is not None, "Error in sendline" |
| 6202 | assert "Command not found:" not in handle, handle |
| 6203 | assert "Unsupported command:" not in handle, handle |
| 6204 | return handle |
| 6205 | except AssertionError: |
| 6206 | main.log.exception( "" ) |
| 6207 | return None |
| 6208 | except TypeError: |
| 6209 | main.log.exception( self.name + ": Object not as expected" ) |
| 6210 | return None |
| 6211 | except pexpect.EOF: |
| 6212 | main.log.error( self.name + ": EOF exception found" ) |
| 6213 | main.log.error( self.name + ": " + self.handle.before ) |
| 6214 | main.cleanAndExit() |
| 6215 | except Exception: |
| 6216 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6217 | main.cleanAndExit() |
| 6218 | |
| 6219 | def issuVersion( self ): |
| 6220 | """ |
| 6221 | Get the version of an In-Service Software Upgrade |
| 6222 | |
| 6223 | Returns the output of the cli command or None on Error |
| 6224 | """ |
| 6225 | try: |
| 6226 | cmdStr = "issu version" |
| 6227 | handle = self.sendline( cmdStr ) |
| 6228 | assert handle is not None, "Error in sendline" |
| 6229 | assert "Command not found:" not in handle, handle |
| 6230 | assert "Unsupported command:" not in handle, handle |
| 6231 | return handle |
| 6232 | except AssertionError: |
| 6233 | main.log.exception( "" ) |
| 6234 | return None |
| 6235 | except TypeError: |
| 6236 | main.log.exception( self.name + ": Object not as expected" ) |
| 6237 | return None |
| 6238 | except pexpect.EOF: |
| 6239 | main.log.error( self.name + ": EOF exception found" ) |
| 6240 | main.log.error( self.name + ": " + self.handle.before ) |
| 6241 | main.cleanAndExit() |
| 6242 | except Exception: |
| 6243 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6244 | main.cleanAndExit() |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6245 | |
| 6246 | def mcastJoin( self, sIP, groupIP, sPort, dPorts ): |
| 6247 | """ |
| 6248 | Create a multicast route by calling 'mcast-join' command |
| 6249 | sIP: source IP of the multicast route |
| 6250 | groupIP: group IP of the multicast route |
| 6251 | sPort: source port (e.g. of:0000000000000001/3 ) of the multicast route |
| 6252 | dPorts: a list of destination ports of the multicast route |
| 6253 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6254 | """ |
| 6255 | try: |
| 6256 | cmdStr = "mcast-join" |
| 6257 | cmdStr += " " + str( sIP ) |
| 6258 | cmdStr += " " + str( groupIP ) |
| 6259 | cmdStr += " " + str( sPort ) |
| 6260 | assert isinstance( dPorts, list ) |
| 6261 | for dPort in dPorts: |
| 6262 | cmdStr += " " + str( dPort ) |
| 6263 | handle = self.sendline( cmdStr ) |
| 6264 | assert handle is not None, "Error in sendline" |
| 6265 | assert "Command not found:" not in handle, handle |
| 6266 | assert "Unsupported command:" not in handle, handle |
| 6267 | assert "Error executing command" not in handle, handle |
| 6268 | if "Added the mcast route" in handle: |
| 6269 | return main.TRUE |
| 6270 | else: |
| 6271 | return main.FALSE |
| 6272 | except AssertionError: |
| 6273 | main.log.exception( "" ) |
| 6274 | return None |
| 6275 | except TypeError: |
| 6276 | main.log.exception( self.name + ": Object not as expected" ) |
| 6277 | return None |
| 6278 | except pexpect.EOF: |
| 6279 | main.log.error( self.name + ": EOF exception found" ) |
| 6280 | main.log.error( self.name + ": " + self.handle.before ) |
| 6281 | main.cleanAndExit() |
| 6282 | except Exception: |
| 6283 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6284 | main.cleanAndExit() |
| 6285 | |
| 6286 | def mcastDelete( self, sIP, groupIP, dPorts ): |
| 6287 | """ |
| 6288 | Delete a multicast route by calling 'mcast-delete' command |
| 6289 | sIP: source IP of the multicast route |
| 6290 | groupIP: group IP of the multicast route |
| 6291 | dPorts: a list of destination ports of the multicast route |
| 6292 | Returns main.TRUE if mcast route is deleted; Otherwise main.FALSE |
| 6293 | """ |
| 6294 | try: |
| 6295 | cmdStr = "mcast-delete" |
| 6296 | cmdStr += " " + str( sIP ) |
| 6297 | cmdStr += " " + str( groupIP ) |
| 6298 | assert isinstance( dPorts, list ) |
| 6299 | for dPort in dPorts: |
| 6300 | cmdStr += " " + str( dPort ) |
| 6301 | handle = self.sendline( cmdStr ) |
| 6302 | assert handle is not None, "Error in sendline" |
| 6303 | assert "Command not found:" not in handle, handle |
| 6304 | assert "Unsupported command:" not in handle, handle |
| 6305 | assert "Error executing command" not in handle, handle |
| 6306 | if "Updated the mcast route" in handle: |
| 6307 | return main.TRUE |
| 6308 | else: |
| 6309 | return main.FALSE |
| 6310 | except AssertionError: |
| 6311 | main.log.exception( "" ) |
| 6312 | return None |
| 6313 | except TypeError: |
| 6314 | main.log.exception( self.name + ": Object not as expected" ) |
| 6315 | return None |
| 6316 | except pexpect.EOF: |
| 6317 | main.log.error( self.name + ": EOF exception found" ) |
| 6318 | main.log.error( self.name + ": " + self.handle.before ) |
| 6319 | main.cleanAndExit() |
| 6320 | except Exception: |
| 6321 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6322 | main.cleanAndExit() |
| 6323 | |
| 6324 | def mcastHostJoin( self, sAddr, gAddr, srcs, sinks ): |
| 6325 | """ |
| 6326 | Create a multicast route by calling 'mcast-host-join' command |
| 6327 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6328 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6329 | 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] | 6330 | sinks: a list of HostId of the sinks e.g. ["00:AA:00:00:01:05/40"] |
| 6331 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6332 | """ |
| 6333 | try: |
| 6334 | cmdStr = "mcast-host-join" |
| 6335 | cmdStr += " -sAddr " + str( sAddr ) |
| 6336 | cmdStr += " -gAddr " + str( gAddr ) |
| 6337 | assert isinstance( srcs, list ) |
| 6338 | for src in srcs: |
| 6339 | cmdStr += " -srcs " + str( src ) |
| 6340 | assert isinstance( sinks, list ) |
| 6341 | for sink in sinks: |
| 6342 | cmdStr += " -sinks " + str( sink ) |
| 6343 | handle = self.sendline( cmdStr ) |
| 6344 | assert handle is not None, "Error in sendline" |
| 6345 | assert "Command not found:" not in handle, handle |
| 6346 | assert "Unsupported command:" not in handle, handle |
| 6347 | assert "Error executing command" not in handle, handle |
| 6348 | if "Added the mcast route" in handle: |
| 6349 | return main.TRUE |
| 6350 | else: |
| 6351 | return main.FALSE |
| 6352 | except AssertionError: |
| 6353 | main.log.exception( "" ) |
| 6354 | return None |
| 6355 | except TypeError: |
| 6356 | main.log.exception( self.name + ": Object not as expected" ) |
| 6357 | return None |
| 6358 | except pexpect.EOF: |
| 6359 | main.log.error( self.name + ": EOF exception found" ) |
| 6360 | main.log.error( self.name + ": " + self.handle.before ) |
| 6361 | main.cleanAndExit() |
| 6362 | except Exception: |
| 6363 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6364 | main.cleanAndExit() |
| 6365 | |
| 6366 | def mcastHostDelete( self, sAddr, gAddr, host=None ): |
| 6367 | """ |
| 6368 | Delete multicast sink(s) by calling 'mcast-host-delete' command |
| 6369 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6370 | gAddr: specifies multicast group address |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 6371 | 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] | 6372 | will delete the route if not specified |
| 6373 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6374 | """ |
| 6375 | try: |
| 6376 | cmdStr = "mcast-host-delete" |
| 6377 | cmdStr += " -sAddr " + str( sAddr ) |
| 6378 | cmdStr += " -gAddr " + str( gAddr ) |
| 6379 | if host: |
| 6380 | cmdStr += " -h " + str( host ) |
| 6381 | handle = self.sendline( cmdStr ) |
| 6382 | assert handle is not None, "Error in sendline" |
| 6383 | assert "Command not found:" not in handle, handle |
| 6384 | assert "Unsupported command:" not in handle, handle |
| 6385 | assert "Error executing command" not in handle, handle |
| 6386 | if "Updated the mcast route" in handle: |
| 6387 | return main.TRUE |
| 6388 | elif "Deleted the mcast route" in handle: |
| 6389 | return main.TRUE |
| 6390 | else: |
| 6391 | return main.FALSE |
| 6392 | except AssertionError: |
| 6393 | main.log.exception( "" ) |
| 6394 | return None |
| 6395 | except TypeError: |
| 6396 | main.log.exception( self.name + ": Object not as expected" ) |
| 6397 | return None |
| 6398 | except pexpect.EOF: |
| 6399 | main.log.error( self.name + ": EOF exception found" ) |
| 6400 | main.log.error( self.name + ": " + self.handle.before ) |
| 6401 | main.cleanAndExit() |
| 6402 | except Exception: |
| 6403 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6404 | main.cleanAndExit() |
| 6405 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6406 | def mcastSinkDelete( self, sAddr, gAddr, sink=None ): |
| 6407 | """ |
| 6408 | Delete multicast sink(s) by calling 'mcast-sink-delete' command |
| 6409 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6410 | gAddr: specifies multicast group address |
| 6411 | host: HostId of the sink e.g. "00:AA:00:00:01:05/40", |
| 6412 | will delete the route if not specified |
| 6413 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6414 | """ |
| 6415 | try: |
| 6416 | cmdStr = "mcast-sink-delete" |
| 6417 | cmdStr += " -sAddr " + str( sAddr ) |
| 6418 | cmdStr += " -gAddr " + str( gAddr ) |
| 6419 | if sink: |
| 6420 | cmdStr += " -s " + str( sink ) |
| 6421 | handle = self.sendline( cmdStr ) |
| 6422 | assert handle is not None, "Error in sendline" |
| 6423 | assert "Command not found:" not in handle, handle |
| 6424 | assert "Unsupported command:" not in handle, handle |
| 6425 | assert "Error executing command" not in handle, handle |
| 6426 | if "Updated the mcast route" in handle: |
| 6427 | return main.TRUE |
| 6428 | elif "Deleted the mcast route" in handle: |
| 6429 | return main.TRUE |
| 6430 | else: |
| 6431 | return main.FALSE |
| 6432 | except AssertionError: |
| 6433 | main.log.exception( "" ) |
| 6434 | return None |
| 6435 | except TypeError: |
| 6436 | main.log.exception( self.name + ": Object not as expected" ) |
| 6437 | return None |
| 6438 | except pexpect.EOF: |
| 6439 | main.log.error( self.name + ": EOF exception found" ) |
| 6440 | main.log.error( self.name + ": " + self.handle.before ) |
| 6441 | main.cleanAndExit() |
| 6442 | except Exception: |
| 6443 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6444 | main.cleanAndExit() |
| 6445 | |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6446 | def mcastSourceDelete( self, sAddr, gAddr, srcs=None ): |
| 6447 | """ |
| 6448 | Delete multicast src(s) by calling 'mcast-source-delete' command |
| 6449 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6450 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6451 | 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] | 6452 | will delete the route if not specified |
| 6453 | Returns main.TRUE if mcast sink is deleted; Otherwise main.FALSE |
| 6454 | """ |
| 6455 | try: |
| 6456 | cmdStr = "mcast-source-delete" |
| 6457 | cmdStr += " -sAddr " + str( sAddr ) |
| 6458 | cmdStr += " -gAddr " + str( gAddr ) |
| 6459 | if srcs: |
| 6460 | assert isinstance( srcs, list ) |
| 6461 | for src in srcs: |
| 6462 | cmdStr += " -src " + str( src ) |
| 6463 | handle = self.sendline( cmdStr ) |
| 6464 | assert handle is not None, "Error in sendline" |
| 6465 | assert "Command not found:" not in handle, handle |
| 6466 | assert "Unsupported command:" not in handle, handle |
| 6467 | assert "Error executing command" not in handle, handle |
| 6468 | if "Updated the mcast route" in handle: |
| 6469 | return main.TRUE |
| 6470 | elif "Deleted the mcast route" in handle: |
| 6471 | return main.TRUE |
| 6472 | else: |
| 6473 | return main.FALSE |
| 6474 | except AssertionError: |
| 6475 | main.log.exception( "" ) |
| 6476 | return None |
| 6477 | except TypeError: |
| 6478 | main.log.exception( self.name + ": Object not as expected" ) |
| 6479 | return None |
| 6480 | except pexpect.EOF: |
| 6481 | main.log.error( self.name + ": EOF exception found" ) |
| 6482 | main.log.error( self.name + ": " + self.handle.before ) |
| 6483 | main.cleanAndExit() |
| 6484 | except Exception: |
| 6485 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6486 | main.cleanAndExit() |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6487 | |
| 6488 | def netcfg( self, jsonFormat=True, args="" ): |
| 6489 | """ |
| 6490 | Run netcfg cli command with given args |
| 6491 | """ |
| 6492 | try: |
| 6493 | cmdStr = "netcfg" |
| 6494 | if jsonFormat: |
| 6495 | cmdStr = cmdStr + " -j" |
| 6496 | if args: |
| 6497 | cmdStr = cmdStr + " " + str( args ) |
| 6498 | handle = self.sendline( cmdStr ) |
| 6499 | assert handle is not None, "Error in sendline" |
| 6500 | assert "Command not found:" not in handle, handle |
| 6501 | assert "Unsupported command:" not in handle, handle |
| 6502 | assert "Error executing command" not in handle, handle |
| 6503 | return handle |
| 6504 | except AssertionError: |
| 6505 | main.log.exception( "" ) |
| 6506 | return None |
| 6507 | except TypeError: |
| 6508 | main.log.exception( self.name + ": Object not as expected" ) |
| 6509 | return None |
| 6510 | except pexpect.EOF: |
| 6511 | main.log.error( self.name + ": EOF exception found" ) |
| 6512 | main.log.error( self.name + ": " + self.handle.before ) |
| 6513 | main.cleanAndExit() |
| 6514 | except Exception: |
| 6515 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6516 | main.cleanAndExit() |
| 6517 | |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6518 | def composeT3Command( self, sAddr, dAddr, ipv6=False, verbose=True, simple=False ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6519 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6520 | 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] | 6521 | Options: |
| 6522 | sAddr: IP address of the source host |
| 6523 | dAddr: IP address of the destination host |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6524 | ipv6: True if hosts are IPv6 |
| 6525 | verbose: return verbose t3 output if True |
| 6526 | simple: compose command for t3-troubleshoot-simple if True |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6527 | """ |
| 6528 | try: |
| 6529 | # Collect information of both hosts from onos |
| 6530 | hosts = self.hosts() |
| 6531 | hosts = json.loads( hosts ) |
| 6532 | sHost = None |
| 6533 | dHost = None |
| 6534 | for host in hosts: |
| 6535 | if sAddr in host[ "ipAddresses" ]: |
| 6536 | sHost = host |
| 6537 | elif dAddr in host[ "ipAddresses" ]: |
| 6538 | dHost = host |
| 6539 | if sHost and dHost: |
| 6540 | break |
| 6541 | assert sHost, "Not able to find host with IP {}".format( sAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6542 | cmdList = [] |
You Wang | 5d9527b | 2018-05-29 17:08:54 -0700 | [diff] [blame] | 6543 | if simple: |
| 6544 | assert dHost, "Not able to find host with IP {}".format( dAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6545 | cmdStr = "t3-troubleshoot-simple" |
| 6546 | if verbose: |
| 6547 | cmdStr += " -vv" |
| 6548 | if ipv6: |
| 6549 | cmdStr += " -et ipv6" |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6550 | cmdStr += " {}/{} {}/{}".format( sHost[ "mac" ], sHost[ "vlan" ], dHost[ "mac" ], dHost[ "vlan" ] ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6551 | cmdList.append( cmdStr ) |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6552 | else: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6553 | for location in sHost[ "locations" ]: |
| 6554 | cmdStr = "t3-troubleshoot" |
| 6555 | if verbose: |
| 6556 | cmdStr += " -vv" |
| 6557 | if ipv6: |
| 6558 | cmdStr += " -et ipv6" |
| 6559 | cmdStr += " -s " + str( sAddr ) |
| 6560 | cmdStr += " -sp " + str( location[ "elementId" ] ) + "/" + str( location[ "port" ] ) |
| 6561 | cmdStr += " -sm " + str( sHost[ "mac" ] ) |
| 6562 | if sHost[ "vlan" ] != "None": |
| 6563 | cmdStr += " -vid " + sHost[ "vlan" ] |
| 6564 | cmdStr += " -d " + str( dAddr ) |
| 6565 | netcfg = self.netcfg( args="devices {}".format( location[ "elementId" ] ) ) |
| 6566 | netcfg = json.loads( netcfg ) |
| 6567 | assert netcfg, "Failed to get netcfg" |
| 6568 | cmdStr += " -dm " + str( netcfg[ "segmentrouting" ][ "routerMac" ] ) |
| 6569 | cmdList.append( cmdStr ) |
| 6570 | return cmdList |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6571 | except AssertionError: |
| 6572 | main.log.exception( "" ) |
| 6573 | return None |
| 6574 | except ( KeyError, TypeError ): |
| 6575 | main.log.exception( self.name + ": Object not as expected" ) |
| 6576 | return None |
| 6577 | except Exception: |
| 6578 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6579 | main.cleanAndExit() |
| 6580 | |
| 6581 | def t3( self, sAddr, dAddr, ipv6=False ): |
| 6582 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6583 | 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] | 6584 | Options: |
| 6585 | sAddr: IP address of the source host |
| 6586 | dAddr: IP address of the destination host |
| 6587 | """ |
| 6588 | try: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6589 | cmdList = self.composeT3Command( sAddr, dAddr, ipv6 ) |
| 6590 | assert cmdList is not None, "composeT3Command returned None" |
| 6591 | t3Output = "" |
| 6592 | for cmdStr in cmdList: |
| 6593 | handle = self.sendline( cmdStr ) |
| 6594 | assert handle is not None, "Error in sendline" |
| 6595 | assert "Command not found:" not in handle, handle |
| 6596 | assert "Unsupported command:" not in handle, handle |
| 6597 | assert "Error executing command" not in handle, handle |
| 6598 | assert "Tracing packet" in handle |
| 6599 | t3Output += handle |
| 6600 | return t3Output |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6601 | except AssertionError: |
| 6602 | main.log.exception( "" ) |
| 6603 | return None |
| 6604 | except pexpect.EOF: |
| 6605 | main.log.error( self.name + ": EOF exception found" ) |
| 6606 | main.log.error( self.name + ": " + self.handle.before ) |
| 6607 | main.cleanAndExit() |
| 6608 | except Exception: |
| 6609 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6610 | main.cleanAndExit() |