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: |
| 283 | # Wait for onos start ( -w ) and enter onos cli |
| 284 | startCliCommand = "onos -w " |
| 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 | |
| 365 | # Wait for onos start ( -w ) and enter onos cli |
| 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 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 463 | def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, dollarSign=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 464 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 465 | Send a completely user specified string to |
| 466 | the onos> prompt. Use this function if you have |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 467 | a very specific command to send. |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 468 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 469 | if noExit is True, TestON will not exit, and return None |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 470 | if dollarSign is True, TestON will not expect for '$' as a new CLI or onos> prompt |
| 471 | since '$' can be in the output. |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 472 | |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 473 | Warning: There are no sanity checking to commands |
| 474 | sent using this method. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 475 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 476 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 477 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 478 | # Try to reconnect if disconnected from cli |
| 479 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 480 | i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ] ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 481 | if i == 1: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 482 | main.log.error( self.name + ": onos cli session closed. " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 483 | if self.onosIp: |
| 484 | main.log.warn( "Trying to reconnect " + self.onosIp ) |
| 485 | reconnectResult = self.startOnosCli( self.onosIp ) |
| 486 | if reconnectResult: |
| 487 | main.log.info( self.name + ": onos cli session reconnected." ) |
| 488 | else: |
| 489 | main.log.error( self.name + ": reconnection failed." ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 490 | if noExit: |
| 491 | return None |
| 492 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 493 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 494 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 495 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 496 | if i == 2: |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 497 | main.log.warn( "Timeout when testing cli responsiveness" ) |
| 498 | main.log.debug( self.handle.before ) |
| 499 | self.handle.send( "\x03" ) # Send ctrl-c to clear previous output |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 500 | self.handle.expect( "onos>" ) |
| 501 | |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 502 | if debug: |
| 503 | # NOTE: This adds and average of .4 seconds per call |
| 504 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 505 | self.log( logStr, noExit=noExit ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 506 | self.handle.sendline( cmdStr ) |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 507 | if dollarSign: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 508 | i = self.handle.expect( [ "onos>" ], timeout ) |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 509 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 510 | i = self.handle.expect( [ "onos>", self.prompt ], timeout ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 511 | response = self.handle.before |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 512 | # TODO: do something with i |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 513 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 514 | + self.name + "." ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 515 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 516 | main.log.debug( self.name + ": Raw output" ) |
| 517 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 518 | |
| 519 | # Remove ANSI color control strings from output |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 520 | ansiEscape = re.compile( r'\x1b[^m]*m' ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 521 | response = ansiEscape.sub( '', response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 522 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 523 | main.log.debug( self.name + ": ansiEscape output" ) |
| 524 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 525 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 526 | # Remove extra return chars that get added |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 527 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 528 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 529 | main.log.debug( self.name + ": Removed extra returns " + |
| 530 | "from output" ) |
| 531 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 532 | |
| 533 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 534 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 535 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 536 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 537 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 538 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 539 | # parse for just the output, remove the cmd from response |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 540 | output = response.split( cmdStr.strip(), 1 ) |
| 541 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 542 | main.log.debug( self.name + ": split output" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 543 | for r in output: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 544 | main.log.debug( self.name + ": " + repr( r ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 545 | output = output[ 1 ].strip() |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 546 | if showResponse: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 547 | main.log.info( "Response from ONOS: {}".format( output ) ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 548 | return output |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 549 | except pexpect.TIMEOUT: |
| 550 | main.log.error( self.name + ":ONOS timeout" ) |
| 551 | if debug: |
| 552 | main.log.debug( self.handle.before ) |
| 553 | return None |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 554 | except IndexError: |
| 555 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 556 | main.log.debug( "response: {}".format( repr( response ) ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 557 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 558 | except TypeError: |
| 559 | main.log.exception( self.name + ": Object not as expected" ) |
| 560 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 561 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 562 | main.log.error( self.name + ": EOF exception found" ) |
| 563 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 564 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 565 | return None |
| 566 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 567 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 568 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 569 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 570 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 571 | return None |
| 572 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 573 | main.cleanAndExit() |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 574 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 575 | # IMPORTANT NOTE: |
| 576 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 577 | # the cli command changing 'a:b' with 'aB'. |
| 578 | # Ex ) onos:topology > onosTopology |
| 579 | # onos:links > onosLinks |
| 580 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 581 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 582 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 583 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 584 | Adds a new cluster node by ID and address information. |
| 585 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 586 | * nodeId |
| 587 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 588 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 589 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 590 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 591 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 592 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 593 | str( ONOSIp ) + " " + str( tcpPort ) |
| 594 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 595 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 596 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 597 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 598 | main.log.error( "Error in adding node" ) |
| 599 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 600 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 601 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 602 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 603 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 604 | except AssertionError: |
| 605 | main.log.exception( "" ) |
| 606 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 607 | except TypeError: |
| 608 | main.log.exception( self.name + ": Object not as expected" ) |
| 609 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 610 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 611 | main.log.error( self.name + ": EOF exception found" ) |
| 612 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 613 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 614 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 615 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 616 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 617 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 618 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 619 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 620 | Removes a cluster by ID |
| 621 | Issues command: 'remove-node [<node-id>]' |
| 622 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 623 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 624 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 625 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 626 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 627 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 628 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 629 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 630 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 631 | if re.search( "Error", handle ): |
| 632 | main.log.error( "Error in removing node" ) |
| 633 | main.log.error( handle ) |
| 634 | return main.FALSE |
| 635 | else: |
| 636 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 637 | except AssertionError: |
| 638 | main.log.exception( "" ) |
| 639 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 640 | except TypeError: |
| 641 | main.log.exception( self.name + ": Object not as expected" ) |
| 642 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 643 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 644 | main.log.error( self.name + ": EOF exception found" ) |
| 645 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 646 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 647 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 648 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 649 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 650 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 651 | def nodes( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 652 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 653 | List the nodes currently visible |
| 654 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 655 | Optional argument: |
| 656 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 657 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 658 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 659 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 660 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 661 | cmdStr += " -j" |
| 662 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 663 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 664 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 665 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 666 | except AssertionError: |
| 667 | main.log.exception( "" ) |
| 668 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 669 | except TypeError: |
| 670 | main.log.exception( self.name + ": Object not as expected" ) |
| 671 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 672 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 673 | main.log.error( self.name + ": EOF exception found" ) |
| 674 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 675 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 676 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 677 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 678 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 679 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 680 | def topology( self ): |
| 681 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 682 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 683 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 684 | Return: |
| 685 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 686 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 687 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 688 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 689 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 690 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 691 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 692 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 693 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 694 | except AssertionError: |
| 695 | main.log.exception( "" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 696 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 697 | except TypeError: |
| 698 | main.log.exception( self.name + ": Object not as expected" ) |
| 699 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 700 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 701 | main.log.error( self.name + ": EOF exception found" ) |
| 702 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 703 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 704 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 705 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 706 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 707 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 708 | def deviceRemove( self, deviceId ): |
| 709 | """ |
| 710 | Removes particular device from storage |
| 711 | |
| 712 | TODO: refactor this function |
| 713 | """ |
| 714 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 715 | cmdStr = "device-remove " + str( deviceId ) |
| 716 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 717 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 718 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 719 | if re.search( "Error", handle ): |
| 720 | main.log.error( "Error in removing device" ) |
| 721 | main.log.error( handle ) |
| 722 | return main.FALSE |
| 723 | else: |
| 724 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 725 | except AssertionError: |
| 726 | main.log.exception( "" ) |
| 727 | return None |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 728 | except TypeError: |
| 729 | main.log.exception( self.name + ": Object not as expected" ) |
| 730 | return None |
| 731 | except pexpect.EOF: |
| 732 | main.log.error( self.name + ": EOF exception found" ) |
| 733 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 734 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 735 | except Exception: |
| 736 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 737 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 738 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 739 | def devices( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 740 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 741 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 742 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 743 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 744 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 745 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 746 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 747 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 748 | cmdStr += " -j" |
| 749 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 750 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 751 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 752 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 753 | except AssertionError: |
| 754 | main.log.exception( "" ) |
| 755 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 756 | except TypeError: |
| 757 | main.log.exception( self.name + ": Object not as expected" ) |
| 758 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 759 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 760 | main.log.error( self.name + ": EOF exception found" ) |
| 761 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 762 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 763 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 764 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 765 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 766 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 767 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 768 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 769 | This balances the devices across all controllers |
| 770 | by issuing command: 'onos> onos:balance-masters' |
| 771 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 772 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 773 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 774 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 775 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 776 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 777 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 778 | if re.search( "Error", handle ): |
| 779 | main.log.error( "Error in balancing masters" ) |
| 780 | main.log.error( handle ) |
| 781 | return main.FALSE |
| 782 | else: |
| 783 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 784 | except AssertionError: |
| 785 | main.log.exception( "" ) |
| 786 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 787 | except TypeError: |
| 788 | main.log.exception( self.name + ": Object not as expected" ) |
| 789 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 790 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 791 | main.log.error( self.name + ": EOF exception found" ) |
| 792 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 793 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 794 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 795 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 796 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 797 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 798 | def checkMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 799 | """ |
| 800 | Returns the output of the masters command. |
| 801 | Optional argument: |
| 802 | * jsonFormat - boolean indicating if you want output in json |
| 803 | """ |
| 804 | try: |
| 805 | cmdStr = "onos:masters" |
| 806 | if jsonFormat: |
| 807 | cmdStr += " -j" |
| 808 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 809 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 810 | assert "Command not found:" not in output, output |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 811 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 812 | except AssertionError: |
| 813 | main.log.exception( "" ) |
| 814 | return None |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 815 | except TypeError: |
| 816 | main.log.exception( self.name + ": Object not as expected" ) |
| 817 | return None |
| 818 | except pexpect.EOF: |
| 819 | main.log.error( self.name + ": EOF exception found" ) |
| 820 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 821 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 822 | except Exception: |
| 823 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 824 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 825 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 826 | def checkBalanceMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 827 | """ |
| 828 | Uses the master command to check that the devices' leadership |
| 829 | is evenly divided |
| 830 | |
| 831 | Dependencies: checkMasters() and summary() |
| 832 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 833 | Returns main.TRUE if the devices are balanced |
| 834 | Returns main.FALSE if the devices are unbalanced |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 835 | Exits on Exception |
| 836 | Returns None on TypeError |
| 837 | """ |
| 838 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 839 | summaryOutput = self.summary() |
| 840 | totalDevices = json.loads( summaryOutput )[ "devices" ] |
| 841 | except ( TypeError, ValueError ): |
| 842 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) ) |
| 843 | return None |
| 844 | try: |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 845 | totalOwnedDevices = 0 |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 846 | mastersOutput = self.checkMasters() |
| 847 | masters = json.loads( mastersOutput ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 848 | first = masters[ 0 ][ "size" ] |
| 849 | for master in masters: |
| 850 | totalOwnedDevices += master[ "size" ] |
| 851 | if master[ "size" ] > first + 1 or master[ "size" ] < first - 1: |
| 852 | main.log.error( "Mastership not balanced" ) |
| 853 | main.log.info( "\n" + self.checkMasters( False ) ) |
| 854 | return main.FALSE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 855 | main.log.info( "Mastership balanced between " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 856 | str( len( masters ) ) + " masters" ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 857 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 858 | except ( TypeError, ValueError ): |
| 859 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 860 | return None |
| 861 | except pexpect.EOF: |
| 862 | main.log.error( self.name + ": EOF exception found" ) |
| 863 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 864 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 865 | except Exception: |
| 866 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 867 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 868 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 869 | def links( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 870 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 871 | Lists all core links |
| 872 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 873 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 874 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 875 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 876 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 877 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 878 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 879 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 880 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 881 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 882 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 883 | except AssertionError: |
| 884 | main.log.exception( "" ) |
| 885 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 886 | except TypeError: |
| 887 | main.log.exception( self.name + ": Object not as expected" ) |
| 888 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 889 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 890 | main.log.error( self.name + ": EOF exception found" ) |
| 891 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 892 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 893 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 894 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 895 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 896 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 897 | def ports( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 898 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 899 | Lists all ports |
| 900 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 901 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 902 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 903 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 904 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 905 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 906 | cmdStr += " -j" |
| 907 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 908 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 909 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 910 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 911 | except AssertionError: |
| 912 | main.log.exception( "" ) |
| 913 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 914 | except TypeError: |
| 915 | main.log.exception( self.name + ": Object not as expected" ) |
| 916 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 917 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 918 | main.log.error( self.name + ": EOF exception found" ) |
| 919 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 920 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 921 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 922 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 923 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 924 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 925 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 926 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 927 | Lists all devices and the controllers with roles assigned to them |
| 928 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 929 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 930 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 931 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 932 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 933 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 934 | cmdStr += " -j" |
| 935 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 936 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 937 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 938 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 939 | except AssertionError: |
| 940 | main.log.exception( "" ) |
| 941 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 942 | except TypeError: |
| 943 | main.log.exception( self.name + ": Object not as expected" ) |
| 944 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 945 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 946 | main.log.error( self.name + ": EOF exception found" ) |
| 947 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 948 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 949 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 950 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 951 | main.cleanAndExit() |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 952 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 953 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 954 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 955 | Given the a string containing the json representation of the "roles" |
| 956 | cli command and a partial or whole device id, returns a json object |
| 957 | containing the roles output for the first device whose id contains |
| 958 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 959 | |
| 960 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 961 | A dict of the role assignments for the given device or |
| 962 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 963 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 964 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 965 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 966 | return None |
| 967 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 968 | rawRoles = self.roles() |
| 969 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 970 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 971 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 972 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 973 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 974 | return device |
| 975 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 976 | except ( TypeError, ValueError ): |
| 977 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 978 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 979 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 980 | main.log.error( self.name + ": EOF exception found" ) |
| 981 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 982 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 983 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 984 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 985 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 986 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 987 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 988 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 989 | Iterates through each device and checks if there is a master assigned |
| 990 | Returns: main.TRUE if each device has a master |
| 991 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 992 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 993 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 994 | rawRoles = self.roles() |
| 995 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 996 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 997 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 998 | # print device |
| 999 | if device[ 'master' ] == "none": |
| 1000 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1001 | return main.FALSE |
| 1002 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1003 | except ( TypeError, ValueError ): |
| 1004 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1005 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1006 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1007 | main.log.error( self.name + ": EOF exception found" ) |
| 1008 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1009 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1010 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1011 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1012 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1013 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1014 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1015 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1016 | Returns string of paths, and the cost. |
| 1017 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1018 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1019 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1020 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 1021 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1022 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1023 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1024 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1025 | main.log.error( "Error in getting paths" ) |
| 1026 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1027 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1028 | path = handle.split( ";" )[ 0 ] |
| 1029 | cost = handle.split( ";" )[ 1 ] |
| 1030 | return ( path, cost ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1031 | except AssertionError: |
| 1032 | main.log.exception( "" ) |
| 1033 | return ( handle, "Error" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1034 | except TypeError: |
| 1035 | main.log.exception( self.name + ": Object not as expected" ) |
| 1036 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1037 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1038 | main.log.error( self.name + ": EOF exception found" ) |
| 1039 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1040 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1041 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1042 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1043 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1044 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1045 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1046 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1047 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1048 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1049 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1050 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1051 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1052 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1053 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1054 | cmdStr += " -j" |
| 1055 | handle = self.sendline( cmdStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1056 | if handle: |
| 1057 | assert "Command not found:" not in handle, handle |
Jon Hall | baf5316 | 2015-12-17 17:04:34 -0800 | [diff] [blame] | 1058 | # TODO: Maybe make this less hardcoded |
| 1059 | # ConsistentMap Exceptions |
| 1060 | assert "org.onosproject.store.service" not in handle |
| 1061 | # Node not leader |
| 1062 | assert "java.lang.IllegalStateException" not in handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1063 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1064 | except AssertionError: |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1065 | main.log.exception( "Error in processing '" + cmdStr + "' " + |
Jeremy Songster | 6949cea | 2016-04-19 18:13:18 -0700 | [diff] [blame] | 1066 | "command: " + str( handle ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1067 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1068 | except TypeError: |
| 1069 | main.log.exception( self.name + ": Object not as expected" ) |
| 1070 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1071 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1072 | main.log.error( self.name + ": EOF exception found" ) |
| 1073 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1074 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1075 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1076 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1077 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1078 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1079 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1080 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1081 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1082 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1083 | 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] | 1084 | partial mac address |
| 1085 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1086 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1087 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1088 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1089 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1090 | return None |
| 1091 | else: |
| 1092 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1093 | rawHosts = self.hosts() |
| 1094 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1095 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1096 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1097 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1098 | if not host: |
| 1099 | pass |
| 1100 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1101 | return host |
| 1102 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1103 | except ( TypeError, ValueError ): |
| 1104 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1105 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1106 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1107 | main.log.error( self.name + ": EOF exception found" ) |
| 1108 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1109 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1110 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1111 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1112 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1113 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1114 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1115 | """ |
| 1116 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1117 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1118 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1119 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1120 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1121 | IMPORTANT: |
| 1122 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1123 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1124 | Furthermore, it assumes that value of VLAN is '-1' |
| 1125 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1126 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1127 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1128 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1129 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1130 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1131 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1132 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1133 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1134 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 1135 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 1136 | i = iter( str( hostHex ) ) |
| 1137 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 1138 | hostHex = hostHex + "/-1" |
| 1139 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1140 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1141 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1142 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1143 | except TypeError: |
| 1144 | main.log.exception( self.name + ": Object not as expected" ) |
| 1145 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1146 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1147 | main.log.error( self.name + ": EOF exception found" ) |
| 1148 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1149 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1150 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1151 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1152 | main.cleanAndExit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1153 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1154 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1155 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1156 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1157 | * hostIdOne: ONOS host id for host1 |
| 1158 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1159 | Optional: |
| 1160 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1161 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1162 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1163 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1164 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1165 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1166 | Returns: |
| 1167 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1168 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1169 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1170 | cmdStr = "add-host-intent " |
| 1171 | if vlanId: |
| 1172 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1173 | if setVlan: |
| 1174 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1175 | if encap: |
| 1176 | cmdStr += "--encapsulation " + str( encap ) + " " |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1177 | if bandwidth: |
| 1178 | cmdStr += "-b " + str( bandwidth ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1179 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1180 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1181 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1182 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1183 | if re.search( "Error", handle ): |
| 1184 | main.log.error( "Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1185 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1186 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1187 | else: |
| 1188 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1189 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1190 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1191 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1192 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1193 | else: |
| 1194 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1195 | main.log.debug( "Response from ONOS was: " + |
| 1196 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1197 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1198 | except AssertionError: |
| 1199 | main.log.exception( "" ) |
| 1200 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1201 | except TypeError: |
| 1202 | main.log.exception( self.name + ": Object not as expected" ) |
| 1203 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1204 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1205 | main.log.error( self.name + ": EOF exception found" ) |
| 1206 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1207 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1208 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1209 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1210 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1211 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1212 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1213 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1214 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1215 | * ingressDevice: device id of ingress device |
| 1216 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1217 | Optional: |
| 1218 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1219 | Description: |
| 1220 | Adds an optical intent by specifying an ingress and egress device |
| 1221 | Returns: |
| 1222 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1223 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1224 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1225 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1226 | " " + str( egressDevice ) |
| 1227 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1228 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1229 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1230 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1231 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1232 | main.log.error( "Error in adding Optical intent" ) |
| 1233 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1234 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1235 | main.log.info( "Optical intent installed between " + |
| 1236 | str( ingressDevice ) + " and " + |
| 1237 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1238 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1239 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1240 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1241 | else: |
| 1242 | main.log.error( "Error, intent ID not found" ) |
| 1243 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1244 | except AssertionError: |
| 1245 | main.log.exception( "" ) |
| 1246 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1247 | except TypeError: |
| 1248 | main.log.exception( self.name + ": Object not as expected" ) |
| 1249 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1250 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1251 | main.log.error( self.name + ": EOF exception found" ) |
| 1252 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1253 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1254 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1255 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1256 | main.cleanAndExit() |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1257 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1258 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1259 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1260 | ingressDevice, |
| 1261 | egressDevice, |
| 1262 | portIngress="", |
| 1263 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1264 | ethType="", |
| 1265 | ethSrc="", |
| 1266 | ethDst="", |
| 1267 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1268 | lambdaAlloc=False, |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1269 | protected=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1270 | ipProto="", |
| 1271 | ipSrc="", |
| 1272 | ipDst="", |
| 1273 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1274 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1275 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1276 | setVlan="", |
| 1277 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1278 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1279 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1280 | * ingressDevice: device id of ingress device |
| 1281 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1282 | Optional: |
| 1283 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1284 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1285 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1286 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1287 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1288 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1289 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1290 | * ipSrc: specify ip source address |
| 1291 | * ipDst: specify ip destination address |
| 1292 | * tcpSrc: specify tcp source port |
| 1293 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1294 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1295 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1296 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1297 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1298 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1299 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1300 | Returns: |
| 1301 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1302 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1303 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1304 | options developers provide for point-to-point |
| 1305 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1306 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1307 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1308 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1309 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1310 | if ethType: |
| 1311 | cmd += " --ethType " + str( ethType ) |
| 1312 | if ethSrc: |
| 1313 | cmd += " --ethSrc " + str( ethSrc ) |
| 1314 | if ethDst: |
| 1315 | cmd += " --ethDst " + str( ethDst ) |
| 1316 | if bandwidth: |
| 1317 | cmd += " --bandwidth " + str( bandwidth ) |
| 1318 | if lambdaAlloc: |
| 1319 | cmd += " --lambda " |
| 1320 | if ipProto: |
| 1321 | cmd += " --ipProto " + str( ipProto ) |
| 1322 | if ipSrc: |
| 1323 | cmd += " --ipSrc " + str( ipSrc ) |
| 1324 | if ipDst: |
| 1325 | cmd += " --ipDst " + str( ipDst ) |
| 1326 | if tcpSrc: |
| 1327 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1328 | if tcpDst: |
| 1329 | cmd += " --tcpDst " + str( tcpDst ) |
| 1330 | if vlanId: |
| 1331 | cmd += " -v " + str( vlanId ) |
| 1332 | if setVlan: |
| 1333 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1334 | if encap: |
| 1335 | cmd += " --encapsulation " + str( encap ) |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1336 | if protected: |
| 1337 | cmd += " --protect " |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1338 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1339 | # Check whether the user appended the port |
| 1340 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1341 | if "/" in ingressDevice: |
| 1342 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1343 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1344 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1345 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1346 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1347 | # Would it make sense to throw an exception and exit |
| 1348 | # the test? |
| 1349 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1350 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1351 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1352 | str( ingressDevice ) + "/" +\ |
| 1353 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1354 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1355 | if "/" in egressDevice: |
| 1356 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1357 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1358 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1359 | main.log.error( "You must specify the egress port" ) |
| 1360 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1361 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1362 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1363 | str( egressDevice ) + "/" +\ |
| 1364 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1365 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1366 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1367 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1368 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1369 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1370 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1371 | main.log.error( "Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1372 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1373 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1374 | # TODO: print out all the options in this message? |
| 1375 | main.log.info( "Point-to-point intent installed between " + |
| 1376 | str( ingressDevice ) + " and " + |
| 1377 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1378 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1379 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1380 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1381 | else: |
| 1382 | main.log.error( "Error, intent ID not found" ) |
| 1383 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1384 | except AssertionError: |
| 1385 | main.log.exception( "" ) |
| 1386 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1387 | except TypeError: |
| 1388 | main.log.exception( self.name + ": Object not as expected" ) |
| 1389 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1390 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1391 | main.log.error( self.name + ": EOF exception found" ) |
| 1392 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1393 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1394 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1395 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1396 | main.cleanAndExit() |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1397 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1398 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1399 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1400 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1401 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1402 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1403 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1404 | ethType="", |
| 1405 | ethSrc="", |
| 1406 | ethDst="", |
| 1407 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1408 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1409 | ipProto="", |
| 1410 | ipSrc="", |
| 1411 | ipDst="", |
| 1412 | tcpSrc="", |
| 1413 | tcpDst="", |
| 1414 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1415 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1416 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1417 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1418 | partial=False, |
| 1419 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1420 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1421 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1422 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1423 | is same. That is, all ingress devices include port numbers |
| 1424 | with a "/" or all ingress devices could specify device |
| 1425 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1426 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1427 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1428 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1429 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1430 | Optional: |
| 1431 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1432 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1433 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1434 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1435 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1436 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1437 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1438 | * ipSrc: specify ip source address |
| 1439 | * ipDst: specify ip destination address |
| 1440 | * tcpSrc: specify tcp source port |
| 1441 | * tcpDst: specify tcp destination port |
| 1442 | * setEthSrc: action to Rewrite Source MAC Address |
| 1443 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1444 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1445 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1446 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1447 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1448 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1449 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1450 | Returns: |
| 1451 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1452 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1453 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1454 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1455 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1456 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1457 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1458 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1459 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1460 | if ethType: |
| 1461 | cmd += " --ethType " + str( ethType ) |
| 1462 | if ethSrc: |
| 1463 | cmd += " --ethSrc " + str( ethSrc ) |
| 1464 | if ethDst: |
| 1465 | cmd += " --ethDst " + str( ethDst ) |
| 1466 | if bandwidth: |
| 1467 | cmd += " --bandwidth " + str( bandwidth ) |
| 1468 | if lambdaAlloc: |
| 1469 | cmd += " --lambda " |
| 1470 | if ipProto: |
| 1471 | cmd += " --ipProto " + str( ipProto ) |
| 1472 | if ipSrc: |
| 1473 | cmd += " --ipSrc " + str( ipSrc ) |
| 1474 | if ipDst: |
| 1475 | cmd += " --ipDst " + str( ipDst ) |
| 1476 | if tcpSrc: |
| 1477 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1478 | if tcpDst: |
| 1479 | cmd += " --tcpDst " + str( tcpDst ) |
| 1480 | if setEthSrc: |
| 1481 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1482 | if setEthDst: |
| 1483 | cmd += " --setEthDst " + str( setEthDst ) |
| 1484 | if vlanId: |
| 1485 | cmd += " -v " + str( vlanId ) |
| 1486 | if setVlan: |
| 1487 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1488 | if partial: |
| 1489 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1490 | if encap: |
| 1491 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1492 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1493 | # Check whether the user appended the port |
| 1494 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1495 | |
| 1496 | if portIngressList is None: |
| 1497 | for ingressDevice in ingressDeviceList: |
| 1498 | if "/" in ingressDevice: |
| 1499 | cmd += " " + str( ingressDevice ) |
| 1500 | else: |
| 1501 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1502 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1503 | # TODO: perhaps more meaningful return |
| 1504 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1505 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1506 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1507 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1508 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1509 | cmd += " " + \ |
| 1510 | str( ingressDevice ) + "/" +\ |
| 1511 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1512 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1513 | main.log.error( "Device list and port list does not " + |
| 1514 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1515 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1516 | if "/" in egressDevice: |
| 1517 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1518 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1519 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1520 | main.log.error( "You must specify " + |
| 1521 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1522 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1523 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1524 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1525 | str( egressDevice ) + "/" +\ |
| 1526 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1527 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1528 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1529 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1530 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1531 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1532 | main.log.error( "Error in adding multipoint-to-singlepoint " + |
| 1533 | "intent" ) |
| 1534 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1535 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1536 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1537 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1538 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1539 | else: |
| 1540 | main.log.error( "Error, intent ID not found" ) |
| 1541 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1542 | except AssertionError: |
| 1543 | main.log.exception( "" ) |
| 1544 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1545 | except TypeError: |
| 1546 | main.log.exception( self.name + ": Object not as expected" ) |
| 1547 | return None |
| 1548 | except pexpect.EOF: |
| 1549 | main.log.error( self.name + ": EOF exception found" ) |
| 1550 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1551 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1552 | except Exception: |
| 1553 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1554 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1555 | |
| 1556 | def addSinglepointToMultipointIntent( |
| 1557 | self, |
| 1558 | ingressDevice, |
| 1559 | egressDeviceList, |
| 1560 | portIngress="", |
| 1561 | portEgressList=None, |
| 1562 | ethType="", |
| 1563 | ethSrc="", |
| 1564 | ethDst="", |
| 1565 | bandwidth="", |
| 1566 | lambdaAlloc=False, |
| 1567 | ipProto="", |
| 1568 | ipSrc="", |
| 1569 | ipDst="", |
| 1570 | tcpSrc="", |
| 1571 | tcpDst="", |
| 1572 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1573 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1574 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1575 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1576 | partial=False, |
| 1577 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1578 | """ |
| 1579 | Note: |
| 1580 | This function assumes the format of all egress devices |
| 1581 | is same. That is, all egress devices include port numbers |
| 1582 | with a "/" or all egress devices could specify device |
| 1583 | ids and port numbers seperately. |
| 1584 | Required: |
| 1585 | * EgressDeviceList: List of device ids of egress device |
| 1586 | ( Atleast 2 eress devices required in the list ) |
| 1587 | * ingressDevice: device id of ingress device |
| 1588 | Optional: |
| 1589 | * ethType: specify ethType |
| 1590 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1591 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1592 | * bandwidth: specify bandwidth capacity of link |
| 1593 | * lambdaAlloc: if True, intent will allocate lambda |
| 1594 | for the specified intent |
| 1595 | * ipProto: specify ip protocol |
| 1596 | * ipSrc: specify ip source address |
| 1597 | * ipDst: specify ip destination address |
| 1598 | * tcpSrc: specify tcp source port |
| 1599 | * tcpDst: specify tcp destination port |
| 1600 | * setEthSrc: action to Rewrite Source MAC Address |
| 1601 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1602 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1603 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1604 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1605 | Description: |
| 1606 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1607 | specifying device id's and optional fields |
| 1608 | Returns: |
| 1609 | A string of the intent id or None on error |
| 1610 | |
| 1611 | NOTE: This function may change depending on the |
| 1612 | options developers provide for singlepoint-to-multipoint |
| 1613 | intent via cli |
| 1614 | """ |
| 1615 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1616 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1617 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1618 | if ethType: |
| 1619 | cmd += " --ethType " + str( ethType ) |
| 1620 | if ethSrc: |
| 1621 | cmd += " --ethSrc " + str( ethSrc ) |
| 1622 | if ethDst: |
| 1623 | cmd += " --ethDst " + str( ethDst ) |
| 1624 | if bandwidth: |
| 1625 | cmd += " --bandwidth " + str( bandwidth ) |
| 1626 | if lambdaAlloc: |
| 1627 | cmd += " --lambda " |
| 1628 | if ipProto: |
| 1629 | cmd += " --ipProto " + str( ipProto ) |
| 1630 | if ipSrc: |
| 1631 | cmd += " --ipSrc " + str( ipSrc ) |
| 1632 | if ipDst: |
| 1633 | cmd += " --ipDst " + str( ipDst ) |
| 1634 | if tcpSrc: |
| 1635 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1636 | if tcpDst: |
| 1637 | cmd += " --tcpDst " + str( tcpDst ) |
| 1638 | if setEthSrc: |
| 1639 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1640 | if setEthDst: |
| 1641 | cmd += " --setEthDst " + str( setEthDst ) |
| 1642 | if vlanId: |
| 1643 | cmd += " -v " + str( vlanId ) |
| 1644 | if setVlan: |
| 1645 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1646 | if partial: |
| 1647 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1648 | if encap: |
| 1649 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1650 | |
| 1651 | # Check whether the user appended the port |
| 1652 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1653 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1654 | if "/" in ingressDevice: |
| 1655 | cmd += " " + str( ingressDevice ) |
| 1656 | else: |
| 1657 | if not portIngress: |
| 1658 | main.log.error( "You must specify " + |
| 1659 | "the Ingress port" ) |
| 1660 | return main.FALSE |
| 1661 | |
| 1662 | cmd += " " +\ |
| 1663 | str( ingressDevice ) + "/" +\ |
| 1664 | str( portIngress ) |
| 1665 | |
| 1666 | if portEgressList is None: |
| 1667 | for egressDevice in egressDeviceList: |
| 1668 | if "/" in egressDevice: |
| 1669 | cmd += " " + str( egressDevice ) |
| 1670 | else: |
| 1671 | main.log.error( "You must specify " + |
| 1672 | "the egress port" ) |
| 1673 | # TODO: perhaps more meaningful return |
| 1674 | return main.FALSE |
| 1675 | else: |
| 1676 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1677 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1678 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1679 | cmd += " " + \ |
| 1680 | str( egressDevice ) + "/" +\ |
| 1681 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1682 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1683 | main.log.error( "Device list and port list does not " + |
| 1684 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1685 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1686 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1687 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1688 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1689 | # If error, return error message |
| 1690 | if re.search( "Error", handle ): |
| 1691 | main.log.error( "Error in adding singlepoint-to-multipoint " + |
| 1692 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1693 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1694 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1695 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1696 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1697 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1698 | else: |
| 1699 | main.log.error( "Error, intent ID not found" ) |
| 1700 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1701 | except AssertionError: |
| 1702 | main.log.exception( "" ) |
| 1703 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1704 | except TypeError: |
| 1705 | main.log.exception( self.name + ": Object not as expected" ) |
| 1706 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1707 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1708 | main.log.error( self.name + ": EOF exception found" ) |
| 1709 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1710 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1711 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1712 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1713 | main.cleanAndExit() |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1714 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1715 | def addMplsIntent( |
| 1716 | self, |
| 1717 | ingressDevice, |
| 1718 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1719 | ingressPort="", |
| 1720 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1721 | ethType="", |
| 1722 | ethSrc="", |
| 1723 | ethDst="", |
| 1724 | bandwidth="", |
| 1725 | lambdaAlloc=False, |
| 1726 | ipProto="", |
| 1727 | ipSrc="", |
| 1728 | ipDst="", |
| 1729 | tcpSrc="", |
| 1730 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1731 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1732 | egressLabel="", |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1733 | priority="" ): |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1734 | """ |
| 1735 | Required: |
| 1736 | * ingressDevice: device id of ingress device |
| 1737 | * egressDevice: device id of egress device |
| 1738 | Optional: |
| 1739 | * ethType: specify ethType |
| 1740 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1741 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1742 | * bandwidth: specify bandwidth capacity of link |
| 1743 | * lambdaAlloc: if True, intent will allocate lambda |
| 1744 | for the specified intent |
| 1745 | * ipProto: specify ip protocol |
| 1746 | * ipSrc: specify ip source address |
| 1747 | * ipDst: specify ip destination address |
| 1748 | * tcpSrc: specify tcp source port |
| 1749 | * tcpDst: specify tcp destination port |
| 1750 | * ingressLabel: Ingress MPLS label |
| 1751 | * egressLabel: Egress MPLS label |
| 1752 | Description: |
| 1753 | Adds MPLS intent by |
| 1754 | specifying device id's and optional fields |
| 1755 | Returns: |
| 1756 | A string of the intent id or None on error |
| 1757 | |
| 1758 | NOTE: This function may change depending on the |
| 1759 | options developers provide for MPLS |
| 1760 | intent via cli |
| 1761 | """ |
| 1762 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1763 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1764 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1765 | if ethType: |
| 1766 | cmd += " --ethType " + str( ethType ) |
| 1767 | if ethSrc: |
| 1768 | cmd += " --ethSrc " + str( ethSrc ) |
| 1769 | if ethDst: |
| 1770 | cmd += " --ethDst " + str( ethDst ) |
| 1771 | if bandwidth: |
| 1772 | cmd += " --bandwidth " + str( bandwidth ) |
| 1773 | if lambdaAlloc: |
| 1774 | cmd += " --lambda " |
| 1775 | if ipProto: |
| 1776 | cmd += " --ipProto " + str( ipProto ) |
| 1777 | if ipSrc: |
| 1778 | cmd += " --ipSrc " + str( ipSrc ) |
| 1779 | if ipDst: |
| 1780 | cmd += " --ipDst " + str( ipDst ) |
| 1781 | if tcpSrc: |
| 1782 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1783 | if tcpDst: |
| 1784 | cmd += " --tcpDst " + str( tcpDst ) |
| 1785 | if ingressLabel: |
| 1786 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 1787 | if egressLabel: |
| 1788 | cmd += " --egressLabel " + str( egressLabel ) |
| 1789 | if priority: |
| 1790 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1791 | |
| 1792 | # Check whether the user appended the port |
| 1793 | # or provided it as an input |
| 1794 | if "/" in ingressDevice: |
| 1795 | cmd += " " + str( ingressDevice ) |
| 1796 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1797 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1798 | main.log.error( "You must specify the ingress port" ) |
| 1799 | return None |
| 1800 | |
| 1801 | cmd += " " + \ |
| 1802 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1803 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1804 | |
| 1805 | if "/" in egressDevice: |
| 1806 | cmd += " " + str( egressDevice ) |
| 1807 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1808 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1809 | main.log.error( "You must specify the egress port" ) |
| 1810 | return None |
| 1811 | |
| 1812 | cmd += " " +\ |
| 1813 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1814 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1815 | |
| 1816 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1817 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1818 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1819 | # If error, return error message |
| 1820 | if re.search( "Error", handle ): |
| 1821 | main.log.error( "Error in adding mpls intent" ) |
| 1822 | return None |
| 1823 | else: |
| 1824 | # TODO: print out all the options in this message? |
| 1825 | main.log.info( "MPLS intent installed between " + |
| 1826 | str( ingressDevice ) + " and " + |
| 1827 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1828 | match = re.search( 'id=0x([\da-f]+),', handle ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1829 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1830 | return match.group()[ 3:-1 ] |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1831 | else: |
| 1832 | main.log.error( "Error, intent ID not found" ) |
| 1833 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1834 | except AssertionError: |
| 1835 | main.log.exception( "" ) |
| 1836 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1837 | except TypeError: |
| 1838 | main.log.exception( self.name + ": Object not as expected" ) |
| 1839 | return None |
| 1840 | except pexpect.EOF: |
| 1841 | main.log.error( self.name + ": EOF exception found" ) |
| 1842 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1843 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1844 | except Exception: |
| 1845 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1846 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1847 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1848 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 1849 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1850 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1851 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1852 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1853 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1854 | -p or --purge: Purge the intent from the store after removal |
| 1855 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1856 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 1857 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1858 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1859 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1860 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1861 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1862 | if purge: |
| 1863 | cmdStr += " -p" |
| 1864 | if sync: |
| 1865 | cmdStr += " -s" |
| 1866 | |
| 1867 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1868 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1869 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1870 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1871 | if re.search( "Error", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1872 | main.log.error( "Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1873 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1874 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1875 | # TODO: Should this be main.TRUE |
| 1876 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1877 | except AssertionError: |
| 1878 | main.log.exception( "" ) |
| 1879 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1880 | except TypeError: |
| 1881 | main.log.exception( self.name + ": Object not as expected" ) |
| 1882 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1883 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1884 | main.log.error( self.name + ": EOF exception found" ) |
| 1885 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1886 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1887 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1888 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1889 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1890 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1891 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1892 | """ |
| 1893 | Description: |
| 1894 | Remove all the intents |
| 1895 | Optional args:- |
| 1896 | -s or --sync: Waits for the removal before returning |
| 1897 | -p or --purge: Purge the intent from the store after removal |
| 1898 | Returns: |
| 1899 | Returns main.TRUE if all intents are removed, otherwise returns |
| 1900 | main.FALSE; Returns None for exception |
| 1901 | """ |
| 1902 | try: |
| 1903 | cmdStr = "remove-intent" |
| 1904 | if purge: |
| 1905 | cmdStr += " -p" |
| 1906 | if sync: |
| 1907 | cmdStr += " -s" |
| 1908 | |
| 1909 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1910 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1911 | assert handle is not None, "Error in sendline" |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1912 | assert "Command not found:" not in handle, handle |
| 1913 | if re.search( "Error", handle ): |
| 1914 | main.log.error( "Error in removing intent" ) |
| 1915 | return main.FALSE |
| 1916 | else: |
| 1917 | return main.TRUE |
| 1918 | except AssertionError: |
| 1919 | main.log.exception( "" ) |
| 1920 | return None |
| 1921 | except TypeError: |
| 1922 | main.log.exception( self.name + ": Object not as expected" ) |
| 1923 | return None |
| 1924 | except pexpect.EOF: |
| 1925 | main.log.error( self.name + ": EOF exception found" ) |
| 1926 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1927 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1928 | except Exception: |
| 1929 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1930 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1931 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 1932 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1933 | """ |
| 1934 | Purges all WITHDRAWN Intents |
| 1935 | """ |
| 1936 | try: |
| 1937 | cmdStr = "purge-intents" |
| 1938 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1939 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1940 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1941 | if re.search( "Error", handle ): |
| 1942 | main.log.error( "Error in purging intents" ) |
| 1943 | return main.FALSE |
| 1944 | else: |
| 1945 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1946 | except AssertionError: |
| 1947 | main.log.exception( "" ) |
| 1948 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1949 | except TypeError: |
| 1950 | main.log.exception( self.name + ": Object not as expected" ) |
| 1951 | return None |
| 1952 | except pexpect.EOF: |
| 1953 | main.log.error( self.name + ": EOF exception found" ) |
| 1954 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1955 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1956 | except Exception: |
| 1957 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1958 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1959 | |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 1960 | def wipeout( self ): |
| 1961 | """ |
| 1962 | Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS. |
| 1963 | """ |
| 1964 | try: |
| 1965 | cmdStr = "wipe-out please" |
| 1966 | handle = self.sendline( cmdStr, timeout=60 ) |
| 1967 | assert handle is not None, "Error in sendline" |
| 1968 | assert "Command not found:" not in handle, handle |
| 1969 | return main.TRUE |
| 1970 | except AssertionError: |
| 1971 | main.log.exception( "" ) |
| 1972 | return None |
| 1973 | except TypeError: |
| 1974 | main.log.exception( self.name + ": Object not as expected" ) |
| 1975 | return None |
| 1976 | except pexpect.EOF: |
| 1977 | main.log.error( self.name + ": EOF exception found" ) |
| 1978 | main.log.error( self.name + ": " + self.handle.before ) |
| 1979 | main.cleanAndExit() |
| 1980 | except Exception: |
| 1981 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1982 | main.cleanAndExit() |
| 1983 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1984 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1985 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1986 | NOTE: This method should be used after installing application: |
| 1987 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1988 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1989 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1990 | Description: |
| 1991 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1992 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1993 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1994 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1995 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1996 | cmdStr += " -j" |
| 1997 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1998 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1999 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2000 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2001 | except AssertionError: |
| 2002 | main.log.exception( "" ) |
| 2003 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2004 | except TypeError: |
| 2005 | main.log.exception( self.name + ": Object not as expected" ) |
| 2006 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2007 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2008 | main.log.error( self.name + ": EOF exception found" ) |
| 2009 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2010 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2011 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2012 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2013 | main.cleanAndExit() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2014 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2015 | def ipv4RouteNumber( self ): |
| 2016 | """ |
| 2017 | NOTE: This method should be used after installing application: |
| 2018 | onos-app-sdnip |
| 2019 | Description: |
| 2020 | Obtain the total IPv4 routes number in the system |
| 2021 | """ |
| 2022 | try: |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2023 | cmdStr = "routes -j" |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2024 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2025 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2026 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2027 | jsonResult = json.loads( handle ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2028 | return len( jsonResult[ 'routes4' ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2029 | except AssertionError: |
| 2030 | main.log.exception( "" ) |
| 2031 | return None |
| 2032 | except ( TypeError, ValueError ): |
| 2033 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2034 | return None |
| 2035 | except pexpect.EOF: |
| 2036 | main.log.error( self.name + ": EOF exception found" ) |
| 2037 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2038 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2039 | except Exception: |
| 2040 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2041 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2042 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2043 | # =============Function to check Bandwidth allocation======== |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2044 | def allocations( self, jsonFormat = True, dollarSign = True ): |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2045 | """ |
| 2046 | Description: |
| 2047 | Obtain Bandwidth Allocation Information from ONOS cli. |
| 2048 | """ |
| 2049 | try: |
| 2050 | cmdStr = "allocations" |
| 2051 | if jsonFormat: |
| 2052 | cmdStr += " -j" |
| 2053 | handle = self.sendline( cmdStr, timeout=300, dollarSign=True ) |
| 2054 | assert handle is not None, "Error in sendline" |
| 2055 | assert "Command not found:" not in handle, handle |
| 2056 | return handle |
| 2057 | except AssertionError: |
| 2058 | main.log.exception( "" ) |
| 2059 | return None |
| 2060 | except ( TypeError, ValueError ): |
| 2061 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
| 2062 | return None |
| 2063 | except pexpect.EOF: |
| 2064 | main.log.error( self.name + ": EOF exception found" ) |
| 2065 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2066 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2067 | except Exception: |
| 2068 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2069 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2070 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2071 | def intents( self, jsonFormat = True, summary = False, **intentargs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2072 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2073 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2074 | Obtain intents from the ONOS cli. |
| 2075 | Optional: |
| 2076 | * jsonFormat: Enable output formatting in json, default to True |
| 2077 | * summary: Whether only output the intent summary, defaults to False |
| 2078 | * type: Only output a certain type of intent. This options is valid |
| 2079 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2080 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2081 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2082 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2083 | if summary: |
| 2084 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2085 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2086 | cmdStr += " -j" |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2087 | handle = self.sendline( cmdStr, timeout=300 ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2088 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2089 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2090 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2091 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2092 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2093 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2094 | intentType = "" |
| 2095 | # IF we want the summary of a specific intent type |
| 2096 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2097 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2098 | if intentType in jsonResult.keys(): |
| 2099 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2100 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2101 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2102 | return handle |
| 2103 | else: |
| 2104 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2105 | except AssertionError: |
| 2106 | main.log.exception( "" ) |
| 2107 | return None |
| 2108 | except ( TypeError, ValueError ): |
| 2109 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2110 | return None |
| 2111 | except pexpect.EOF: |
| 2112 | main.log.error( self.name + ": EOF exception found" ) |
| 2113 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2114 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2115 | except Exception: |
| 2116 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2117 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2118 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2119 | def getIntentState( self, intentsId, intentsJson=None ): |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2120 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2121 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2122 | Gets intent state. Accepts a single intent ID (string type) or a |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2123 | list of intent IDs. |
| 2124 | Parameters: |
| 2125 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2126 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2127 | Returns: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2128 | 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] | 2129 | accepted. |
| 2130 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2131 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2132 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2133 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2134 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2135 | try: |
| 2136 | state = "State is Undefined" |
| 2137 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2138 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2139 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2140 | rawJson = intentsJson |
| 2141 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2142 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2143 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2144 | if intentsId == intent[ 'id' ]: |
| 2145 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2146 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2147 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2148 | " in the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2149 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2150 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2151 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2152 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2153 | stateDict = {} |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2154 | for intent in parsedIntentsJson: |
| 2155 | if intentsId[ i ] == intent[ 'id' ]: |
| 2156 | stateDict[ 'state' ] = intent[ 'state' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2157 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2158 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2159 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2160 | if len( intentsId ) != len( dictList ): |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2161 | main.log.warn( "Could not find all intents in ONOS output" ) |
| 2162 | main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2163 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2164 | else: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2165 | main.log.info( "Invalid type for intentsId argument" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2166 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2167 | except ( TypeError, ValueError ): |
| 2168 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2169 | return None |
| 2170 | except pexpect.EOF: |
| 2171 | main.log.error( self.name + ": EOF exception found" ) |
| 2172 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2173 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2174 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2175 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2176 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2177 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2178 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2179 | """ |
| 2180 | Description: |
| 2181 | Check intents state |
| 2182 | Required: |
| 2183 | intentsId - List of intents ID to be checked |
| 2184 | Optional: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2185 | expectedState - Check the expected state(s) of each intents |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2186 | state in the list. |
| 2187 | *NOTE: You can pass in a list of expected state, |
| 2188 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2189 | Return: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2190 | Returns main.TRUE only if all intent are the same as expected states, |
| 2191 | otherwise returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2192 | """ |
| 2193 | try: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2194 | returnValue = main.TRUE |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2195 | # Generating a dictionary: intent id as a key and state as value |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2196 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2197 | # intentsDict = self.getIntentState( intentsId ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2198 | intentsDict = [] |
| 2199 | for intent in json.loads( self.intents() ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2200 | if isinstance( intentsId, types.StringType ) \ |
| 2201 | and intent.get( 'id' ) == intentsId: |
| 2202 | intentsDict.append( intent ) |
| 2203 | elif isinstance( intentsId, types.ListType ) \ |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2204 | and any( intent.get( 'id' ) == ids for ids in intentsId ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2205 | intentsDict.append( intent ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2206 | |
| 2207 | if not intentsDict: |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2208 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2209 | "getting intents state" ) |
| 2210 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2211 | |
| 2212 | if isinstance( expectedState, types.StringType ): |
| 2213 | for intents in intentsDict: |
| 2214 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2215 | main.log.debug( self.name + " : Intent ID - " + |
| 2216 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2217 | " actual state = " + |
| 2218 | intents.get( 'state' ) |
| 2219 | + " does not equal expected state = " |
| 2220 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2221 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2222 | elif isinstance( expectedState, types.ListType ): |
| 2223 | for intents in intentsDict: |
| 2224 | if not any( state == intents.get( 'state' ) for state in |
| 2225 | expectedState ): |
| 2226 | main.log.debug( self.name + " : Intent ID - " + |
| 2227 | intents.get( 'id' ) + |
| 2228 | " actual state = " + |
| 2229 | intents.get( 'state' ) + |
| 2230 | " does not equal expected states = " |
| 2231 | + str( expectedState ) ) |
| 2232 | returnValue = main.FALSE |
| 2233 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2234 | if returnValue == main.TRUE: |
| 2235 | main.log.info( self.name + ": All " + |
| 2236 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2237 | " intents are in " + str( expectedState ) + |
| 2238 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2239 | return returnValue |
| 2240 | except TypeError: |
| 2241 | main.log.exception( self.name + ": Object not as expected" ) |
| 2242 | return None |
| 2243 | except pexpect.EOF: |
| 2244 | main.log.error( self.name + ": EOF exception found" ) |
| 2245 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2246 | main.cleanAndExit() |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2247 | except Exception: |
| 2248 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2249 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2250 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2251 | def compareBandwidthAllocations( self, expectedAllocations ): |
| 2252 | """ |
| 2253 | Description: |
| 2254 | Compare the allocated bandwidth with the given allocations |
| 2255 | Required: |
| 2256 | expectedAllocations - The expected ONOS output of the allocations command |
| 2257 | Return: |
| 2258 | Returns main.TRUE only if all intent are the same as expected states, |
| 2259 | otherwise returns main.FALSE. |
| 2260 | """ |
| 2261 | # FIXME: Convert these string comparisons to object comparisons |
| 2262 | try: |
| 2263 | returnValue = main.TRUE |
| 2264 | bandwidthFailed = False |
| 2265 | rawAlloc = self.allocations() |
| 2266 | expectedFormat = StringIO( expectedAllocations ) |
| 2267 | ONOSOutput = StringIO( rawAlloc ) |
| 2268 | main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ), |
| 2269 | str( expectedFormat ) ) ) |
| 2270 | |
| 2271 | for actual, expected in izip( ONOSOutput, expectedFormat ): |
| 2272 | actual = actual.rstrip() |
| 2273 | expected = expected.rstrip() |
| 2274 | main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) ) |
| 2275 | if actual != expected and 'allocated' in actual and 'allocated' in expected: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2276 | marker1 = actual.find( 'allocated' ) |
| 2277 | m1 = actual[ :marker1 ] |
| 2278 | marker2 = expected.find( 'allocated' ) |
| 2279 | m2 = expected[ :marker2 ] |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2280 | if m1 != m2: |
| 2281 | bandwidthFailed = True |
| 2282 | elif actual != expected and 'allocated' not in actual and 'allocated' not in expected: |
| 2283 | bandwidthFailed = True |
| 2284 | expectedFormat.close() |
| 2285 | ONOSOutput.close() |
| 2286 | |
| 2287 | if bandwidthFailed: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2288 | main.log.error( "Bandwidth not allocated correctly using Intents!!" ) |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2289 | returnValue = main.FALSE |
| 2290 | return returnValue |
| 2291 | except TypeError: |
| 2292 | main.log.exception( self.name + ": Object not as expected" ) |
| 2293 | return None |
| 2294 | except pexpect.EOF: |
| 2295 | main.log.error( self.name + ": EOF exception found" ) |
| 2296 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2297 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2298 | except Exception: |
| 2299 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2300 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2301 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2302 | def compareIntent( self, intentDict ): |
| 2303 | """ |
| 2304 | Description: |
| 2305 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2306 | Return: |
| 2307 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2308 | Arguments: |
| 2309 | intentDict: a dictionary which maps intent ids to intent states |
| 2310 | """ |
| 2311 | try: |
| 2312 | intentsRaw = self.intents() |
| 2313 | intentsJson = json.loads( intentsRaw ) |
| 2314 | intentDictONOS = {} |
| 2315 | for intent in intentsJson: |
| 2316 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2317 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2318 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2319 | 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] | 2320 | str( len( intentDict ) ) + " expected and " + |
| 2321 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2322 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2323 | for intentID in intentDict.keys(): |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2324 | if intentID not in intentDictONOS.keys(): |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2325 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2326 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2327 | else: |
| 2328 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2329 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2330 | " expected state is " + intentDict[ intentID ] + |
| 2331 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2332 | returnValue = main.FALSE |
| 2333 | intentDictONOS.pop( intentID ) |
| 2334 | if len( intentDictONOS ) > 0: |
| 2335 | returnValue = main.FALSE |
| 2336 | for intentID in intentDictONOS.keys(): |
| 2337 | 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] | 2338 | if returnValue == main.TRUE: |
| 2339 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2340 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2341 | except KeyError: |
| 2342 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2343 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2344 | except ( TypeError, ValueError ): |
| 2345 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2346 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2347 | except pexpect.EOF: |
| 2348 | main.log.error( self.name + ": EOF exception found" ) |
| 2349 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2350 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2351 | except Exception: |
| 2352 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2353 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2354 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2355 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2356 | """ |
| 2357 | Description: |
| 2358 | Check the number of installed intents. |
| 2359 | Optional: |
| 2360 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2361 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2362 | Return: |
| 2363 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2364 | , otherwise, returns main.FALSE. |
| 2365 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2366 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2367 | try: |
| 2368 | cmd = "intents -s -j" |
| 2369 | |
| 2370 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2371 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2372 | if response is None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2373 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2374 | response = json.loads( response ) |
| 2375 | |
| 2376 | # get total and installed number, see if they are match |
| 2377 | allState = response.get( 'all' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2378 | if allState.get( 'total' ) == allState.get( 'installed' ): |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2379 | main.log.info( 'Total Intents: {} Installed Intents: {}'.format( |
| 2380 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2381 | return main.TRUE |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2382 | main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format( |
| 2383 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2384 | return main.FALSE |
| 2385 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2386 | except ( TypeError, ValueError ): |
| 2387 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2388 | return None |
| 2389 | except pexpect.EOF: |
| 2390 | main.log.error( self.name + ": EOF exception found" ) |
| 2391 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2392 | if noExit: |
| 2393 | return main.FALSE |
| 2394 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2395 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2396 | except pexpect.TIMEOUT: |
| 2397 | main.log.error( self.name + ": ONOS timeout" ) |
| 2398 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2399 | except Exception: |
| 2400 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2401 | if noExit: |
| 2402 | return main.FALSE |
| 2403 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2404 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2405 | |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2406 | def flows( self, state="", jsonFormat=True, timeout=60, noExit=False, noCore=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2407 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2408 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2409 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2410 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2411 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2412 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2413 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2414 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2415 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2416 | if jsonFormat: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2417 | cmdStr += " -j " |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2418 | if noCore: |
| 2419 | cmdStr += " -n " |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2420 | cmdStr += state |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2421 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2422 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2423 | assert "Command not found:" not in handle, handle |
| 2424 | if re.search( "Error:", handle ): |
| 2425 | main.log.error( self.name + ": flows() response: " + |
| 2426 | str( handle ) ) |
| 2427 | return handle |
| 2428 | except AssertionError: |
| 2429 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2430 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2431 | except TypeError: |
| 2432 | main.log.exception( self.name + ": Object not as expected" ) |
| 2433 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2434 | except pexpect.TIMEOUT: |
| 2435 | main.log.error( self.name + ": ONOS timeout" ) |
| 2436 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2437 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2438 | main.log.error( self.name + ": EOF exception found" ) |
| 2439 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2440 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2441 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2442 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2443 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2444 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2445 | def checkFlowCount( self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2446 | count = self.getTotalFlowsNum( timeout=timeout ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2447 | count = int( count ) if count else 0 |
| 2448 | return count if ( count > min ) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2449 | |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2450 | def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2451 | """ |
| 2452 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2453 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2454 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2455 | if the count of those states is 0, which means all current flows |
| 2456 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2457 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2458 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2459 | Return: |
| 2460 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2461 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2462 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2463 | """ |
| 2464 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2465 | states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2466 | checkedStates = [] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2467 | statesCount = [ 0, 0, 0, 0 ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2468 | for s in states: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2469 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2470 | if rawFlows: |
| 2471 | # if we didn't get flows or flows function return None, we should return |
| 2472 | # main.Flase |
| 2473 | checkedStates.append( json.loads( rawFlows ) ) |
| 2474 | else: |
| 2475 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2476 | for i in range( len( states ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2477 | for c in checkedStates[ i ]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2478 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2479 | statesCount[ i ] += int( c.get( "flowCount" ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2480 | except TypeError: |
| 2481 | main.log.exception( "Json object not as expected" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2482 | main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2483 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2484 | # We want to count PENDING_ADD if isPENDING is true |
| 2485 | if isPENDING: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2486 | if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2487 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2488 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2489 | if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2490 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2491 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2492 | except ( TypeError, ValueError ): |
| 2493 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2494 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2495 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2496 | except AssertionError: |
| 2497 | main.log.exception( "" ) |
| 2498 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2499 | except pexpect.TIMEOUT: |
| 2500 | main.log.error( self.name + ": ONOS timeout" ) |
| 2501 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2502 | except pexpect.EOF: |
| 2503 | main.log.error( self.name + ": EOF exception found" ) |
| 2504 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2505 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2506 | except Exception: |
| 2507 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2508 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2509 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2510 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2511 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2512 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2513 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2514 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2515 | a specific point-to-point intent definition |
| 2516 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2517 | * ingress: specify source dpid |
| 2518 | * egress: specify destination dpid |
| 2519 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2520 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2521 | * offset: the keyOffset is where the next batch of intents |
| 2522 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2523 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2524 | * getResponse: If set to True, function will return ONOS response. |
| 2525 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2526 | Returns: If failed to push test intents, it will returen None, |
| 2527 | if successful, return true. |
| 2528 | Timeout expection will return None, |
| 2529 | TypeError will return false |
| 2530 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2531 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2532 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2533 | if background: |
| 2534 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2535 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2536 | back = "" |
| 2537 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2538 | ingress, |
| 2539 | egress, |
| 2540 | batchSize, |
| 2541 | offset, |
| 2542 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2543 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2544 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2545 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2546 | main.log.info( response ) |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2547 | if getResponse: |
| 2548 | return response |
| 2549 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2550 | # TODO: We should handle if there is failure in installation |
| 2551 | return main.TRUE |
| 2552 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2553 | except AssertionError: |
| 2554 | main.log.exception( "" ) |
| 2555 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2556 | except pexpect.TIMEOUT: |
| 2557 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2558 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2559 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2560 | main.log.error( self.name + ": EOF exception found" ) |
| 2561 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2562 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2563 | except TypeError: |
| 2564 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2565 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2566 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2567 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2568 | main.cleanAndExit() |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2569 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2570 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2571 | """ |
| 2572 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2573 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2574 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2575 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2576 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2577 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2578 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2579 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2580 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2581 | cmd = "flows -c added" |
| 2582 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2583 | if rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2584 | rawFlows = rawFlows.split( "\n" ) |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2585 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2586 | for l in rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2587 | totalFlows += int( l.split( "Count=" )[ 1 ] ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2588 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2589 | main.log.error( "Response not as expected!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2590 | return None |
| 2591 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2592 | |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2593 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2594 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2595 | return None |
| 2596 | except pexpect.EOF: |
| 2597 | main.log.error( self.name + ": EOF exception found" ) |
| 2598 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2599 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2600 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2601 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2602 | except pexpect.TIMEOUT: |
| 2603 | main.log.error( self.name + ": ONOS timeout" ) |
| 2604 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2605 | except Exception: |
| 2606 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2607 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2608 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2609 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2610 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2611 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2612 | """ |
| 2613 | Description: |
| 2614 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2615 | Optional: |
| 2616 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2617 | Return: |
| 2618 | The number of intents |
| 2619 | """ |
| 2620 | try: |
| 2621 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2622 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2623 | if response is None: |
| 2624 | return -1 |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2625 | response = json.loads( response ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2626 | return int( response.get( "intents" ) ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2627 | except ( TypeError, ValueError ): |
| 2628 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2629 | return None |
| 2630 | except pexpect.EOF: |
| 2631 | main.log.error( self.name + ": EOF exception found" ) |
| 2632 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2633 | if noExit: |
| 2634 | return -1 |
| 2635 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2636 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2637 | except Exception: |
| 2638 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2639 | if noExit: |
| 2640 | return -1 |
| 2641 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2642 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2643 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2644 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2645 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2646 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2647 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2648 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2649 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2650 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2651 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2652 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2653 | cmdStr += " -j" |
| 2654 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2655 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2656 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2657 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2658 | except AssertionError: |
| 2659 | main.log.exception( "" ) |
| 2660 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2661 | except TypeError: |
| 2662 | main.log.exception( self.name + ": Object not as expected" ) |
| 2663 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2664 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2665 | main.log.error( self.name + ": EOF exception found" ) |
| 2666 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2667 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2668 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2669 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2670 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2671 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2672 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2673 | """ |
| 2674 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2675 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2676 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2677 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2678 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2679 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2680 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2681 | cmdStr += " -j" |
| 2682 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2683 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2684 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2685 | if handle: |
| 2686 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2687 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2688 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2689 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2690 | else: |
| 2691 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2692 | except AssertionError: |
| 2693 | main.log.exception( "" ) |
| 2694 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2695 | except TypeError: |
| 2696 | main.log.exception( self.name + ": Object not as expected" ) |
| 2697 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2698 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2699 | main.log.error( self.name + ": EOF exception found" ) |
| 2700 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2701 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2702 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2703 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2704 | main.cleanAndExit() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2705 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2706 | # Wrapper functions **************** |
| 2707 | # Wrapper functions use existing driver |
| 2708 | # functions and extends their use case. |
| 2709 | # For example, we may use the output of |
| 2710 | # a normal driver function, and parse it |
| 2711 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2712 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2713 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2714 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2715 | Description: |
| 2716 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2717 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2718 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2719 | # Obtain output of intents function |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2720 | intentsStr = self.intents( jsonFormat=True ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 2721 | if intentsStr is None: |
| 2722 | raise TypeError |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2723 | # Convert to a dictionary |
| 2724 | intents = json.loads( intentsStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2725 | intentIdList = [] |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2726 | for intent in intents: |
| 2727 | intentIdList.append( intent[ 'id' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2728 | return intentIdList |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2729 | except TypeError: |
| 2730 | main.log.exception( self.name + ": Object not as expected" ) |
| 2731 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2732 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2733 | main.log.error( self.name + ": EOF exception found" ) |
| 2734 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2735 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2736 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2737 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2738 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2739 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2740 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2741 | """ |
| 2742 | Determine the number of flow rules for the given device id that are |
| 2743 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2744 | Params: |
| 2745 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2746 | """ |
| 2747 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2748 | if core: |
| 2749 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2750 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2751 | else: |
| 2752 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2753 | "grep 'state=ADDED' | wc -l" |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2754 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2755 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2756 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2757 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2758 | except AssertionError: |
| 2759 | main.log.exception( "" ) |
| 2760 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2761 | except pexpect.EOF: |
| 2762 | main.log.error( self.name + ": EOF exception found" ) |
| 2763 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2764 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2765 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2766 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2767 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2768 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2769 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2770 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2771 | Use 'devices' function to obtain list of all devices |
| 2772 | and parse the result to obtain a list of all device |
| 2773 | id's. Returns this list. Returns empty list if no |
| 2774 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2775 | List is ordered sequentially |
| 2776 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2777 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2778 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2779 | the ids. By obtaining the list of device ids on the fly, |
| 2780 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2781 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2782 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2783 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2784 | devicesStr = self.devices( jsonFormat=False ) |
| 2785 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2786 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2787 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2788 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2789 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2790 | |
| 2791 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2792 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2793 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2794 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2795 | # Split list further into arguments before and after string |
| 2796 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2797 | # append to idList |
| 2798 | for arg in tempList: |
| 2799 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 2800 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2801 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2802 | except TypeError: |
| 2803 | main.log.exception( self.name + ": Object not as expected" ) |
| 2804 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2805 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2806 | main.log.error( self.name + ": EOF exception found" ) |
| 2807 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2808 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2809 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2810 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2811 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2812 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2813 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2814 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2815 | Uses 'nodes' function to obtain list of all nodes |
| 2816 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2817 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2818 | Returns: |
| 2819 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2820 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2821 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2822 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2823 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2824 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 2825 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2826 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2827 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2828 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2829 | nodesJson = json.loads( nodesStr ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2830 | idList = [ node.get( 'id' ) for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2831 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2832 | except ( TypeError, ValueError ): |
| 2833 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2834 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2835 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2836 | main.log.error( self.name + ": EOF exception found" ) |
| 2837 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2838 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2839 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2840 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2841 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2842 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2843 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2844 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2845 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 2846 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2847 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2848 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2849 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2850 | return None |
| 2851 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2852 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2853 | rawDevices = self.devices() |
| 2854 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2855 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2856 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2857 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 2858 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2859 | return device |
| 2860 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2861 | except ( TypeError, ValueError ): |
| 2862 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2863 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2864 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2865 | main.log.error( self.name + ": EOF exception found" ) |
| 2866 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2867 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2868 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2869 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2870 | main.cleanAndExit() |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2871 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2872 | def getTopology( self, topologyOutput ): |
| 2873 | """ |
| 2874 | Definition: |
| 2875 | Loads a json topology output |
| 2876 | Return: |
| 2877 | topology = current ONOS topology |
| 2878 | """ |
| 2879 | import json |
| 2880 | try: |
| 2881 | # either onos:topology or 'topology' will work in CLI |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2882 | topology = json.loads( topologyOutput ) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 2883 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2884 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2885 | except ( TypeError, ValueError ): |
| 2886 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 2887 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2888 | except pexpect.EOF: |
| 2889 | main.log.error( self.name + ": EOF exception found" ) |
| 2890 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2891 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2892 | except Exception: |
| 2893 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2894 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2895 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2896 | def checkStatus( self, numoswitch, numolink, numoctrl = -1, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2897 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2898 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2899 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2900 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2901 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2902 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2903 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2904 | numoctrl = expected number of controllers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2905 | logLevel = level to log to. |
| 2906 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2907 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2908 | Returns: main.TRUE if the number of switches and links are correct, |
| 2909 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2910 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2911 | """ |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2912 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2913 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 2914 | summary = self.summary() |
| 2915 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 2916 | except ( TypeError, ValueError ): |
| 2917 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 2918 | return main.ERROR |
| 2919 | try: |
| 2920 | topology = self.getTopology( self.topology() ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2921 | if topology == {} or topology is None or summary == {} or summary is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2922 | return main.ERROR |
| 2923 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2924 | # Is the number of switches is what we expected |
| 2925 | devices = topology.get( 'devices', False ) |
| 2926 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2927 | nodes = summary.get( 'nodes', False ) |
| 2928 | if devices is False or links is False or nodes is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2929 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2930 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2931 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2932 | linkCheck = ( int( links ) == int( numolink ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2933 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
| 2934 | if switchCheck and linkCheck and nodeCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2935 | # We expected the correct numbers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2936 | output = output + "The number of links and switches match "\ |
| 2937 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2938 | result = main.TRUE |
| 2939 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2940 | output = output + \ |
| 2941 | "The number of links and switches does not match " + \ |
| 2942 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2943 | result = main.FALSE |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2944 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 2945 | output = output + " (%i expected) " % int( numoswitch ) |
| 2946 | output = output + "and %i links " % int( links ) |
| 2947 | output = output + "(%i expected)" % int( numolink ) |
YPZhang | d7e4b6e | 2016-06-17 16:07:55 -0700 | [diff] [blame] | 2948 | if int( numoctrl ) > 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 2949 | output = output + "and %i controllers " % int( nodes ) |
| 2950 | output = output + "(%i expected)" % int( numoctrl ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2951 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2952 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2953 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2954 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2955 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 2956 | main.log.info( output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2957 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 2958 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2959 | main.log.error( self.name + ": EOF exception found" ) |
| 2960 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2961 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2962 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2963 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2964 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2965 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2966 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2967 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2968 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2969 | deviceId must be the id of a device as seen in the onos devices command |
| 2970 | 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] | 2971 | role must be either master, standby, or none |
| 2972 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2973 | Returns: |
| 2974 | main.TRUE or main.FALSE based on argument verification and |
| 2975 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2976 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2977 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2978 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2979 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2980 | cmdStr = "device-role " +\ |
| 2981 | str( deviceId ) + " " +\ |
| 2982 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2983 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2984 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2985 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2986 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2987 | if re.search( "Error", handle ): |
| 2988 | # end color output to escape any colours |
| 2989 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2990 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2991 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2992 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2993 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2994 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2995 | main.log.error( "Invalid 'role' given to device_role(). " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2996 | "Value was '" + str( role ) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 2997 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2998 | except AssertionError: |
| 2999 | main.log.exception( "" ) |
| 3000 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3001 | except TypeError: |
| 3002 | main.log.exception( self.name + ": Object not as expected" ) |
| 3003 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3004 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3005 | main.log.error( self.name + ": EOF exception found" ) |
| 3006 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3007 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3008 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3009 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3010 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3011 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3012 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3013 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3014 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 3015 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3016 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3017 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3018 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3019 | cmdStr = "clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3020 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3021 | cmdStr += " -j" |
| 3022 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3023 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3024 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3025 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3026 | except AssertionError: |
| 3027 | main.log.exception( "" ) |
| 3028 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3029 | except TypeError: |
| 3030 | main.log.exception( self.name + ": Object not as expected" ) |
| 3031 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3032 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3033 | main.log.error( self.name + ": EOF exception found" ) |
| 3034 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3035 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3036 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3037 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3038 | main.cleanAndExit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3039 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3040 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3041 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3042 | CLI command to get the current leader for the Election test application |
| 3043 | NOTE: Requires installation of the onos-app-election feature |
| 3044 | Returns: Node IP of the leader if one exists |
| 3045 | None if none exists |
| 3046 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3047 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3048 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3049 | cmdStr = "election-test-leader" |
| 3050 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3051 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3052 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3053 | # Leader |
| 3054 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3055 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3056 | nodeSearch = re.search( leaderPattern, response ) |
| 3057 | if nodeSearch: |
| 3058 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3059 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3060 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3061 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3062 | # no leader |
| 3063 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3064 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3065 | nullSearch = re.search( nullPattern, response ) |
| 3066 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3067 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3068 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3069 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3070 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3071 | main.log.error( "Error in electionTestLeader on " + self.name + |
| 3072 | ": " + "unexpected response" ) |
| 3073 | main.log.error( repr( response ) ) |
| 3074 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3075 | except AssertionError: |
| 3076 | main.log.exception( "" ) |
| 3077 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3078 | except TypeError: |
| 3079 | main.log.exception( self.name + ": Object not as expected" ) |
| 3080 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3081 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3082 | main.log.error( self.name + ": EOF exception found" ) |
| 3083 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3084 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3085 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3086 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3087 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3088 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3089 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3090 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3091 | CLI command to run for leadership of the Election test application. |
| 3092 | NOTE: Requires installation of the onos-app-election feature |
| 3093 | Returns: Main.TRUE on success |
| 3094 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3095 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3096 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3097 | cmdStr = "election-test-run" |
| 3098 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3099 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3100 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3101 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3102 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3103 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3104 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3105 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3106 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3107 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3108 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3109 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3110 | main.log.error( "Error in electionTestRun on " + self.name + |
| 3111 | ": " + "unexpected response" ) |
| 3112 | main.log.error( repr( response ) ) |
| 3113 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3114 | except AssertionError: |
| 3115 | main.log.exception( "" ) |
| 3116 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3117 | except TypeError: |
| 3118 | main.log.exception( self.name + ": Object not as expected" ) |
| 3119 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3120 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3121 | main.log.error( self.name + ": EOF exception found" ) |
| 3122 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3123 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3124 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3125 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3126 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3127 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3128 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3129 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3130 | * CLI command to withdraw the local node from leadership election for |
| 3131 | * the Election test application. |
| 3132 | #NOTE: Requires installation of the onos-app-election feature |
| 3133 | Returns: Main.TRUE on success |
| 3134 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3135 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3136 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3137 | cmdStr = "election-test-withdraw" |
| 3138 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3139 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3140 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3141 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3142 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3143 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3144 | if re.search( successPattern, response ): |
| 3145 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3146 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3147 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3148 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3149 | main.log.error( "Error in electionTestWithdraw on " + |
| 3150 | self.name + ": " + "unexpected response" ) |
| 3151 | main.log.error( repr( response ) ) |
| 3152 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3153 | except AssertionError: |
| 3154 | main.log.exception( "" ) |
| 3155 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3156 | except TypeError: |
| 3157 | main.log.exception( self.name + ": Object not as expected" ) |
| 3158 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3159 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3160 | main.log.error( self.name + ": EOF exception found" ) |
| 3161 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3162 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3163 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3164 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3165 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3166 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3167 | def getDevicePortsEnabledCount( self, dpid ): |
| 3168 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3169 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3170 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3171 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3172 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3173 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 3174 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3175 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3176 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3177 | if re.search( "No such device", output ): |
| 3178 | main.log.error( "Error in getting ports" ) |
| 3179 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3180 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3181 | except AssertionError: |
| 3182 | main.log.exception( "" ) |
| 3183 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3184 | except TypeError: |
| 3185 | main.log.exception( self.name + ": Object not as expected" ) |
| 3186 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3187 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3188 | main.log.error( self.name + ": EOF exception found" ) |
| 3189 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3190 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3191 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3192 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3193 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3194 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3195 | def getDeviceLinksActiveCount( self, dpid ): |
| 3196 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3197 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3198 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3199 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3200 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3201 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 3202 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3203 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3204 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3205 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3206 | main.log.error( "Error in getting ports " ) |
| 3207 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3208 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3209 | except AssertionError: |
| 3210 | main.log.exception( "" ) |
| 3211 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3212 | except TypeError: |
| 3213 | main.log.exception( self.name + ": Object not as expected" ) |
| 3214 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3215 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3216 | main.log.error( self.name + ": EOF exception found" ) |
| 3217 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3218 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3219 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3220 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3221 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3222 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3223 | def getAllIntentIds( self ): |
| 3224 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3225 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3226 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3227 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3228 | cmdStr = "onos:intents | grep id=" |
| 3229 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3230 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3231 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3232 | if re.search( "Error", output ): |
| 3233 | main.log.error( "Error in getting ports" ) |
| 3234 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3235 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3236 | except AssertionError: |
| 3237 | main.log.exception( "" ) |
| 3238 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3239 | except TypeError: |
| 3240 | main.log.exception( self.name + ": Object not as expected" ) |
| 3241 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3242 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3243 | main.log.error( self.name + ": EOF exception found" ) |
| 3244 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3245 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3246 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3247 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3248 | main.cleanAndExit() |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3249 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3250 | def intentSummary( self ): |
| 3251 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3252 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3253 | """ |
| 3254 | try: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3255 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3256 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3257 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3258 | states.append( intent.get( 'state', None ) ) |
| 3259 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3260 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3261 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3262 | except ( TypeError, ValueError ): |
| 3263 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3264 | return None |
| 3265 | except pexpect.EOF: |
| 3266 | main.log.error( self.name + ": EOF exception found" ) |
| 3267 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3268 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3269 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3270 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3271 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3272 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3273 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3274 | """ |
| 3275 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3276 | Optional argument: |
| 3277 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3278 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3279 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3280 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3281 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3282 | cmdStr += " -j" |
| 3283 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3284 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3285 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3286 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3287 | except AssertionError: |
| 3288 | main.log.exception( "" ) |
| 3289 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3290 | except TypeError: |
| 3291 | main.log.exception( self.name + ": Object not as expected" ) |
| 3292 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3293 | except pexpect.EOF: |
| 3294 | main.log.error( self.name + ": EOF exception found" ) |
| 3295 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3296 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3297 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3298 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3299 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3300 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3301 | def leaderCandidates( self, jsonFormat=True ): |
| 3302 | """ |
| 3303 | Returns the output of the leaders -c command. |
| 3304 | Optional argument: |
| 3305 | * jsonFormat - boolean indicating if you want output in json |
| 3306 | """ |
| 3307 | try: |
| 3308 | cmdStr = "onos:leaders -c" |
| 3309 | if jsonFormat: |
| 3310 | cmdStr += " -j" |
| 3311 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3312 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3313 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3314 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3315 | except AssertionError: |
| 3316 | main.log.exception( "" ) |
| 3317 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3318 | except TypeError: |
| 3319 | main.log.exception( self.name + ": Object not as expected" ) |
| 3320 | return None |
| 3321 | except pexpect.EOF: |
| 3322 | main.log.error( self.name + ": EOF exception found" ) |
| 3323 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3324 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3325 | except Exception: |
| 3326 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3327 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3328 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3329 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3330 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3331 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3332 | topic parameter and an empty list if the topic doesn't exist |
| 3333 | If no leader is elected leader in the returned list will be "none" |
| 3334 | Returns None if there is a type error processing the json object |
| 3335 | """ |
| 3336 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3337 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3338 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3339 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3340 | assert "Command not found:" not in rawOutput, rawOutput |
| 3341 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3342 | results = [] |
| 3343 | for dict in output: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3344 | if dict[ "topic" ] == topic: |
| 3345 | leader = dict[ "leader" ] |
| 3346 | candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3347 | results.append( leader ) |
| 3348 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3349 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3350 | except AssertionError: |
| 3351 | main.log.exception( "" ) |
| 3352 | return None |
| 3353 | except ( TypeError, ValueError ): |
| 3354 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3355 | return None |
| 3356 | except pexpect.EOF: |
| 3357 | main.log.error( self.name + ": EOF exception found" ) |
| 3358 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3359 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3360 | except Exception: |
| 3361 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3362 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3363 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3364 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3365 | """ |
| 3366 | Returns the output of the intent Pending map. |
| 3367 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3368 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3369 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3370 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3371 | cmdStr += " -j" |
| 3372 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3373 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3374 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3375 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3376 | except AssertionError: |
| 3377 | main.log.exception( "" ) |
| 3378 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3379 | except TypeError: |
| 3380 | main.log.exception( self.name + ": Object not as expected" ) |
| 3381 | return None |
| 3382 | except pexpect.EOF: |
| 3383 | main.log.error( self.name + ": EOF exception found" ) |
| 3384 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3385 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3386 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3387 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3388 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3389 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3390 | def partitions( self, candidates=False, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3391 | """ |
| 3392 | Returns the output of the raft partitions command for ONOS. |
| 3393 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3394 | # Sample JSON |
| 3395 | # { |
| 3396 | # "leader": "tcp://10.128.30.11:7238", |
| 3397 | # "members": [ |
| 3398 | # "tcp://10.128.30.11:7238", |
| 3399 | # "tcp://10.128.30.17:7238", |
| 3400 | # "tcp://10.128.30.13:7238", |
| 3401 | # ], |
| 3402 | # "name": "p1", |
| 3403 | # "term": 3 |
| 3404 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3405 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3406 | cmdStr = "onos:partitions" |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3407 | if candidates: |
| 3408 | cmdStr += " -c" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3409 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3410 | cmdStr += " -j" |
| 3411 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3412 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3413 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3414 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3415 | except AssertionError: |
| 3416 | main.log.exception( "" ) |
| 3417 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3418 | except TypeError: |
| 3419 | main.log.exception( self.name + ": Object not as expected" ) |
| 3420 | return None |
| 3421 | except pexpect.EOF: |
| 3422 | main.log.error( self.name + ": EOF exception found" ) |
| 3423 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3424 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3425 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3426 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3427 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3428 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3429 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3430 | """ |
| 3431 | Returns the output of the apps command for ONOS. This command lists |
| 3432 | information about installed ONOS applications |
| 3433 | """ |
| 3434 | # Sample JSON object |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3435 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3436 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3437 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3438 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3439 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3440 | cmdStr = "onos:apps" |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3441 | if summary: |
| 3442 | cmdStr += " -s" |
| 3443 | if active: |
| 3444 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3445 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3446 | cmdStr += " -j" |
| 3447 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3448 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3449 | assert "Command not found:" not in output, output |
| 3450 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3451 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3452 | # FIXME: look at specific exceptions/Errors |
| 3453 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3454 | main.log.exception( "Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3455 | return None |
| 3456 | except TypeError: |
| 3457 | main.log.exception( self.name + ": Object not as expected" ) |
| 3458 | return None |
| 3459 | except pexpect.EOF: |
| 3460 | main.log.error( self.name + ": EOF exception found" ) |
| 3461 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3462 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3463 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3464 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3465 | main.cleanAndExit() |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3466 | |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3467 | def appStatus( self, appName ): |
| 3468 | """ |
| 3469 | Uses the onos:apps cli command to return the status of an application. |
| 3470 | Returns: |
| 3471 | "ACTIVE" - If app is installed and activated |
| 3472 | "INSTALLED" - If app is installed and deactivated |
| 3473 | "UNINSTALLED" - If app is not installed |
| 3474 | None - on error |
| 3475 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3476 | try: |
| 3477 | if not isinstance( appName, types.StringType ): |
| 3478 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3479 | " a string" ) |
| 3480 | return None |
| 3481 | output = self.apps( jsonFormat=True ) |
| 3482 | appsJson = json.loads( output ) |
| 3483 | state = None |
| 3484 | for app in appsJson: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3485 | if appName == app.get( 'name' ): |
| 3486 | state = app.get( 'state' ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3487 | break |
| 3488 | if state == "ACTIVE" or state == "INSTALLED": |
| 3489 | return state |
| 3490 | elif state is None: |
Jon Hall | 8bafdc0 | 2017-09-05 11:36:26 -0700 | [diff] [blame] | 3491 | main.log.warn( "{} app not found", appName ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3492 | return "UNINSTALLED" |
| 3493 | elif state: |
| 3494 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3495 | str( state ) ) |
| 3496 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3497 | except ( TypeError, ValueError ): |
| 3498 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3499 | return None |
| 3500 | except pexpect.EOF: |
| 3501 | main.log.error( self.name + ": EOF exception found" ) |
| 3502 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3503 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3504 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3505 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3506 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3507 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3508 | def app( self, appName, option ): |
| 3509 | """ |
| 3510 | Interacts with the app command for ONOS. This command manages |
| 3511 | application inventory. |
| 3512 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3513 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3514 | # Validate argument types |
| 3515 | valid = True |
| 3516 | if not isinstance( appName, types.StringType ): |
| 3517 | main.log.error( self.name + ".app(): appName must be a " + |
| 3518 | "string" ) |
| 3519 | valid = False |
| 3520 | if not isinstance( option, types.StringType ): |
| 3521 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3522 | valid = False |
| 3523 | if not valid: |
| 3524 | return main.FALSE |
| 3525 | # Validate Option |
| 3526 | option = option.lower() |
| 3527 | # NOTE: Install may become a valid option |
| 3528 | if option == "activate": |
| 3529 | pass |
| 3530 | elif option == "deactivate": |
| 3531 | pass |
| 3532 | elif option == "uninstall": |
| 3533 | pass |
| 3534 | else: |
| 3535 | # Invalid option |
| 3536 | main.log.error( "The ONOS app command argument only takes " + |
| 3537 | "the values: (activate|deactivate|uninstall)" + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3538 | "; was given '" + option + "'" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3539 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3540 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3541 | output = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3542 | assert output is not None, "Error in sendline" |
| 3543 | assert "Command not found:" not in output, output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3544 | if "Error executing command" in output: |
| 3545 | main.log.error( "Error in processing onos:app command: " + |
| 3546 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3547 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3548 | elif "No such application" in output: |
| 3549 | main.log.error( "The application '" + appName + |
| 3550 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3551 | return main.FALSE |
| 3552 | elif "Command not found:" in output: |
| 3553 | main.log.error( "Error in processing onos:app command: " + |
| 3554 | str( output ) ) |
| 3555 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3556 | elif "Unsupported command:" in output: |
| 3557 | main.log.error( "Incorrect command given to 'app': " + |
| 3558 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3559 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3560 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3561 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3562 | return main.TRUE |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3563 | except AssertionError: |
| 3564 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 3565 | return main.ERROR |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3566 | except TypeError: |
| 3567 | main.log.exception( self.name + ": Object not as expected" ) |
| 3568 | return main.ERROR |
| 3569 | except pexpect.EOF: |
| 3570 | main.log.error( self.name + ": EOF exception found" ) |
| 3571 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3572 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3573 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3574 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3575 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3576 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3577 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3578 | """ |
| 3579 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3580 | appName is the hierarchical app name, not the feature name |
| 3581 | If check is True, method will check the status of the app after the |
| 3582 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3583 | Returns main.TRUE if the command was successfully sent |
| 3584 | main.FALSE if the cli responded with an error or given |
| 3585 | incorrect input |
| 3586 | """ |
| 3587 | try: |
| 3588 | if not isinstance( appName, types.StringType ): |
| 3589 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3590 | " a string" ) |
| 3591 | return main.FALSE |
| 3592 | status = self.appStatus( appName ) |
| 3593 | if status == "INSTALLED": |
| 3594 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3595 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3596 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3597 | status = self.appStatus( appName ) |
| 3598 | if status == "ACTIVE": |
| 3599 | return main.TRUE |
| 3600 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3601 | main.log.debug( "The state of application " + |
| 3602 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3603 | time.sleep( 1 ) |
| 3604 | return main.FALSE |
| 3605 | else: # not 'check' or command didn't succeed |
| 3606 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3607 | elif status == "ACTIVE": |
| 3608 | return main.TRUE |
| 3609 | elif status == "UNINSTALLED": |
| 3610 | main.log.error( self.name + ": Tried to activate the " + |
| 3611 | "application '" + appName + "' which is not " + |
| 3612 | "installed." ) |
| 3613 | else: |
| 3614 | main.log.error( "Unexpected return value from appStatus: " + |
| 3615 | str( status ) ) |
| 3616 | return main.ERROR |
| 3617 | except TypeError: |
| 3618 | main.log.exception( self.name + ": Object not as expected" ) |
| 3619 | return main.ERROR |
| 3620 | except pexpect.EOF: |
| 3621 | main.log.error( self.name + ": EOF exception found" ) |
| 3622 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3623 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3624 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3625 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3626 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3627 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3628 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3629 | """ |
| 3630 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3631 | appName is the hierarchical app name, not the feature name |
| 3632 | If check is True, method will check the status of the app after the |
| 3633 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3634 | Returns main.TRUE if the command was successfully sent |
| 3635 | main.FALSE if the cli responded with an error or given |
| 3636 | incorrect input |
| 3637 | """ |
| 3638 | try: |
| 3639 | if not isinstance( appName, types.StringType ): |
| 3640 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 3641 | "be a string" ) |
| 3642 | return main.FALSE |
| 3643 | status = self.appStatus( appName ) |
| 3644 | if status == "INSTALLED": |
| 3645 | return main.TRUE |
| 3646 | elif status == "ACTIVE": |
| 3647 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3648 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3649 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3650 | status = self.appStatus( appName ) |
| 3651 | if status == "INSTALLED": |
| 3652 | return main.TRUE |
| 3653 | else: |
| 3654 | time.sleep( 1 ) |
| 3655 | return main.FALSE |
| 3656 | else: # not check or command didn't succeed |
| 3657 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3658 | elif status == "UNINSTALLED": |
| 3659 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 3660 | "application '" + appName + "' which is not " + |
| 3661 | "installed." ) |
| 3662 | return main.TRUE |
| 3663 | else: |
| 3664 | main.log.error( "Unexpected return value from appStatus: " + |
| 3665 | str( status ) ) |
| 3666 | return main.ERROR |
| 3667 | except TypeError: |
| 3668 | main.log.exception( self.name + ": Object not as expected" ) |
| 3669 | return main.ERROR |
| 3670 | except pexpect.EOF: |
| 3671 | main.log.error( self.name + ": EOF exception found" ) |
| 3672 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3673 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3674 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3675 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3676 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3677 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3678 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3679 | """ |
| 3680 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3681 | appName is the hierarchical app name, not the feature name |
| 3682 | If check is True, method will check the status of the app after the |
| 3683 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3684 | Returns main.TRUE if the command was successfully sent |
| 3685 | main.FALSE if the cli responded with an error or given |
| 3686 | incorrect input |
| 3687 | """ |
| 3688 | # TODO: check with Thomas about the state machine for apps |
| 3689 | try: |
| 3690 | if not isinstance( appName, types.StringType ): |
| 3691 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 3692 | "be a string" ) |
| 3693 | return main.FALSE |
| 3694 | status = self.appStatus( appName ) |
| 3695 | if status == "INSTALLED": |
| 3696 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3697 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3698 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3699 | status = self.appStatus( appName ) |
| 3700 | if status == "UNINSTALLED": |
| 3701 | return main.TRUE |
| 3702 | else: |
| 3703 | time.sleep( 1 ) |
| 3704 | return main.FALSE |
| 3705 | else: # not check or command didn't succeed |
| 3706 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3707 | elif status == "ACTIVE": |
| 3708 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 3709 | "application '" + appName + "' which is " + |
| 3710 | "currently active." ) |
| 3711 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3712 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3713 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3714 | status = self.appStatus( appName ) |
| 3715 | if status == "UNINSTALLED": |
| 3716 | return main.TRUE |
| 3717 | else: |
| 3718 | time.sleep( 1 ) |
| 3719 | return main.FALSE |
| 3720 | else: # not check or command didn't succeed |
| 3721 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3722 | elif status == "UNINSTALLED": |
| 3723 | return main.TRUE |
| 3724 | else: |
| 3725 | main.log.error( "Unexpected return value from appStatus: " + |
| 3726 | str( status ) ) |
| 3727 | return main.ERROR |
| 3728 | except TypeError: |
| 3729 | main.log.exception( self.name + ": Object not as expected" ) |
| 3730 | return main.ERROR |
| 3731 | except pexpect.EOF: |
| 3732 | main.log.error( self.name + ": EOF exception found" ) |
| 3733 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3734 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3735 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3736 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3737 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3738 | |
| 3739 | def appIDs( self, jsonFormat=True ): |
| 3740 | """ |
| 3741 | Show the mappings between app id and app names given by the 'app-ids' |
| 3742 | cli command |
| 3743 | """ |
| 3744 | try: |
| 3745 | cmdStr = "app-ids" |
| 3746 | if jsonFormat: |
| 3747 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3748 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3749 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3750 | assert "Command not found:" not in output, output |
| 3751 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3752 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3753 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3754 | main.log.exception( "Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3755 | return None |
| 3756 | except TypeError: |
| 3757 | main.log.exception( self.name + ": Object not as expected" ) |
| 3758 | return None |
| 3759 | except pexpect.EOF: |
| 3760 | main.log.error( self.name + ": EOF exception found" ) |
| 3761 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3762 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3763 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3764 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3765 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3766 | |
| 3767 | def appToIDCheck( self ): |
| 3768 | """ |
| 3769 | This method will check that each application's ID listed in 'apps' is |
| 3770 | the same as the ID listed in 'app-ids'. The check will also check that |
| 3771 | there are no duplicate IDs issued. Note that an app ID should be |
| 3772 | a globaly unique numerical identifier for app/app-like features. Once |
| 3773 | an ID is registered, the ID is never freed up so that if an app is |
| 3774 | reinstalled it will have the same ID. |
| 3775 | |
| 3776 | Returns: main.TRUE if the check passes and |
| 3777 | main.FALSE if the check fails or |
| 3778 | main.ERROR if there is some error in processing the test |
| 3779 | """ |
| 3780 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3781 | bail = False |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3782 | rawJson = self.appIDs( jsonFormat=True ) |
| 3783 | if rawJson: |
| 3784 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3785 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3786 | main.log.error( "app-ids returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3787 | bail = True |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3788 | rawJson = self.apps( jsonFormat=True ) |
| 3789 | if rawJson: |
| 3790 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3791 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3792 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3793 | bail = True |
| 3794 | if bail: |
| 3795 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3796 | result = main.TRUE |
| 3797 | for app in apps: |
| 3798 | appID = app.get( 'id' ) |
| 3799 | if appID is None: |
| 3800 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3801 | result = main.FALSE |
| 3802 | appName = app.get( 'name' ) |
| 3803 | if appName is None: |
| 3804 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3805 | result = main.FALSE |
| 3806 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3807 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3808 | # main.log.debug( "Comparing " + str( app ) + " to " + |
| 3809 | # str( current ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3810 | if not current: # if ids doesn't have this id |
| 3811 | result = main.FALSE |
| 3812 | main.log.error( "'app-ids' does not have the ID for " + |
| 3813 | str( appName ) + " that apps does." ) |
| 3814 | elif len( current ) > 1: |
| 3815 | # there is more than one app with this ID |
| 3816 | result = main.FALSE |
| 3817 | # We will log this later in the method |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3818 | elif not current[ 0 ][ 'name' ] == appName: |
| 3819 | currentName = current[ 0 ][ 'name' ] |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3820 | result = main.FALSE |
| 3821 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 3822 | " registered under id:" + str( appID ) + |
| 3823 | " but 'apps' has " + str( appName ) ) |
| 3824 | else: |
| 3825 | pass # id and name match! |
| 3826 | # now make sure that app-ids has no duplicates |
| 3827 | idsList = [] |
| 3828 | namesList = [] |
| 3829 | for item in ids: |
| 3830 | idsList.append( item[ 'id' ] ) |
| 3831 | namesList.append( item[ 'name' ] ) |
| 3832 | if len( idsList ) != len( set( idsList ) ) or\ |
| 3833 | len( namesList ) != len( set( namesList ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3834 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 3835 | + json.dumps( ids, |
| 3836 | sort_keys=True, |
| 3837 | indent=4, |
| 3838 | separators=( ',', ': ' ) ) ) |
| 3839 | result = main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3840 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3841 | except ( TypeError, ValueError ): |
| 3842 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3843 | return main.ERROR |
| 3844 | except pexpect.EOF: |
| 3845 | main.log.error( self.name + ": EOF exception found" ) |
| 3846 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3847 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3848 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3849 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3850 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3851 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3852 | def getCfg( self, component=None, propName=None, short=False, |
| 3853 | jsonFormat=True ): |
| 3854 | """ |
| 3855 | Get configuration settings from onos cli |
| 3856 | Optional arguments: |
| 3857 | component - Optionally only list configurations for a specific |
| 3858 | component. If None, all components with configurations |
| 3859 | are displayed. Case Sensitive string. |
| 3860 | propName - If component is specified, propName option will show |
| 3861 | only this specific configuration from that component. |
| 3862 | Case Sensitive string. |
| 3863 | jsonFormat - Returns output as json. Note that this will override |
| 3864 | the short option |
| 3865 | short - Short, less verbose, version of configurations. |
| 3866 | This is overridden by the json option |
| 3867 | returns: |
| 3868 | Output from cli as a string or None on error |
| 3869 | """ |
| 3870 | try: |
| 3871 | baseStr = "cfg" |
| 3872 | cmdStr = " get" |
| 3873 | componentStr = "" |
| 3874 | if component: |
| 3875 | componentStr += " " + component |
| 3876 | if propName: |
| 3877 | componentStr += " " + propName |
| 3878 | if jsonFormat: |
| 3879 | baseStr += " -j" |
| 3880 | elif short: |
| 3881 | baseStr += " -s" |
| 3882 | output = self.sendline( baseStr + cmdStr + componentStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3883 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3884 | assert "Command not found:" not in output, output |
| 3885 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3886 | return output |
| 3887 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3888 | main.log.exception( "Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3889 | return None |
| 3890 | except TypeError: |
| 3891 | main.log.exception( self.name + ": Object not as expected" ) |
| 3892 | return None |
| 3893 | except pexpect.EOF: |
| 3894 | main.log.error( self.name + ": EOF exception found" ) |
| 3895 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3896 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3897 | except Exception: |
| 3898 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3899 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3900 | |
| 3901 | def setCfg( self, component, propName, value=None, check=True ): |
| 3902 | """ |
| 3903 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3904 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3905 | component - The case sensitive name of the component whose |
| 3906 | property is to be set |
| 3907 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3908 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3909 | 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] | 3910 | property and revert it to it's default value(if applicable) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3911 | check - Boolean, Check whether the option was successfully set this |
| 3912 | only applies when a value is given. |
| 3913 | returns: |
| 3914 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 3915 | will return main.TRUE unless there is an error |
| 3916 | """ |
| 3917 | try: |
| 3918 | baseStr = "cfg" |
| 3919 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 3920 | if value is not None: |
| 3921 | cmdStr += " " + str( value ) |
| 3922 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3923 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3924 | assert "Command not found:" not in output, output |
| 3925 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3926 | if value and check: |
| 3927 | results = self.getCfg( component=str( component ), |
| 3928 | propName=str( propName ), |
| 3929 | jsonFormat=True ) |
| 3930 | # Check if current value is what we just set |
| 3931 | try: |
| 3932 | jsonOutput = json.loads( results ) |
| 3933 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3934 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3935 | main.log.exception( "Error parsing cfg output" ) |
| 3936 | main.log.error( "output:" + repr( results ) ) |
| 3937 | return main.FALSE |
| 3938 | if current == str( value ): |
| 3939 | return main.TRUE |
| 3940 | return main.FALSE |
| 3941 | return main.TRUE |
| 3942 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3943 | main.log.exception( "Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3944 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3945 | except ( TypeError, ValueError ): |
| 3946 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3947 | return main.FALSE |
| 3948 | except pexpect.EOF: |
| 3949 | main.log.error( self.name + ": EOF exception found" ) |
| 3950 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3951 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3952 | except Exception: |
| 3953 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3954 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3955 | |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 3956 | def distPrimitivesSend( self, cmd ): |
| 3957 | """ |
| 3958 | Function to handle sending cli commands for the distributed primitives test app |
| 3959 | |
| 3960 | This command will catch some exceptions and retry the command on some |
| 3961 | specific store exceptions. |
| 3962 | |
| 3963 | Required arguments: |
| 3964 | cmd - The command to send to the cli |
| 3965 | returns: |
| 3966 | string containing the cli output |
| 3967 | None on Error |
| 3968 | """ |
| 3969 | try: |
| 3970 | output = self.sendline( cmd ) |
| 3971 | try: |
| 3972 | assert output is not None, "Error in sendline" |
| 3973 | # TODO: Maybe make this less hardcoded |
| 3974 | # ConsistentMap Exceptions |
| 3975 | assert "org.onosproject.store.service" not in output |
| 3976 | # Node not leader |
| 3977 | assert "java.lang.IllegalStateException" not in output |
| 3978 | except AssertionError: |
| 3979 | main.log.error( "Error in processing '" + cmd + "' " + |
| 3980 | "command: " + str( output ) ) |
| 3981 | retryTime = 30 # Conservative time, given by Madan |
| 3982 | main.log.info( "Waiting " + str( retryTime ) + |
| 3983 | "seconds before retrying." ) |
| 3984 | time.sleep( retryTime ) # Due to change in mastership |
| 3985 | output = self.sendline( cmd ) |
| 3986 | assert output is not None, "Error in sendline" |
| 3987 | assert "Command not found:" not in output, output |
| 3988 | assert "Error executing command" not in output, output |
| 3989 | main.log.info( self.name + ": " + output ) |
| 3990 | return output |
| 3991 | except AssertionError: |
| 3992 | main.log.exception( "Error in processing '" + cmd + "' command." ) |
| 3993 | return None |
| 3994 | except TypeError: |
| 3995 | main.log.exception( self.name + ": Object not as expected" ) |
| 3996 | return None |
| 3997 | except pexpect.EOF: |
| 3998 | main.log.error( self.name + ": EOF exception found" ) |
| 3999 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4000 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4001 | except Exception: |
| 4002 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4003 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4004 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4005 | def setTestAdd( self, setName, values ): |
| 4006 | """ |
| 4007 | CLI command to add elements to a distributed set. |
| 4008 | Arguments: |
| 4009 | setName - The name of the set to add to. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4010 | values - The value(s) to add to the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4011 | Example usages: |
| 4012 | setTestAdd( "set1", "a b c" ) |
| 4013 | setTestAdd( "set2", "1" ) |
| 4014 | returns: |
| 4015 | main.TRUE on success OR |
| 4016 | main.FALSE if elements were already in the set OR |
| 4017 | main.ERROR on error |
| 4018 | """ |
| 4019 | try: |
| 4020 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4021 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4022 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 4023 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4024 | if re.search( positiveMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4025 | return main.TRUE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4026 | elif re.search( negativeMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4027 | return main.FALSE |
| 4028 | else: |
| 4029 | main.log.error( self.name + ": setTestAdd did not" + |
| 4030 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4031 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4032 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4033 | except TypeError: |
| 4034 | main.log.exception( self.name + ": Object not as expected" ) |
| 4035 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4036 | except Exception: |
| 4037 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4038 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4039 | |
| 4040 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 4041 | """ |
| 4042 | CLI command to remove elements from a distributed set. |
| 4043 | Required arguments: |
| 4044 | setName - The name of the set to remove from. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4045 | values - The value(s) to remove from the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4046 | Optional arguments: |
| 4047 | clear - Clear all elements from the set |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4048 | retain - Retain only the given values. (intersection of the |
| 4049 | original set and the given set) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4050 | returns: |
| 4051 | main.TRUE on success OR |
| 4052 | main.FALSE if the set was not changed OR |
| 4053 | main.ERROR on error |
| 4054 | """ |
| 4055 | try: |
| 4056 | cmdStr = "set-test-remove " |
| 4057 | if clear: |
| 4058 | cmdStr += "-c " + str( setName ) |
| 4059 | elif retain: |
| 4060 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4061 | else: |
| 4062 | cmdStr += str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4063 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4064 | if clear: |
| 4065 | pattern = "Set " + str( setName ) + " cleared" |
| 4066 | if re.search( pattern, output ): |
| 4067 | return main.TRUE |
| 4068 | elif retain: |
| 4069 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4070 | "only elements of set \[(.*)\]" |
| 4071 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4072 | "retaining only elements of the set " +\ |
| 4073 | "\[(.*)\]" |
| 4074 | if re.search( positivePattern, output ): |
| 4075 | return main.TRUE |
| 4076 | elif re.search( negativePattern, output ): |
| 4077 | return main.FALSE |
| 4078 | else: |
| 4079 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4080 | str( setName ) |
| 4081 | if ( len( values.split() ) == 1 ): |
| 4082 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4083 | str( setName ) |
| 4084 | else: |
| 4085 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4086 | str( setName ) |
| 4087 | if re.search( positivePattern, output ): |
| 4088 | return main.TRUE |
| 4089 | elif re.search( negativePattern, output ): |
| 4090 | return main.FALSE |
| 4091 | main.log.error( self.name + ": setTestRemove did not" + |
| 4092 | " match expected output" ) |
| 4093 | main.log.debug( self.name + " expected: " + pattern ) |
| 4094 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4095 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4096 | except TypeError: |
| 4097 | main.log.exception( self.name + ": Object not as expected" ) |
| 4098 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4099 | except Exception: |
| 4100 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4101 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4102 | |
| 4103 | def setTestGet( self, setName, values="" ): |
| 4104 | """ |
| 4105 | CLI command to get the elements in a distributed set. |
| 4106 | Required arguments: |
| 4107 | setName - The name of the set to remove from. |
| 4108 | Optional arguments: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4109 | values - The value(s) to check if in the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4110 | returns: |
| 4111 | main.ERROR on error OR |
| 4112 | A list of elements in the set if no optional arguments are |
| 4113 | supplied OR |
| 4114 | A tuple containing the list then: |
| 4115 | main.FALSE if the given values are not in the set OR |
| 4116 | main.TRUE if the given values are in the set OR |
| 4117 | """ |
| 4118 | try: |
| 4119 | values = str( values ).strip() |
| 4120 | setName = str( setName ).strip() |
| 4121 | length = len( values.split() ) |
| 4122 | containsCheck = None |
| 4123 | # Patterns to match |
| 4124 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4125 | pattern = "Items in set " + setName + ":\r\n" + setPattern |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4126 | containsTrue = "Set " + setName + " contains the value " + values |
| 4127 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4128 | values |
| 4129 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4130 | setPattern |
| 4131 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4132 | " subset " + setPattern |
| 4133 | |
| 4134 | cmdStr = "set-test-get " |
| 4135 | cmdStr += setName + " " + values |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4136 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4137 | if length == 0: |
| 4138 | match = re.search( pattern, output ) |
| 4139 | else: # if given values |
| 4140 | if length == 1: # Contains output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4141 | patternTrue = pattern + "\r\n" + containsTrue |
| 4142 | patternFalse = pattern + "\r\n" + containsFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4143 | else: # ContainsAll output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4144 | patternTrue = pattern + "\r\n" + containsAllTrue |
| 4145 | patternFalse = pattern + "\r\n" + containsAllFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4146 | matchTrue = re.search( patternTrue, output ) |
| 4147 | matchFalse = re.search( patternFalse, output ) |
| 4148 | if matchTrue: |
| 4149 | containsCheck = main.TRUE |
| 4150 | match = matchTrue |
| 4151 | elif matchFalse: |
| 4152 | containsCheck = main.FALSE |
| 4153 | match = matchFalse |
| 4154 | else: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4155 | main.log.error( self.name + " setTestGet did not match " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4156 | "expected output" ) |
| 4157 | main.log.debug( self.name + " expected: " + pattern ) |
| 4158 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4159 | match = None |
| 4160 | if match: |
| 4161 | setMatch = match.group( 1 ) |
| 4162 | if setMatch == '': |
| 4163 | setList = [] |
| 4164 | else: |
| 4165 | setList = setMatch.split( ", " ) |
| 4166 | if length > 0: |
| 4167 | return ( setList, containsCheck ) |
| 4168 | else: |
| 4169 | return setList |
| 4170 | else: # no match |
| 4171 | main.log.error( self.name + ": setTestGet did not" + |
| 4172 | " match expected output" ) |
| 4173 | main.log.debug( self.name + " expected: " + pattern ) |
| 4174 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4175 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4176 | except TypeError: |
| 4177 | main.log.exception( self.name + ": Object not as expected" ) |
| 4178 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4179 | except Exception: |
| 4180 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4181 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4182 | |
| 4183 | def setTestSize( self, setName ): |
| 4184 | """ |
| 4185 | CLI command to get the elements in a distributed set. |
| 4186 | Required arguments: |
| 4187 | setName - The name of the set to remove from. |
| 4188 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4189 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4190 | None on error |
| 4191 | """ |
| 4192 | try: |
| 4193 | # TODO: Should this check against the number of elements returned |
| 4194 | # and then return true/false based on that? |
| 4195 | setName = str( setName ).strip() |
| 4196 | # Patterns to match |
| 4197 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4198 | pattern = "There are (\d+) items in set " + setName + ":\r\n" +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4199 | setPattern |
| 4200 | cmdStr = "set-test-get -s " |
| 4201 | cmdStr += setName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4202 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4203 | match = re.search( pattern, output ) |
| 4204 | if match: |
| 4205 | setSize = int( match.group( 1 ) ) |
| 4206 | setMatch = match.group( 2 ) |
| 4207 | if len( setMatch.split() ) == setSize: |
| 4208 | main.log.info( "The size returned by " + self.name + |
| 4209 | " matches the number of elements in " + |
| 4210 | "the returned set" ) |
| 4211 | else: |
| 4212 | main.log.error( "The size returned by " + self.name + |
| 4213 | " does not match the number of " + |
| 4214 | "elements in the returned set." ) |
| 4215 | return setSize |
| 4216 | else: # no match |
| 4217 | main.log.error( self.name + ": setTestGet did not" + |
| 4218 | " match expected output" ) |
| 4219 | main.log.debug( self.name + " expected: " + pattern ) |
| 4220 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4221 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4222 | except TypeError: |
| 4223 | main.log.exception( self.name + ": Object not as expected" ) |
| 4224 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4225 | except Exception: |
| 4226 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4227 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4228 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4229 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4230 | """ |
| 4231 | Command to list the various counters in the system. |
| 4232 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4233 | if jsonFormat, a string of the json object returned by the cli |
| 4234 | command |
| 4235 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4236 | None on error |
| 4237 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4238 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4239 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4240 | if jsonFormat: |
| 4241 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4242 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4243 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4244 | assert "Command not found:" not in output, output |
| 4245 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4246 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4247 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4248 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4249 | main.log.exception( "Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4250 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4251 | except TypeError: |
| 4252 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4253 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4254 | except pexpect.EOF: |
| 4255 | main.log.error( self.name + ": EOF exception found" ) |
| 4256 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4257 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4258 | except Exception: |
| 4259 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4260 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4261 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4262 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4263 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4264 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4265 | Required arguments: |
| 4266 | counter - The name of the counter to increment. |
| 4267 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4268 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4269 | returns: |
| 4270 | integer value of the counter or |
| 4271 | None on Error |
| 4272 | """ |
| 4273 | try: |
| 4274 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4275 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4276 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4277 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4278 | if delta != 1: |
| 4279 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4280 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4281 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4282 | match = re.search( pattern, output ) |
| 4283 | if match: |
| 4284 | return int( match.group( 1 ) ) |
| 4285 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4286 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4287 | " match expected output." ) |
| 4288 | main.log.debug( self.name + " expected: " + pattern ) |
| 4289 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4290 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4291 | except TypeError: |
| 4292 | main.log.exception( self.name + ": Object not as expected" ) |
| 4293 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4294 | except Exception: |
| 4295 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4296 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4297 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4298 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4299 | """ |
| 4300 | CLI command to get a distributed counter then add a delta to it. |
| 4301 | Required arguments: |
| 4302 | counter - The name of the counter to increment. |
| 4303 | Optional arguments: |
| 4304 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4305 | returns: |
| 4306 | integer value of the counter or |
| 4307 | None on Error |
| 4308 | """ |
| 4309 | try: |
| 4310 | counter = str( counter ) |
| 4311 | delta = int( delta ) |
| 4312 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4313 | cmdStr += counter |
| 4314 | if delta != 1: |
| 4315 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4316 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4317 | pattern = counter + " was updated to (-?\d+)" |
| 4318 | match = re.search( pattern, output ) |
| 4319 | if match: |
| 4320 | return int( match.group( 1 ) ) |
| 4321 | else: |
| 4322 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4323 | " match expected output." ) |
| 4324 | main.log.debug( self.name + " expected: " + pattern ) |
| 4325 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4326 | return None |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4327 | except TypeError: |
| 4328 | main.log.exception( self.name + ": Object not as expected" ) |
| 4329 | return None |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4330 | except Exception: |
| 4331 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4332 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4333 | |
| 4334 | def valueTestGet( self, valueName ): |
| 4335 | """ |
| 4336 | CLI command to get the value of an atomic value. |
| 4337 | Required arguments: |
| 4338 | valueName - The name of the value to get. |
| 4339 | returns: |
| 4340 | string value of the value or |
| 4341 | None on Error |
| 4342 | """ |
| 4343 | try: |
| 4344 | valueName = str( valueName ) |
| 4345 | cmdStr = "value-test " |
| 4346 | operation = "get" |
| 4347 | cmdStr = "value-test {} {}".format( valueName, |
| 4348 | operation ) |
| 4349 | output = self.distPrimitivesSend( cmdStr ) |
| 4350 | pattern = "(\w+)" |
| 4351 | match = re.search( pattern, output ) |
| 4352 | if match: |
| 4353 | return match.group( 1 ) |
| 4354 | else: |
| 4355 | main.log.error( self.name + ": valueTestGet did not" + |
| 4356 | " match expected output." ) |
| 4357 | main.log.debug( self.name + " expected: " + pattern ) |
| 4358 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4359 | return None |
| 4360 | except TypeError: |
| 4361 | main.log.exception( self.name + ": Object not as expected" ) |
| 4362 | return None |
| 4363 | except Exception: |
| 4364 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4365 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4366 | |
| 4367 | def valueTestSet( self, valueName, newValue ): |
| 4368 | """ |
| 4369 | CLI command to set the value of an atomic value. |
| 4370 | Required arguments: |
| 4371 | valueName - The name of the value to set. |
| 4372 | newValue - The value to assign to the given value. |
| 4373 | returns: |
| 4374 | main.TRUE on success or |
| 4375 | main.ERROR on Error |
| 4376 | """ |
| 4377 | try: |
| 4378 | valueName = str( valueName ) |
| 4379 | newValue = str( newValue ) |
| 4380 | operation = "set" |
| 4381 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4382 | operation, |
| 4383 | newValue ) |
| 4384 | output = self.distPrimitivesSend( cmdStr ) |
| 4385 | if output is not None: |
| 4386 | return main.TRUE |
| 4387 | else: |
| 4388 | return main.ERROR |
| 4389 | except TypeError: |
| 4390 | main.log.exception( self.name + ": Object not as expected" ) |
| 4391 | return main.ERROR |
| 4392 | except Exception: |
| 4393 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4394 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4395 | |
| 4396 | def valueTestCompareAndSet( self, valueName, oldValue, newValue ): |
| 4397 | """ |
| 4398 | CLI command to compareAndSet the value of an atomic value. |
| 4399 | Required arguments: |
| 4400 | valueName - The name of the value. |
| 4401 | oldValue - Compare the current value of the atomic value to this |
| 4402 | newValue - If the value equals oldValue, set the value to newValue |
| 4403 | returns: |
| 4404 | main.TRUE on success or |
| 4405 | main.FALSE on failure or |
| 4406 | main.ERROR on Error |
| 4407 | """ |
| 4408 | try: |
| 4409 | valueName = str( valueName ) |
| 4410 | oldValue = str( oldValue ) |
| 4411 | newValue = str( newValue ) |
| 4412 | operation = "compareAndSet" |
| 4413 | cmdStr = "value-test {} {} {} {}".format( valueName, |
| 4414 | operation, |
| 4415 | oldValue, |
| 4416 | newValue ) |
| 4417 | output = self.distPrimitivesSend( cmdStr ) |
| 4418 | pattern = "(\w+)" |
| 4419 | match = re.search( pattern, output ) |
| 4420 | if match: |
| 4421 | result = match.group( 1 ) |
| 4422 | if result == "true": |
| 4423 | return main.TRUE |
| 4424 | elif result == "false": |
| 4425 | return main.FALSE |
| 4426 | else: |
| 4427 | main.log.error( self.name + ": valueTestCompareAndSet did not" + |
| 4428 | " match expected output." ) |
| 4429 | main.log.debug( self.name + " expected: " + pattern ) |
| 4430 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4431 | return main.ERROR |
| 4432 | except TypeError: |
| 4433 | main.log.exception( self.name + ": Object not as expected" ) |
| 4434 | return main.ERROR |
| 4435 | except Exception: |
| 4436 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4437 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4438 | |
| 4439 | def valueTestGetAndSet( self, valueName, newValue ): |
| 4440 | """ |
| 4441 | CLI command to getAndSet the value of an atomic value. |
| 4442 | Required arguments: |
| 4443 | valueName - The name of the value to get. |
| 4444 | newValue - The value to assign to the given value |
| 4445 | returns: |
| 4446 | string value of the value or |
| 4447 | None on Error |
| 4448 | """ |
| 4449 | try: |
| 4450 | valueName = str( valueName ) |
| 4451 | cmdStr = "value-test " |
| 4452 | operation = "getAndSet" |
| 4453 | cmdStr += valueName + " " + operation |
| 4454 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4455 | operation, |
| 4456 | newValue ) |
| 4457 | output = self.distPrimitivesSend( cmdStr ) |
| 4458 | pattern = "(\w+)" |
| 4459 | match = re.search( pattern, output ) |
| 4460 | if match: |
| 4461 | return match.group( 1 ) |
| 4462 | else: |
| 4463 | main.log.error( self.name + ": valueTestGetAndSet did not" + |
| 4464 | " match expected output." ) |
| 4465 | main.log.debug( self.name + " expected: " + pattern ) |
| 4466 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4467 | return None |
| 4468 | except TypeError: |
| 4469 | main.log.exception( self.name + ": Object not as expected" ) |
| 4470 | return None |
| 4471 | except Exception: |
| 4472 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4473 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4474 | |
| 4475 | def valueTestDestroy( self, valueName ): |
| 4476 | """ |
| 4477 | CLI command to destroy an atomic value. |
| 4478 | Required arguments: |
| 4479 | valueName - The name of the value to destroy. |
| 4480 | returns: |
| 4481 | main.TRUE on success or |
| 4482 | main.ERROR on Error |
| 4483 | """ |
| 4484 | try: |
| 4485 | valueName = str( valueName ) |
| 4486 | cmdStr = "value-test " |
| 4487 | operation = "destroy" |
| 4488 | cmdStr += valueName + " " + operation |
| 4489 | output = self.distPrimitivesSend( cmdStr ) |
| 4490 | if output is not None: |
| 4491 | return main.TRUE |
| 4492 | else: |
| 4493 | return main.ERROR |
| 4494 | except TypeError: |
| 4495 | main.log.exception( self.name + ": Object not as expected" ) |
| 4496 | return main.ERROR |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4497 | except Exception: |
| 4498 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4499 | main.cleanAndExit() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4500 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4501 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4502 | """ |
| 4503 | Description: Execute summary command in onos |
| 4504 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4505 | no output |
| 4506 | |
| 4507 | """ |
| 4508 | try: |
| 4509 | cmdStr = "summary" |
| 4510 | if jsonFormat: |
| 4511 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4512 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4513 | assert handle 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 handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4515 | assert "Error:" not in handle, handle |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 4516 | assert "Error executing" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4517 | if not handle: |
| 4518 | main.log.error( self.name + ": There is no output in " + |
| 4519 | "summary command" ) |
| 4520 | return main.FALSE |
| 4521 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4522 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4523 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4524 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4525 | except TypeError: |
| 4526 | main.log.exception( self.name + ": Object not as expected" ) |
| 4527 | return None |
| 4528 | except pexpect.EOF: |
| 4529 | main.log.error( self.name + ": EOF exception found" ) |
| 4530 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4531 | main.cleanAndExit() |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4532 | except Exception: |
| 4533 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4534 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4535 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4536 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4537 | """ |
| 4538 | CLI command to get the value of a key in a consistent map using |
| 4539 | transactions. This a test function and can only get keys from the |
| 4540 | test map hard coded into the cli command |
| 4541 | Required arguments: |
| 4542 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4543 | returns: |
| 4544 | The string value of the key or |
| 4545 | None on Error |
| 4546 | """ |
| 4547 | try: |
| 4548 | keyName = str( keyName ) |
| 4549 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4550 | cmdStr += keyName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4551 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4552 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4553 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4554 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4555 | return None |
| 4556 | else: |
| 4557 | match = re.search( pattern, output ) |
| 4558 | if match: |
| 4559 | return match.groupdict()[ 'value' ] |
| 4560 | else: |
| 4561 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4562 | " match expected output." ) |
| 4563 | main.log.debug( self.name + " expected: " + pattern ) |
| 4564 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4565 | return None |
| 4566 | except TypeError: |
| 4567 | main.log.exception( self.name + ": Object not as expected" ) |
| 4568 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4569 | except Exception: |
| 4570 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4571 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4572 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4573 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4574 | """ |
| 4575 | CLI command to put a value into 'numKeys' number of keys in a |
| 4576 | consistent map using transactions. This a test function and can only |
| 4577 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4578 | Required arguments: |
| 4579 | numKeys - Number of keys to add the value to |
| 4580 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4581 | returns: |
| 4582 | A dictionary whose keys are the name of the keys put into the map |
| 4583 | and the values of the keys are dictionaries whose key-values are |
| 4584 | 'value': value put into map and optionaly |
| 4585 | 'oldValue': Previous value in the key or |
| 4586 | None on Error |
| 4587 | |
| 4588 | Example output |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4589 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4590 | 'Key2': {'value': 'Testing'} } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4591 | """ |
| 4592 | try: |
| 4593 | numKeys = str( numKeys ) |
| 4594 | value = str( value ) |
| 4595 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4596 | cmdStr += numKeys + " " + value |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4597 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4598 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4599 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4600 | results = {} |
| 4601 | for line in output.splitlines(): |
| 4602 | new = re.search( newPattern, line ) |
| 4603 | updated = re.search( updatedPattern, line ) |
| 4604 | if new: |
| 4605 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 4606 | elif updated: |
| 4607 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4608 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4609 | else: |
| 4610 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4611 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4612 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 4613 | newPattern, |
| 4614 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4615 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4616 | return results |
| 4617 | except TypeError: |
| 4618 | main.log.exception( self.name + ": Object not as expected" ) |
| 4619 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4620 | except Exception: |
| 4621 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4622 | main.cleanAndExit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4623 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4624 | def maps( self, jsonFormat=True ): |
| 4625 | """ |
| 4626 | Description: Returns result of onos:maps |
| 4627 | Optional: |
| 4628 | * jsonFormat: enable json formatting of output |
| 4629 | """ |
| 4630 | try: |
| 4631 | cmdStr = "maps" |
| 4632 | if jsonFormat: |
| 4633 | cmdStr += " -j" |
| 4634 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4635 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4636 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4637 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4638 | except AssertionError: |
| 4639 | main.log.exception( "" ) |
| 4640 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4641 | except TypeError: |
| 4642 | main.log.exception( self.name + ": Object not as expected" ) |
| 4643 | return None |
| 4644 | except pexpect.EOF: |
| 4645 | main.log.error( self.name + ": EOF exception found" ) |
| 4646 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4647 | main.cleanAndExit() |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4648 | except Exception: |
| 4649 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4650 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4651 | |
| 4652 | def getSwController( self, uri, jsonFormat=True ): |
| 4653 | """ |
| 4654 | Descrition: Gets the controller information from the device |
| 4655 | """ |
| 4656 | try: |
| 4657 | cmd = "device-controllers " |
| 4658 | if jsonFormat: |
| 4659 | cmd += "-j " |
| 4660 | response = self.sendline( cmd + uri ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4661 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4662 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4663 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4664 | except AssertionError: |
| 4665 | main.log.exception( "" ) |
| 4666 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4667 | except TypeError: |
| 4668 | main.log.exception( self.name + ": Object not as expected" ) |
| 4669 | return None |
| 4670 | except pexpect.EOF: |
| 4671 | main.log.error( self.name + ": EOF exception found" ) |
| 4672 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4673 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4674 | except Exception: |
| 4675 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4676 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4677 | |
| 4678 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 4679 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4680 | Descrition: sets the controller(s) for the specified device |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4681 | |
| 4682 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4683 | Required: uri - String: The uri of the device(switch). |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4684 | ip - String or List: The ip address of the controller. |
| 4685 | This parameter can be formed in a couple of different ways. |
| 4686 | VALID: |
| 4687 | 10.0.0.1 - just the ip address |
| 4688 | tcp:10.0.0.1 - the protocol and the ip address |
| 4689 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 4690 | so that you can add controllers with different |
| 4691 | protocols and ports |
| 4692 | INVALID: |
| 4693 | 10.0.0.1:6653 - this is not supported by ONOS |
| 4694 | |
| 4695 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 4696 | port - The port number. |
| 4697 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 4698 | |
| 4699 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 4700 | """ |
| 4701 | try: |
| 4702 | cmd = "device-setcontrollers" |
| 4703 | |
| 4704 | if jsonFormat: |
| 4705 | cmd += " -j" |
| 4706 | cmd += " " + uri |
| 4707 | if isinstance( ip, str ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4708 | ip = [ ip ] |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4709 | for item in ip: |
| 4710 | if ":" in item: |
| 4711 | sitem = item.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4712 | if len( sitem ) == 3: |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4713 | cmd += " " + item |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4714 | elif "." in sitem[ 1 ]: |
| 4715 | cmd += " {}:{}".format( item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4716 | else: |
| 4717 | main.log.error( "Malformed entry: " + item ) |
| 4718 | raise TypeError |
| 4719 | else: |
| 4720 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4721 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4722 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4723 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4724 | if "Error" in response: |
| 4725 | main.log.error( response ) |
| 4726 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4727 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4728 | except AssertionError: |
| 4729 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4730 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4731 | except TypeError: |
| 4732 | main.log.exception( self.name + ": Object not as expected" ) |
| 4733 | return main.FALSE |
| 4734 | except pexpect.EOF: |
| 4735 | main.log.error( self.name + ": EOF exception found" ) |
| 4736 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4737 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4738 | except Exception: |
| 4739 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4740 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4741 | |
| 4742 | def removeDevice( self, device ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4743 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4744 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4745 | Remove a device from ONOS by passing the uri of the device(s). |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4746 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4747 | 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] | 4748 | Returns: |
| 4749 | Returns main.FALSE if an exception is thrown or an error is present |
| 4750 | in the response. Otherwise, returns main.TRUE. |
| 4751 | NOTE: |
| 4752 | 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] | 4753 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4754 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4755 | if isinstance( device, str ): |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 4756 | deviceStr = device |
| 4757 | device = [] |
| 4758 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4759 | |
| 4760 | for d in device: |
| 4761 | time.sleep( 1 ) |
| 4762 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4763 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4764 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4765 | if "Error" in response: |
| 4766 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 4767 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4768 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4769 | except AssertionError: |
| 4770 | main.log.exception( "" ) |
| 4771 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4772 | except TypeError: |
| 4773 | main.log.exception( self.name + ": Object not as expected" ) |
| 4774 | return main.FALSE |
| 4775 | except pexpect.EOF: |
| 4776 | main.log.error( self.name + ": EOF exception found" ) |
| 4777 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4778 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4779 | except Exception: |
| 4780 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4781 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4782 | |
| 4783 | def removeHost( self, host ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4784 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4785 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4786 | Remove a host from ONOS by passing the id of the host(s) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4787 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4788 | 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] | 4789 | Returns: |
| 4790 | Returns main.FALSE if an exception is thrown or an error is present |
| 4791 | in the response. Otherwise, returns main.TRUE. |
| 4792 | NOTE: |
| 4793 | 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] | 4794 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4795 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4796 | if isinstance( host, str ): |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4797 | host = list( host ) |
| 4798 | |
| 4799 | for h in host: |
| 4800 | time.sleep( 1 ) |
| 4801 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4802 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4803 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4804 | if "Error" in response: |
| 4805 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 4806 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4807 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4808 | except AssertionError: |
| 4809 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4810 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4811 | except TypeError: |
| 4812 | main.log.exception( self.name + ": Object not as expected" ) |
| 4813 | return main.FALSE |
| 4814 | except pexpect.EOF: |
| 4815 | main.log.error( self.name + ": EOF exception found" ) |
| 4816 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4817 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4818 | except Exception: |
| 4819 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4820 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4821 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4822 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4823 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4824 | Description: |
| 4825 | Bring link down or up in the null-provider. |
| 4826 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4827 | begin - (string) One end of a device or switch. |
| 4828 | end - (string) the other end of the device or switch |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4829 | returns: |
| 4830 | main.TRUE if no exceptions were thrown and no Errors are |
| 4831 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4832 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4833 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4834 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4835 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4836 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4837 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4838 | if "Error" in response or "Failure" in response: |
| 4839 | main.log.error( response ) |
| 4840 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4841 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4842 | except AssertionError: |
| 4843 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4844 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4845 | except TypeError: |
| 4846 | main.log.exception( self.name + ": Object not as expected" ) |
| 4847 | return main.FALSE |
| 4848 | except pexpect.EOF: |
| 4849 | main.log.error( self.name + ": EOF exception found" ) |
| 4850 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4851 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4852 | except Exception: |
| 4853 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4854 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4855 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4856 | def portstate( self, dpid, port, state ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4857 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4858 | Description: |
| 4859 | Changes the state of port in an OF switch by means of the |
| 4860 | PORTSTATUS OF messages. |
| 4861 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4862 | dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102' |
| 4863 | port - (string) target port in the device. Ex: '2' |
| 4864 | state - (string) target state (enable or disable) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4865 | returns: |
| 4866 | main.TRUE if no exceptions were thrown and no Errors are |
| 4867 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4868 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4869 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4870 | state = state.lower() |
| 4871 | assert state == 'enable' or state == 'disable', "Unknown state" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4872 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4873 | response = self.sendline( cmd, showResponse=True ) |
| 4874 | assert response is not None, "Error in sendline" |
| 4875 | assert "Command not found:" not in response, response |
| 4876 | if "Error" in response or "Failure" in response: |
| 4877 | main.log.error( response ) |
| 4878 | return main.FALSE |
| 4879 | return main.TRUE |
| 4880 | except AssertionError: |
| 4881 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4882 | return main.FALSE |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4883 | except TypeError: |
| 4884 | main.log.exception( self.name + ": Object not as expected" ) |
| 4885 | return main.FALSE |
| 4886 | except pexpect.EOF: |
| 4887 | main.log.error( self.name + ": EOF exception found" ) |
| 4888 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4889 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -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() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4893 | |
| 4894 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 4895 | """ |
| 4896 | Set the logging level to lvl for a specific app |
| 4897 | returns main.TRUE on success |
| 4898 | returns main.FALSE if Error occurred |
| 4899 | if noExit is True, TestON will not exit, but clean up |
| 4900 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 4901 | Level defaults to INFO |
| 4902 | """ |
| 4903 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4904 | self.handle.sendline( "log:set %s %s" % ( level, app ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 4905 | self.handle.expect( "onos>" ) |
| 4906 | |
| 4907 | response = self.handle.before |
| 4908 | if re.search( "Error", response ): |
| 4909 | return main.FALSE |
| 4910 | return main.TRUE |
| 4911 | except pexpect.TIMEOUT: |
| 4912 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4913 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 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() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -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() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 4921 | |
| 4922 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 4923 | """ |
| 4924 | Return a dictionary which describes the latest network topology data as a |
| 4925 | graph. |
| 4926 | An example of the dictionary: |
| 4927 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 4928 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 4929 | Each vertex should at least have an 'edges' attribute which describes the |
| 4930 | adjacency information. The value of 'edges' attribute is also represented by |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4931 | 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] | 4932 | list of attributes. |
| 4933 | An example of the edges dictionary: |
| 4934 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 4935 | vertex3: { 'port': ..., 'weight': ... } } |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4936 | If includeHost == True, all hosts (and host-switch links) will be included |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 4937 | in topology data. |
| 4938 | """ |
| 4939 | graphDict = {} |
| 4940 | try: |
| 4941 | links = self.links() |
| 4942 | links = json.loads( links ) |
| 4943 | devices = self.devices() |
| 4944 | devices = json.loads( devices ) |
| 4945 | idToDevice = {} |
| 4946 | for device in devices: |
| 4947 | idToDevice[ device[ 'id' ] ] = device |
| 4948 | if includeHost: |
| 4949 | hosts = self.hosts() |
| 4950 | # FIXME: support 'includeHost' argument |
| 4951 | for link in links: |
| 4952 | nodeA = link[ 'src' ][ 'device' ] |
| 4953 | nodeB = link[ 'dst' ][ 'device' ] |
| 4954 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4955 | if nodeA not in graphDict.keys(): |
| 4956 | graphDict[ nodeA ] = { 'edges': {}, |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4957 | 'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ], |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4958 | 'type': idToDevice[ nodeA ][ 'type' ], |
| 4959 | 'available': idToDevice[ nodeA ][ 'available' ], |
| 4960 | 'role': idToDevice[ nodeA ][ 'role' ], |
| 4961 | 'mfr': idToDevice[ nodeA ][ 'mfr' ], |
| 4962 | 'hw': idToDevice[ nodeA ][ 'hw' ], |
| 4963 | 'sw': idToDevice[ nodeA ][ 'sw' ], |
| 4964 | 'serial': idToDevice[ nodeA ][ 'serial' ], |
| 4965 | 'chassisId': idToDevice[ nodeA ][ 'chassisId' ], |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4966 | 'annotations': idToDevice[ nodeA ][ 'annotations' ]} |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 4967 | else: |
| 4968 | # Assert nodeB is not connected to any current links of nodeA |
| 4969 | assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4970 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ], |
| 4971 | 'type': link[ 'type' ], |
| 4972 | 'state': link[ 'state' ] } |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 4973 | return graphDict |
| 4974 | except ( TypeError, ValueError ): |
| 4975 | main.log.exception( self.name + ": Object not as expected" ) |
| 4976 | return None |
| 4977 | except KeyError: |
| 4978 | main.log.exception( self.name + ": KeyError exception found" ) |
| 4979 | return None |
| 4980 | except AssertionError: |
| 4981 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 4982 | return None |
| 4983 | except pexpect.EOF: |
| 4984 | main.log.error( self.name + ": EOF exception found" ) |
| 4985 | main.log.error( self.name + ": " + self.handle.before ) |
| 4986 | return None |
| 4987 | except Exception: |
| 4988 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 4989 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 4990 | |
| 4991 | def getIntentPerfSummary( self ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4992 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 4993 | Send command to check intent-perf summary |
| 4994 | Returns: dictionary for intent-perf summary |
| 4995 | if something wrong, function will return None |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4996 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 4997 | cmd = "intent-perf -s" |
| 4998 | respDic = {} |
| 4999 | resp = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 5000 | assert resp is not None, "Error in sendline" |
| 5001 | assert "Command not found:" not in resp, resp |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5002 | try: |
| 5003 | # Generate the dictionary to return |
| 5004 | for l in resp.split( "\n" ): |
| 5005 | # Delete any white space in line |
| 5006 | temp = re.sub( r'\s+', '', l ) |
| 5007 | temp = temp.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5008 | respDic[ temp[ 0 ] ] = temp[ 1 ] |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5009 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5010 | except ( TypeError, ValueError ): |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5011 | main.log.exception( self.name + ": Object not as expected" ) |
| 5012 | return None |
| 5013 | except KeyError: |
| 5014 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5015 | return None |
| 5016 | except AssertionError: |
| 5017 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5018 | return None |
| 5019 | except pexpect.EOF: |
| 5020 | main.log.error( self.name + ": EOF exception found" ) |
| 5021 | main.log.error( self.name + ": " + self.handle.before ) |
| 5022 | return None |
| 5023 | except Exception: |
| 5024 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5025 | return None |
| 5026 | return respDic |
| 5027 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5028 | def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ): |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5029 | """ |
| 5030 | Searches the latest ONOS log file for the given search term and |
| 5031 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5032 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5033 | Arguments: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5034 | searchTerm: |
| 5035 | The string to grep from the ONOS log. |
| 5036 | startLine: |
| 5037 | The term that decides which line is the start to search the searchTerm in |
| 5038 | the karaf log. For now, startTerm only works in 'first' mode. |
| 5039 | logNum: |
| 5040 | In some extreme cases, one karaf log is not big enough to contain all the |
| 5041 | information.Because of this, search mutiply logs is necessary to capture |
| 5042 | the right result. logNum is the number of karaf logs that we need to search |
| 5043 | the searchTerm. |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5044 | mode: |
| 5045 | all: return all the strings that contain the search term |
| 5046 | last: return the last string that contains the search term |
| 5047 | first: return the first string that contains the search term |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5048 | num: return the number of times that the searchTerm appears in the log |
| 5049 | total: return how many lines in karaf log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5050 | """ |
| 5051 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5052 | assert isinstance( searchTerm, str ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5053 | # Build the log paths string |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5054 | logPath = '/opt/onos/log/karaf.log.' |
| 5055 | logPaths = '/opt/onos/log/karaf.log' |
| 5056 | for i in range( 1, logNum ): |
| 5057 | logPaths = logPath + str( i ) + " " + logPaths |
| 5058 | cmd = "cat " + logPaths |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5059 | if startLine: |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5060 | # 100000000 is just a extreme large number to make sure this function can |
| 5061 | # grep all the lines after startLine |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5062 | cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'" |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5063 | if mode == 'all': |
| 5064 | cmd = cmd + " | grep \'" + searchTerm + "\'" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5065 | elif mode == 'last': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5066 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5067 | elif mode == 'first': |
| 5068 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1" |
| 5069 | elif mode == 'num': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5070 | cmd = cmd + " | grep -c \'" + searchTerm + "\'" |
You Wang | 118ba58 | 2017-01-02 17:14:43 -0800 | [diff] [blame] | 5071 | num = self.sendline( cmd ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5072 | return num |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5073 | elif mode == 'total': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5074 | totalLines = self.sendline( "cat /opt/onos/log/karaf.log | wc -l" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5075 | return int( totalLines ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5076 | else: |
| 5077 | main.log.error( self.name + " unsupported mode" ) |
| 5078 | return main.ERROR |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5079 | before = self.sendline( cmd ) |
| 5080 | before = before.splitlines() |
| 5081 | # make sure the returned list only contains the search term |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5082 | returnLines = [ line for line in before if searchTerm in line ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5083 | return returnLines |
| 5084 | except AssertionError: |
| 5085 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5086 | return None |
| 5087 | except pexpect.EOF: |
| 5088 | main.log.error( self.name + ": EOF exception found" ) |
| 5089 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5090 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5091 | except pexpect.TIMEOUT: |
| 5092 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5093 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5094 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5095 | except Exception: |
| 5096 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5097 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5098 | |
| 5099 | def vplsShow( self, jsonFormat=True ): |
| 5100 | """ |
| 5101 | Description: Returns result of onos:vpls show, which should list the |
| 5102 | configured VPLS networks and the assigned interfaces. |
| 5103 | Optional: |
| 5104 | * jsonFormat: enable json formatting of output |
| 5105 | Returns: |
| 5106 | The output of the command or None on error. |
| 5107 | """ |
| 5108 | try: |
| 5109 | cmdStr = "vpls show" |
| 5110 | if jsonFormat: |
| 5111 | raise NotImplementedError |
| 5112 | cmdStr += " -j" |
| 5113 | handle = self.sendline( cmdStr ) |
| 5114 | assert handle is not None, "Error in sendline" |
| 5115 | assert "Command not found:" not in handle, handle |
| 5116 | return handle |
| 5117 | except AssertionError: |
| 5118 | main.log.exception( "" ) |
| 5119 | return None |
| 5120 | except TypeError: |
| 5121 | main.log.exception( self.name + ": Object not as expected" ) |
| 5122 | return None |
| 5123 | except pexpect.EOF: |
| 5124 | main.log.error( self.name + ": EOF exception found" ) |
| 5125 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5126 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5127 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5128 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5129 | return None |
| 5130 | except Exception: |
| 5131 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5132 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5133 | |
| 5134 | def parseVplsShow( self ): |
| 5135 | """ |
| 5136 | Parse the cli output of 'vpls show' into json output. This is required |
| 5137 | as there is currently no json output available. |
| 5138 | """ |
| 5139 | try: |
| 5140 | output = [] |
| 5141 | raw = self.vplsShow( jsonFormat=False ) |
| 5142 | namePat = "VPLS name: (?P<name>\w+)" |
| 5143 | interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]" |
| 5144 | encapPat = "Encapsulation: (?P<encap>\w+)" |
| 5145 | pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] ) |
| 5146 | mIter = re.finditer( pattern, raw ) |
| 5147 | for match in mIter: |
| 5148 | item = {} |
| 5149 | item[ 'name' ] = match.group( 'name' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5150 | ifaces = match.group( 'interfaces' ).split( ', ' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5151 | if ifaces == [ "" ]: |
| 5152 | ifaces = [] |
| 5153 | item[ 'interfaces' ] = ifaces |
| 5154 | encap = match.group( 'encap' ) |
| 5155 | if encap != 'NONE': |
| 5156 | item[ 'encapsulation' ] = encap.lower() |
| 5157 | output.append( item ) |
| 5158 | return output |
| 5159 | except Exception: |
| 5160 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5161 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5162 | |
| 5163 | def vplsList( self, jsonFormat=True ): |
| 5164 | """ |
| 5165 | Description: Returns result of onos:vpls list, which should list the |
| 5166 | configured VPLS networks. |
| 5167 | Optional: |
| 5168 | * jsonFormat: enable json formatting of output |
| 5169 | """ |
| 5170 | try: |
| 5171 | cmdStr = "vpls list" |
| 5172 | if jsonFormat: |
| 5173 | raise NotImplementedError |
| 5174 | cmdStr += " -j" |
| 5175 | handle = self.sendline( cmdStr ) |
| 5176 | assert handle is not None, "Error in sendline" |
| 5177 | assert "Command not found:" not in handle, handle |
| 5178 | return handle |
| 5179 | except AssertionError: |
| 5180 | main.log.exception( "" ) |
| 5181 | return None |
| 5182 | except TypeError: |
| 5183 | main.log.exception( self.name + ": Object not as expected" ) |
| 5184 | return None |
| 5185 | except pexpect.EOF: |
| 5186 | main.log.error( self.name + ": EOF exception found" ) |
| 5187 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5188 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5189 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5190 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5191 | return None |
| 5192 | except Exception: |
| 5193 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5194 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5195 | |
| 5196 | def vplsCreate( self, network ): |
| 5197 | """ |
| 5198 | CLI command to create a new VPLS network. |
| 5199 | Required arguments: |
| 5200 | network - String name of the network to create. |
| 5201 | returns: |
| 5202 | main.TRUE on success and main.FALSE on failure |
| 5203 | """ |
| 5204 | try: |
| 5205 | network = str( network ) |
| 5206 | cmdStr = "vpls create " |
| 5207 | cmdStr += network |
| 5208 | output = self.sendline( cmdStr ) |
| 5209 | assert output is not None, "Error in sendline" |
| 5210 | assert "Command not found:" not in output, output |
| 5211 | assert "Error executing command" not in output, output |
| 5212 | assert "VPLS already exists:" not in output, output |
| 5213 | return main.TRUE |
| 5214 | except AssertionError: |
| 5215 | main.log.exception( "" ) |
| 5216 | return main.FALSE |
| 5217 | except TypeError: |
| 5218 | main.log.exception( self.name + ": Object not as expected" ) |
| 5219 | return main.FALSE |
| 5220 | except pexpect.EOF: |
| 5221 | main.log.error( self.name + ": EOF exception found" ) |
| 5222 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5223 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5224 | except Exception: |
| 5225 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5226 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5227 | |
| 5228 | def vplsDelete( self, network ): |
| 5229 | """ |
| 5230 | CLI command to delete a VPLS network. |
| 5231 | Required arguments: |
| 5232 | network - Name of the network to delete. |
| 5233 | returns: |
| 5234 | main.TRUE on success and main.FALSE on failure |
| 5235 | """ |
| 5236 | try: |
| 5237 | network = str( network ) |
| 5238 | cmdStr = "vpls delete " |
| 5239 | cmdStr += network |
| 5240 | output = self.sendline( cmdStr ) |
| 5241 | assert output is not None, "Error in sendline" |
| 5242 | assert "Command not found:" not in output, output |
| 5243 | assert "Error executing command" not in output, output |
| 5244 | assert " not found" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5245 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5246 | return main.TRUE |
| 5247 | except AssertionError: |
| 5248 | main.log.exception( "" ) |
| 5249 | return main.FALSE |
| 5250 | except TypeError: |
| 5251 | main.log.exception( self.name + ": Object not as expected" ) |
| 5252 | return main.FALSE |
| 5253 | except pexpect.EOF: |
| 5254 | main.log.error( self.name + ": EOF exception found" ) |
| 5255 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5256 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5257 | except Exception: |
| 5258 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5259 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5260 | |
| 5261 | def vplsAddIface( self, network, iface ): |
| 5262 | """ |
| 5263 | CLI command to add an interface to a VPLS network. |
| 5264 | Required arguments: |
| 5265 | network - Name of the network to add the interface to. |
| 5266 | iface - The ONOS name for an interface. |
| 5267 | returns: |
| 5268 | main.TRUE on success and main.FALSE on failure |
| 5269 | """ |
| 5270 | try: |
| 5271 | network = str( network ) |
| 5272 | iface = str( iface ) |
| 5273 | cmdStr = "vpls add-if " |
| 5274 | cmdStr += network + " " + iface |
| 5275 | output = self.sendline( cmdStr ) |
| 5276 | assert output is not None, "Error in sendline" |
| 5277 | assert "Command not found:" not in output, output |
| 5278 | assert "Error executing command" not in output, output |
| 5279 | assert "already associated to network" not in output, output |
| 5280 | assert "Interface cannot be added." not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5281 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5282 | return main.TRUE |
| 5283 | except AssertionError: |
| 5284 | main.log.exception( "" ) |
| 5285 | return main.FALSE |
| 5286 | except TypeError: |
| 5287 | main.log.exception( self.name + ": Object not as expected" ) |
| 5288 | return main.FALSE |
| 5289 | except pexpect.EOF: |
| 5290 | main.log.error( self.name + ": EOF exception found" ) |
| 5291 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5292 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5293 | except Exception: |
| 5294 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5295 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5296 | |
| 5297 | def vplsRemIface( self, network, iface ): |
| 5298 | """ |
| 5299 | CLI command to remove an interface from a VPLS network. |
| 5300 | Required arguments: |
| 5301 | network - Name of the network to remove the interface from. |
| 5302 | iface - Name of the interface to remove. |
| 5303 | returns: |
| 5304 | main.TRUE on success and main.FALSE on failure |
| 5305 | """ |
| 5306 | try: |
| 5307 | iface = str( iface ) |
| 5308 | cmdStr = "vpls rem-if " |
| 5309 | cmdStr += network + " " + iface |
| 5310 | output = self.sendline( cmdStr ) |
| 5311 | assert output is not None, "Error in sendline" |
| 5312 | assert "Command not found:" not in output, output |
| 5313 | assert "Error executing command" not in output, output |
| 5314 | assert "is not configured" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5315 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5316 | return main.TRUE |
| 5317 | except AssertionError: |
| 5318 | main.log.exception( "" ) |
| 5319 | return main.FALSE |
| 5320 | except TypeError: |
| 5321 | main.log.exception( self.name + ": Object not as expected" ) |
| 5322 | return main.FALSE |
| 5323 | except pexpect.EOF: |
| 5324 | main.log.error( self.name + ": EOF exception found" ) |
| 5325 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5326 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5327 | except Exception: |
| 5328 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5329 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5330 | |
| 5331 | def vplsClean( self ): |
| 5332 | """ |
| 5333 | Description: Clears the VPLS app configuration. |
| 5334 | Returns: main.TRUE on success and main.FALSE on failure |
| 5335 | """ |
| 5336 | try: |
| 5337 | cmdStr = "vpls clean" |
| 5338 | handle = self.sendline( cmdStr ) |
| 5339 | assert handle is not None, "Error in sendline" |
| 5340 | assert "Command not found:" not in handle, handle |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5341 | assert "still updating" not in handle, handle |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5342 | return handle |
| 5343 | except AssertionError: |
| 5344 | main.log.exception( "" ) |
| 5345 | return main.FALSE |
| 5346 | except TypeError: |
| 5347 | main.log.exception( self.name + ": Object not as expected" ) |
| 5348 | return main.FALSE |
| 5349 | except pexpect.EOF: |
| 5350 | main.log.error( self.name + ": EOF exception found" ) |
| 5351 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5352 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5353 | except Exception: |
| 5354 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5355 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5356 | |
| 5357 | def vplsSetEncap( self, network, encapType ): |
| 5358 | """ |
| 5359 | CLI command to add an interface to a VPLS network. |
| 5360 | Required arguments: |
| 5361 | network - Name of the network to create. |
| 5362 | encapType - Type of encapsulation. |
| 5363 | returns: |
| 5364 | main.TRUE on success and main.FALSE on failure |
| 5365 | """ |
| 5366 | try: |
| 5367 | network = str( network ) |
| 5368 | encapType = str( encapType ).upper() |
| 5369 | assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type" |
| 5370 | cmdStr = "vpls set-encap " |
| 5371 | cmdStr += network + " " + encapType |
| 5372 | output = self.sendline( cmdStr ) |
| 5373 | assert output is not None, "Error in sendline" |
| 5374 | assert "Command not found:" not in output, output |
| 5375 | assert "Error executing command" not in output, output |
| 5376 | assert "already associated to network" not in output, output |
| 5377 | assert "Encapsulation type " not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5378 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5379 | return main.TRUE |
| 5380 | except AssertionError: |
| 5381 | main.log.exception( "" ) |
| 5382 | return main.FALSE |
| 5383 | except TypeError: |
| 5384 | main.log.exception( self.name + ": Object not as expected" ) |
| 5385 | return main.FALSE |
| 5386 | except pexpect.EOF: |
| 5387 | main.log.error( self.name + ": EOF exception found" ) |
| 5388 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5389 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5390 | except Exception: |
| 5391 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5392 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5393 | |
| 5394 | def interfaces( self, jsonFormat=True ): |
| 5395 | """ |
| 5396 | Description: Returns result of interfaces command. |
| 5397 | Optional: |
| 5398 | * jsonFormat: enable json formatting of output |
| 5399 | Returns: |
| 5400 | The output of the command or None on error. |
| 5401 | """ |
| 5402 | try: |
| 5403 | cmdStr = "interfaces" |
| 5404 | if jsonFormat: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5405 | raise NotImplementedError |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5406 | cmdStr += " -j" |
| 5407 | handle = self.sendline( cmdStr ) |
| 5408 | assert handle is not None, "Error in sendline" |
| 5409 | assert "Command not found:" not in handle, handle |
| 5410 | return handle |
| 5411 | except AssertionError: |
| 5412 | main.log.exception( "" ) |
| 5413 | return None |
| 5414 | except TypeError: |
| 5415 | main.log.exception( self.name + ": Object not as expected" ) |
| 5416 | return None |
| 5417 | except pexpect.EOF: |
| 5418 | main.log.error( self.name + ": EOF exception found" ) |
| 5419 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5420 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5421 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5422 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5423 | return None |
| 5424 | except Exception: |
| 5425 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5426 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5427 | |
| 5428 | def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5429 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5430 | Get the timestamp of searchTerm from karaf log. |
| 5431 | |
| 5432 | Arguments: |
| 5433 | splitTerm_before and splitTerm_after: |
| 5434 | |
| 5435 | The terms that split the string that contains the timeStamp of |
| 5436 | searchTerm. For example, if that string is "xxxxxxxcreationTime = |
| 5437 | 1419510501xxxxxx", then the splitTerm_before is "CreationTime = " |
| 5438 | and the splitTerm_after is "x" |
| 5439 | |
| 5440 | others: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5441 | Please look at the "logsearch" Function in onosclidriver.py |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5442 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5443 | if logNum < 0: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5444 | main.log.error( "Get wrong log number ") |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5445 | return main.ERROR |
| 5446 | lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5447 | if len( lines ) == 0: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5448 | main.log.warn( "Captured timestamp string is empty" ) |
| 5449 | return main.ERROR |
| 5450 | lines = lines[ 0 ] |
| 5451 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5452 | assert isinstance( lines, str ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5453 | # get the target value |
| 5454 | line = lines.split( splitTerm_before ) |
| 5455 | key = line[ 1 ].split( splitTerm_after ) |
| 5456 | return int( key[ 0 ] ) |
| 5457 | except IndexError: |
| 5458 | main.log.warn( "Index Error!" ) |
| 5459 | return main.ERROR |
| 5460 | except AssertionError: |
| 5461 | main.log.warn( "Search Term Not Found " ) |
| 5462 | return main.ERROR |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5463 | |
| 5464 | def workQueueAdd( self, queueName, value ): |
| 5465 | """ |
| 5466 | CLI command to add a string to the specified Work Queue. |
| 5467 | This function uses the distributed primitives test app, which |
| 5468 | gives some cli access to distributed primitives for testing |
| 5469 | purposes only. |
| 5470 | |
| 5471 | Required arguments: |
| 5472 | queueName - The name of the queue to add to |
| 5473 | value - The value to add to the queue |
| 5474 | returns: |
| 5475 | main.TRUE on success, main.FALSE on failure and |
| 5476 | main.ERROR on error. |
| 5477 | """ |
| 5478 | try: |
| 5479 | queueName = str( queueName ) |
| 5480 | value = str( value ) |
| 5481 | prefix = "work-queue-test" |
| 5482 | operation = "add" |
| 5483 | cmdStr = " ".join( [ prefix, queueName, operation, value ] ) |
| 5484 | output = self.distPrimitivesSend( cmdStr ) |
| 5485 | if "Invalid operation name" in output: |
| 5486 | main.log.warn( output ) |
| 5487 | return main.ERROR |
| 5488 | elif "Done" in output: |
| 5489 | return main.TRUE |
| 5490 | except TypeError: |
| 5491 | main.log.exception( self.name + ": Object not as expected" ) |
| 5492 | return main.ERROR |
| 5493 | except Exception: |
| 5494 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5495 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5496 | |
| 5497 | def workQueueAddMultiple( self, queueName, value1, value2 ): |
| 5498 | """ |
| 5499 | CLI command to add two strings to the specified Work Queue. |
| 5500 | This function uses the distributed primitives test app, which |
| 5501 | gives some cli access to distributed primitives for testing |
| 5502 | purposes only. |
| 5503 | |
| 5504 | Required arguments: |
| 5505 | queueName - The name of the queue to add to |
| 5506 | value1 - The first value to add to the queue |
| 5507 | value2 - The second value to add to the queue |
| 5508 | returns: |
| 5509 | main.TRUE on success, main.FALSE on failure and |
| 5510 | main.ERROR on error. |
| 5511 | """ |
| 5512 | try: |
| 5513 | queueName = str( queueName ) |
| 5514 | value1 = str( value1 ) |
| 5515 | value2 = str( value2 ) |
| 5516 | prefix = "work-queue-test" |
| 5517 | operation = "addMultiple" |
| 5518 | cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] ) |
| 5519 | output = self.distPrimitivesSend( cmdStr ) |
| 5520 | if "Invalid operation name" in output: |
| 5521 | main.log.warn( output ) |
| 5522 | return main.ERROR |
| 5523 | elif "Done" in output: |
| 5524 | return main.TRUE |
| 5525 | except TypeError: |
| 5526 | main.log.exception( self.name + ": Object not as expected" ) |
| 5527 | return main.ERROR |
| 5528 | except Exception: |
| 5529 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5530 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5531 | |
| 5532 | def workQueueTakeAndComplete( self, queueName, number=1 ): |
| 5533 | """ |
| 5534 | CLI command to take a value from the specified Work Queue and compelte it. |
| 5535 | This function uses the distributed primitives test app, which |
| 5536 | gives some cli access to distributed primitives for testing |
| 5537 | purposes only. |
| 5538 | |
| 5539 | Required arguments: |
| 5540 | queueName - The name of the queue to add to |
| 5541 | number - The number of items to take and complete |
| 5542 | returns: |
| 5543 | main.TRUE on success, main.FALSE on failure and |
| 5544 | main.ERROR on error. |
| 5545 | """ |
| 5546 | try: |
| 5547 | queueName = str( queueName ) |
| 5548 | number = str( int( number ) ) |
| 5549 | prefix = "work-queue-test" |
| 5550 | operation = "takeAndComplete" |
| 5551 | cmdStr = " ".join( [ prefix, queueName, operation, number ] ) |
| 5552 | output = self.distPrimitivesSend( cmdStr ) |
| 5553 | if "Invalid operation name" in output: |
| 5554 | main.log.warn( output ) |
| 5555 | return main.ERROR |
| 5556 | elif "Done" in output: |
| 5557 | return main.TRUE |
| 5558 | except TypeError: |
| 5559 | main.log.exception( self.name + ": Object not as expected" ) |
| 5560 | return main.ERROR |
| 5561 | except Exception: |
| 5562 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5563 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5564 | |
| 5565 | def workQueueDestroy( self, queueName ): |
| 5566 | """ |
| 5567 | CLI command to destroy the specified Work Queue. |
| 5568 | This function uses the distributed primitives test app, which |
| 5569 | gives some cli access to distributed primitives for testing |
| 5570 | purposes only. |
| 5571 | |
| 5572 | Required arguments: |
| 5573 | queueName - The name of the queue to add to |
| 5574 | returns: |
| 5575 | main.TRUE on success, main.FALSE on failure and |
| 5576 | main.ERROR on error. |
| 5577 | """ |
| 5578 | try: |
| 5579 | queueName = str( queueName ) |
| 5580 | prefix = "work-queue-test" |
| 5581 | operation = "destroy" |
| 5582 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5583 | output = self.distPrimitivesSend( cmdStr ) |
| 5584 | if "Invalid operation name" in output: |
| 5585 | main.log.warn( output ) |
| 5586 | return main.ERROR |
| 5587 | return main.TRUE |
| 5588 | except TypeError: |
| 5589 | main.log.exception( self.name + ": Object not as expected" ) |
| 5590 | return main.ERROR |
| 5591 | except Exception: |
| 5592 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5593 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5594 | |
| 5595 | def workQueueTotalPending( self, queueName ): |
| 5596 | """ |
| 5597 | CLI command to get the Total Pending items of the specified Work Queue. |
| 5598 | This function uses the distributed primitives test app, which |
| 5599 | gives some cli access to distributed primitives for testing |
| 5600 | purposes only. |
| 5601 | |
| 5602 | Required arguments: |
| 5603 | queueName - The name of the queue to add to |
| 5604 | returns: |
| 5605 | The number of Pending items in the specified work queue or |
| 5606 | None on error |
| 5607 | """ |
| 5608 | try: |
| 5609 | queueName = str( queueName ) |
| 5610 | prefix = "work-queue-test" |
| 5611 | operation = "totalPending" |
| 5612 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5613 | output = self.distPrimitivesSend( cmdStr ) |
| 5614 | pattern = r'\d+' |
| 5615 | if "Invalid operation name" in output: |
| 5616 | main.log.warn( output ) |
| 5617 | return None |
| 5618 | else: |
| 5619 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5620 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5621 | except ( AttributeError, TypeError ): |
| 5622 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5623 | return None |
| 5624 | except Exception: |
| 5625 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5626 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5627 | |
| 5628 | def workQueueTotalCompleted( self, queueName ): |
| 5629 | """ |
| 5630 | CLI command to get the Total Completed items of the specified Work Queue. |
| 5631 | This function uses the distributed primitives test app, which |
| 5632 | gives some cli access to distributed primitives for testing |
| 5633 | purposes only. |
| 5634 | |
| 5635 | Required arguments: |
| 5636 | queueName - The name of the queue to add to |
| 5637 | returns: |
| 5638 | The number of complete items in the specified work queue or |
| 5639 | None on error |
| 5640 | """ |
| 5641 | try: |
| 5642 | queueName = str( queueName ) |
| 5643 | prefix = "work-queue-test" |
| 5644 | operation = "totalCompleted" |
| 5645 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5646 | output = self.distPrimitivesSend( cmdStr ) |
| 5647 | pattern = r'\d+' |
| 5648 | if "Invalid operation name" in output: |
| 5649 | main.log.warn( output ) |
| 5650 | return None |
| 5651 | else: |
| 5652 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5653 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5654 | except ( AttributeError, TypeError ): |
| 5655 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5656 | return None |
| 5657 | except Exception: |
| 5658 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5659 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5660 | |
| 5661 | def workQueueTotalInProgress( self, queueName ): |
| 5662 | """ |
| 5663 | CLI command to get the Total In Progress items of the specified Work Queue. |
| 5664 | This function uses the distributed primitives test app, which |
| 5665 | gives some cli access to distributed primitives for testing |
| 5666 | purposes only. |
| 5667 | |
| 5668 | Required arguments: |
| 5669 | queueName - The name of the queue to add to |
| 5670 | returns: |
| 5671 | The number of In Progress items in the specified work queue or |
| 5672 | None on error |
| 5673 | """ |
| 5674 | try: |
| 5675 | queueName = str( queueName ) |
| 5676 | prefix = "work-queue-test" |
| 5677 | operation = "totalInProgress" |
| 5678 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5679 | output = self.distPrimitivesSend( cmdStr ) |
| 5680 | pattern = r'\d+' |
| 5681 | if "Invalid operation name" in output: |
| 5682 | main.log.warn( output ) |
| 5683 | return None |
| 5684 | else: |
| 5685 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5686 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5687 | except ( AttributeError, TypeError ): |
| 5688 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5689 | return None |
| 5690 | except Exception: |
| 5691 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5692 | main.cleanAndExit() |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 5693 | |
| 5694 | def events( self, args='-a' ): |
| 5695 | """ |
| 5696 | Description: Returns events -a command output |
| 5697 | Optional: |
| 5698 | add other arguments |
| 5699 | """ |
| 5700 | try: |
| 5701 | cmdStr = "events" |
| 5702 | if args: |
| 5703 | cmdStr += " " + args |
| 5704 | handle = self.sendline( cmdStr ) |
| 5705 | assert handle is not None, "Error in sendline" |
| 5706 | assert "Command not found:" not in handle, handle |
| 5707 | return handle |
| 5708 | except AssertionError: |
| 5709 | main.log.exception( "" ) |
| 5710 | return None |
| 5711 | except TypeError: |
| 5712 | main.log.exception( self.name + ": Object not as expected" ) |
| 5713 | return None |
| 5714 | except pexpect.EOF: |
| 5715 | main.log.error( self.name + ": EOF exception found" ) |
| 5716 | main.log.error( self.name + ": " + self.handle.before ) |
| 5717 | main.cleanAndExit() |
| 5718 | except Exception: |
| 5719 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5720 | main.cleanAndExit() |
| 5721 | |
| 5722 | def getMaster( self, deviceID ): |
| 5723 | """ |
| 5724 | Description: Obtains current master using "roles" command for a specific deviceID |
| 5725 | """ |
| 5726 | try: |
| 5727 | return str( self.getRole( deviceID )[ 'master' ] ) |
| 5728 | except AssertionError: |
| 5729 | main.log.exception( "" ) |
| 5730 | return None |
| 5731 | except TypeError: |
| 5732 | main.log.exception( self.name + ": Object not as expected" ) |
| 5733 | return None |
| 5734 | except pexpect.EOF: |
| 5735 | main.log.error( self.name + ": EOF exception found" ) |
| 5736 | main.log.error( self.name + ": " + self.handle.before ) |
| 5737 | main.cleanAndExit() |
| 5738 | except Exception: |
| 5739 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 5740 | main.cleanAndExit() |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5741 | |
| 5742 | def issu( self ): |
| 5743 | """ |
| 5744 | Short summary of In-Service Software Upgrade status |
| 5745 | |
| 5746 | Returns the output of the cli command or None on Error |
| 5747 | """ |
| 5748 | try: |
| 5749 | cmdStr = "issu" |
| 5750 | handle = self.sendline( cmdStr ) |
| 5751 | assert handle is not None, "Error in sendline" |
| 5752 | assert "Command not found:" not in handle, handle |
| 5753 | assert "Unsupported command:" not in handle, handle |
| 5754 | return handle |
| 5755 | except AssertionError: |
| 5756 | main.log.exception( "" ) |
| 5757 | return None |
| 5758 | except TypeError: |
| 5759 | main.log.exception( self.name + ": Object not as expected" ) |
| 5760 | return None |
| 5761 | except pexpect.EOF: |
| 5762 | main.log.error( self.name + ": EOF exception found" ) |
| 5763 | main.log.error( self.name + ": " + self.handle.before ) |
| 5764 | main.cleanAndExit() |
| 5765 | except Exception: |
| 5766 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5767 | main.cleanAndExit() |
| 5768 | |
| 5769 | def issuInit( self ): |
| 5770 | """ |
| 5771 | Initiates an In-Service Software Upgrade |
| 5772 | |
| 5773 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5774 | """ |
| 5775 | try: |
| 5776 | cmdStr = "issu init" |
| 5777 | handle = self.sendline( cmdStr ) |
| 5778 | assert handle is not None, "Error in sendline" |
| 5779 | assert "Command not found:" not in handle, handle |
| 5780 | assert "Unsupported command:" not in handle, handle |
| 5781 | if "Initialized" in handle: |
| 5782 | return main.TRUE |
| 5783 | else: |
| 5784 | return main.FALSE |
| 5785 | except AssertionError: |
| 5786 | main.log.exception( "" ) |
| 5787 | return main.ERROR |
| 5788 | except TypeError: |
| 5789 | main.log.exception( self.name + ": Object not as expected" ) |
| 5790 | return main.ERROR |
| 5791 | except pexpect.EOF: |
| 5792 | main.log.error( self.name + ": EOF exception found" ) |
| 5793 | main.log.error( self.name + ": " + self.handle.before ) |
| 5794 | main.cleanAndExit() |
| 5795 | except Exception: |
| 5796 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5797 | main.cleanAndExit() |
| 5798 | |
| 5799 | def issuUpgrade( self ): |
| 5800 | """ |
| 5801 | Transitions stores to upgraded nodes |
| 5802 | |
| 5803 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5804 | """ |
| 5805 | try: |
| 5806 | cmdStr = "issu upgrade" |
| 5807 | handle = self.sendline( cmdStr ) |
| 5808 | assert handle is not None, "Error in sendline" |
| 5809 | assert "Command not found:" not in handle, handle |
| 5810 | assert "Unsupported command:" not in handle, handle |
| 5811 | if "Upgraded" in handle: |
| 5812 | return main.TRUE |
| 5813 | else: |
| 5814 | return main.FALSE |
| 5815 | except AssertionError: |
| 5816 | main.log.exception( "" ) |
| 5817 | return main.ERROR |
| 5818 | except TypeError: |
| 5819 | main.log.exception( self.name + ": Object not as expected" ) |
| 5820 | return main.ERROR |
| 5821 | except pexpect.EOF: |
| 5822 | main.log.error( self.name + ": EOF exception found" ) |
| 5823 | main.log.error( self.name + ": " + self.handle.before ) |
| 5824 | main.cleanAndExit() |
| 5825 | except Exception: |
| 5826 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5827 | main.cleanAndExit() |
| 5828 | |
| 5829 | def issuCommit( self ): |
| 5830 | """ |
| 5831 | Finalizes an In-Service Software Upgrade |
| 5832 | |
| 5833 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5834 | """ |
| 5835 | try: |
| 5836 | cmdStr = "issu commit" |
| 5837 | handle = self.sendline( cmdStr ) |
| 5838 | assert handle is not None, "Error in sendline" |
| 5839 | assert "Command not found:" not in handle, handle |
| 5840 | assert "Unsupported command:" not in handle, handle |
| 5841 | # TODO: Check the version returned by this command |
| 5842 | if "Committed version" in handle: |
| 5843 | return main.TRUE |
| 5844 | else: |
| 5845 | return main.FALSE |
| 5846 | except AssertionError: |
| 5847 | main.log.exception( "" ) |
| 5848 | return main.ERROR |
| 5849 | except TypeError: |
| 5850 | main.log.exception( self.name + ": Object not as expected" ) |
| 5851 | return main.ERROR |
| 5852 | except pexpect.EOF: |
| 5853 | main.log.error( self.name + ": EOF exception found" ) |
| 5854 | main.log.error( self.name + ": " + self.handle.before ) |
| 5855 | main.cleanAndExit() |
| 5856 | except Exception: |
| 5857 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5858 | main.cleanAndExit() |
| 5859 | |
| 5860 | def issuRollback( self ): |
| 5861 | """ |
| 5862 | Rolls back an In-Service Software Upgrade |
| 5863 | |
| 5864 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5865 | """ |
| 5866 | try: |
| 5867 | cmdStr = "issu rollback" |
| 5868 | handle = self.sendline( cmdStr ) |
| 5869 | assert handle is not None, "Error in sendline" |
| 5870 | assert "Command not found:" not in handle, handle |
| 5871 | assert "Unsupported command:" not in handle, handle |
| 5872 | # TODO: Check the version returned by this command |
| 5873 | if "Rolled back to version" in handle: |
| 5874 | return main.TRUE |
| 5875 | else: |
| 5876 | return main.FALSE |
| 5877 | except AssertionError: |
| 5878 | main.log.exception( "" ) |
| 5879 | return main.ERROR |
| 5880 | except TypeError: |
| 5881 | main.log.exception( self.name + ": Object not as expected" ) |
| 5882 | return main.ERROR |
| 5883 | except pexpect.EOF: |
| 5884 | main.log.error( self.name + ": EOF exception found" ) |
| 5885 | main.log.error( self.name + ": " + self.handle.before ) |
| 5886 | main.cleanAndExit() |
| 5887 | except Exception: |
| 5888 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5889 | main.cleanAndExit() |
| 5890 | |
| 5891 | def issuReset( self ): |
| 5892 | """ |
| 5893 | Resets the In-Service Software Upgrade status after a rollback |
| 5894 | |
| 5895 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5896 | """ |
| 5897 | try: |
| 5898 | cmdStr = "issu reset" |
| 5899 | handle = self.sendline( cmdStr ) |
| 5900 | assert handle is not None, "Error in sendline" |
| 5901 | assert "Command not found:" not in handle, handle |
| 5902 | assert "Unsupported command:" not in handle, handle |
| 5903 | # TODO: Check the version returned by this command |
| 5904 | if "Reset version" in handle: |
| 5905 | return main.TRUE |
| 5906 | else: |
| 5907 | return main.FALSE |
| 5908 | except AssertionError: |
| 5909 | main.log.exception( "" ) |
| 5910 | return main.ERROR |
| 5911 | except TypeError: |
| 5912 | main.log.exception( self.name + ": Object not as expected" ) |
| 5913 | return main.ERROR |
| 5914 | except pexpect.EOF: |
| 5915 | main.log.error( self.name + ": EOF exception found" ) |
| 5916 | main.log.error( self.name + ": " + self.handle.before ) |
| 5917 | main.cleanAndExit() |
| 5918 | except Exception: |
| 5919 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5920 | main.cleanAndExit() |
| 5921 | |
| 5922 | def issuStatus( self ): |
| 5923 | """ |
| 5924 | Status of an In-Service Software Upgrade |
| 5925 | |
| 5926 | Returns the output of the cli command or None on Error |
| 5927 | """ |
| 5928 | try: |
| 5929 | cmdStr = "issu status" |
| 5930 | handle = self.sendline( cmdStr ) |
| 5931 | assert handle is not None, "Error in sendline" |
| 5932 | assert "Command not found:" not in handle, handle |
| 5933 | assert "Unsupported command:" not in handle, handle |
| 5934 | return handle |
| 5935 | except AssertionError: |
| 5936 | main.log.exception( "" ) |
| 5937 | return None |
| 5938 | except TypeError: |
| 5939 | main.log.exception( self.name + ": Object not as expected" ) |
| 5940 | return None |
| 5941 | except pexpect.EOF: |
| 5942 | main.log.error( self.name + ": EOF exception found" ) |
| 5943 | main.log.error( self.name + ": " + self.handle.before ) |
| 5944 | main.cleanAndExit() |
| 5945 | except Exception: |
| 5946 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5947 | main.cleanAndExit() |
| 5948 | |
| 5949 | def issuVersion( self ): |
| 5950 | """ |
| 5951 | Get the version of an In-Service Software Upgrade |
| 5952 | |
| 5953 | Returns the output of the cli command or None on Error |
| 5954 | """ |
| 5955 | try: |
| 5956 | cmdStr = "issu version" |
| 5957 | handle = self.sendline( cmdStr ) |
| 5958 | assert handle is not None, "Error in sendline" |
| 5959 | assert "Command not found:" not in handle, handle |
| 5960 | assert "Unsupported command:" not in handle, handle |
| 5961 | return handle |
| 5962 | except AssertionError: |
| 5963 | main.log.exception( "" ) |
| 5964 | return None |
| 5965 | except TypeError: |
| 5966 | main.log.exception( self.name + ": Object not as expected" ) |
| 5967 | return None |
| 5968 | except pexpect.EOF: |
| 5969 | main.log.error( self.name + ": EOF exception found" ) |
| 5970 | main.log.error( self.name + ": " + self.handle.before ) |
| 5971 | main.cleanAndExit() |
| 5972 | except Exception: |
| 5973 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5974 | main.cleanAndExit() |