andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 4 | OCT 13 2014 |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5 | Copyright 2014 Open Networking Foundation (ONF) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 6 | |
| 7 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 8 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 9 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 10 | |
| 11 | TestON is free software: you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 14 | (at your option) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 15 | |
| 16 | TestON is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 23 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 24 | |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 25 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 26 | This driver enters the onos> prompt to issue commands. |
| 27 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 28 | Please follow the coding style demonstrated by existing |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 29 | functions and document properly. |
| 30 | |
| 31 | If you are a contributor to the driver, please |
| 32 | list your email here for future contact: |
| 33 | |
| 34 | jhall@onlab.us |
| 35 | andrew@onlab.us |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 36 | shreya@onlab.us |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 37 | jeremyr@opennetworking.org |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 38 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 39 | import pexpect |
| 40 | import re |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 41 | import json |
| 42 | import types |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 43 | import time |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 44 | import os |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 45 | from drivers.common.clidriver import CLI |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 46 | from core.graph import Graph |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 47 | from cStringIO import StringIO |
| 48 | from itertools import izip |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 49 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 50 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 51 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 52 | def __init__( self ): |
| 53 | """ |
| 54 | Initialize client |
| 55 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 56 | self.name = None |
| 57 | self.home = None |
| 58 | self.handle = None |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 59 | self.karafUser = None |
| 60 | self.karafPass = None |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 61 | self.graph = Graph() |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 62 | super( OnosCliDriver, self ).__init__() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 63 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 64 | def checkOptions( self, var, defaultVar ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 65 | if var is None or var == "": |
| 66 | return defaultVar |
| 67 | return var |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 68 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 69 | def connect( self, **connectargs ): |
| 70 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 71 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 72 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 73 | try: |
| 74 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 75 | vars( self )[ key ] = connectargs[ key ] |
andrew@onlab.us | 658ec01 | 2015-03-11 15:13:09 -0700 | [diff] [blame] | 76 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 77 | for key in self.options: |
| 78 | if key == "home": |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 79 | self.home = self.options[ key ] |
| 80 | elif key == "karaf_username": |
| 81 | self.karafUser = self.options[ key ] |
| 82 | elif key == "karaf_password": |
| 83 | self.karafPass = self.options[ key ] |
| 84 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 85 | self.home = self.checkOptions( self.home, "~/onos" ) |
| 86 | self.karafUser = self.checkOptions( self.karafUser, self.user_name ) |
| 87 | self.karafPass = self.checkOptions( self.karafPass, self.pwd ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 88 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 89 | for key in self.options: |
| 90 | if key == 'onosIp': |
| 91 | self.onosIp = self.options[ 'onosIp' ] |
| 92 | break |
| 93 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 94 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 95 | |
| 96 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 97 | if os.getenv( str( self.ip_address ) ) is not None: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 98 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 99 | else: |
| 100 | main.log.info( self.name + |
| 101 | ": Trying to connect to " + |
| 102 | self.ip_address ) |
| 103 | |
| 104 | except KeyError: |
| 105 | main.log.info( "Invalid host name," + |
| 106 | " connecting to local host instead" ) |
| 107 | self.ip_address = 'localhost' |
| 108 | except Exception as inst: |
| 109 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 110 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 111 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 112 | user_name=self.user_name, |
| 113 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 114 | port=self.port, |
| 115 | pwd=self.pwd, |
| 116 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 117 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 118 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 119 | self.handle.expect( self.prompt ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 120 | if self.handle: |
| 121 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 122 | else: |
| 123 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 124 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 125 | except TypeError: |
| 126 | main.log.exception( self.name + ": Object not as expected" ) |
| 127 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 128 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 129 | main.log.error( self.name + ": EOF exception found" ) |
| 130 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 131 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 132 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 133 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 134 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 135 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 136 | def disconnect( self ): |
| 137 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 138 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 139 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 140 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 141 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 142 | if self.handle: |
| 143 | i = self.logout() |
| 144 | if i == main.TRUE: |
| 145 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 146 | self.handle.expect( self.prompt ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 147 | self.handle.sendline( "exit" ) |
| 148 | self.handle.expect( "closed" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 149 | except TypeError: |
| 150 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 151 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 152 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 153 | main.log.error( self.name + ": EOF exception found" ) |
| 154 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 155 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 156 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 157 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 158 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 159 | main.log.exception( self.name + ": Connection failed to the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 160 | response = main.FALSE |
| 161 | return response |
| 162 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 163 | def logout( self ): |
| 164 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 165 | Sends 'logout' command to ONOS cli |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 166 | Returns main.TRUE if exited CLI and |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 167 | main.FALSE on timeout (not guranteed you are disconnected) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 168 | None on TypeError |
| 169 | Exits test on unknown error or pexpect exits unexpectedly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 170 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 171 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 172 | if self.handle: |
| 173 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 174 | i = self.handle.expect( [ "onos>", self.prompt, pexpect.TIMEOUT ], |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 175 | timeout=10 ) |
| 176 | if i == 0: # In ONOS CLI |
| 177 | self.handle.sendline( "logout" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 178 | j = self.handle.expect( [ self.prompt, |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 179 | "Command not found:", |
| 180 | pexpect.TIMEOUT ] ) |
| 181 | if j == 0: # Successfully logged out |
| 182 | return main.TRUE |
| 183 | elif j == 1 or j == 2: |
| 184 | # ONOS didn't fully load, and logout command isn't working |
| 185 | # or the command timed out |
| 186 | self.handle.send( "\x04" ) # send ctrl-d |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 187 | try: |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 188 | self.handle.expect( self.prompt ) |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 189 | except pexpect.TIMEOUT: |
| 190 | main.log.error( "ONOS did not respond to 'logout' or CTRL-d" ) |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 191 | return main.TRUE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 192 | else: # some other output |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 193 | main.log.warn( "Unknown repsonse to logout command: '{}'", |
| 194 | repr( self.handle.before ) ) |
| 195 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 196 | elif i == 1: # not in CLI |
| 197 | return main.TRUE |
| 198 | elif i == 3: # Timeout |
| 199 | return main.FALSE |
| 200 | else: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 201 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 202 | except TypeError: |
| 203 | main.log.exception( self.name + ": Object not as expected" ) |
| 204 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 205 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 206 | main.log.error( self.name + ": eof exception found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 207 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 208 | main.cleanAndExit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 209 | except ValueError: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 210 | main.log.error( self.name + |
| 211 | "ValueError exception in logout method" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 212 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 213 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 214 | main.cleanAndExit() |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 215 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 216 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 217 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 218 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 219 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 220 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 221 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 222 | try: |
| 223 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 224 | main.log.error( "Must define cellname" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 225 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 226 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 227 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 228 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 229 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 230 | # and that this driver will have to change accordingly |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 231 | self.handle.expect( str( cellname ) ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 232 | handleBefore = self.handle.before |
| 233 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 234 | # Get the rest of the handle |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 235 | self.handle.sendline( "" ) |
| 236 | self.handle.expect( self.prompt ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 237 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 238 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 239 | main.log.info( "Cell call returned: " + handleBefore + |
| 240 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 241 | |
| 242 | return main.TRUE |
| 243 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 244 | except TypeError: |
| 245 | main.log.exception( self.name + ": Object not as expected" ) |
| 246 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 247 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 248 | main.log.error( self.name + ": eof exception found" ) |
| 249 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 250 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 251 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 252 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 253 | main.cleanAndExit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 254 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 255 | def startOnosCli( self, ONOSIp, karafTimeout="", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 256 | commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 257 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 258 | karafTimeout is an optional argument. karafTimeout value passed |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 259 | by user would be used to set the current karaf shell idle timeout. |
| 260 | Note that when ever this property is modified the shell will exit and |
Hari Krishna | d7b9c20 | 2015-01-05 10:38:14 -0800 | [diff] [blame] | 261 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 262 | Below is an example to start a session with 60 seconds idle timeout |
| 263 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 264 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 265 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 266 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 267 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 268 | Note: karafTimeout is left as str so that this could be read |
| 269 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 270 | """ |
You Wang | f69ab39 | 2016-01-26 16:34:38 -0800 | [diff] [blame] | 271 | self.onosIp = ONOSIp |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 272 | try: |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 273 | # Check if we are already in the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 274 | self.handle.sendline( "" ) |
| 275 | x = self.handle.expect( [ |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 276 | self.prompt, "onos>" ], commandlineTimeout ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 277 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 278 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 279 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 280 | |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 281 | # Not in CLI so login |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 282 | if waitForStart: |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 283 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
| 284 | startCliCommand = "onos-wait-for-start " |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 285 | else: |
| 286 | startCliCommand = "onos " |
| 287 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 288 | i = self.handle.expect( [ |
| 289 | "onos>", |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 290 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 291 | |
| 292 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 293 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 294 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 295 | self.handle.sendline( |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 296 | "config:property-set -p org.apache.karaf.shell\ |
| 297 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 298 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 299 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 300 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 301 | self.handle.expect( "onos>" ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 302 | return main.TRUE |
| 303 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 304 | # If failed, send ctrl+c to process and try again |
| 305 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 306 | self.handle.send( "\x03" ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 307 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 308 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 309 | timeout=30 ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 310 | if i == 0: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 311 | main.log.info( str( ONOSIp ) + " CLI Started " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 312 | "successfully after retry attempt" ) |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 313 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 314 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 315 | "config:property-set -p org.apache.karaf.shell\ |
| 316 | sshIdleTimeout " + |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 317 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 318 | self.handle.expect( self.prompt ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 319 | self.handle.sendline( startCliCommand + str( ONOSIp ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 320 | self.handle.expect( "onos>" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 321 | return main.TRUE |
| 322 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 323 | main.log.error( "Connection to CLI " + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 324 | str( ONOSIp ) + " timeout" ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 325 | return main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 326 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 327 | except TypeError: |
| 328 | main.log.exception( self.name + ": Object not as expected" ) |
| 329 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 330 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 331 | main.log.error( self.name + ": EOF exception found" ) |
| 332 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 333 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 334 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 335 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 336 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 337 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 338 | def startCellCli( self, karafTimeout="", |
| 339 | commandlineTimeout=10, onosStartTimeout=60 ): |
| 340 | """ |
| 341 | Start CLI on onos ecll handle. |
| 342 | |
| 343 | karafTimeout is an optional argument. karafTimeout value passed |
| 344 | by user would be used to set the current karaf shell idle timeout. |
| 345 | Note that when ever this property is modified the shell will exit and |
| 346 | the subsequent login would reflect new idle timeout. |
| 347 | Below is an example to start a session with 60 seconds idle timeout |
| 348 | ( input value is in milliseconds ): |
| 349 | |
| 350 | tValue = "60000" |
| 351 | |
| 352 | Note: karafTimeout is left as str so that this could be read |
| 353 | and passed to startOnosCli from PARAMS file as str. |
| 354 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 355 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 356 | try: |
| 357 | self.handle.sendline( "" ) |
| 358 | x = self.handle.expect( [ |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 359 | self.prompt, "onos>" ], commandlineTimeout ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 360 | |
| 361 | if x == 1: |
| 362 | main.log.info( "ONOS cli is already running" ) |
| 363 | return main.TRUE |
| 364 | |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 365 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 366 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 367 | i = self.handle.expect( [ |
| 368 | "onos>", |
| 369 | pexpect.TIMEOUT ], onosStartTimeout ) |
| 370 | |
| 371 | if i == 0: |
| 372 | main.log.info( self.name + " CLI Started successfully" ) |
| 373 | if karafTimeout: |
| 374 | self.handle.sendline( |
| 375 | "config:property-set -p org.apache.karaf.shell\ |
| 376 | sshIdleTimeout " + |
| 377 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 378 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 379 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 380 | self.handle.expect( "onos>" ) |
| 381 | return main.TRUE |
| 382 | else: |
| 383 | # If failed, send ctrl+c to process and try again |
| 384 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 385 | self.handle.send( "\x03" ) |
| 386 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 387 | i = self.handle.expect( [ "onos>", pexpect.TIMEOUT ], |
| 388 | timeout=30 ) |
| 389 | if i == 0: |
| 390 | main.log.info( self.name + " CLI Started " + |
| 391 | "successfully after retry attempt" ) |
| 392 | if karafTimeout: |
| 393 | self.handle.sendline( |
| 394 | "config:property-set -p org.apache.karaf.shell\ |
| 395 | sshIdleTimeout " + |
| 396 | karafTimeout ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 397 | self.handle.expect( self.prompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 398 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 399 | self.handle.expect( "onos>" ) |
| 400 | return main.TRUE |
| 401 | else: |
| 402 | main.log.error( "Connection to CLI " + |
| 403 | self.name + " timeout" ) |
| 404 | return main.FALSE |
| 405 | |
| 406 | except TypeError: |
| 407 | main.log.exception( self.name + ": Object not as expected" ) |
| 408 | return None |
| 409 | except pexpect.EOF: |
| 410 | main.log.error( self.name + ": EOF exception found" ) |
| 411 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 412 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 413 | except Exception: |
| 414 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 415 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 416 | |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 417 | def log( self, cmdStr, level="", noExit=False ): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 418 | """ |
| 419 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 420 | returns main.TRUE on success |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 421 | returns main.FALSE if Error occurred |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 422 | if noExit is True, TestON will not exit, but clean up |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 423 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 424 | Level defaults to INFO |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 425 | if cmdStr has spaces then put quotes in the passed string |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 426 | """ |
| 427 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 428 | lvlStr = "" |
| 429 | if level: |
| 430 | lvlStr = "--level=" + level |
| 431 | |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 432 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 433 | self.handle.expect( "log:log" ) |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 434 | self.handle.expect( "onos>" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 435 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 436 | response = self.handle.before |
| 437 | if re.search( "Error", response ): |
| 438 | return main.FALSE |
| 439 | return main.TRUE |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 440 | except pexpect.TIMEOUT: |
| 441 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 442 | if noExit: |
| 443 | main.cleanup() |
| 444 | return None |
| 445 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 446 | main.cleanAndExit() |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 447 | except pexpect.EOF: |
| 448 | main.log.error( self.name + ": EOF exception found" ) |
| 449 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 450 | if noExit: |
| 451 | main.cleanup() |
| 452 | return None |
| 453 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 454 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 455 | except Exception: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 456 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 457 | if noExit: |
| 458 | main.cleanup() |
| 459 | return None |
| 460 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 461 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 462 | |
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 | |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1154 | def verifyHostIp( self, hostList=[], prefix="" ): |
| 1155 | """ |
| 1156 | Description: |
| 1157 | Verify that all hosts have IP address assigned to them |
| 1158 | Optional: |
| 1159 | hostList: If specified, verifications only happen to the hosts |
| 1160 | in hostList |
| 1161 | prefix: at least one of the ip address assigned to the host |
| 1162 | needs to have the specified prefix |
| 1163 | Returns: |
| 1164 | main.TRUE if all hosts have specific IP address assigned; |
| 1165 | main.FALSE otherwise |
| 1166 | """ |
| 1167 | import json |
| 1168 | try: |
| 1169 | hosts = self.hosts() |
| 1170 | hosts = json.loads( hosts ) |
| 1171 | if not hostList: |
| 1172 | hostList = [ host[ "id" ] for host in hosts ] |
| 1173 | for host in hosts: |
| 1174 | hostId = host[ "id" ] |
| 1175 | if hostId not in hostList: |
| 1176 | continue |
| 1177 | ipList = host[ "ipAddresses" ] |
| 1178 | main.log.debug( self.name + ": IP list on host " + str( hostId ) + ": " + str( ipList ) ) |
| 1179 | if not ipList: |
| 1180 | main.log.warn( self.name + ": Failed to discover any IP addresses on host " + str( hostId ) ) |
| 1181 | else: |
| 1182 | if not any( ip.startswith( str( prefix ) ) for ip in ipList ): |
| 1183 | main.log.warn( self.name + ": None of the IPs on host " + str( hostId ) + " has prefix " + str( prefix ) ) |
| 1184 | else: |
| 1185 | main.log.debug( self.name + ": Found matching IP on host " + str( hostId ) ) |
| 1186 | hostList.remove( hostId ) |
| 1187 | if hostList: |
| 1188 | main.log.warn( self.name + ": failed to verify IP on following hosts: " + str( hostList) ) |
| 1189 | return main.FALSE |
| 1190 | else: |
| 1191 | return main.TRUE |
| 1192 | except KeyError: |
| 1193 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1194 | return None |
| 1195 | except pexpect.EOF: |
| 1196 | main.log.error( self.name + ": EOF exception found" ) |
| 1197 | main.log.error( self.name + ": " + self.handle.before ) |
| 1198 | main.cleanAndExit() |
| 1199 | except Exception: |
| 1200 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1201 | return None |
| 1202 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1203 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1204 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1205 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1206 | * hostIdOne: ONOS host id for host1 |
| 1207 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1208 | Optional: |
| 1209 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1210 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1211 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1212 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1213 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1214 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1215 | Returns: |
| 1216 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1217 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1218 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1219 | cmdStr = "add-host-intent " |
| 1220 | if vlanId: |
| 1221 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1222 | if setVlan: |
| 1223 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1224 | if encap: |
| 1225 | cmdStr += "--encapsulation " + str( encap ) + " " |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1226 | if bandwidth: |
| 1227 | cmdStr += "-b " + str( bandwidth ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1228 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1229 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1230 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1231 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1232 | if re.search( "Error", handle ): |
| 1233 | main.log.error( "Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1234 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1235 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1236 | else: |
| 1237 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1238 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1239 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1240 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1241 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1242 | else: |
| 1243 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1244 | main.log.debug( "Response from ONOS was: " + |
| 1245 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1246 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1247 | except AssertionError: |
| 1248 | main.log.exception( "" ) |
| 1249 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1250 | except TypeError: |
| 1251 | main.log.exception( self.name + ": Object not as expected" ) |
| 1252 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1253 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1254 | main.log.error( self.name + ": EOF exception found" ) |
| 1255 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1256 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1257 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1258 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1259 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1260 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1261 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1262 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1263 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1264 | * ingressDevice: device id of ingress device |
| 1265 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1266 | Optional: |
| 1267 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1268 | Description: |
| 1269 | Adds an optical intent by specifying an ingress and egress device |
| 1270 | Returns: |
| 1271 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1272 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1273 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1274 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1275 | " " + str( egressDevice ) |
| 1276 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1277 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1278 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1279 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1280 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1281 | main.log.error( "Error in adding Optical intent" ) |
| 1282 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1283 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1284 | main.log.info( "Optical intent installed between " + |
| 1285 | str( ingressDevice ) + " and " + |
| 1286 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1287 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1288 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1289 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1290 | else: |
| 1291 | main.log.error( "Error, intent ID not found" ) |
| 1292 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1293 | except AssertionError: |
| 1294 | main.log.exception( "" ) |
| 1295 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1296 | except TypeError: |
| 1297 | main.log.exception( self.name + ": Object not as expected" ) |
| 1298 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1299 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1300 | main.log.error( self.name + ": EOF exception found" ) |
| 1301 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1302 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1303 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1304 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1305 | main.cleanAndExit() |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1306 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1307 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1308 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1309 | ingressDevice, |
| 1310 | egressDevice, |
| 1311 | portIngress="", |
| 1312 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1313 | ethType="", |
| 1314 | ethSrc="", |
| 1315 | ethDst="", |
| 1316 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1317 | lambdaAlloc=False, |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1318 | protected=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1319 | ipProto="", |
| 1320 | ipSrc="", |
| 1321 | ipDst="", |
| 1322 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1323 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1324 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1325 | setVlan="", |
| 1326 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1327 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1328 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1329 | * ingressDevice: device id of ingress device |
| 1330 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1331 | Optional: |
| 1332 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1333 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1334 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1335 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1336 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1337 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1338 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1339 | * ipSrc: specify ip source address |
| 1340 | * ipDst: specify ip destination address |
| 1341 | * tcpSrc: specify tcp source port |
| 1342 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1343 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1344 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1345 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1346 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1347 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1348 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1349 | Returns: |
| 1350 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1351 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1352 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1353 | options developers provide for point-to-point |
| 1354 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1355 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1356 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1357 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1358 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1359 | if ethType: |
| 1360 | cmd += " --ethType " + str( ethType ) |
| 1361 | if ethSrc: |
| 1362 | cmd += " --ethSrc " + str( ethSrc ) |
| 1363 | if ethDst: |
| 1364 | cmd += " --ethDst " + str( ethDst ) |
| 1365 | if bandwidth: |
| 1366 | cmd += " --bandwidth " + str( bandwidth ) |
| 1367 | if lambdaAlloc: |
| 1368 | cmd += " --lambda " |
| 1369 | if ipProto: |
| 1370 | cmd += " --ipProto " + str( ipProto ) |
| 1371 | if ipSrc: |
| 1372 | cmd += " --ipSrc " + str( ipSrc ) |
| 1373 | if ipDst: |
| 1374 | cmd += " --ipDst " + str( ipDst ) |
| 1375 | if tcpSrc: |
| 1376 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1377 | if tcpDst: |
| 1378 | cmd += " --tcpDst " + str( tcpDst ) |
| 1379 | if vlanId: |
| 1380 | cmd += " -v " + str( vlanId ) |
| 1381 | if setVlan: |
| 1382 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1383 | if encap: |
| 1384 | cmd += " --encapsulation " + str( encap ) |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1385 | if protected: |
| 1386 | cmd += " --protect " |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1387 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1388 | # Check whether the user appended the port |
| 1389 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1390 | if "/" in ingressDevice: |
| 1391 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1392 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1393 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1394 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1395 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1396 | # Would it make sense to throw an exception and exit |
| 1397 | # the test? |
| 1398 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1399 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1400 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1401 | str( ingressDevice ) + "/" +\ |
| 1402 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1403 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1404 | if "/" in egressDevice: |
| 1405 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1406 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1407 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1408 | main.log.error( "You must specify the egress port" ) |
| 1409 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1410 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1411 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1412 | str( egressDevice ) + "/" +\ |
| 1413 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1414 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1415 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1416 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1417 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1418 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1419 | if re.search( "Error", handle ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1420 | main.log.error( "Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1421 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1422 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1423 | # TODO: print out all the options in this message? |
| 1424 | main.log.info( "Point-to-point intent installed between " + |
| 1425 | str( ingressDevice ) + " and " + |
| 1426 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1427 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1428 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1429 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1430 | else: |
| 1431 | main.log.error( "Error, intent ID not found" ) |
| 1432 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1433 | except AssertionError: |
| 1434 | main.log.exception( "" ) |
| 1435 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1436 | except TypeError: |
| 1437 | main.log.exception( self.name + ": Object not as expected" ) |
| 1438 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1439 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1440 | main.log.error( self.name + ": EOF exception found" ) |
| 1441 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1442 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1443 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1444 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1445 | main.cleanAndExit() |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1446 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1447 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1448 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1449 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1450 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1451 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1452 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1453 | ethType="", |
| 1454 | ethSrc="", |
| 1455 | ethDst="", |
| 1456 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1457 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1458 | ipProto="", |
| 1459 | ipSrc="", |
| 1460 | ipDst="", |
| 1461 | tcpSrc="", |
| 1462 | tcpDst="", |
| 1463 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1464 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1465 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1466 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1467 | partial=False, |
| 1468 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1469 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1470 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1471 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1472 | is same. That is, all ingress devices include port numbers |
| 1473 | with a "/" or all ingress devices could specify device |
| 1474 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1475 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1476 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1477 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1478 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1479 | Optional: |
| 1480 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1481 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1482 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1483 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1484 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1485 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1486 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1487 | * ipSrc: specify ip source address |
| 1488 | * ipDst: specify ip destination address |
| 1489 | * tcpSrc: specify tcp source port |
| 1490 | * tcpDst: specify tcp destination port |
| 1491 | * setEthSrc: action to Rewrite Source MAC Address |
| 1492 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1493 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1494 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1495 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1496 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1497 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1498 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1499 | Returns: |
| 1500 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1501 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1502 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1503 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1504 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1505 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1506 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1507 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1508 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1509 | if ethType: |
| 1510 | cmd += " --ethType " + str( ethType ) |
| 1511 | if ethSrc: |
| 1512 | cmd += " --ethSrc " + str( ethSrc ) |
| 1513 | if ethDst: |
| 1514 | cmd += " --ethDst " + str( ethDst ) |
| 1515 | if bandwidth: |
| 1516 | cmd += " --bandwidth " + str( bandwidth ) |
| 1517 | if lambdaAlloc: |
| 1518 | cmd += " --lambda " |
| 1519 | if ipProto: |
| 1520 | cmd += " --ipProto " + str( ipProto ) |
| 1521 | if ipSrc: |
| 1522 | cmd += " --ipSrc " + str( ipSrc ) |
| 1523 | if ipDst: |
| 1524 | cmd += " --ipDst " + str( ipDst ) |
| 1525 | if tcpSrc: |
| 1526 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1527 | if tcpDst: |
| 1528 | cmd += " --tcpDst " + str( tcpDst ) |
| 1529 | if setEthSrc: |
| 1530 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1531 | if setEthDst: |
| 1532 | cmd += " --setEthDst " + str( setEthDst ) |
| 1533 | if vlanId: |
| 1534 | cmd += " -v " + str( vlanId ) |
| 1535 | if setVlan: |
| 1536 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1537 | if partial: |
| 1538 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1539 | if encap: |
| 1540 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1541 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1542 | # Check whether the user appended the port |
| 1543 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1544 | |
| 1545 | if portIngressList is None: |
| 1546 | for ingressDevice in ingressDeviceList: |
| 1547 | if "/" in ingressDevice: |
| 1548 | cmd += " " + str( ingressDevice ) |
| 1549 | else: |
| 1550 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1551 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1552 | # TODO: perhaps more meaningful return |
| 1553 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1554 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1555 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1556 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1557 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1558 | cmd += " " + \ |
| 1559 | str( ingressDevice ) + "/" +\ |
| 1560 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1561 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1562 | main.log.error( "Device list and port list does not " + |
| 1563 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1564 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1565 | if "/" in egressDevice: |
| 1566 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1567 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1568 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1569 | main.log.error( "You must specify " + |
| 1570 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1571 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1572 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1573 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1574 | str( egressDevice ) + "/" +\ |
| 1575 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1576 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1577 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1578 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1579 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1580 | if re.search( "Error", handle ): |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1581 | main.log.error( "Error in adding multipoint-to-singlepoint " + |
| 1582 | "intent" ) |
| 1583 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1584 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1585 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1586 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1587 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1588 | else: |
| 1589 | main.log.error( "Error, intent ID not found" ) |
| 1590 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1591 | except AssertionError: |
| 1592 | main.log.exception( "" ) |
| 1593 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1594 | except TypeError: |
| 1595 | main.log.exception( self.name + ": Object not as expected" ) |
| 1596 | return None |
| 1597 | except pexpect.EOF: |
| 1598 | main.log.error( self.name + ": EOF exception found" ) |
| 1599 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1600 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1601 | except Exception: |
| 1602 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1603 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1604 | |
| 1605 | def addSinglepointToMultipointIntent( |
| 1606 | self, |
| 1607 | ingressDevice, |
| 1608 | egressDeviceList, |
| 1609 | portIngress="", |
| 1610 | portEgressList=None, |
| 1611 | ethType="", |
| 1612 | ethSrc="", |
| 1613 | ethDst="", |
| 1614 | bandwidth="", |
| 1615 | lambdaAlloc=False, |
| 1616 | ipProto="", |
| 1617 | ipSrc="", |
| 1618 | ipDst="", |
| 1619 | tcpSrc="", |
| 1620 | tcpDst="", |
| 1621 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1622 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1623 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1624 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1625 | partial=False, |
| 1626 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1627 | """ |
| 1628 | Note: |
| 1629 | This function assumes the format of all egress devices |
| 1630 | is same. That is, all egress devices include port numbers |
| 1631 | with a "/" or all egress devices could specify device |
| 1632 | ids and port numbers seperately. |
| 1633 | Required: |
| 1634 | * EgressDeviceList: List of device ids of egress device |
| 1635 | ( Atleast 2 eress devices required in the list ) |
| 1636 | * ingressDevice: device id of ingress device |
| 1637 | Optional: |
| 1638 | * ethType: specify ethType |
| 1639 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1640 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1641 | * bandwidth: specify bandwidth capacity of link |
| 1642 | * lambdaAlloc: if True, intent will allocate lambda |
| 1643 | for the specified intent |
| 1644 | * ipProto: specify ip protocol |
| 1645 | * ipSrc: specify ip source address |
| 1646 | * ipDst: specify ip destination address |
| 1647 | * tcpSrc: specify tcp source port |
| 1648 | * tcpDst: specify tcp destination port |
| 1649 | * setEthSrc: action to Rewrite Source MAC Address |
| 1650 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1651 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1652 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1653 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1654 | Description: |
| 1655 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1656 | specifying device id's and optional fields |
| 1657 | Returns: |
| 1658 | A string of the intent id or None on error |
| 1659 | |
| 1660 | NOTE: This function may change depending on the |
| 1661 | options developers provide for singlepoint-to-multipoint |
| 1662 | intent via cli |
| 1663 | """ |
| 1664 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1665 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1666 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1667 | if ethType: |
| 1668 | cmd += " --ethType " + str( ethType ) |
| 1669 | if ethSrc: |
| 1670 | cmd += " --ethSrc " + str( ethSrc ) |
| 1671 | if ethDst: |
| 1672 | cmd += " --ethDst " + str( ethDst ) |
| 1673 | if bandwidth: |
| 1674 | cmd += " --bandwidth " + str( bandwidth ) |
| 1675 | if lambdaAlloc: |
| 1676 | cmd += " --lambda " |
| 1677 | if ipProto: |
| 1678 | cmd += " --ipProto " + str( ipProto ) |
| 1679 | if ipSrc: |
| 1680 | cmd += " --ipSrc " + str( ipSrc ) |
| 1681 | if ipDst: |
| 1682 | cmd += " --ipDst " + str( ipDst ) |
| 1683 | if tcpSrc: |
| 1684 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1685 | if tcpDst: |
| 1686 | cmd += " --tcpDst " + str( tcpDst ) |
| 1687 | if setEthSrc: |
| 1688 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1689 | if setEthDst: |
| 1690 | cmd += " --setEthDst " + str( setEthDst ) |
| 1691 | if vlanId: |
| 1692 | cmd += " -v " + str( vlanId ) |
| 1693 | if setVlan: |
| 1694 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1695 | if partial: |
| 1696 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1697 | if encap: |
| 1698 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1699 | |
| 1700 | # Check whether the user appended the port |
| 1701 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1702 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1703 | if "/" in ingressDevice: |
| 1704 | cmd += " " + str( ingressDevice ) |
| 1705 | else: |
| 1706 | if not portIngress: |
| 1707 | main.log.error( "You must specify " + |
| 1708 | "the Ingress port" ) |
| 1709 | return main.FALSE |
| 1710 | |
| 1711 | cmd += " " +\ |
| 1712 | str( ingressDevice ) + "/" +\ |
| 1713 | str( portIngress ) |
| 1714 | |
| 1715 | if portEgressList is None: |
| 1716 | for egressDevice in egressDeviceList: |
| 1717 | if "/" in egressDevice: |
| 1718 | cmd += " " + str( egressDevice ) |
| 1719 | else: |
| 1720 | main.log.error( "You must specify " + |
| 1721 | "the egress port" ) |
| 1722 | # TODO: perhaps more meaningful return |
| 1723 | return main.FALSE |
| 1724 | else: |
| 1725 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1726 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1727 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1728 | cmd += " " + \ |
| 1729 | str( egressDevice ) + "/" +\ |
| 1730 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1731 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1732 | main.log.error( "Device list and port list does not " + |
| 1733 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1734 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1735 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1736 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1737 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1738 | # If error, return error message |
| 1739 | if re.search( "Error", handle ): |
| 1740 | main.log.error( "Error in adding singlepoint-to-multipoint " + |
| 1741 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1742 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1743 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1744 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1745 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1746 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1747 | else: |
| 1748 | main.log.error( "Error, intent ID not found" ) |
| 1749 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1750 | except AssertionError: |
| 1751 | main.log.exception( "" ) |
| 1752 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1753 | except TypeError: |
| 1754 | main.log.exception( self.name + ": Object not as expected" ) |
| 1755 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1756 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1757 | main.log.error( self.name + ": EOF exception found" ) |
| 1758 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1759 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1760 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1761 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1762 | main.cleanAndExit() |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1763 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1764 | def addMplsIntent( |
| 1765 | self, |
| 1766 | ingressDevice, |
| 1767 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1768 | ingressPort="", |
| 1769 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1770 | ethType="", |
| 1771 | ethSrc="", |
| 1772 | ethDst="", |
| 1773 | bandwidth="", |
| 1774 | lambdaAlloc=False, |
| 1775 | ipProto="", |
| 1776 | ipSrc="", |
| 1777 | ipDst="", |
| 1778 | tcpSrc="", |
| 1779 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1780 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1781 | egressLabel="", |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1782 | priority="" ): |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1783 | """ |
| 1784 | Required: |
| 1785 | * ingressDevice: device id of ingress device |
| 1786 | * egressDevice: device id of egress device |
| 1787 | Optional: |
| 1788 | * ethType: specify ethType |
| 1789 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1790 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1791 | * bandwidth: specify bandwidth capacity of link |
| 1792 | * lambdaAlloc: if True, intent will allocate lambda |
| 1793 | for the specified intent |
| 1794 | * ipProto: specify ip protocol |
| 1795 | * ipSrc: specify ip source address |
| 1796 | * ipDst: specify ip destination address |
| 1797 | * tcpSrc: specify tcp source port |
| 1798 | * tcpDst: specify tcp destination port |
| 1799 | * ingressLabel: Ingress MPLS label |
| 1800 | * egressLabel: Egress MPLS label |
| 1801 | Description: |
| 1802 | Adds MPLS intent by |
| 1803 | specifying device id's and optional fields |
| 1804 | Returns: |
| 1805 | A string of the intent id or None on error |
| 1806 | |
| 1807 | NOTE: This function may change depending on the |
| 1808 | options developers provide for MPLS |
| 1809 | intent via cli |
| 1810 | """ |
| 1811 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1812 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1813 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1814 | if ethType: |
| 1815 | cmd += " --ethType " + str( ethType ) |
| 1816 | if ethSrc: |
| 1817 | cmd += " --ethSrc " + str( ethSrc ) |
| 1818 | if ethDst: |
| 1819 | cmd += " --ethDst " + str( ethDst ) |
| 1820 | if bandwidth: |
| 1821 | cmd += " --bandwidth " + str( bandwidth ) |
| 1822 | if lambdaAlloc: |
| 1823 | cmd += " --lambda " |
| 1824 | if ipProto: |
| 1825 | cmd += " --ipProto " + str( ipProto ) |
| 1826 | if ipSrc: |
| 1827 | cmd += " --ipSrc " + str( ipSrc ) |
| 1828 | if ipDst: |
| 1829 | cmd += " --ipDst " + str( ipDst ) |
| 1830 | if tcpSrc: |
| 1831 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1832 | if tcpDst: |
| 1833 | cmd += " --tcpDst " + str( tcpDst ) |
| 1834 | if ingressLabel: |
| 1835 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 1836 | if egressLabel: |
| 1837 | cmd += " --egressLabel " + str( egressLabel ) |
| 1838 | if priority: |
| 1839 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1840 | |
| 1841 | # Check whether the user appended the port |
| 1842 | # or provided it as an input |
| 1843 | if "/" in ingressDevice: |
| 1844 | cmd += " " + str( ingressDevice ) |
| 1845 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1846 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1847 | main.log.error( "You must specify the ingress port" ) |
| 1848 | return None |
| 1849 | |
| 1850 | cmd += " " + \ |
| 1851 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1852 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1853 | |
| 1854 | if "/" in egressDevice: |
| 1855 | cmd += " " + str( egressDevice ) |
| 1856 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1857 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1858 | main.log.error( "You must specify the egress port" ) |
| 1859 | return None |
| 1860 | |
| 1861 | cmd += " " +\ |
| 1862 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1863 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1864 | |
| 1865 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1866 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1867 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1868 | # If error, return error message |
| 1869 | if re.search( "Error", handle ): |
| 1870 | main.log.error( "Error in adding mpls intent" ) |
| 1871 | return None |
| 1872 | else: |
| 1873 | # TODO: print out all the options in this message? |
| 1874 | main.log.info( "MPLS intent installed between " + |
| 1875 | str( ingressDevice ) + " and " + |
| 1876 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1877 | match = re.search( 'id=0x([\da-f]+),', handle ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1878 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1879 | return match.group()[ 3:-1 ] |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1880 | else: |
| 1881 | main.log.error( "Error, intent ID not found" ) |
| 1882 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1883 | except AssertionError: |
| 1884 | main.log.exception( "" ) |
| 1885 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1886 | except TypeError: |
| 1887 | main.log.exception( self.name + ": Object not as expected" ) |
| 1888 | return None |
| 1889 | except pexpect.EOF: |
| 1890 | main.log.error( self.name + ": EOF exception found" ) |
| 1891 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1892 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1893 | except Exception: |
| 1894 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1895 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1896 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1897 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 1898 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1899 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1900 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1901 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1902 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1903 | -p or --purge: Purge the intent from the store after removal |
| 1904 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1905 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 1906 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1907 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1908 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1909 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1910 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 1911 | if purge: |
| 1912 | cmdStr += " -p" |
| 1913 | if sync: |
| 1914 | cmdStr += " -s" |
| 1915 | |
| 1916 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1917 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1918 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1919 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1920 | if re.search( "Error", handle ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1921 | main.log.error( "Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1922 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1923 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1924 | # TODO: Should this be main.TRUE |
| 1925 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1926 | except AssertionError: |
| 1927 | main.log.exception( "" ) |
| 1928 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1929 | except TypeError: |
| 1930 | main.log.exception( self.name + ": Object not as expected" ) |
| 1931 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1932 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1933 | main.log.error( self.name + ": EOF exception found" ) |
| 1934 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1935 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1936 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1937 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1938 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 1939 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1940 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1941 | """ |
| 1942 | Description: |
| 1943 | Remove all the intents |
| 1944 | Optional args:- |
| 1945 | -s or --sync: Waits for the removal before returning |
| 1946 | -p or --purge: Purge the intent from the store after removal |
| 1947 | Returns: |
| 1948 | Returns main.TRUE if all intents are removed, otherwise returns |
| 1949 | main.FALSE; Returns None for exception |
| 1950 | """ |
| 1951 | try: |
| 1952 | cmdStr = "remove-intent" |
| 1953 | if purge: |
| 1954 | cmdStr += " -p" |
| 1955 | if sync: |
| 1956 | cmdStr += " -s" |
| 1957 | |
| 1958 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1959 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1960 | assert handle is not None, "Error in sendline" |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1961 | assert "Command not found:" not in handle, handle |
| 1962 | if re.search( "Error", handle ): |
| 1963 | main.log.error( "Error in removing intent" ) |
| 1964 | return main.FALSE |
| 1965 | else: |
| 1966 | return main.TRUE |
| 1967 | except AssertionError: |
| 1968 | main.log.exception( "" ) |
| 1969 | return None |
| 1970 | except TypeError: |
| 1971 | main.log.exception( self.name + ": Object not as expected" ) |
| 1972 | return None |
| 1973 | except pexpect.EOF: |
| 1974 | main.log.error( self.name + ": EOF exception found" ) |
| 1975 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1976 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1977 | except Exception: |
| 1978 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1979 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 1980 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 1981 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1982 | """ |
| 1983 | Purges all WITHDRAWN Intents |
| 1984 | """ |
| 1985 | try: |
| 1986 | cmdStr = "purge-intents" |
| 1987 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1988 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1989 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1990 | if re.search( "Error", handle ): |
| 1991 | main.log.error( "Error in purging intents" ) |
| 1992 | return main.FALSE |
| 1993 | else: |
| 1994 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1995 | except AssertionError: |
| 1996 | main.log.exception( "" ) |
| 1997 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 1998 | except TypeError: |
| 1999 | main.log.exception( self.name + ": Object not as expected" ) |
| 2000 | return None |
| 2001 | except pexpect.EOF: |
| 2002 | main.log.error( self.name + ": EOF exception found" ) |
| 2003 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2004 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2005 | except Exception: |
| 2006 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2007 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2008 | |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 2009 | def wipeout( self ): |
| 2010 | """ |
| 2011 | Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS. |
| 2012 | """ |
| 2013 | try: |
| 2014 | cmdStr = "wipe-out please" |
| 2015 | handle = self.sendline( cmdStr, timeout=60 ) |
| 2016 | assert handle is not None, "Error in sendline" |
| 2017 | assert "Command not found:" not in handle, handle |
| 2018 | return main.TRUE |
| 2019 | except AssertionError: |
| 2020 | main.log.exception( "" ) |
| 2021 | return None |
| 2022 | except TypeError: |
| 2023 | main.log.exception( self.name + ": Object not as expected" ) |
| 2024 | return None |
| 2025 | except pexpect.EOF: |
| 2026 | main.log.error( self.name + ": EOF exception found" ) |
| 2027 | main.log.error( self.name + ": " + self.handle.before ) |
| 2028 | main.cleanAndExit() |
| 2029 | except Exception: |
| 2030 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2031 | main.cleanAndExit() |
| 2032 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2033 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2034 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2035 | NOTE: This method should be used after installing application: |
| 2036 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2037 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2038 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2039 | Description: |
| 2040 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2041 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2042 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2043 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2044 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2045 | cmdStr += " -j" |
| 2046 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2047 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2048 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2049 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2050 | except AssertionError: |
| 2051 | main.log.exception( "" ) |
| 2052 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2053 | except TypeError: |
| 2054 | main.log.exception( self.name + ": Object not as expected" ) |
| 2055 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2056 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2057 | main.log.error( self.name + ": EOF exception found" ) |
| 2058 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2059 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2060 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2061 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2062 | main.cleanAndExit() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2063 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2064 | def ipv4RouteNumber( self ): |
| 2065 | """ |
| 2066 | NOTE: This method should be used after installing application: |
| 2067 | onos-app-sdnip |
| 2068 | Description: |
| 2069 | Obtain the total IPv4 routes number in the system |
| 2070 | """ |
| 2071 | try: |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2072 | cmdStr = "routes -j" |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2073 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2074 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2075 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2076 | jsonResult = json.loads( handle ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2077 | return len( jsonResult[ 'routes4' ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2078 | except AssertionError: |
| 2079 | main.log.exception( "" ) |
| 2080 | return None |
| 2081 | except ( TypeError, ValueError ): |
| 2082 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2083 | return None |
| 2084 | except pexpect.EOF: |
| 2085 | main.log.error( self.name + ": EOF exception found" ) |
| 2086 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2087 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2088 | except Exception: |
| 2089 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2090 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2091 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2092 | # =============Function to check Bandwidth allocation======== |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2093 | def allocations( self, jsonFormat = True, dollarSign = True ): |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2094 | """ |
| 2095 | Description: |
| 2096 | Obtain Bandwidth Allocation Information from ONOS cli. |
| 2097 | """ |
| 2098 | try: |
| 2099 | cmdStr = "allocations" |
| 2100 | if jsonFormat: |
| 2101 | cmdStr += " -j" |
| 2102 | handle = self.sendline( cmdStr, timeout=300, dollarSign=True ) |
| 2103 | assert handle is not None, "Error in sendline" |
| 2104 | assert "Command not found:" not in handle, handle |
| 2105 | return handle |
| 2106 | except AssertionError: |
| 2107 | main.log.exception( "" ) |
| 2108 | return None |
| 2109 | except ( TypeError, ValueError ): |
| 2110 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
| 2111 | return None |
| 2112 | except pexpect.EOF: |
| 2113 | main.log.error( self.name + ": EOF exception found" ) |
| 2114 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2115 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2116 | except Exception: |
| 2117 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2118 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2119 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2120 | def intents( self, jsonFormat = True, summary = False, **intentargs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2121 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2122 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2123 | Obtain intents from the ONOS cli. |
| 2124 | Optional: |
| 2125 | * jsonFormat: Enable output formatting in json, default to True |
| 2126 | * summary: Whether only output the intent summary, defaults to False |
| 2127 | * type: Only output a certain type of intent. This options is valid |
| 2128 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2129 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2130 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2131 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2132 | if summary: |
| 2133 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2134 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2135 | cmdStr += " -j" |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2136 | handle = self.sendline( cmdStr, timeout=300 ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2137 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2138 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2139 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2140 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2141 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2142 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2143 | intentType = "" |
| 2144 | # IF we want the summary of a specific intent type |
| 2145 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2146 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2147 | if intentType in jsonResult.keys(): |
| 2148 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2149 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2150 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2151 | return handle |
| 2152 | else: |
| 2153 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2154 | except AssertionError: |
| 2155 | main.log.exception( "" ) |
| 2156 | return None |
| 2157 | except ( TypeError, ValueError ): |
| 2158 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2159 | return None |
| 2160 | except pexpect.EOF: |
| 2161 | main.log.error( self.name + ": EOF exception found" ) |
| 2162 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2163 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2164 | except Exception: |
| 2165 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2166 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2167 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2168 | def getIntentState( self, intentsId, intentsJson=None ): |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2169 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2170 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2171 | Gets intent state. Accepts a single intent ID (string type) or a |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2172 | list of intent IDs. |
| 2173 | Parameters: |
| 2174 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2175 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2176 | Returns: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2177 | 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] | 2178 | accepted. |
| 2179 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2180 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2181 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2182 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2183 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2184 | try: |
| 2185 | state = "State is Undefined" |
| 2186 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2187 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2188 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2189 | rawJson = intentsJson |
| 2190 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2191 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2192 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2193 | if intentsId == intent[ 'id' ]: |
| 2194 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2195 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2196 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2197 | " in the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2198 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2199 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2200 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2201 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2202 | stateDict = {} |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2203 | for intent in parsedIntentsJson: |
| 2204 | if intentsId[ i ] == intent[ 'id' ]: |
| 2205 | stateDict[ 'state' ] = intent[ 'state' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2206 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2207 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2208 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2209 | if len( intentsId ) != len( dictList ): |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2210 | main.log.warn( "Could not find all intents in ONOS output" ) |
| 2211 | main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2212 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2213 | else: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2214 | main.log.info( "Invalid type for intentsId argument" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2215 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2216 | except ( TypeError, ValueError ): |
| 2217 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2218 | return None |
| 2219 | except pexpect.EOF: |
| 2220 | main.log.error( self.name + ": EOF exception found" ) |
| 2221 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2222 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2223 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2224 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2225 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2226 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2227 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2228 | """ |
| 2229 | Description: |
| 2230 | Check intents state |
| 2231 | Required: |
| 2232 | intentsId - List of intents ID to be checked |
| 2233 | Optional: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2234 | expectedState - Check the expected state(s) of each intents |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2235 | state in the list. |
| 2236 | *NOTE: You can pass in a list of expected state, |
| 2237 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2238 | Return: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2239 | Returns main.TRUE only if all intent are the same as expected states, |
| 2240 | otherwise returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2241 | """ |
| 2242 | try: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2243 | returnValue = main.TRUE |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2244 | # Generating a dictionary: intent id as a key and state as value |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2245 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2246 | # intentsDict = self.getIntentState( intentsId ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2247 | intentsDict = [] |
| 2248 | for intent in json.loads( self.intents() ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2249 | if isinstance( intentsId, types.StringType ) \ |
| 2250 | and intent.get( 'id' ) == intentsId: |
| 2251 | intentsDict.append( intent ) |
| 2252 | elif isinstance( intentsId, types.ListType ) \ |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2253 | and any( intent.get( 'id' ) == ids for ids in intentsId ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2254 | intentsDict.append( intent ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2255 | |
| 2256 | if not intentsDict: |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2257 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2258 | "getting intents state" ) |
| 2259 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2260 | |
| 2261 | if isinstance( expectedState, types.StringType ): |
| 2262 | for intents in intentsDict: |
| 2263 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2264 | main.log.debug( self.name + " : Intent ID - " + |
| 2265 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2266 | " actual state = " + |
| 2267 | intents.get( 'state' ) |
| 2268 | + " does not equal expected state = " |
| 2269 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2270 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2271 | elif isinstance( expectedState, types.ListType ): |
| 2272 | for intents in intentsDict: |
| 2273 | if not any( state == intents.get( 'state' ) for state in |
| 2274 | expectedState ): |
| 2275 | main.log.debug( self.name + " : Intent ID - " + |
| 2276 | intents.get( 'id' ) + |
| 2277 | " actual state = " + |
| 2278 | intents.get( 'state' ) + |
| 2279 | " does not equal expected states = " |
| 2280 | + str( expectedState ) ) |
| 2281 | returnValue = main.FALSE |
| 2282 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2283 | if returnValue == main.TRUE: |
| 2284 | main.log.info( self.name + ": All " + |
| 2285 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2286 | " intents are in " + str( expectedState ) + |
| 2287 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2288 | return returnValue |
| 2289 | except TypeError: |
| 2290 | main.log.exception( self.name + ": Object not as expected" ) |
| 2291 | return None |
| 2292 | except pexpect.EOF: |
| 2293 | main.log.error( self.name + ": EOF exception found" ) |
| 2294 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2295 | main.cleanAndExit() |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2296 | except Exception: |
| 2297 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2298 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2299 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2300 | def compareBandwidthAllocations( self, expectedAllocations ): |
| 2301 | """ |
| 2302 | Description: |
| 2303 | Compare the allocated bandwidth with the given allocations |
| 2304 | Required: |
| 2305 | expectedAllocations - The expected ONOS output of the allocations command |
| 2306 | Return: |
| 2307 | Returns main.TRUE only if all intent are the same as expected states, |
| 2308 | otherwise returns main.FALSE. |
| 2309 | """ |
| 2310 | # FIXME: Convert these string comparisons to object comparisons |
| 2311 | try: |
| 2312 | returnValue = main.TRUE |
| 2313 | bandwidthFailed = False |
| 2314 | rawAlloc = self.allocations() |
| 2315 | expectedFormat = StringIO( expectedAllocations ) |
| 2316 | ONOSOutput = StringIO( rawAlloc ) |
| 2317 | main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ), |
| 2318 | str( expectedFormat ) ) ) |
| 2319 | |
| 2320 | for actual, expected in izip( ONOSOutput, expectedFormat ): |
| 2321 | actual = actual.rstrip() |
| 2322 | expected = expected.rstrip() |
| 2323 | main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) ) |
| 2324 | if actual != expected and 'allocated' in actual and 'allocated' in expected: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2325 | marker1 = actual.find( 'allocated' ) |
| 2326 | m1 = actual[ :marker1 ] |
| 2327 | marker2 = expected.find( 'allocated' ) |
| 2328 | m2 = expected[ :marker2 ] |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2329 | if m1 != m2: |
| 2330 | bandwidthFailed = True |
| 2331 | elif actual != expected and 'allocated' not in actual and 'allocated' not in expected: |
| 2332 | bandwidthFailed = True |
| 2333 | expectedFormat.close() |
| 2334 | ONOSOutput.close() |
| 2335 | |
| 2336 | if bandwidthFailed: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2337 | main.log.error( "Bandwidth not allocated correctly using Intents!!" ) |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2338 | returnValue = main.FALSE |
| 2339 | return returnValue |
| 2340 | except TypeError: |
| 2341 | main.log.exception( self.name + ": Object not as expected" ) |
| 2342 | return None |
| 2343 | except pexpect.EOF: |
| 2344 | main.log.error( self.name + ": EOF exception found" ) |
| 2345 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2346 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2347 | except Exception: |
| 2348 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2349 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2350 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2351 | def compareIntent( self, intentDict ): |
| 2352 | """ |
| 2353 | Description: |
| 2354 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2355 | Return: |
| 2356 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2357 | Arguments: |
| 2358 | intentDict: a dictionary which maps intent ids to intent states |
| 2359 | """ |
| 2360 | try: |
| 2361 | intentsRaw = self.intents() |
| 2362 | intentsJson = json.loads( intentsRaw ) |
| 2363 | intentDictONOS = {} |
| 2364 | for intent in intentsJson: |
| 2365 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2366 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2367 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2368 | 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] | 2369 | str( len( intentDict ) ) + " expected and " + |
| 2370 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2371 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2372 | for intentID in intentDict.keys(): |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2373 | if intentID not in intentDictONOS.keys(): |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2374 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2375 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2376 | else: |
| 2377 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2378 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2379 | " expected state is " + intentDict[ intentID ] + |
| 2380 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2381 | returnValue = main.FALSE |
| 2382 | intentDictONOS.pop( intentID ) |
| 2383 | if len( intentDictONOS ) > 0: |
| 2384 | returnValue = main.FALSE |
| 2385 | for intentID in intentDictONOS.keys(): |
| 2386 | 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] | 2387 | if returnValue == main.TRUE: |
| 2388 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2389 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2390 | except KeyError: |
| 2391 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2392 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2393 | except ( TypeError, ValueError ): |
| 2394 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2395 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2396 | except pexpect.EOF: |
| 2397 | main.log.error( self.name + ": EOF exception found" ) |
| 2398 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2399 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2400 | except Exception: |
| 2401 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2402 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2403 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2404 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2405 | """ |
| 2406 | Description: |
| 2407 | Check the number of installed intents. |
| 2408 | Optional: |
| 2409 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2410 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2411 | Return: |
| 2412 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2413 | , otherwise, returns main.FALSE. |
| 2414 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2415 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2416 | try: |
| 2417 | cmd = "intents -s -j" |
| 2418 | |
| 2419 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2420 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2421 | if response is None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2422 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2423 | response = json.loads( response ) |
| 2424 | |
| 2425 | # get total and installed number, see if they are match |
| 2426 | allState = response.get( 'all' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2427 | if allState.get( 'total' ) == allState.get( 'installed' ): |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2428 | main.log.info( 'Total Intents: {} Installed Intents: {}'.format( |
| 2429 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2430 | return main.TRUE |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2431 | main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format( |
| 2432 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2433 | return main.FALSE |
| 2434 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2435 | except ( TypeError, ValueError ): |
| 2436 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2437 | return None |
| 2438 | except pexpect.EOF: |
| 2439 | main.log.error( self.name + ": EOF exception found" ) |
| 2440 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2441 | if noExit: |
| 2442 | return main.FALSE |
| 2443 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2444 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2445 | except pexpect.TIMEOUT: |
| 2446 | main.log.error( self.name + ": ONOS timeout" ) |
| 2447 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2448 | except Exception: |
| 2449 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2450 | if noExit: |
| 2451 | return main.FALSE |
| 2452 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2453 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2454 | |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2455 | def flows( self, state="", jsonFormat=True, timeout=60, noExit=False, noCore=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2456 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2457 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2458 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2459 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2460 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2461 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2462 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2463 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2464 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2465 | if jsonFormat: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2466 | cmdStr += " -j " |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2467 | if noCore: |
| 2468 | cmdStr += " -n " |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2469 | cmdStr += state |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2470 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2471 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2472 | assert "Command not found:" not in handle, handle |
| 2473 | if re.search( "Error:", handle ): |
| 2474 | main.log.error( self.name + ": flows() response: " + |
| 2475 | str( handle ) ) |
| 2476 | return handle |
| 2477 | except AssertionError: |
| 2478 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2479 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2480 | except TypeError: |
| 2481 | main.log.exception( self.name + ": Object not as expected" ) |
| 2482 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2483 | except pexpect.TIMEOUT: |
| 2484 | main.log.error( self.name + ": ONOS timeout" ) |
| 2485 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2486 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2487 | main.log.error( self.name + ": EOF exception found" ) |
| 2488 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2489 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2490 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2491 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2492 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2493 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2494 | def checkFlowCount( self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2495 | count = self.getTotalFlowsNum( timeout=timeout ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2496 | count = int( count ) if count else 0 |
| 2497 | return count if ( count > min ) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2498 | |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2499 | def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2500 | """ |
| 2501 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2502 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2503 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2504 | if the count of those states is 0, which means all current flows |
| 2505 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2506 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2507 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2508 | Return: |
| 2509 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2510 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2511 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2512 | """ |
| 2513 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2514 | states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2515 | checkedStates = [] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2516 | statesCount = [ 0, 0, 0, 0 ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2517 | for s in states: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2518 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2519 | if rawFlows: |
| 2520 | # if we didn't get flows or flows function return None, we should return |
| 2521 | # main.Flase |
| 2522 | checkedStates.append( json.loads( rawFlows ) ) |
| 2523 | else: |
| 2524 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2525 | for i in range( len( states ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2526 | for c in checkedStates[ i ]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2527 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2528 | statesCount[ i ] += int( c.get( "flowCount" ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2529 | except TypeError: |
| 2530 | main.log.exception( "Json object not as expected" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2531 | main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2532 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2533 | # We want to count PENDING_ADD if isPENDING is true |
| 2534 | if isPENDING: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2535 | if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2536 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2537 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2538 | if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2539 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2540 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2541 | except ( TypeError, ValueError ): |
| 2542 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2543 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2544 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2545 | except AssertionError: |
| 2546 | main.log.exception( "" ) |
| 2547 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2548 | except pexpect.TIMEOUT: |
| 2549 | main.log.error( self.name + ": ONOS timeout" ) |
| 2550 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2551 | except pexpect.EOF: |
| 2552 | main.log.error( self.name + ": EOF exception found" ) |
| 2553 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2554 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2555 | except Exception: |
| 2556 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2557 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2558 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2559 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2560 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2561 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2562 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2563 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2564 | a specific point-to-point intent definition |
| 2565 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2566 | * ingress: specify source dpid |
| 2567 | * egress: specify destination dpid |
| 2568 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2569 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2570 | * offset: the keyOffset is where the next batch of intents |
| 2571 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2572 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2573 | * getResponse: If set to True, function will return ONOS response. |
| 2574 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2575 | Returns: If failed to push test intents, it will returen None, |
| 2576 | if successful, return true. |
| 2577 | Timeout expection will return None, |
| 2578 | TypeError will return false |
| 2579 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2580 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2581 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2582 | if background: |
| 2583 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2584 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2585 | back = "" |
| 2586 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2587 | ingress, |
| 2588 | egress, |
| 2589 | batchSize, |
| 2590 | offset, |
| 2591 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2592 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2593 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2594 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2595 | main.log.info( response ) |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2596 | if getResponse: |
| 2597 | return response |
| 2598 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2599 | # TODO: We should handle if there is failure in installation |
| 2600 | return main.TRUE |
| 2601 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2602 | except AssertionError: |
| 2603 | main.log.exception( "" ) |
| 2604 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2605 | except pexpect.TIMEOUT: |
| 2606 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2607 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2608 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2609 | main.log.error( self.name + ": EOF exception found" ) |
| 2610 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2611 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2612 | except TypeError: |
| 2613 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2614 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2615 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2616 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2617 | main.cleanAndExit() |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2618 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2619 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2620 | """ |
| 2621 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2622 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2623 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2624 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2625 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2626 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2627 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2628 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2629 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2630 | cmd = "flows -c added" |
| 2631 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2632 | if rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2633 | rawFlows = rawFlows.split( "\n" ) |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2634 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2635 | for l in rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2636 | totalFlows += int( l.split( "Count=" )[ 1 ] ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2637 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2638 | main.log.error( "Response not as expected!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2639 | return None |
| 2640 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2641 | |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2642 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2643 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2644 | return None |
| 2645 | except pexpect.EOF: |
| 2646 | main.log.error( self.name + ": EOF exception found" ) |
| 2647 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2648 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2649 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2650 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2651 | except pexpect.TIMEOUT: |
| 2652 | main.log.error( self.name + ": ONOS timeout" ) |
| 2653 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2654 | except Exception: |
| 2655 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2656 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2657 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2658 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2659 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2660 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2661 | """ |
| 2662 | Description: |
| 2663 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2664 | Optional: |
| 2665 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2666 | Return: |
| 2667 | The number of intents |
| 2668 | """ |
| 2669 | try: |
| 2670 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2671 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2672 | if response is None: |
| 2673 | return -1 |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2674 | response = json.loads( response ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2675 | return int( response.get( "intents" ) ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2676 | except ( TypeError, ValueError ): |
| 2677 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2678 | return None |
| 2679 | except pexpect.EOF: |
| 2680 | main.log.error( self.name + ": EOF exception found" ) |
| 2681 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2682 | if noExit: |
| 2683 | return -1 |
| 2684 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2685 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2686 | except Exception: |
| 2687 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2688 | if noExit: |
| 2689 | return -1 |
| 2690 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2691 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2692 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2693 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2694 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2695 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2696 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2697 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2698 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2699 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2700 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2701 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2702 | cmdStr += " -j" |
| 2703 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2704 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2705 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2706 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2707 | except AssertionError: |
| 2708 | main.log.exception( "" ) |
| 2709 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2710 | except TypeError: |
| 2711 | main.log.exception( self.name + ": Object not as expected" ) |
| 2712 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2713 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2714 | main.log.error( self.name + ": EOF exception found" ) |
| 2715 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2716 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2717 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2718 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2719 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2720 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2721 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2722 | """ |
| 2723 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2724 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2725 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2726 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2727 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2728 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2729 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2730 | cmdStr += " -j" |
| 2731 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2732 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2733 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2734 | if handle: |
| 2735 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2736 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2737 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2738 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2739 | else: |
| 2740 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2741 | except AssertionError: |
| 2742 | main.log.exception( "" ) |
| 2743 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2744 | except TypeError: |
| 2745 | main.log.exception( self.name + ": Object not as expected" ) |
| 2746 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2747 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2748 | main.log.error( self.name + ": EOF exception found" ) |
| 2749 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2750 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2751 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2752 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2753 | main.cleanAndExit() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2754 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2755 | # Wrapper functions **************** |
| 2756 | # Wrapper functions use existing driver |
| 2757 | # functions and extends their use case. |
| 2758 | # For example, we may use the output of |
| 2759 | # a normal driver function, and parse it |
| 2760 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2761 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2762 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2763 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2764 | Description: |
| 2765 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2766 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2767 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2768 | # Obtain output of intents function |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2769 | intentsStr = self.intents( jsonFormat=True ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 2770 | if intentsStr is None: |
| 2771 | raise TypeError |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2772 | # Convert to a dictionary |
| 2773 | intents = json.loads( intentsStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2774 | intentIdList = [] |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2775 | for intent in intents: |
| 2776 | intentIdList.append( intent[ 'id' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2777 | return intentIdList |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2778 | except TypeError: |
| 2779 | main.log.exception( self.name + ": Object not as expected" ) |
| 2780 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2781 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2782 | main.log.error( self.name + ": EOF exception found" ) |
| 2783 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2784 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2785 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2786 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2787 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2788 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2789 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2790 | """ |
| 2791 | Determine the number of flow rules for the given device id that are |
| 2792 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2793 | Params: |
| 2794 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2795 | """ |
| 2796 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2797 | if core: |
| 2798 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2799 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2800 | else: |
| 2801 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2802 | "grep 'state=ADDED' | wc -l" |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2803 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2804 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2805 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2806 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2807 | except AssertionError: |
| 2808 | main.log.exception( "" ) |
| 2809 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2810 | except pexpect.EOF: |
| 2811 | main.log.error( self.name + ": EOF exception found" ) |
| 2812 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2813 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2814 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2815 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2816 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 2817 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2818 | def groupAddedCount( self, deviceId, core=False ): |
| 2819 | """ |
| 2820 | Determine the number of group rules for the given device id that are |
| 2821 | in the added state |
| 2822 | Params: |
| 2823 | core: if True, only return the number of core groups added |
| 2824 | """ |
| 2825 | try: |
| 2826 | if core: |
| 2827 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 2828 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2829 | else: |
| 2830 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 2831 | "grep 'state=ADDED' | wc -l" |
| 2832 | handle = self.sendline( cmdStr ) |
| 2833 | assert handle is not None, "Error in sendline" |
| 2834 | assert "Command not found:" not in handle, handle |
| 2835 | return handle |
| 2836 | except AssertionError: |
| 2837 | main.log.exception( "" ) |
| 2838 | return None |
| 2839 | except pexpect.EOF: |
| 2840 | main.log.error( self.name + ": EOF exception found" ) |
| 2841 | main.log.error( self.name + ": " + self.handle.before ) |
| 2842 | main.cleanAndExit() |
| 2843 | except Exception: |
| 2844 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2845 | main.cleanAndExit() |
| 2846 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 2847 | def addStaticRoute( self, subnet, intf): |
| 2848 | """ |
| 2849 | Adds a static route to onos. |
| 2850 | Params: |
| 2851 | subnet: The subnet reaching through this route |
| 2852 | intf: The interface this route is reachable through |
| 2853 | """ |
| 2854 | try: |
| 2855 | cmdStr = "route-add " + subnet + " " + intf |
| 2856 | handle = self.sendline( cmdStr ) |
| 2857 | assert handle is not None, "Error in sendline" |
| 2858 | assert "Command not found:" not in handle, handle |
| 2859 | return handle |
| 2860 | except AssertionError: |
| 2861 | main.log.exception( "" ) |
| 2862 | return None |
| 2863 | except pexpect.EOF: |
| 2864 | main.log.error( self.name + ": EOF exception found" ) |
| 2865 | main.log.error( self.name + ": " + self.handle.before ) |
| 2866 | main.cleanAndExit() |
| 2867 | except Exception: |
| 2868 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2869 | main.cleanAndExit() |
| 2870 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2871 | def checkGroupAddedCount( self, deviceId, expectedGroupCount=0, core=False, comparison=0): |
| 2872 | """ |
| 2873 | Description: |
| 2874 | Check whether the number of groups for the given device id that |
| 2875 | are in ADDED state is bigger than minGroupCount. |
| 2876 | Required: |
| 2877 | * deviceId: device id to check the number of added group rules |
| 2878 | Optional: |
| 2879 | * minGroupCount: the number of groups to compare |
| 2880 | * core: if True, only check the number of core groups added |
| 2881 | * comparison: if 0, compare with greater than minFlowCount |
| 2882 | * if 1, compare with equal to minFlowCount |
| 2883 | Return: |
| 2884 | Returns the number of groups if it is bigger than minGroupCount, |
| 2885 | returns main.FALSE otherwise. |
| 2886 | """ |
| 2887 | count = self.groupAddedCount( deviceId, core ) |
| 2888 | count = int( count ) if count else 0 |
| 2889 | return count if ((count > expectedGroupCount) if (comparison == 0) else (count == expectedGroupCount)) else main.FALSE |
| 2890 | |
| 2891 | def checkFlowAddedCount( self, deviceId, expectedFlowCount=0, core=False, comparison=0): |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 2892 | """ |
| 2893 | Description: |
| 2894 | Check whether the number of flow rules for the given device id that |
| 2895 | are in ADDED state is bigger than minFlowCount. |
| 2896 | Required: |
| 2897 | * deviceId: device id to check the number of added flow rules |
| 2898 | Optional: |
| 2899 | * minFlowCount: the number of flow rules to compare |
| 2900 | * core: if True, only check the number of core flows added |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 2901 | * comparison: if 0, compare with greater than minFlowCount |
| 2902 | * if 1, compare with equal to minFlowCount |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 2903 | Return: |
| 2904 | Returns the number of flow rules if it is bigger than minFlowCount, |
| 2905 | returns main.FALSE otherwise. |
| 2906 | """ |
| 2907 | count = self.flowAddedCount( deviceId, core ) |
| 2908 | count = int( count ) if count else 0 |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 2909 | return count if ((count > expectedFlowCount) if (comparison == 0) else (count == expectedFlowCount)) else main.FALSE |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 2910 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2911 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2912 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2913 | Use 'devices' function to obtain list of all devices |
| 2914 | and parse the result to obtain a list of all device |
| 2915 | id's. Returns this list. Returns empty list if no |
| 2916 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2917 | List is ordered sequentially |
| 2918 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2919 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2920 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 2921 | the ids. By obtaining the list of device ids on the fly, |
| 2922 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2923 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2924 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2925 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2926 | devicesStr = self.devices( jsonFormat=False ) |
| 2927 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2928 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2929 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2930 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2931 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2932 | |
| 2933 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2934 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2935 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2936 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2937 | # Split list further into arguments before and after string |
| 2938 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2939 | # append to idList |
| 2940 | for arg in tempList: |
| 2941 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 2942 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2943 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2944 | except TypeError: |
| 2945 | main.log.exception( self.name + ": Object not as expected" ) |
| 2946 | return None |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2947 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2948 | main.log.error( self.name + ": EOF exception found" ) |
| 2949 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2950 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2951 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2952 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2953 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2954 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2955 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2956 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2957 | Uses 'nodes' function to obtain list of all nodes |
| 2958 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2959 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2960 | Returns: |
| 2961 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2962 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2963 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2964 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2965 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2966 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 2967 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2968 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2969 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2970 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 2971 | nodesJson = json.loads( nodesStr ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2972 | idList = [ node.get( 'id' ) for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2973 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2974 | except ( TypeError, ValueError ): |
| 2975 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2976 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 2977 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2978 | main.log.error( self.name + ": EOF exception found" ) |
| 2979 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2980 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2981 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2982 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2983 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 2984 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2985 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2986 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2987 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 2988 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2989 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2990 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2991 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 2992 | return None |
| 2993 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2994 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2995 | rawDevices = self.devices() |
| 2996 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2997 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2998 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2999 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 3000 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3001 | return device |
| 3002 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3003 | except ( TypeError, ValueError ): |
| 3004 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3005 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3006 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3007 | main.log.error( self.name + ": EOF exception found" ) |
| 3008 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3009 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3010 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3011 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3012 | main.cleanAndExit() |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3013 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3014 | def getTopology( self, topologyOutput ): |
| 3015 | """ |
| 3016 | Definition: |
| 3017 | Loads a json topology output |
| 3018 | Return: |
| 3019 | topology = current ONOS topology |
| 3020 | """ |
| 3021 | import json |
| 3022 | try: |
| 3023 | # either onos:topology or 'topology' will work in CLI |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3024 | topology = json.loads( topologyOutput ) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 3025 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3026 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 3027 | except ( TypeError, ValueError ): |
| 3028 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 3029 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3030 | except pexpect.EOF: |
| 3031 | main.log.error( self.name + ": EOF exception found" ) |
| 3032 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3033 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3034 | except Exception: |
| 3035 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3036 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3037 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3038 | def checkStatus( self, numoswitch, numolink, numoctrl = -1, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3039 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3040 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3041 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3042 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3043 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3044 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3045 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3046 | numoctrl = expected number of controllers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3047 | logLevel = level to log to. |
| 3048 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3049 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3050 | Returns: main.TRUE if the number of switches and links are correct, |
| 3051 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3052 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3053 | """ |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3054 | import json |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3055 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 3056 | summary = self.summary() |
| 3057 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 3058 | except ( TypeError, ValueError ): |
| 3059 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 3060 | return main.ERROR |
| 3061 | try: |
| 3062 | topology = self.getTopology( self.topology() ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 3063 | if topology == {} or topology is None or summary == {} or summary is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3064 | return main.ERROR |
| 3065 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3066 | # Is the number of switches is what we expected |
| 3067 | devices = topology.get( 'devices', False ) |
| 3068 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3069 | nodes = summary.get( 'nodes', False ) |
| 3070 | if devices is False or links is False or nodes is False: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3071 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3072 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3073 | # Is the number of links is what we expected |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3074 | linkCheck = ( int( links ) == int( numolink ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3075 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
| 3076 | if switchCheck and linkCheck and nodeCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3077 | # We expected the correct numbers |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3078 | output = output + "The number of links and switches match "\ |
| 3079 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3080 | result = main.TRUE |
| 3081 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3082 | output = output + \ |
| 3083 | "The number of links and switches does not match " + \ |
| 3084 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3085 | result = main.FALSE |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3086 | output = output + "\n ONOS sees %i devices" % int( devices ) |
| 3087 | output = output + " (%i expected) " % int( numoswitch ) |
| 3088 | output = output + "and %i links " % int( links ) |
| 3089 | output = output + "(%i expected)" % int( numolink ) |
YPZhang | d7e4b6e | 2016-06-17 16:07:55 -0700 | [diff] [blame] | 3090 | if int( numoctrl ) > 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3091 | output = output + "and %i controllers " % int( nodes ) |
| 3092 | output = output + "(%i expected)" % int( numoctrl ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3093 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3094 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3095 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3096 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3097 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3098 | main.log.info( output ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3099 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3100 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3101 | main.log.error( self.name + ": EOF exception found" ) |
| 3102 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3103 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3104 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3105 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3106 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3107 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3108 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3109 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3110 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3111 | deviceId must be the id of a device as seen in the onos devices command |
| 3112 | 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] | 3113 | role must be either master, standby, or none |
| 3114 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3115 | Returns: |
| 3116 | main.TRUE or main.FALSE based on argument verification and |
| 3117 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3118 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3119 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3120 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3121 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3122 | cmdStr = "device-role " +\ |
| 3123 | str( deviceId ) + " " +\ |
| 3124 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3125 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3126 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3127 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3128 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3129 | if re.search( "Error", handle ): |
| 3130 | # end color output to escape any colours |
| 3131 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3132 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3133 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3134 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3135 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3136 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3137 | main.log.error( "Invalid 'role' given to device_role(). " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3138 | "Value was '" + str( role ) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3139 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3140 | except AssertionError: |
| 3141 | main.log.exception( "" ) |
| 3142 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3143 | except TypeError: |
| 3144 | main.log.exception( self.name + ": Object not as expected" ) |
| 3145 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3146 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3147 | main.log.error( self.name + ": EOF exception found" ) |
| 3148 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3149 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3150 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3151 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3152 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3153 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3154 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3155 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3156 | Lists all clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 3157 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3158 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3159 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3160 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3161 | cmdStr = "clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3162 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3163 | cmdStr += " -j" |
| 3164 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3165 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3166 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3167 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3168 | except AssertionError: |
| 3169 | main.log.exception( "" ) |
| 3170 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3171 | except TypeError: |
| 3172 | main.log.exception( self.name + ": Object not as expected" ) |
| 3173 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3174 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3175 | main.log.error( self.name + ": EOF exception found" ) |
| 3176 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3177 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3178 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3179 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3180 | main.cleanAndExit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3181 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3182 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3183 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3184 | CLI command to get the current leader for the Election test application |
| 3185 | NOTE: Requires installation of the onos-app-election feature |
| 3186 | Returns: Node IP of the leader if one exists |
| 3187 | None if none exists |
| 3188 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3189 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3190 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3191 | cmdStr = "election-test-leader" |
| 3192 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3193 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3194 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3195 | # Leader |
| 3196 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3197 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3198 | nodeSearch = re.search( leaderPattern, response ) |
| 3199 | if nodeSearch: |
| 3200 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3201 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3202 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3203 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3204 | # no leader |
| 3205 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3206 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3207 | nullSearch = re.search( nullPattern, response ) |
| 3208 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3209 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3210 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3211 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3212 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3213 | main.log.error( "Error in electionTestLeader on " + self.name + |
| 3214 | ": " + "unexpected response" ) |
| 3215 | main.log.error( repr( response ) ) |
| 3216 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3217 | except AssertionError: |
| 3218 | main.log.exception( "" ) |
| 3219 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3220 | except TypeError: |
| 3221 | main.log.exception( self.name + ": Object not as expected" ) |
| 3222 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3223 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3224 | main.log.error( self.name + ": EOF exception found" ) |
| 3225 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3226 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3227 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3228 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3229 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3230 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3231 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3232 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3233 | CLI command to run for leadership of the Election test application. |
| 3234 | NOTE: Requires installation of the onos-app-election feature |
| 3235 | Returns: Main.TRUE on success |
| 3236 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3237 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3238 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3239 | cmdStr = "election-test-run" |
| 3240 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3241 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3242 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3243 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3244 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3245 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3246 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3247 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3248 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3249 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3250 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3251 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3252 | main.log.error( "Error in electionTestRun on " + self.name + |
| 3253 | ": " + "unexpected response" ) |
| 3254 | main.log.error( repr( response ) ) |
| 3255 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3256 | except AssertionError: |
| 3257 | main.log.exception( "" ) |
| 3258 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3259 | except TypeError: |
| 3260 | main.log.exception( self.name + ": Object not as expected" ) |
| 3261 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3262 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3263 | main.log.error( self.name + ": EOF exception found" ) |
| 3264 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3265 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3266 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3267 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3268 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3269 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3270 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3271 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3272 | * CLI command to withdraw the local node from leadership election for |
| 3273 | * the Election test application. |
| 3274 | #NOTE: Requires installation of the onos-app-election feature |
| 3275 | Returns: Main.TRUE on success |
| 3276 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3277 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3278 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3279 | cmdStr = "election-test-withdraw" |
| 3280 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3281 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3282 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3283 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3284 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3285 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3286 | if re.search( successPattern, response ): |
| 3287 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3288 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3289 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3290 | # error |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3291 | main.log.error( "Error in electionTestWithdraw on " + |
| 3292 | self.name + ": " + "unexpected response" ) |
| 3293 | main.log.error( repr( response ) ) |
| 3294 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3295 | except AssertionError: |
| 3296 | main.log.exception( "" ) |
| 3297 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3298 | except TypeError: |
| 3299 | main.log.exception( self.name + ": Object not as expected" ) |
| 3300 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3301 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3302 | main.log.error( self.name + ": EOF exception found" ) |
| 3303 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3304 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3305 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3306 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3307 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3308 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3309 | def getDevicePortsEnabledCount( self, dpid ): |
| 3310 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3311 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3312 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3313 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3314 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3315 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
| 3316 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3317 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3318 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3319 | if re.search( "No such device", output ): |
| 3320 | main.log.error( "Error in getting ports" ) |
| 3321 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3322 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3323 | except AssertionError: |
| 3324 | main.log.exception( "" ) |
| 3325 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3326 | except TypeError: |
| 3327 | main.log.exception( self.name + ": Object not as expected" ) |
| 3328 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3329 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3330 | main.log.error( self.name + ": EOF exception found" ) |
| 3331 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3332 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3333 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3334 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3335 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3336 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3337 | def getDeviceLinksActiveCount( self, dpid ): |
| 3338 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3339 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3340 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3341 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3342 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3343 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
| 3344 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3345 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3346 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3347 | if re.search( "No such device", output ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3348 | main.log.error( "Error in getting ports " ) |
| 3349 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3350 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3351 | except AssertionError: |
| 3352 | main.log.exception( "" ) |
| 3353 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3354 | except TypeError: |
| 3355 | main.log.exception( self.name + ": Object not as expected" ) |
| 3356 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3357 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3358 | main.log.error( self.name + ": EOF exception found" ) |
| 3359 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3360 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3361 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3362 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3363 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3364 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3365 | def getAllIntentIds( self ): |
| 3366 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3367 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3368 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3369 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3370 | cmdStr = "onos:intents | grep id=" |
| 3371 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3372 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3373 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3374 | if re.search( "Error", output ): |
| 3375 | main.log.error( "Error in getting ports" ) |
| 3376 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3377 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3378 | except AssertionError: |
| 3379 | main.log.exception( "" ) |
| 3380 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3381 | except TypeError: |
| 3382 | main.log.exception( self.name + ": Object not as expected" ) |
| 3383 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3384 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3385 | main.log.error( self.name + ": EOF exception found" ) |
| 3386 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3387 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3388 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3389 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3390 | main.cleanAndExit() |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3391 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3392 | def intentSummary( self ): |
| 3393 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3394 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3395 | """ |
| 3396 | try: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3397 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3398 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3399 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3400 | states.append( intent.get( 'state', None ) ) |
| 3401 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3402 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3403 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3404 | except ( TypeError, ValueError ): |
| 3405 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3406 | return None |
| 3407 | except pexpect.EOF: |
| 3408 | main.log.error( self.name + ": EOF exception found" ) |
| 3409 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3410 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3411 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3412 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3413 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3414 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3415 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3416 | """ |
| 3417 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3418 | Optional argument: |
| 3419 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3420 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3421 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3422 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3423 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3424 | cmdStr += " -j" |
| 3425 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3426 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3427 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3428 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3429 | except AssertionError: |
| 3430 | main.log.exception( "" ) |
| 3431 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3432 | except TypeError: |
| 3433 | main.log.exception( self.name + ": Object not as expected" ) |
| 3434 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3435 | except pexpect.EOF: |
| 3436 | main.log.error( self.name + ": EOF exception found" ) |
| 3437 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3438 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3439 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3440 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3441 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3442 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3443 | def leaderCandidates( self, jsonFormat=True ): |
| 3444 | """ |
| 3445 | Returns the output of the leaders -c command. |
| 3446 | Optional argument: |
| 3447 | * jsonFormat - boolean indicating if you want output in json |
| 3448 | """ |
| 3449 | try: |
| 3450 | cmdStr = "onos:leaders -c" |
| 3451 | if jsonFormat: |
| 3452 | cmdStr += " -j" |
| 3453 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3454 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3455 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3456 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3457 | except AssertionError: |
| 3458 | main.log.exception( "" ) |
| 3459 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3460 | except TypeError: |
| 3461 | main.log.exception( self.name + ": Object not as expected" ) |
| 3462 | return None |
| 3463 | except pexpect.EOF: |
| 3464 | main.log.error( self.name + ": EOF exception found" ) |
| 3465 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3466 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3467 | except Exception: |
| 3468 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3469 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3470 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3471 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3472 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3473 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3474 | topic parameter and an empty list if the topic doesn't exist |
| 3475 | If no leader is elected leader in the returned list will be "none" |
| 3476 | Returns None if there is a type error processing the json object |
| 3477 | """ |
| 3478 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3479 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3480 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3481 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3482 | assert "Command not found:" not in rawOutput, rawOutput |
| 3483 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3484 | results = [] |
| 3485 | for dict in output: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3486 | if dict[ "topic" ] == topic: |
| 3487 | leader = dict[ "leader" ] |
| 3488 | candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3489 | results.append( leader ) |
| 3490 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3491 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3492 | except AssertionError: |
| 3493 | main.log.exception( "" ) |
| 3494 | return None |
| 3495 | except ( TypeError, ValueError ): |
| 3496 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3497 | return None |
| 3498 | except pexpect.EOF: |
| 3499 | main.log.error( self.name + ": EOF exception found" ) |
| 3500 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3501 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3502 | except Exception: |
| 3503 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3504 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3505 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3506 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3507 | """ |
| 3508 | Returns the output of the intent Pending map. |
| 3509 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3510 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3511 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3512 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3513 | cmdStr += " -j" |
| 3514 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3515 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3516 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3517 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3518 | except AssertionError: |
| 3519 | main.log.exception( "" ) |
| 3520 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3521 | except TypeError: |
| 3522 | main.log.exception( self.name + ": Object not as expected" ) |
| 3523 | return None |
| 3524 | except pexpect.EOF: |
| 3525 | main.log.error( self.name + ": EOF exception found" ) |
| 3526 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3527 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3528 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3529 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3530 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3531 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3532 | def partitions( self, candidates=False, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3533 | """ |
| 3534 | Returns the output of the raft partitions command for ONOS. |
| 3535 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3536 | # Sample JSON |
| 3537 | # { |
| 3538 | # "leader": "tcp://10.128.30.11:7238", |
| 3539 | # "members": [ |
| 3540 | # "tcp://10.128.30.11:7238", |
| 3541 | # "tcp://10.128.30.17:7238", |
| 3542 | # "tcp://10.128.30.13:7238", |
| 3543 | # ], |
| 3544 | # "name": "p1", |
| 3545 | # "term": 3 |
| 3546 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3547 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3548 | cmdStr = "onos:partitions" |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3549 | if candidates: |
| 3550 | cmdStr += " -c" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3551 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3552 | cmdStr += " -j" |
| 3553 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3554 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3555 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3556 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3557 | except AssertionError: |
| 3558 | main.log.exception( "" ) |
| 3559 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3560 | except TypeError: |
| 3561 | main.log.exception( self.name + ": Object not as expected" ) |
| 3562 | return None |
| 3563 | except pexpect.EOF: |
| 3564 | main.log.error( self.name + ": EOF exception found" ) |
| 3565 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3566 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3567 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3568 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3569 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3570 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3571 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3572 | """ |
| 3573 | Returns the output of the apps command for ONOS. This command lists |
| 3574 | information about installed ONOS applications |
| 3575 | """ |
| 3576 | # Sample JSON object |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3577 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3578 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3579 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3580 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3581 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3582 | cmdStr = "onos:apps" |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3583 | if summary: |
| 3584 | cmdStr += " -s" |
| 3585 | if active: |
| 3586 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3587 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3588 | cmdStr += " -j" |
| 3589 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3590 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3591 | assert "Command not found:" not in output, output |
| 3592 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3593 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3594 | # FIXME: look at specific exceptions/Errors |
| 3595 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3596 | main.log.exception( "Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3597 | return None |
| 3598 | except TypeError: |
| 3599 | main.log.exception( self.name + ": Object not as expected" ) |
| 3600 | return None |
| 3601 | except pexpect.EOF: |
| 3602 | main.log.error( self.name + ": EOF exception found" ) |
| 3603 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3604 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3605 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3606 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3607 | main.cleanAndExit() |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3608 | |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3609 | def appStatus( self, appName ): |
| 3610 | """ |
| 3611 | Uses the onos:apps cli command to return the status of an application. |
| 3612 | Returns: |
| 3613 | "ACTIVE" - If app is installed and activated |
| 3614 | "INSTALLED" - If app is installed and deactivated |
| 3615 | "UNINSTALLED" - If app is not installed |
| 3616 | None - on error |
| 3617 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3618 | try: |
| 3619 | if not isinstance( appName, types.StringType ): |
| 3620 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3621 | " a string" ) |
| 3622 | return None |
| 3623 | output = self.apps( jsonFormat=True ) |
| 3624 | appsJson = json.loads( output ) |
| 3625 | state = None |
| 3626 | for app in appsJson: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3627 | if appName == app.get( 'name' ): |
| 3628 | state = app.get( 'state' ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3629 | break |
| 3630 | if state == "ACTIVE" or state == "INSTALLED": |
| 3631 | return state |
| 3632 | elif state is None: |
Jon Hall | 8bafdc0 | 2017-09-05 11:36:26 -0700 | [diff] [blame] | 3633 | main.log.warn( "{} app not found", appName ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3634 | return "UNINSTALLED" |
| 3635 | elif state: |
| 3636 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3637 | str( state ) ) |
| 3638 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3639 | except ( TypeError, ValueError ): |
| 3640 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3641 | return None |
| 3642 | except pexpect.EOF: |
| 3643 | main.log.error( self.name + ": EOF exception found" ) |
| 3644 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3645 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3646 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3647 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3648 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3649 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3650 | def app( self, appName, option ): |
| 3651 | """ |
| 3652 | Interacts with the app command for ONOS. This command manages |
| 3653 | application inventory. |
| 3654 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3655 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3656 | # Validate argument types |
| 3657 | valid = True |
| 3658 | if not isinstance( appName, types.StringType ): |
| 3659 | main.log.error( self.name + ".app(): appName must be a " + |
| 3660 | "string" ) |
| 3661 | valid = False |
| 3662 | if not isinstance( option, types.StringType ): |
| 3663 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3664 | valid = False |
| 3665 | if not valid: |
| 3666 | return main.FALSE |
| 3667 | # Validate Option |
| 3668 | option = option.lower() |
| 3669 | # NOTE: Install may become a valid option |
| 3670 | if option == "activate": |
| 3671 | pass |
| 3672 | elif option == "deactivate": |
| 3673 | pass |
| 3674 | elif option == "uninstall": |
| 3675 | pass |
| 3676 | else: |
| 3677 | # Invalid option |
| 3678 | main.log.error( "The ONOS app command argument only takes " + |
| 3679 | "the values: (activate|deactivate|uninstall)" + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3680 | "; was given '" + option + "'" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3681 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3682 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3683 | output = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3684 | assert output is not None, "Error in sendline" |
| 3685 | assert "Command not found:" not in output, output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3686 | if "Error executing command" in output: |
| 3687 | main.log.error( "Error in processing onos:app command: " + |
| 3688 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3689 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3690 | elif "No such application" in output: |
| 3691 | main.log.error( "The application '" + appName + |
| 3692 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3693 | return main.FALSE |
| 3694 | elif "Command not found:" in output: |
| 3695 | main.log.error( "Error in processing onos:app command: " + |
| 3696 | str( output ) ) |
| 3697 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3698 | elif "Unsupported command:" in output: |
| 3699 | main.log.error( "Incorrect command given to 'app': " + |
| 3700 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3701 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3702 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3703 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3704 | return main.TRUE |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3705 | except AssertionError: |
| 3706 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 3707 | return main.ERROR |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3708 | except TypeError: |
| 3709 | main.log.exception( self.name + ": Object not as expected" ) |
| 3710 | return main.ERROR |
| 3711 | except pexpect.EOF: |
| 3712 | main.log.error( self.name + ": EOF exception found" ) |
| 3713 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3714 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3715 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3716 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3717 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3718 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3719 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3720 | """ |
| 3721 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3722 | appName is the hierarchical app name, not the feature name |
| 3723 | If check is True, method will check the status of the app after the |
| 3724 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3725 | Returns main.TRUE if the command was successfully sent |
| 3726 | main.FALSE if the cli responded with an error or given |
| 3727 | incorrect input |
| 3728 | """ |
| 3729 | try: |
| 3730 | if not isinstance( appName, types.StringType ): |
| 3731 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3732 | " a string" ) |
| 3733 | return main.FALSE |
| 3734 | status = self.appStatus( appName ) |
| 3735 | if status == "INSTALLED": |
| 3736 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3737 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3738 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3739 | status = self.appStatus( appName ) |
| 3740 | if status == "ACTIVE": |
| 3741 | return main.TRUE |
| 3742 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3743 | main.log.debug( "The state of application " + |
| 3744 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3745 | time.sleep( 1 ) |
| 3746 | return main.FALSE |
| 3747 | else: # not 'check' or command didn't succeed |
| 3748 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3749 | elif status == "ACTIVE": |
| 3750 | return main.TRUE |
| 3751 | elif status == "UNINSTALLED": |
| 3752 | main.log.error( self.name + ": Tried to activate the " + |
| 3753 | "application '" + appName + "' which is not " + |
| 3754 | "installed." ) |
| 3755 | else: |
| 3756 | main.log.error( "Unexpected return value from appStatus: " + |
| 3757 | str( status ) ) |
| 3758 | return main.ERROR |
| 3759 | except TypeError: |
| 3760 | main.log.exception( self.name + ": Object not as expected" ) |
| 3761 | return main.ERROR |
| 3762 | except pexpect.EOF: |
| 3763 | main.log.error( self.name + ": EOF exception found" ) |
| 3764 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3765 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3766 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3767 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3768 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3769 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3770 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3771 | """ |
| 3772 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3773 | appName is the hierarchical app name, not the feature name |
| 3774 | If check is True, method will check the status of the app after the |
| 3775 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3776 | Returns main.TRUE if the command was successfully sent |
| 3777 | main.FALSE if the cli responded with an error or given |
| 3778 | incorrect input |
| 3779 | """ |
| 3780 | try: |
| 3781 | if not isinstance( appName, types.StringType ): |
| 3782 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 3783 | "be a string" ) |
| 3784 | return main.FALSE |
| 3785 | status = self.appStatus( appName ) |
| 3786 | if status == "INSTALLED": |
| 3787 | return main.TRUE |
| 3788 | elif status == "ACTIVE": |
| 3789 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3790 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3791 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3792 | status = self.appStatus( appName ) |
| 3793 | if status == "INSTALLED": |
| 3794 | return main.TRUE |
| 3795 | else: |
| 3796 | time.sleep( 1 ) |
| 3797 | return main.FALSE |
| 3798 | else: # not check or command didn't succeed |
| 3799 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3800 | elif status == "UNINSTALLED": |
| 3801 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 3802 | "application '" + appName + "' which is not " + |
| 3803 | "installed." ) |
| 3804 | return main.TRUE |
| 3805 | else: |
| 3806 | main.log.error( "Unexpected return value from appStatus: " + |
| 3807 | str( status ) ) |
| 3808 | return main.ERROR |
| 3809 | except TypeError: |
| 3810 | main.log.exception( self.name + ": Object not as expected" ) |
| 3811 | return main.ERROR |
| 3812 | except pexpect.EOF: |
| 3813 | main.log.error( self.name + ": EOF exception found" ) |
| 3814 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3815 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3816 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3817 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3818 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3819 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3820 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3821 | """ |
| 3822 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3823 | appName is the hierarchical app name, not the feature name |
| 3824 | If check is True, method will check the status of the app after the |
| 3825 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3826 | Returns main.TRUE if the command was successfully sent |
| 3827 | main.FALSE if the cli responded with an error or given |
| 3828 | incorrect input |
| 3829 | """ |
| 3830 | # TODO: check with Thomas about the state machine for apps |
| 3831 | try: |
| 3832 | if not isinstance( appName, types.StringType ): |
| 3833 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 3834 | "be a string" ) |
| 3835 | return main.FALSE |
| 3836 | status = self.appStatus( appName ) |
| 3837 | if status == "INSTALLED": |
| 3838 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3839 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3840 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3841 | status = self.appStatus( appName ) |
| 3842 | if status == "UNINSTALLED": |
| 3843 | return main.TRUE |
| 3844 | else: |
| 3845 | time.sleep( 1 ) |
| 3846 | return main.FALSE |
| 3847 | else: # not check or command didn't succeed |
| 3848 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3849 | elif status == "ACTIVE": |
| 3850 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 3851 | "application '" + appName + "' which is " + |
| 3852 | "currently active." ) |
| 3853 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3854 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3855 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3856 | status = self.appStatus( appName ) |
| 3857 | if status == "UNINSTALLED": |
| 3858 | return main.TRUE |
| 3859 | else: |
| 3860 | time.sleep( 1 ) |
| 3861 | return main.FALSE |
| 3862 | else: # not check or command didn't succeed |
| 3863 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3864 | elif status == "UNINSTALLED": |
| 3865 | return main.TRUE |
| 3866 | else: |
| 3867 | main.log.error( "Unexpected return value from appStatus: " + |
| 3868 | str( status ) ) |
| 3869 | return main.ERROR |
| 3870 | except TypeError: |
| 3871 | main.log.exception( self.name + ": Object not as expected" ) |
| 3872 | return main.ERROR |
| 3873 | except pexpect.EOF: |
| 3874 | main.log.error( self.name + ": EOF exception found" ) |
| 3875 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3876 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3877 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3878 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3879 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3880 | |
| 3881 | def appIDs( self, jsonFormat=True ): |
| 3882 | """ |
| 3883 | Show the mappings between app id and app names given by the 'app-ids' |
| 3884 | cli command |
| 3885 | """ |
| 3886 | try: |
| 3887 | cmdStr = "app-ids" |
| 3888 | if jsonFormat: |
| 3889 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3890 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3891 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3892 | assert "Command not found:" not in output, output |
| 3893 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3894 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3895 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3896 | main.log.exception( "Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3897 | return None |
| 3898 | except TypeError: |
| 3899 | main.log.exception( self.name + ": Object not as expected" ) |
| 3900 | return None |
| 3901 | except pexpect.EOF: |
| 3902 | main.log.error( self.name + ": EOF exception found" ) |
| 3903 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3904 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3905 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3906 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3907 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3908 | |
| 3909 | def appToIDCheck( self ): |
| 3910 | """ |
| 3911 | This method will check that each application's ID listed in 'apps' is |
| 3912 | the same as the ID listed in 'app-ids'. The check will also check that |
| 3913 | there are no duplicate IDs issued. Note that an app ID should be |
| 3914 | a globaly unique numerical identifier for app/app-like features. Once |
| 3915 | an ID is registered, the ID is never freed up so that if an app is |
| 3916 | reinstalled it will have the same ID. |
| 3917 | |
| 3918 | Returns: main.TRUE if the check passes and |
| 3919 | main.FALSE if the check fails or |
| 3920 | main.ERROR if there is some error in processing the test |
| 3921 | """ |
| 3922 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3923 | bail = False |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3924 | rawJson = self.appIDs( jsonFormat=True ) |
| 3925 | if rawJson: |
| 3926 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3927 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3928 | main.log.error( "app-ids returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3929 | bail = True |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3930 | rawJson = self.apps( jsonFormat=True ) |
| 3931 | if rawJson: |
| 3932 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3933 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3934 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3935 | bail = True |
| 3936 | if bail: |
| 3937 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3938 | result = main.TRUE |
| 3939 | for app in apps: |
| 3940 | appID = app.get( 'id' ) |
| 3941 | if appID is None: |
| 3942 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3943 | result = main.FALSE |
| 3944 | appName = app.get( 'name' ) |
| 3945 | if appName is None: |
| 3946 | main.log.error( "Error parsing app: " + str( app ) ) |
| 3947 | result = main.FALSE |
| 3948 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 3949 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3950 | if not current: # if ids doesn't have this id |
| 3951 | result = main.FALSE |
| 3952 | main.log.error( "'app-ids' does not have the ID for " + |
| 3953 | str( appName ) + " that apps does." ) |
Jon Hall | b9d381e | 2018-02-05 12:02:10 -0800 | [diff] [blame] | 3954 | main.log.debug( "apps command returned: " + str( app ) + |
| 3955 | "; app-ids has: " + str( ids ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3956 | elif len( current ) > 1: |
| 3957 | # there is more than one app with this ID |
| 3958 | result = main.FALSE |
| 3959 | # We will log this later in the method |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3960 | elif not current[ 0 ][ 'name' ] == appName: |
| 3961 | currentName = current[ 0 ][ 'name' ] |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3962 | result = main.FALSE |
| 3963 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 3964 | " registered under id:" + str( appID ) + |
| 3965 | " but 'apps' has " + str( appName ) ) |
| 3966 | else: |
| 3967 | pass # id and name match! |
| 3968 | # now make sure that app-ids has no duplicates |
| 3969 | idsList = [] |
| 3970 | namesList = [] |
| 3971 | for item in ids: |
| 3972 | idsList.append( item[ 'id' ] ) |
| 3973 | namesList.append( item[ 'name' ] ) |
| 3974 | if len( idsList ) != len( set( idsList ) ) or\ |
| 3975 | len( namesList ) != len( set( namesList ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3976 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 3977 | + json.dumps( ids, |
| 3978 | sort_keys=True, |
| 3979 | indent=4, |
| 3980 | separators=( ',', ': ' ) ) ) |
| 3981 | result = main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3982 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3983 | except ( TypeError, ValueError ): |
| 3984 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3985 | return main.ERROR |
| 3986 | except pexpect.EOF: |
| 3987 | main.log.error( self.name + ": EOF exception found" ) |
| 3988 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3989 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3990 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3991 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3992 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3993 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 3994 | def getCfg( self, component=None, propName=None, short=False, |
| 3995 | jsonFormat=True ): |
| 3996 | """ |
| 3997 | Get configuration settings from onos cli |
| 3998 | Optional arguments: |
| 3999 | component - Optionally only list configurations for a specific |
| 4000 | component. If None, all components with configurations |
| 4001 | are displayed. Case Sensitive string. |
| 4002 | propName - If component is specified, propName option will show |
| 4003 | only this specific configuration from that component. |
| 4004 | Case Sensitive string. |
| 4005 | jsonFormat - Returns output as json. Note that this will override |
| 4006 | the short option |
| 4007 | short - Short, less verbose, version of configurations. |
| 4008 | This is overridden by the json option |
| 4009 | returns: |
| 4010 | Output from cli as a string or None on error |
| 4011 | """ |
| 4012 | try: |
| 4013 | baseStr = "cfg" |
| 4014 | cmdStr = " get" |
| 4015 | componentStr = "" |
| 4016 | if component: |
| 4017 | componentStr += " " + component |
| 4018 | if propName: |
| 4019 | componentStr += " " + propName |
| 4020 | if jsonFormat: |
| 4021 | baseStr += " -j" |
| 4022 | elif short: |
| 4023 | baseStr += " -s" |
| 4024 | output = self.sendline( baseStr + cmdStr + componentStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4025 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4026 | assert "Command not found:" not in output, output |
| 4027 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4028 | return output |
| 4029 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4030 | main.log.exception( "Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4031 | return None |
| 4032 | except TypeError: |
| 4033 | main.log.exception( self.name + ": Object not as expected" ) |
| 4034 | return None |
| 4035 | except pexpect.EOF: |
| 4036 | main.log.error( self.name + ": EOF exception found" ) |
| 4037 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4038 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4039 | except Exception: |
| 4040 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4041 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4042 | |
| 4043 | def setCfg( self, component, propName, value=None, check=True ): |
| 4044 | """ |
| 4045 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4046 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4047 | component - The case sensitive name of the component whose |
| 4048 | property is to be set |
| 4049 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4050 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4051 | 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] | 4052 | property and revert it to it's default value(if applicable) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4053 | check - Boolean, Check whether the option was successfully set this |
| 4054 | only applies when a value is given. |
| 4055 | returns: |
| 4056 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 4057 | will return main.TRUE unless there is an error |
| 4058 | """ |
| 4059 | try: |
| 4060 | baseStr = "cfg" |
| 4061 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 4062 | if value is not None: |
| 4063 | cmdStr += " " + str( value ) |
| 4064 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4065 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4066 | assert "Command not found:" not in output, output |
| 4067 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4068 | if value and check: |
| 4069 | results = self.getCfg( component=str( component ), |
| 4070 | propName=str( propName ), |
| 4071 | jsonFormat=True ) |
| 4072 | # Check if current value is what we just set |
| 4073 | try: |
| 4074 | jsonOutput = json.loads( results ) |
| 4075 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4076 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4077 | main.log.exception( "Error parsing cfg output" ) |
| 4078 | main.log.error( "output:" + repr( results ) ) |
| 4079 | return main.FALSE |
| 4080 | if current == str( value ): |
| 4081 | return main.TRUE |
| 4082 | return main.FALSE |
| 4083 | return main.TRUE |
| 4084 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4085 | main.log.exception( "Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4086 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4087 | except ( TypeError, ValueError ): |
| 4088 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4089 | return main.FALSE |
| 4090 | except pexpect.EOF: |
| 4091 | main.log.error( self.name + ": EOF exception found" ) |
| 4092 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4093 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4094 | except Exception: |
| 4095 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4096 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4097 | |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4098 | def distPrimitivesSend( self, cmd ): |
| 4099 | """ |
| 4100 | Function to handle sending cli commands for the distributed primitives test app |
| 4101 | |
| 4102 | This command will catch some exceptions and retry the command on some |
| 4103 | specific store exceptions. |
| 4104 | |
| 4105 | Required arguments: |
| 4106 | cmd - The command to send to the cli |
| 4107 | returns: |
| 4108 | string containing the cli output |
| 4109 | None on Error |
| 4110 | """ |
| 4111 | try: |
| 4112 | output = self.sendline( cmd ) |
| 4113 | try: |
| 4114 | assert output is not None, "Error in sendline" |
| 4115 | # TODO: Maybe make this less hardcoded |
| 4116 | # ConsistentMap Exceptions |
| 4117 | assert "org.onosproject.store.service" not in output |
| 4118 | # Node not leader |
| 4119 | assert "java.lang.IllegalStateException" not in output |
| 4120 | except AssertionError: |
| 4121 | main.log.error( "Error in processing '" + cmd + "' " + |
| 4122 | "command: " + str( output ) ) |
| 4123 | retryTime = 30 # Conservative time, given by Madan |
| 4124 | main.log.info( "Waiting " + str( retryTime ) + |
| 4125 | "seconds before retrying." ) |
| 4126 | time.sleep( retryTime ) # Due to change in mastership |
| 4127 | output = self.sendline( cmd ) |
| 4128 | assert output is not None, "Error in sendline" |
| 4129 | assert "Command not found:" not in output, output |
| 4130 | assert "Error executing command" not in output, output |
| 4131 | main.log.info( self.name + ": " + output ) |
| 4132 | return output |
| 4133 | except AssertionError: |
| 4134 | main.log.exception( "Error in processing '" + cmd + "' command." ) |
| 4135 | return None |
| 4136 | except TypeError: |
| 4137 | main.log.exception( self.name + ": Object not as expected" ) |
| 4138 | return None |
| 4139 | except pexpect.EOF: |
| 4140 | main.log.error( self.name + ": EOF exception found" ) |
| 4141 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4142 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4143 | except Exception: |
| 4144 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4145 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4146 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4147 | def setTestAdd( self, setName, values ): |
| 4148 | """ |
| 4149 | CLI command to add elements to a distributed set. |
| 4150 | Arguments: |
| 4151 | setName - The name of the set to add to. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4152 | values - The value(s) to add to the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4153 | Example usages: |
| 4154 | setTestAdd( "set1", "a b c" ) |
| 4155 | setTestAdd( "set2", "1" ) |
| 4156 | returns: |
| 4157 | main.TRUE on success OR |
| 4158 | main.FALSE if elements were already in the set OR |
| 4159 | main.ERROR on error |
| 4160 | """ |
| 4161 | try: |
| 4162 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4163 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4164 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 4165 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4166 | if re.search( positiveMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4167 | return main.TRUE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4168 | elif re.search( negativeMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4169 | return main.FALSE |
| 4170 | else: |
| 4171 | main.log.error( self.name + ": setTestAdd did not" + |
| 4172 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4173 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4174 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4175 | except TypeError: |
| 4176 | main.log.exception( self.name + ": Object not as expected" ) |
| 4177 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4178 | except Exception: |
| 4179 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4180 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4181 | |
| 4182 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 4183 | """ |
| 4184 | CLI command to remove elements from a distributed set. |
| 4185 | Required arguments: |
| 4186 | setName - The name of the set to remove from. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4187 | values - The value(s) to remove from the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4188 | Optional arguments: |
| 4189 | clear - Clear all elements from the set |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4190 | retain - Retain only the given values. (intersection of the |
| 4191 | original set and the given set) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4192 | returns: |
| 4193 | main.TRUE on success OR |
| 4194 | main.FALSE if the set was not changed OR |
| 4195 | main.ERROR on error |
| 4196 | """ |
| 4197 | try: |
| 4198 | cmdStr = "set-test-remove " |
| 4199 | if clear: |
| 4200 | cmdStr += "-c " + str( setName ) |
| 4201 | elif retain: |
| 4202 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4203 | else: |
| 4204 | cmdStr += str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4205 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4206 | if clear: |
| 4207 | pattern = "Set " + str( setName ) + " cleared" |
| 4208 | if re.search( pattern, output ): |
| 4209 | return main.TRUE |
| 4210 | elif retain: |
| 4211 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4212 | "only elements of set \[(.*)\]" |
| 4213 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4214 | "retaining only elements of the set " +\ |
| 4215 | "\[(.*)\]" |
| 4216 | if re.search( positivePattern, output ): |
| 4217 | return main.TRUE |
| 4218 | elif re.search( negativePattern, output ): |
| 4219 | return main.FALSE |
| 4220 | else: |
| 4221 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4222 | str( setName ) |
| 4223 | if ( len( values.split() ) == 1 ): |
| 4224 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4225 | str( setName ) |
| 4226 | else: |
| 4227 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4228 | str( setName ) |
| 4229 | if re.search( positivePattern, output ): |
| 4230 | return main.TRUE |
| 4231 | elif re.search( negativePattern, output ): |
| 4232 | return main.FALSE |
| 4233 | main.log.error( self.name + ": setTestRemove did not" + |
| 4234 | " match expected output" ) |
| 4235 | main.log.debug( self.name + " expected: " + pattern ) |
| 4236 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4237 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4238 | except TypeError: |
| 4239 | main.log.exception( self.name + ": Object not as expected" ) |
| 4240 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4241 | except Exception: |
| 4242 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4243 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4244 | |
| 4245 | def setTestGet( self, setName, values="" ): |
| 4246 | """ |
| 4247 | CLI command to get the elements in a distributed set. |
| 4248 | Required arguments: |
| 4249 | setName - The name of the set to remove from. |
| 4250 | Optional arguments: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4251 | values - The value(s) to check if in the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4252 | returns: |
| 4253 | main.ERROR on error OR |
| 4254 | A list of elements in the set if no optional arguments are |
| 4255 | supplied OR |
| 4256 | A tuple containing the list then: |
| 4257 | main.FALSE if the given values are not in the set OR |
| 4258 | main.TRUE if the given values are in the set OR |
| 4259 | """ |
| 4260 | try: |
| 4261 | values = str( values ).strip() |
| 4262 | setName = str( setName ).strip() |
| 4263 | length = len( values.split() ) |
| 4264 | containsCheck = None |
| 4265 | # Patterns to match |
| 4266 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4267 | pattern = "Items in set " + setName + ":\r\n" + setPattern |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4268 | containsTrue = "Set " + setName + " contains the value " + values |
| 4269 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4270 | values |
| 4271 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4272 | setPattern |
| 4273 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4274 | " subset " + setPattern |
| 4275 | |
| 4276 | cmdStr = "set-test-get " |
| 4277 | cmdStr += setName + " " + values |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4278 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4279 | if length == 0: |
| 4280 | match = re.search( pattern, output ) |
| 4281 | else: # if given values |
| 4282 | if length == 1: # Contains output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4283 | patternTrue = pattern + "\r\n" + containsTrue |
| 4284 | patternFalse = pattern + "\r\n" + containsFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4285 | else: # ContainsAll output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4286 | patternTrue = pattern + "\r\n" + containsAllTrue |
| 4287 | patternFalse = pattern + "\r\n" + containsAllFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4288 | matchTrue = re.search( patternTrue, output ) |
| 4289 | matchFalse = re.search( patternFalse, output ) |
| 4290 | if matchTrue: |
| 4291 | containsCheck = main.TRUE |
| 4292 | match = matchTrue |
| 4293 | elif matchFalse: |
| 4294 | containsCheck = main.FALSE |
| 4295 | match = matchFalse |
| 4296 | else: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4297 | main.log.error( self.name + " setTestGet did not match " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4298 | "expected output" ) |
| 4299 | main.log.debug( self.name + " expected: " + pattern ) |
| 4300 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4301 | match = None |
| 4302 | if match: |
| 4303 | setMatch = match.group( 1 ) |
| 4304 | if setMatch == '': |
| 4305 | setList = [] |
| 4306 | else: |
| 4307 | setList = setMatch.split( ", " ) |
| 4308 | if length > 0: |
| 4309 | return ( setList, containsCheck ) |
| 4310 | else: |
| 4311 | return setList |
| 4312 | else: # no match |
| 4313 | main.log.error( self.name + ": setTestGet did not" + |
| 4314 | " match expected output" ) |
| 4315 | main.log.debug( self.name + " expected: " + pattern ) |
| 4316 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4317 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4318 | except TypeError: |
| 4319 | main.log.exception( self.name + ": Object not as expected" ) |
| 4320 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4321 | except Exception: |
| 4322 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4323 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4324 | |
| 4325 | def setTestSize( self, setName ): |
| 4326 | """ |
| 4327 | CLI command to get the elements in a distributed set. |
| 4328 | Required arguments: |
| 4329 | setName - The name of the set to remove from. |
| 4330 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4331 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4332 | None on error |
| 4333 | """ |
| 4334 | try: |
| 4335 | # TODO: Should this check against the number of elements returned |
| 4336 | # and then return true/false based on that? |
| 4337 | setName = str( setName ).strip() |
| 4338 | # Patterns to match |
| 4339 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4340 | pattern = "There are (\d+) items in set " + setName + ":\r\n" +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4341 | setPattern |
| 4342 | cmdStr = "set-test-get -s " |
| 4343 | cmdStr += setName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4344 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4345 | match = re.search( pattern, output ) |
| 4346 | if match: |
| 4347 | setSize = int( match.group( 1 ) ) |
| 4348 | setMatch = match.group( 2 ) |
| 4349 | if len( setMatch.split() ) == setSize: |
| 4350 | main.log.info( "The size returned by " + self.name + |
| 4351 | " matches the number of elements in " + |
| 4352 | "the returned set" ) |
| 4353 | else: |
| 4354 | main.log.error( "The size returned by " + self.name + |
| 4355 | " does not match the number of " + |
| 4356 | "elements in the returned set." ) |
| 4357 | return setSize |
| 4358 | else: # no match |
| 4359 | main.log.error( self.name + ": setTestGet did not" + |
| 4360 | " match expected output" ) |
| 4361 | main.log.debug( self.name + " expected: " + pattern ) |
| 4362 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4363 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4364 | except TypeError: |
| 4365 | main.log.exception( self.name + ": Object not as expected" ) |
| 4366 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4367 | except Exception: |
| 4368 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4369 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4370 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4371 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4372 | """ |
| 4373 | Command to list the various counters in the system. |
| 4374 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4375 | if jsonFormat, a string of the json object returned by the cli |
| 4376 | command |
| 4377 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4378 | None on error |
| 4379 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4380 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4381 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4382 | if jsonFormat: |
| 4383 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4384 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4385 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4386 | assert "Command not found:" not in output, output |
| 4387 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4388 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4389 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4390 | except AssertionError: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4391 | main.log.exception( "Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4392 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4393 | except TypeError: |
| 4394 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4395 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4396 | except pexpect.EOF: |
| 4397 | main.log.error( self.name + ": EOF exception found" ) |
| 4398 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4399 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4400 | except Exception: |
| 4401 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4402 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4403 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4404 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4405 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4406 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4407 | Required arguments: |
| 4408 | counter - The name of the counter to increment. |
| 4409 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4410 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4411 | returns: |
| 4412 | integer value of the counter or |
| 4413 | None on Error |
| 4414 | """ |
| 4415 | try: |
| 4416 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4417 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4418 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4419 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4420 | if delta != 1: |
| 4421 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4422 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4423 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4424 | match = re.search( pattern, output ) |
| 4425 | if match: |
| 4426 | return int( match.group( 1 ) ) |
| 4427 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4428 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4429 | " match expected output." ) |
| 4430 | main.log.debug( self.name + " expected: " + pattern ) |
| 4431 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4432 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4433 | except TypeError: |
| 4434 | main.log.exception( self.name + ": Object not as expected" ) |
| 4435 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4436 | except Exception: |
| 4437 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4438 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4439 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4440 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4441 | """ |
| 4442 | CLI command to get a distributed counter then add a delta to it. |
| 4443 | Required arguments: |
| 4444 | counter - The name of the counter to increment. |
| 4445 | Optional arguments: |
| 4446 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4447 | returns: |
| 4448 | integer value of the counter or |
| 4449 | None on Error |
| 4450 | """ |
| 4451 | try: |
| 4452 | counter = str( counter ) |
| 4453 | delta = int( delta ) |
| 4454 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4455 | cmdStr += counter |
| 4456 | if delta != 1: |
| 4457 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4458 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4459 | pattern = counter + " was updated to (-?\d+)" |
| 4460 | match = re.search( pattern, output ) |
| 4461 | if match: |
| 4462 | return int( match.group( 1 ) ) |
| 4463 | else: |
| 4464 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4465 | " match expected output." ) |
| 4466 | main.log.debug( self.name + " expected: " + pattern ) |
| 4467 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4468 | return None |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4469 | except TypeError: |
| 4470 | main.log.exception( self.name + ": Object not as expected" ) |
| 4471 | return None |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4472 | except Exception: |
| 4473 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4474 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4475 | |
| 4476 | def valueTestGet( self, valueName ): |
| 4477 | """ |
| 4478 | CLI command to get the value of an atomic value. |
| 4479 | Required arguments: |
| 4480 | valueName - The name of the value to get. |
| 4481 | returns: |
| 4482 | string value of the value or |
| 4483 | None on Error |
| 4484 | """ |
| 4485 | try: |
| 4486 | valueName = str( valueName ) |
| 4487 | cmdStr = "value-test " |
| 4488 | operation = "get" |
| 4489 | cmdStr = "value-test {} {}".format( valueName, |
| 4490 | operation ) |
| 4491 | output = self.distPrimitivesSend( cmdStr ) |
| 4492 | pattern = "(\w+)" |
| 4493 | match = re.search( pattern, output ) |
| 4494 | if match: |
| 4495 | return match.group( 1 ) |
| 4496 | else: |
| 4497 | main.log.error( self.name + ": valueTestGet did not" + |
| 4498 | " match expected output." ) |
| 4499 | main.log.debug( self.name + " expected: " + pattern ) |
| 4500 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4501 | return None |
| 4502 | except TypeError: |
| 4503 | main.log.exception( self.name + ": Object not as expected" ) |
| 4504 | return None |
| 4505 | except Exception: |
| 4506 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4507 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4508 | |
| 4509 | def valueTestSet( self, valueName, newValue ): |
| 4510 | """ |
| 4511 | CLI command to set the value of an atomic value. |
| 4512 | Required arguments: |
| 4513 | valueName - The name of the value to set. |
| 4514 | newValue - The value to assign to the given value. |
| 4515 | returns: |
| 4516 | main.TRUE on success or |
| 4517 | main.ERROR on Error |
| 4518 | """ |
| 4519 | try: |
| 4520 | valueName = str( valueName ) |
| 4521 | newValue = str( newValue ) |
| 4522 | operation = "set" |
| 4523 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4524 | operation, |
| 4525 | newValue ) |
| 4526 | output = self.distPrimitivesSend( cmdStr ) |
| 4527 | if output is not None: |
| 4528 | return main.TRUE |
| 4529 | else: |
| 4530 | return main.ERROR |
| 4531 | except TypeError: |
| 4532 | main.log.exception( self.name + ": Object not as expected" ) |
| 4533 | return main.ERROR |
| 4534 | except Exception: |
| 4535 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4536 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4537 | |
| 4538 | def valueTestCompareAndSet( self, valueName, oldValue, newValue ): |
| 4539 | """ |
| 4540 | CLI command to compareAndSet the value of an atomic value. |
| 4541 | Required arguments: |
| 4542 | valueName - The name of the value. |
| 4543 | oldValue - Compare the current value of the atomic value to this |
| 4544 | newValue - If the value equals oldValue, set the value to newValue |
| 4545 | returns: |
| 4546 | main.TRUE on success or |
| 4547 | main.FALSE on failure or |
| 4548 | main.ERROR on Error |
| 4549 | """ |
| 4550 | try: |
| 4551 | valueName = str( valueName ) |
| 4552 | oldValue = str( oldValue ) |
| 4553 | newValue = str( newValue ) |
| 4554 | operation = "compareAndSet" |
| 4555 | cmdStr = "value-test {} {} {} {}".format( valueName, |
| 4556 | operation, |
| 4557 | oldValue, |
| 4558 | newValue ) |
| 4559 | output = self.distPrimitivesSend( cmdStr ) |
| 4560 | pattern = "(\w+)" |
| 4561 | match = re.search( pattern, output ) |
| 4562 | if match: |
| 4563 | result = match.group( 1 ) |
| 4564 | if result == "true": |
| 4565 | return main.TRUE |
| 4566 | elif result == "false": |
| 4567 | return main.FALSE |
| 4568 | else: |
| 4569 | main.log.error( self.name + ": valueTestCompareAndSet did not" + |
| 4570 | " match expected output." ) |
| 4571 | main.log.debug( self.name + " expected: " + pattern ) |
| 4572 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4573 | return main.ERROR |
| 4574 | except TypeError: |
| 4575 | main.log.exception( self.name + ": Object not as expected" ) |
| 4576 | return main.ERROR |
| 4577 | except Exception: |
| 4578 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4579 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4580 | |
| 4581 | def valueTestGetAndSet( self, valueName, newValue ): |
| 4582 | """ |
| 4583 | CLI command to getAndSet the value of an atomic value. |
| 4584 | Required arguments: |
| 4585 | valueName - The name of the value to get. |
| 4586 | newValue - The value to assign to the given value |
| 4587 | returns: |
| 4588 | string value of the value or |
| 4589 | None on Error |
| 4590 | """ |
| 4591 | try: |
| 4592 | valueName = str( valueName ) |
| 4593 | cmdStr = "value-test " |
| 4594 | operation = "getAndSet" |
| 4595 | cmdStr += valueName + " " + operation |
| 4596 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4597 | operation, |
| 4598 | newValue ) |
| 4599 | output = self.distPrimitivesSend( cmdStr ) |
| 4600 | pattern = "(\w+)" |
| 4601 | match = re.search( pattern, output ) |
| 4602 | if match: |
| 4603 | return match.group( 1 ) |
| 4604 | else: |
| 4605 | main.log.error( self.name + ": valueTestGetAndSet did not" + |
| 4606 | " match expected output." ) |
| 4607 | main.log.debug( self.name + " expected: " + pattern ) |
| 4608 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4609 | return None |
| 4610 | except TypeError: |
| 4611 | main.log.exception( self.name + ": Object not as expected" ) |
| 4612 | return None |
| 4613 | except Exception: |
| 4614 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4615 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4616 | |
| 4617 | def valueTestDestroy( self, valueName ): |
| 4618 | """ |
| 4619 | CLI command to destroy an atomic value. |
| 4620 | Required arguments: |
| 4621 | valueName - The name of the value to destroy. |
| 4622 | returns: |
| 4623 | main.TRUE on success or |
| 4624 | main.ERROR on Error |
| 4625 | """ |
| 4626 | try: |
| 4627 | valueName = str( valueName ) |
| 4628 | cmdStr = "value-test " |
| 4629 | operation = "destroy" |
| 4630 | cmdStr += valueName + " " + operation |
| 4631 | output = self.distPrimitivesSend( cmdStr ) |
| 4632 | if output is not None: |
| 4633 | return main.TRUE |
| 4634 | else: |
| 4635 | return main.ERROR |
| 4636 | except TypeError: |
| 4637 | main.log.exception( self.name + ": Object not as expected" ) |
| 4638 | return main.ERROR |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4639 | except Exception: |
| 4640 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4641 | main.cleanAndExit() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4642 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4643 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4644 | """ |
| 4645 | Description: Execute summary command in onos |
| 4646 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4647 | no output |
| 4648 | |
| 4649 | """ |
| 4650 | try: |
| 4651 | cmdStr = "summary" |
| 4652 | if jsonFormat: |
| 4653 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4654 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4655 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4656 | assert "Command not found:" not in handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4657 | assert "Error:" not in handle, handle |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 4658 | assert "Error executing" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4659 | if not handle: |
| 4660 | main.log.error( self.name + ": There is no output in " + |
| 4661 | "summary command" ) |
| 4662 | return main.FALSE |
| 4663 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4664 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4665 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4666 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [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() |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [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() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4677 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4678 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4679 | """ |
| 4680 | CLI command to get the value of a key in a consistent map using |
| 4681 | transactions. This a test function and can only get keys from the |
| 4682 | test map hard coded into the cli command |
| 4683 | Required arguments: |
| 4684 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4685 | returns: |
| 4686 | The string value of the key or |
| 4687 | None on Error |
| 4688 | """ |
| 4689 | try: |
| 4690 | keyName = str( keyName ) |
| 4691 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4692 | cmdStr += keyName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4693 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4694 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4695 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4696 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4697 | return None |
| 4698 | else: |
| 4699 | match = re.search( pattern, output ) |
| 4700 | if match: |
| 4701 | return match.groupdict()[ 'value' ] |
| 4702 | else: |
| 4703 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4704 | " match expected output." ) |
| 4705 | main.log.debug( self.name + " expected: " + pattern ) |
| 4706 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4707 | return None |
| 4708 | except TypeError: |
| 4709 | main.log.exception( self.name + ": Object not as expected" ) |
| 4710 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4711 | except Exception: |
| 4712 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4713 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4714 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4715 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4716 | """ |
| 4717 | CLI command to put a value into 'numKeys' number of keys in a |
| 4718 | consistent map using transactions. This a test function and can only |
| 4719 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4720 | Required arguments: |
| 4721 | numKeys - Number of keys to add the value to |
| 4722 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4723 | returns: |
| 4724 | A dictionary whose keys are the name of the keys put into the map |
| 4725 | and the values of the keys are dictionaries whose key-values are |
| 4726 | 'value': value put into map and optionaly |
| 4727 | 'oldValue': Previous value in the key or |
| 4728 | None on Error |
| 4729 | |
| 4730 | Example output |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4731 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4732 | 'Key2': {'value': 'Testing'} } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4733 | """ |
| 4734 | try: |
| 4735 | numKeys = str( numKeys ) |
| 4736 | value = str( value ) |
| 4737 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4738 | cmdStr += numKeys + " " + value |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4739 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4740 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4741 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4742 | results = {} |
| 4743 | for line in output.splitlines(): |
| 4744 | new = re.search( newPattern, line ) |
| 4745 | updated = re.search( updatedPattern, line ) |
| 4746 | if new: |
| 4747 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 4748 | elif updated: |
| 4749 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4750 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4751 | else: |
| 4752 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4753 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4754 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 4755 | newPattern, |
| 4756 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4757 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4758 | return results |
| 4759 | except TypeError: |
| 4760 | main.log.exception( self.name + ": Object not as expected" ) |
| 4761 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4762 | except Exception: |
| 4763 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4764 | main.cleanAndExit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4765 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4766 | def maps( self, jsonFormat=True ): |
| 4767 | """ |
| 4768 | Description: Returns result of onos:maps |
| 4769 | Optional: |
| 4770 | * jsonFormat: enable json formatting of output |
| 4771 | """ |
| 4772 | try: |
| 4773 | cmdStr = "maps" |
| 4774 | if jsonFormat: |
| 4775 | cmdStr += " -j" |
| 4776 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4777 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4778 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4779 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4780 | except AssertionError: |
| 4781 | main.log.exception( "" ) |
| 4782 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4783 | except TypeError: |
| 4784 | main.log.exception( self.name + ": Object not as expected" ) |
| 4785 | return None |
| 4786 | except pexpect.EOF: |
| 4787 | main.log.error( self.name + ": EOF exception found" ) |
| 4788 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4789 | main.cleanAndExit() |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 4790 | except Exception: |
| 4791 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4792 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4793 | |
| 4794 | def getSwController( self, uri, jsonFormat=True ): |
| 4795 | """ |
| 4796 | Descrition: Gets the controller information from the device |
| 4797 | """ |
| 4798 | try: |
| 4799 | cmd = "device-controllers " |
| 4800 | if jsonFormat: |
| 4801 | cmd += "-j " |
| 4802 | response = self.sendline( cmd + uri ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4803 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4804 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4805 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4806 | except AssertionError: |
| 4807 | main.log.exception( "" ) |
| 4808 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4809 | except TypeError: |
| 4810 | main.log.exception( self.name + ": Object not as expected" ) |
| 4811 | return None |
| 4812 | except pexpect.EOF: |
| 4813 | main.log.error( self.name + ": EOF exception found" ) |
| 4814 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4815 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4816 | except Exception: |
| 4817 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4818 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4819 | |
| 4820 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 4821 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4822 | Descrition: sets the controller(s) for the specified device |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4823 | |
| 4824 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4825 | Required: uri - String: The uri of the device(switch). |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4826 | ip - String or List: The ip address of the controller. |
| 4827 | This parameter can be formed in a couple of different ways. |
| 4828 | VALID: |
| 4829 | 10.0.0.1 - just the ip address |
| 4830 | tcp:10.0.0.1 - the protocol and the ip address |
| 4831 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 4832 | so that you can add controllers with different |
| 4833 | protocols and ports |
| 4834 | INVALID: |
| 4835 | 10.0.0.1:6653 - this is not supported by ONOS |
| 4836 | |
| 4837 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 4838 | port - The port number. |
| 4839 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 4840 | |
| 4841 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 4842 | """ |
| 4843 | try: |
| 4844 | cmd = "device-setcontrollers" |
| 4845 | |
| 4846 | if jsonFormat: |
| 4847 | cmd += " -j" |
| 4848 | cmd += " " + uri |
| 4849 | if isinstance( ip, str ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4850 | ip = [ ip ] |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4851 | for item in ip: |
| 4852 | if ":" in item: |
| 4853 | sitem = item.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4854 | if len( sitem ) == 3: |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4855 | cmd += " " + item |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4856 | elif "." in sitem[ 1 ]: |
| 4857 | cmd += " {}:{}".format( item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4858 | else: |
| 4859 | main.log.error( "Malformed entry: " + item ) |
| 4860 | raise TypeError |
| 4861 | else: |
| 4862 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4863 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4864 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4865 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4866 | if "Error" in response: |
| 4867 | main.log.error( response ) |
| 4868 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4869 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4870 | except AssertionError: |
| 4871 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4872 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4873 | except TypeError: |
| 4874 | main.log.exception( self.name + ": Object not as expected" ) |
| 4875 | return main.FALSE |
| 4876 | except pexpect.EOF: |
| 4877 | main.log.error( self.name + ": EOF exception found" ) |
| 4878 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4879 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 4880 | except Exception: |
| 4881 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4882 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4883 | |
| 4884 | def removeDevice( self, device ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4885 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4886 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4887 | Remove a device from ONOS by passing the uri of the device(s). |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4888 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4889 | 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] | 4890 | Returns: |
| 4891 | Returns main.FALSE if an exception is thrown or an error is present |
| 4892 | in the response. Otherwise, returns main.TRUE. |
| 4893 | NOTE: |
| 4894 | 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] | 4895 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4896 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4897 | if isinstance( device, str ): |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 4898 | deviceStr = device |
| 4899 | device = [] |
| 4900 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4901 | |
| 4902 | for d in device: |
| 4903 | time.sleep( 1 ) |
| 4904 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4905 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4906 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4907 | if "Error" in response: |
| 4908 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 4909 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4910 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4911 | except AssertionError: |
| 4912 | main.log.exception( "" ) |
| 4913 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4914 | except TypeError: |
| 4915 | main.log.exception( self.name + ": Object not as expected" ) |
| 4916 | return main.FALSE |
| 4917 | except pexpect.EOF: |
| 4918 | main.log.error( self.name + ": EOF exception found" ) |
| 4919 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4920 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4921 | except Exception: |
| 4922 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4923 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4924 | |
| 4925 | def removeHost( self, host ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4926 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4927 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4928 | Remove a host from ONOS by passing the id of the host(s) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4929 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4930 | 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] | 4931 | Returns: |
| 4932 | Returns main.FALSE if an exception is thrown or an error is present |
| 4933 | in the response. Otherwise, returns main.TRUE. |
| 4934 | NOTE: |
| 4935 | 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] | 4936 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4937 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4938 | if isinstance( host, str ): |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4939 | host = list( host ) |
| 4940 | |
| 4941 | for h in host: |
| 4942 | time.sleep( 1 ) |
| 4943 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4944 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4945 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4946 | if "Error" in response: |
| 4947 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 4948 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4949 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4950 | except AssertionError: |
| 4951 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4952 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4953 | except TypeError: |
| 4954 | main.log.exception( self.name + ": Object not as expected" ) |
| 4955 | return main.FALSE |
| 4956 | except pexpect.EOF: |
| 4957 | main.log.error( self.name + ": EOF exception found" ) |
| 4958 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4959 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 4960 | except Exception: |
| 4961 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4962 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4963 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4964 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4965 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4966 | Description: |
| 4967 | Bring link down or up in the null-provider. |
| 4968 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4969 | begin - (string) One end of a device or switch. |
| 4970 | end - (string) the other end of the device or switch |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4971 | returns: |
| 4972 | main.TRUE if no exceptions were thrown and no Errors are |
| 4973 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4974 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4975 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4976 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4977 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4978 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4979 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4980 | if "Error" in response or "Failure" in response: |
| 4981 | main.log.error( response ) |
| 4982 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4983 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4984 | except AssertionError: |
| 4985 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4986 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4987 | except TypeError: |
| 4988 | main.log.exception( self.name + ": Object not as expected" ) |
| 4989 | return main.FALSE |
| 4990 | except pexpect.EOF: |
| 4991 | main.log.error( self.name + ": EOF exception found" ) |
| 4992 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4993 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4994 | except Exception: |
| 4995 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4996 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 4997 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 4998 | def portstate( self, dpid, port, state ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4999 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5000 | Description: |
| 5001 | Changes the state of port in an OF switch by means of the |
| 5002 | PORTSTATUS OF messages. |
| 5003 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5004 | dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102' |
| 5005 | port - (string) target port in the device. Ex: '2' |
| 5006 | state - (string) target state (enable or disable) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5007 | returns: |
| 5008 | main.TRUE if no exceptions were thrown and no Errors are |
| 5009 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5010 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5011 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5012 | state = state.lower() |
| 5013 | assert state == 'enable' or state == 'disable', "Unknown state" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5014 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5015 | response = self.sendline( cmd, showResponse=True ) |
| 5016 | assert response is not None, "Error in sendline" |
| 5017 | assert "Command not found:" not in response, response |
| 5018 | if "Error" in response or "Failure" in response: |
| 5019 | main.log.error( response ) |
| 5020 | return main.FALSE |
| 5021 | return main.TRUE |
| 5022 | except AssertionError: |
| 5023 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5024 | return main.FALSE |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5025 | except TypeError: |
| 5026 | main.log.exception( self.name + ": Object not as expected" ) |
| 5027 | return main.FALSE |
| 5028 | except pexpect.EOF: |
| 5029 | main.log.error( self.name + ": EOF exception found" ) |
| 5030 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5031 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5032 | except Exception: |
| 5033 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5034 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5035 | |
| 5036 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 5037 | """ |
| 5038 | Set the logging level to lvl for a specific app |
| 5039 | returns main.TRUE on success |
| 5040 | returns main.FALSE if Error occurred |
| 5041 | if noExit is True, TestON will not exit, but clean up |
| 5042 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 5043 | Level defaults to INFO |
| 5044 | """ |
| 5045 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5046 | self.handle.sendline( "log:set %s %s" % ( level, app ) ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5047 | self.handle.expect( "onos>" ) |
| 5048 | |
| 5049 | response = self.handle.before |
| 5050 | if re.search( "Error", response ): |
| 5051 | return main.FALSE |
| 5052 | return main.TRUE |
| 5053 | except pexpect.TIMEOUT: |
| 5054 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5055 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5056 | except pexpect.EOF: |
| 5057 | main.log.error( self.name + ": EOF exception found" ) |
| 5058 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5059 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5060 | except Exception: |
| 5061 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5062 | main.cleanAndExit() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5063 | |
| 5064 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 5065 | """ |
| 5066 | Return a dictionary which describes the latest network topology data as a |
| 5067 | graph. |
| 5068 | An example of the dictionary: |
| 5069 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 5070 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 5071 | Each vertex should at least have an 'edges' attribute which describes the |
| 5072 | adjacency information. The value of 'edges' attribute is also represented by |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5073 | 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] | 5074 | list of attributes. |
| 5075 | An example of the edges dictionary: |
| 5076 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 5077 | vertex3: { 'port': ..., 'weight': ... } } |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5078 | If includeHost == True, all hosts (and host-switch links) will be included |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5079 | in topology data. |
| 5080 | """ |
| 5081 | graphDict = {} |
| 5082 | try: |
| 5083 | links = self.links() |
| 5084 | links = json.loads( links ) |
| 5085 | devices = self.devices() |
| 5086 | devices = json.loads( devices ) |
| 5087 | idToDevice = {} |
| 5088 | for device in devices: |
| 5089 | idToDevice[ device[ 'id' ] ] = device |
| 5090 | if includeHost: |
| 5091 | hosts = self.hosts() |
| 5092 | # FIXME: support 'includeHost' argument |
| 5093 | for link in links: |
| 5094 | nodeA = link[ 'src' ][ 'device' ] |
| 5095 | nodeB = link[ 'dst' ][ 'device' ] |
| 5096 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5097 | if nodeA not in graphDict.keys(): |
| 5098 | graphDict[ nodeA ] = { 'edges': {}, |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5099 | 'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ], |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5100 | 'type': idToDevice[ nodeA ][ 'type' ], |
| 5101 | 'available': idToDevice[ nodeA ][ 'available' ], |
| 5102 | 'role': idToDevice[ nodeA ][ 'role' ], |
| 5103 | 'mfr': idToDevice[ nodeA ][ 'mfr' ], |
| 5104 | 'hw': idToDevice[ nodeA ][ 'hw' ], |
| 5105 | 'sw': idToDevice[ nodeA ][ 'sw' ], |
| 5106 | 'serial': idToDevice[ nodeA ][ 'serial' ], |
| 5107 | 'chassisId': idToDevice[ nodeA ][ 'chassisId' ], |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5108 | 'annotations': idToDevice[ nodeA ][ 'annotations' ]} |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5109 | else: |
| 5110 | # Assert nodeB is not connected to any current links of nodeA |
| 5111 | assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5112 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ], |
| 5113 | 'type': link[ 'type' ], |
| 5114 | 'state': link[ 'state' ] } |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5115 | return graphDict |
| 5116 | except ( TypeError, ValueError ): |
| 5117 | main.log.exception( self.name + ": Object not as expected" ) |
| 5118 | return None |
| 5119 | except KeyError: |
| 5120 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5121 | return None |
| 5122 | except AssertionError: |
| 5123 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5124 | return None |
| 5125 | except pexpect.EOF: |
| 5126 | main.log.error( self.name + ": EOF exception found" ) |
| 5127 | main.log.error( self.name + ": " + self.handle.before ) |
| 5128 | return None |
| 5129 | except Exception: |
| 5130 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5131 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5132 | |
| 5133 | def getIntentPerfSummary( self ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5134 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5135 | Send command to check intent-perf summary |
| 5136 | Returns: dictionary for intent-perf summary |
| 5137 | if something wrong, function will return None |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5138 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5139 | cmd = "intent-perf -s" |
| 5140 | respDic = {} |
| 5141 | resp = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 5142 | assert resp is not None, "Error in sendline" |
| 5143 | assert "Command not found:" not in resp, resp |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5144 | try: |
| 5145 | # Generate the dictionary to return |
| 5146 | for l in resp.split( "\n" ): |
| 5147 | # Delete any white space in line |
| 5148 | temp = re.sub( r'\s+', '', l ) |
| 5149 | temp = temp.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5150 | respDic[ temp[ 0 ] ] = temp[ 1 ] |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5151 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5152 | except ( TypeError, ValueError ): |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5153 | main.log.exception( self.name + ": Object not as expected" ) |
| 5154 | return None |
| 5155 | except KeyError: |
| 5156 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5157 | return None |
| 5158 | except AssertionError: |
| 5159 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5160 | return None |
| 5161 | except pexpect.EOF: |
| 5162 | main.log.error( self.name + ": EOF exception found" ) |
| 5163 | main.log.error( self.name + ": " + self.handle.before ) |
| 5164 | return None |
| 5165 | except Exception: |
| 5166 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5167 | return None |
| 5168 | return respDic |
| 5169 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5170 | def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ): |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5171 | """ |
| 5172 | Searches the latest ONOS log file for the given search term and |
| 5173 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5174 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5175 | Arguments: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5176 | searchTerm: |
| 5177 | The string to grep from the ONOS log. |
| 5178 | startLine: |
| 5179 | The term that decides which line is the start to search the searchTerm in |
| 5180 | the karaf log. For now, startTerm only works in 'first' mode. |
| 5181 | logNum: |
| 5182 | In some extreme cases, one karaf log is not big enough to contain all the |
| 5183 | information.Because of this, search mutiply logs is necessary to capture |
| 5184 | the right result. logNum is the number of karaf logs that we need to search |
| 5185 | the searchTerm. |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5186 | mode: |
| 5187 | all: return all the strings that contain the search term |
| 5188 | last: return the last string that contains the search term |
| 5189 | first: return the first string that contains the search term |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5190 | num: return the number of times that the searchTerm appears in the log |
| 5191 | total: return how many lines in karaf log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5192 | """ |
| 5193 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5194 | assert isinstance( searchTerm, str ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5195 | # Build the log paths string |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5196 | logPath = '/opt/onos/log/karaf.log.' |
| 5197 | logPaths = '/opt/onos/log/karaf.log' |
| 5198 | for i in range( 1, logNum ): |
| 5199 | logPaths = logPath + str( i ) + " " + logPaths |
| 5200 | cmd = "cat " + logPaths |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5201 | if startLine: |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5202 | # 100000000 is just a extreme large number to make sure this function can |
| 5203 | # grep all the lines after startLine |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5204 | cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'" |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5205 | if mode == 'all': |
| 5206 | cmd = cmd + " | grep \'" + searchTerm + "\'" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5207 | elif mode == 'last': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5208 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5209 | elif mode == 'first': |
| 5210 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1" |
| 5211 | elif mode == 'num': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5212 | cmd = cmd + " | grep -c \'" + searchTerm + "\'" |
You Wang | 118ba58 | 2017-01-02 17:14:43 -0800 | [diff] [blame] | 5213 | num = self.sendline( cmd ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5214 | return num |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5215 | elif mode == 'total': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5216 | totalLines = self.sendline( "cat /opt/onos/log/karaf.log | wc -l" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5217 | return int( totalLines ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5218 | else: |
| 5219 | main.log.error( self.name + " unsupported mode" ) |
| 5220 | return main.ERROR |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5221 | before = self.sendline( cmd ) |
| 5222 | before = before.splitlines() |
| 5223 | # make sure the returned list only contains the search term |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5224 | returnLines = [ line for line in before if searchTerm in line ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5225 | return returnLines |
| 5226 | except AssertionError: |
| 5227 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5228 | return None |
| 5229 | except pexpect.EOF: |
| 5230 | main.log.error( self.name + ": EOF exception found" ) |
| 5231 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5232 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5233 | except pexpect.TIMEOUT: |
| 5234 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5235 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5236 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5237 | except Exception: |
| 5238 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5239 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5240 | |
| 5241 | def vplsShow( self, jsonFormat=True ): |
| 5242 | """ |
| 5243 | Description: Returns result of onos:vpls show, which should list the |
| 5244 | configured VPLS networks and the assigned interfaces. |
| 5245 | Optional: |
| 5246 | * jsonFormat: enable json formatting of output |
| 5247 | Returns: |
| 5248 | The output of the command or None on error. |
| 5249 | """ |
| 5250 | try: |
| 5251 | cmdStr = "vpls show" |
| 5252 | if jsonFormat: |
| 5253 | raise NotImplementedError |
| 5254 | cmdStr += " -j" |
| 5255 | handle = self.sendline( cmdStr ) |
| 5256 | assert handle is not None, "Error in sendline" |
| 5257 | assert "Command not found:" not in handle, handle |
| 5258 | return handle |
| 5259 | except AssertionError: |
| 5260 | main.log.exception( "" ) |
| 5261 | return None |
| 5262 | except TypeError: |
| 5263 | main.log.exception( self.name + ": Object not as expected" ) |
| 5264 | return None |
| 5265 | except pexpect.EOF: |
| 5266 | main.log.error( self.name + ": EOF exception found" ) |
| 5267 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5268 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5269 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5270 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5271 | return None |
| 5272 | except Exception: |
| 5273 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5274 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5275 | |
| 5276 | def parseVplsShow( self ): |
| 5277 | """ |
| 5278 | Parse the cli output of 'vpls show' into json output. This is required |
| 5279 | as there is currently no json output available. |
| 5280 | """ |
| 5281 | try: |
| 5282 | output = [] |
| 5283 | raw = self.vplsShow( jsonFormat=False ) |
| 5284 | namePat = "VPLS name: (?P<name>\w+)" |
| 5285 | interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]" |
| 5286 | encapPat = "Encapsulation: (?P<encap>\w+)" |
| 5287 | pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] ) |
| 5288 | mIter = re.finditer( pattern, raw ) |
| 5289 | for match in mIter: |
| 5290 | item = {} |
| 5291 | item[ 'name' ] = match.group( 'name' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5292 | ifaces = match.group( 'interfaces' ).split( ', ' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5293 | if ifaces == [ "" ]: |
| 5294 | ifaces = [] |
| 5295 | item[ 'interfaces' ] = ifaces |
| 5296 | encap = match.group( 'encap' ) |
| 5297 | if encap != 'NONE': |
| 5298 | item[ 'encapsulation' ] = encap.lower() |
| 5299 | output.append( item ) |
| 5300 | return output |
| 5301 | except Exception: |
| 5302 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5303 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5304 | |
| 5305 | def vplsList( self, jsonFormat=True ): |
| 5306 | """ |
| 5307 | Description: Returns result of onos:vpls list, which should list the |
| 5308 | configured VPLS networks. |
| 5309 | Optional: |
| 5310 | * jsonFormat: enable json formatting of output |
| 5311 | """ |
| 5312 | try: |
| 5313 | cmdStr = "vpls list" |
| 5314 | if jsonFormat: |
| 5315 | raise NotImplementedError |
| 5316 | cmdStr += " -j" |
| 5317 | handle = self.sendline( cmdStr ) |
| 5318 | assert handle is not None, "Error in sendline" |
| 5319 | assert "Command not found:" not in handle, handle |
| 5320 | return handle |
| 5321 | except AssertionError: |
| 5322 | main.log.exception( "" ) |
| 5323 | return None |
| 5324 | except TypeError: |
| 5325 | main.log.exception( self.name + ": Object not as expected" ) |
| 5326 | return None |
| 5327 | except pexpect.EOF: |
| 5328 | main.log.error( self.name + ": EOF exception found" ) |
| 5329 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5330 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5331 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5332 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5333 | return None |
| 5334 | except Exception: |
| 5335 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5336 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5337 | |
| 5338 | def vplsCreate( self, network ): |
| 5339 | """ |
| 5340 | CLI command to create a new VPLS network. |
| 5341 | Required arguments: |
| 5342 | network - String name of the network to create. |
| 5343 | returns: |
| 5344 | main.TRUE on success and main.FALSE on failure |
| 5345 | """ |
| 5346 | try: |
| 5347 | network = str( network ) |
| 5348 | cmdStr = "vpls create " |
| 5349 | cmdStr += network |
| 5350 | output = self.sendline( cmdStr ) |
| 5351 | assert output is not None, "Error in sendline" |
| 5352 | assert "Command not found:" not in output, output |
| 5353 | assert "Error executing command" not in output, output |
| 5354 | assert "VPLS already exists:" not in output, output |
| 5355 | return main.TRUE |
| 5356 | except AssertionError: |
| 5357 | main.log.exception( "" ) |
| 5358 | return main.FALSE |
| 5359 | except TypeError: |
| 5360 | main.log.exception( self.name + ": Object not as expected" ) |
| 5361 | return main.FALSE |
| 5362 | except pexpect.EOF: |
| 5363 | main.log.error( self.name + ": EOF exception found" ) |
| 5364 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5365 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5366 | except Exception: |
| 5367 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5368 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5369 | |
| 5370 | def vplsDelete( self, network ): |
| 5371 | """ |
| 5372 | CLI command to delete a VPLS network. |
| 5373 | Required arguments: |
| 5374 | network - Name of the network to delete. |
| 5375 | returns: |
| 5376 | main.TRUE on success and main.FALSE on failure |
| 5377 | """ |
| 5378 | try: |
| 5379 | network = str( network ) |
| 5380 | cmdStr = "vpls delete " |
| 5381 | cmdStr += network |
| 5382 | output = self.sendline( cmdStr ) |
| 5383 | assert output is not None, "Error in sendline" |
| 5384 | assert "Command not found:" not in output, output |
| 5385 | assert "Error executing command" not in output, output |
| 5386 | assert " not found" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5387 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5388 | return main.TRUE |
| 5389 | except AssertionError: |
| 5390 | main.log.exception( "" ) |
| 5391 | return main.FALSE |
| 5392 | except TypeError: |
| 5393 | main.log.exception( self.name + ": Object not as expected" ) |
| 5394 | return main.FALSE |
| 5395 | except pexpect.EOF: |
| 5396 | main.log.error( self.name + ": EOF exception found" ) |
| 5397 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5398 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5399 | except Exception: |
| 5400 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5401 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5402 | |
| 5403 | def vplsAddIface( self, network, iface ): |
| 5404 | """ |
| 5405 | CLI command to add an interface to a VPLS network. |
| 5406 | Required arguments: |
| 5407 | network - Name of the network to add the interface to. |
| 5408 | iface - The ONOS name for an interface. |
| 5409 | returns: |
| 5410 | main.TRUE on success and main.FALSE on failure |
| 5411 | """ |
| 5412 | try: |
| 5413 | network = str( network ) |
| 5414 | iface = str( iface ) |
| 5415 | cmdStr = "vpls add-if " |
| 5416 | cmdStr += network + " " + iface |
| 5417 | output = self.sendline( cmdStr ) |
| 5418 | assert output is not None, "Error in sendline" |
| 5419 | assert "Command not found:" not in output, output |
| 5420 | assert "Error executing command" not in output, output |
| 5421 | assert "already associated to network" not in output, output |
| 5422 | assert "Interface cannot be added." not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5423 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5424 | return main.TRUE |
| 5425 | except AssertionError: |
| 5426 | main.log.exception( "" ) |
| 5427 | return main.FALSE |
| 5428 | except TypeError: |
| 5429 | main.log.exception( self.name + ": Object not as expected" ) |
| 5430 | return main.FALSE |
| 5431 | except pexpect.EOF: |
| 5432 | main.log.error( self.name + ": EOF exception found" ) |
| 5433 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5434 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5435 | except Exception: |
| 5436 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5437 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5438 | |
| 5439 | def vplsRemIface( self, network, iface ): |
| 5440 | """ |
| 5441 | CLI command to remove an interface from a VPLS network. |
| 5442 | Required arguments: |
| 5443 | network - Name of the network to remove the interface from. |
| 5444 | iface - Name of the interface to remove. |
| 5445 | returns: |
| 5446 | main.TRUE on success and main.FALSE on failure |
| 5447 | """ |
| 5448 | try: |
| 5449 | iface = str( iface ) |
| 5450 | cmdStr = "vpls rem-if " |
| 5451 | cmdStr += network + " " + iface |
| 5452 | output = self.sendline( cmdStr ) |
| 5453 | assert output is not None, "Error in sendline" |
| 5454 | assert "Command not found:" not in output, output |
| 5455 | assert "Error executing command" not in output, output |
| 5456 | assert "is not configured" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5457 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5458 | return main.TRUE |
| 5459 | except AssertionError: |
| 5460 | main.log.exception( "" ) |
| 5461 | return main.FALSE |
| 5462 | except TypeError: |
| 5463 | main.log.exception( self.name + ": Object not as expected" ) |
| 5464 | return main.FALSE |
| 5465 | except pexpect.EOF: |
| 5466 | main.log.error( self.name + ": EOF exception found" ) |
| 5467 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5468 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5469 | except Exception: |
| 5470 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5471 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5472 | |
| 5473 | def vplsClean( self ): |
| 5474 | """ |
| 5475 | Description: Clears the VPLS app configuration. |
| 5476 | Returns: main.TRUE on success and main.FALSE on failure |
| 5477 | """ |
| 5478 | try: |
| 5479 | cmdStr = "vpls clean" |
| 5480 | handle = self.sendline( cmdStr ) |
| 5481 | assert handle is not None, "Error in sendline" |
| 5482 | assert "Command not found:" not in handle, handle |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5483 | assert "still updating" not in handle, handle |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5484 | return handle |
| 5485 | except AssertionError: |
| 5486 | main.log.exception( "" ) |
| 5487 | return main.FALSE |
| 5488 | except TypeError: |
| 5489 | main.log.exception( self.name + ": Object not as expected" ) |
| 5490 | return main.FALSE |
| 5491 | except pexpect.EOF: |
| 5492 | main.log.error( self.name + ": EOF exception found" ) |
| 5493 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5494 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5495 | except Exception: |
| 5496 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5497 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5498 | |
| 5499 | def vplsSetEncap( self, network, encapType ): |
| 5500 | """ |
| 5501 | CLI command to add an interface to a VPLS network. |
| 5502 | Required arguments: |
| 5503 | network - Name of the network to create. |
| 5504 | encapType - Type of encapsulation. |
| 5505 | returns: |
| 5506 | main.TRUE on success and main.FALSE on failure |
| 5507 | """ |
| 5508 | try: |
| 5509 | network = str( network ) |
| 5510 | encapType = str( encapType ).upper() |
| 5511 | assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type" |
| 5512 | cmdStr = "vpls set-encap " |
| 5513 | cmdStr += network + " " + encapType |
| 5514 | output = self.sendline( cmdStr ) |
| 5515 | assert output is not None, "Error in sendline" |
| 5516 | assert "Command not found:" not in output, output |
| 5517 | assert "Error executing command" not in output, output |
| 5518 | assert "already associated to network" not in output, output |
| 5519 | assert "Encapsulation type " not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5520 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5521 | return main.TRUE |
| 5522 | except AssertionError: |
| 5523 | main.log.exception( "" ) |
| 5524 | return main.FALSE |
| 5525 | except TypeError: |
| 5526 | main.log.exception( self.name + ": Object not as expected" ) |
| 5527 | return main.FALSE |
| 5528 | except pexpect.EOF: |
| 5529 | main.log.error( self.name + ": EOF exception found" ) |
| 5530 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5531 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5532 | except Exception: |
| 5533 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5534 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5535 | |
| 5536 | def interfaces( self, jsonFormat=True ): |
| 5537 | """ |
| 5538 | Description: Returns result of interfaces command. |
| 5539 | Optional: |
| 5540 | * jsonFormat: enable json formatting of output |
| 5541 | Returns: |
| 5542 | The output of the command or None on error. |
| 5543 | """ |
| 5544 | try: |
| 5545 | cmdStr = "interfaces" |
| 5546 | if jsonFormat: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5547 | raise NotImplementedError |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5548 | cmdStr += " -j" |
| 5549 | handle = self.sendline( cmdStr ) |
| 5550 | assert handle is not None, "Error in sendline" |
| 5551 | assert "Command not found:" not in handle, handle |
| 5552 | return handle |
| 5553 | except AssertionError: |
| 5554 | main.log.exception( "" ) |
| 5555 | return None |
| 5556 | except TypeError: |
| 5557 | main.log.exception( self.name + ": Object not as expected" ) |
| 5558 | return None |
| 5559 | except pexpect.EOF: |
| 5560 | main.log.error( self.name + ": EOF exception found" ) |
| 5561 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5562 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5563 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5564 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5565 | return None |
| 5566 | except Exception: |
| 5567 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5568 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5569 | |
| 5570 | def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5571 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5572 | Get the timestamp of searchTerm from karaf log. |
| 5573 | |
| 5574 | Arguments: |
| 5575 | splitTerm_before and splitTerm_after: |
| 5576 | |
| 5577 | The terms that split the string that contains the timeStamp of |
| 5578 | searchTerm. For example, if that string is "xxxxxxxcreationTime = |
| 5579 | 1419510501xxxxxx", then the splitTerm_before is "CreationTime = " |
| 5580 | and the splitTerm_after is "x" |
| 5581 | |
| 5582 | others: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5583 | Please look at the "logsearch" Function in onosclidriver.py |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5584 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5585 | if logNum < 0: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5586 | main.log.error( "Get wrong log number ") |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5587 | return main.ERROR |
| 5588 | lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5589 | if len( lines ) == 0: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5590 | main.log.warn( "Captured timestamp string is empty" ) |
| 5591 | return main.ERROR |
| 5592 | lines = lines[ 0 ] |
| 5593 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5594 | assert isinstance( lines, str ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5595 | # get the target value |
| 5596 | line = lines.split( splitTerm_before ) |
| 5597 | key = line[ 1 ].split( splitTerm_after ) |
| 5598 | return int( key[ 0 ] ) |
| 5599 | except IndexError: |
| 5600 | main.log.warn( "Index Error!" ) |
| 5601 | return main.ERROR |
| 5602 | except AssertionError: |
| 5603 | main.log.warn( "Search Term Not Found " ) |
| 5604 | return main.ERROR |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5605 | |
| 5606 | def workQueueAdd( self, queueName, value ): |
| 5607 | """ |
| 5608 | CLI command to add a string to the specified Work Queue. |
| 5609 | This function uses the distributed primitives test app, which |
| 5610 | gives some cli access to distributed primitives for testing |
| 5611 | purposes only. |
| 5612 | |
| 5613 | Required arguments: |
| 5614 | queueName - The name of the queue to add to |
| 5615 | value - The value to add to the queue |
| 5616 | returns: |
| 5617 | main.TRUE on success, main.FALSE on failure and |
| 5618 | main.ERROR on error. |
| 5619 | """ |
| 5620 | try: |
| 5621 | queueName = str( queueName ) |
| 5622 | value = str( value ) |
| 5623 | prefix = "work-queue-test" |
| 5624 | operation = "add" |
| 5625 | cmdStr = " ".join( [ prefix, queueName, operation, value ] ) |
| 5626 | output = self.distPrimitivesSend( cmdStr ) |
| 5627 | if "Invalid operation name" in output: |
| 5628 | main.log.warn( output ) |
| 5629 | return main.ERROR |
| 5630 | elif "Done" in output: |
| 5631 | return main.TRUE |
| 5632 | except TypeError: |
| 5633 | main.log.exception( self.name + ": Object not as expected" ) |
| 5634 | return main.ERROR |
| 5635 | except Exception: |
| 5636 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5637 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5638 | |
| 5639 | def workQueueAddMultiple( self, queueName, value1, value2 ): |
| 5640 | """ |
| 5641 | CLI command to add two strings to the specified Work Queue. |
| 5642 | This function uses the distributed primitives test app, which |
| 5643 | gives some cli access to distributed primitives for testing |
| 5644 | purposes only. |
| 5645 | |
| 5646 | Required arguments: |
| 5647 | queueName - The name of the queue to add to |
| 5648 | value1 - The first value to add to the queue |
| 5649 | value2 - The second value to add to the queue |
| 5650 | returns: |
| 5651 | main.TRUE on success, main.FALSE on failure and |
| 5652 | main.ERROR on error. |
| 5653 | """ |
| 5654 | try: |
| 5655 | queueName = str( queueName ) |
| 5656 | value1 = str( value1 ) |
| 5657 | value2 = str( value2 ) |
| 5658 | prefix = "work-queue-test" |
| 5659 | operation = "addMultiple" |
| 5660 | cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] ) |
| 5661 | output = self.distPrimitivesSend( cmdStr ) |
| 5662 | if "Invalid operation name" in output: |
| 5663 | main.log.warn( output ) |
| 5664 | return main.ERROR |
| 5665 | elif "Done" in output: |
| 5666 | return main.TRUE |
| 5667 | except TypeError: |
| 5668 | main.log.exception( self.name + ": Object not as expected" ) |
| 5669 | return main.ERROR |
| 5670 | except Exception: |
| 5671 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5672 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5673 | |
| 5674 | def workQueueTakeAndComplete( self, queueName, number=1 ): |
| 5675 | """ |
| 5676 | CLI command to take a value from the specified Work Queue and compelte it. |
| 5677 | This function uses the distributed primitives test app, which |
| 5678 | gives some cli access to distributed primitives for testing |
| 5679 | purposes only. |
| 5680 | |
| 5681 | Required arguments: |
| 5682 | queueName - The name of the queue to add to |
| 5683 | number - The number of items to take and complete |
| 5684 | returns: |
| 5685 | main.TRUE on success, main.FALSE on failure and |
| 5686 | main.ERROR on error. |
| 5687 | """ |
| 5688 | try: |
| 5689 | queueName = str( queueName ) |
| 5690 | number = str( int( number ) ) |
| 5691 | prefix = "work-queue-test" |
| 5692 | operation = "takeAndComplete" |
| 5693 | cmdStr = " ".join( [ prefix, queueName, operation, number ] ) |
| 5694 | output = self.distPrimitivesSend( cmdStr ) |
| 5695 | if "Invalid operation name" in output: |
| 5696 | main.log.warn( output ) |
| 5697 | return main.ERROR |
| 5698 | elif "Done" in output: |
| 5699 | return main.TRUE |
| 5700 | except TypeError: |
| 5701 | main.log.exception( self.name + ": Object not as expected" ) |
| 5702 | return main.ERROR |
| 5703 | except Exception: |
| 5704 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5705 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5706 | |
| 5707 | def workQueueDestroy( self, queueName ): |
| 5708 | """ |
| 5709 | CLI command to destroy the specified Work Queue. |
| 5710 | This function uses the distributed primitives test app, which |
| 5711 | gives some cli access to distributed primitives for testing |
| 5712 | purposes only. |
| 5713 | |
| 5714 | Required arguments: |
| 5715 | queueName - The name of the queue to add to |
| 5716 | returns: |
| 5717 | main.TRUE on success, main.FALSE on failure and |
| 5718 | main.ERROR on error. |
| 5719 | """ |
| 5720 | try: |
| 5721 | queueName = str( queueName ) |
| 5722 | prefix = "work-queue-test" |
| 5723 | operation = "destroy" |
| 5724 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5725 | output = self.distPrimitivesSend( cmdStr ) |
| 5726 | if "Invalid operation name" in output: |
| 5727 | main.log.warn( output ) |
| 5728 | return main.ERROR |
| 5729 | return main.TRUE |
| 5730 | except TypeError: |
| 5731 | main.log.exception( self.name + ": Object not as expected" ) |
| 5732 | return main.ERROR |
| 5733 | except Exception: |
| 5734 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5735 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5736 | |
| 5737 | def workQueueTotalPending( self, queueName ): |
| 5738 | """ |
| 5739 | CLI command to get the Total Pending items of the specified Work Queue. |
| 5740 | This function uses the distributed primitives test app, which |
| 5741 | gives some cli access to distributed primitives for testing |
| 5742 | purposes only. |
| 5743 | |
| 5744 | Required arguments: |
| 5745 | queueName - The name of the queue to add to |
| 5746 | returns: |
| 5747 | The number of Pending items in the specified work queue or |
| 5748 | None on error |
| 5749 | """ |
| 5750 | try: |
| 5751 | queueName = str( queueName ) |
| 5752 | prefix = "work-queue-test" |
| 5753 | operation = "totalPending" |
| 5754 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5755 | output = self.distPrimitivesSend( cmdStr ) |
| 5756 | pattern = r'\d+' |
| 5757 | if "Invalid operation name" in output: |
| 5758 | main.log.warn( output ) |
| 5759 | return None |
| 5760 | else: |
| 5761 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5762 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5763 | except ( AttributeError, TypeError ): |
| 5764 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5765 | return None |
| 5766 | except Exception: |
| 5767 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5768 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5769 | |
| 5770 | def workQueueTotalCompleted( self, queueName ): |
| 5771 | """ |
| 5772 | CLI command to get the Total Completed items of the specified Work Queue. |
| 5773 | This function uses the distributed primitives test app, which |
| 5774 | gives some cli access to distributed primitives for testing |
| 5775 | purposes only. |
| 5776 | |
| 5777 | Required arguments: |
| 5778 | queueName - The name of the queue to add to |
| 5779 | returns: |
| 5780 | The number of complete items in the specified work queue or |
| 5781 | None on error |
| 5782 | """ |
| 5783 | try: |
| 5784 | queueName = str( queueName ) |
| 5785 | prefix = "work-queue-test" |
| 5786 | operation = "totalCompleted" |
| 5787 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5788 | output = self.distPrimitivesSend( cmdStr ) |
| 5789 | pattern = r'\d+' |
| 5790 | if "Invalid operation name" in output: |
| 5791 | main.log.warn( output ) |
| 5792 | return None |
| 5793 | else: |
| 5794 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5795 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5796 | except ( AttributeError, TypeError ): |
| 5797 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5798 | return None |
| 5799 | except Exception: |
| 5800 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5801 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5802 | |
| 5803 | def workQueueTotalInProgress( self, queueName ): |
| 5804 | """ |
| 5805 | CLI command to get the Total In Progress items of the specified Work Queue. |
| 5806 | This function uses the distributed primitives test app, which |
| 5807 | gives some cli access to distributed primitives for testing |
| 5808 | purposes only. |
| 5809 | |
| 5810 | Required arguments: |
| 5811 | queueName - The name of the queue to add to |
| 5812 | returns: |
| 5813 | The number of In Progress items in the specified work queue or |
| 5814 | None on error |
| 5815 | """ |
| 5816 | try: |
| 5817 | queueName = str( queueName ) |
| 5818 | prefix = "work-queue-test" |
| 5819 | operation = "totalInProgress" |
| 5820 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5821 | output = self.distPrimitivesSend( cmdStr ) |
| 5822 | pattern = r'\d+' |
| 5823 | if "Invalid operation name" in output: |
| 5824 | main.log.warn( output ) |
| 5825 | return None |
| 5826 | else: |
| 5827 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5828 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5829 | except ( AttributeError, TypeError ): |
| 5830 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 5831 | return None |
| 5832 | except Exception: |
| 5833 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5834 | main.cleanAndExit() |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 5835 | |
| 5836 | def events( self, args='-a' ): |
| 5837 | """ |
| 5838 | Description: Returns events -a command output |
| 5839 | Optional: |
| 5840 | add other arguments |
| 5841 | """ |
| 5842 | try: |
| 5843 | cmdStr = "events" |
| 5844 | if args: |
| 5845 | cmdStr += " " + args |
| 5846 | handle = self.sendline( cmdStr ) |
| 5847 | assert handle is not None, "Error in sendline" |
| 5848 | assert "Command not found:" not in handle, handle |
| 5849 | return handle |
| 5850 | except AssertionError: |
| 5851 | main.log.exception( "" ) |
| 5852 | return None |
| 5853 | except TypeError: |
| 5854 | main.log.exception( self.name + ": Object not as expected" ) |
| 5855 | return None |
| 5856 | except pexpect.EOF: |
| 5857 | main.log.error( self.name + ": EOF exception found" ) |
| 5858 | main.log.error( self.name + ": " + self.handle.before ) |
| 5859 | main.cleanAndExit() |
| 5860 | except Exception: |
| 5861 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5862 | main.cleanAndExit() |
| 5863 | |
| 5864 | def getMaster( self, deviceID ): |
| 5865 | """ |
| 5866 | Description: Obtains current master using "roles" command for a specific deviceID |
| 5867 | """ |
| 5868 | try: |
| 5869 | return str( self.getRole( deviceID )[ 'master' ] ) |
| 5870 | except AssertionError: |
| 5871 | main.log.exception( "" ) |
| 5872 | return None |
| 5873 | except TypeError: |
| 5874 | main.log.exception( self.name + ": Object not as expected" ) |
| 5875 | return None |
| 5876 | except pexpect.EOF: |
| 5877 | main.log.error( self.name + ": EOF exception found" ) |
| 5878 | main.log.error( self.name + ": " + self.handle.before ) |
| 5879 | main.cleanAndExit() |
| 5880 | except Exception: |
| 5881 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 5882 | main.cleanAndExit() |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5883 | |
| 5884 | def issu( self ): |
| 5885 | """ |
| 5886 | Short summary of In-Service Software Upgrade status |
| 5887 | |
| 5888 | Returns the output of the cli command or None on Error |
| 5889 | """ |
| 5890 | try: |
| 5891 | cmdStr = "issu" |
| 5892 | handle = self.sendline( cmdStr ) |
| 5893 | assert handle is not None, "Error in sendline" |
| 5894 | assert "Command not found:" not in handle, handle |
| 5895 | assert "Unsupported command:" not in handle, handle |
| 5896 | return handle |
| 5897 | except AssertionError: |
| 5898 | main.log.exception( "" ) |
| 5899 | return None |
| 5900 | except TypeError: |
| 5901 | main.log.exception( self.name + ": Object not as expected" ) |
| 5902 | return None |
| 5903 | except pexpect.EOF: |
| 5904 | main.log.error( self.name + ": EOF exception found" ) |
| 5905 | main.log.error( self.name + ": " + self.handle.before ) |
| 5906 | main.cleanAndExit() |
| 5907 | except Exception: |
| 5908 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5909 | main.cleanAndExit() |
| 5910 | |
| 5911 | def issuInit( self ): |
| 5912 | """ |
| 5913 | Initiates an In-Service Software Upgrade |
| 5914 | |
| 5915 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5916 | """ |
| 5917 | try: |
| 5918 | cmdStr = "issu init" |
| 5919 | handle = self.sendline( cmdStr ) |
| 5920 | assert handle is not None, "Error in sendline" |
| 5921 | assert "Command not found:" not in handle, handle |
| 5922 | assert "Unsupported command:" not in handle, handle |
| 5923 | if "Initialized" in handle: |
| 5924 | return main.TRUE |
| 5925 | else: |
| 5926 | return main.FALSE |
| 5927 | except AssertionError: |
| 5928 | main.log.exception( "" ) |
| 5929 | return main.ERROR |
| 5930 | except TypeError: |
| 5931 | main.log.exception( self.name + ": Object not as expected" ) |
| 5932 | return main.ERROR |
| 5933 | except pexpect.EOF: |
| 5934 | main.log.error( self.name + ": EOF exception found" ) |
| 5935 | main.log.error( self.name + ": " + self.handle.before ) |
| 5936 | main.cleanAndExit() |
| 5937 | except Exception: |
| 5938 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5939 | main.cleanAndExit() |
| 5940 | |
| 5941 | def issuUpgrade( self ): |
| 5942 | """ |
| 5943 | Transitions stores to upgraded nodes |
| 5944 | |
| 5945 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5946 | """ |
| 5947 | try: |
| 5948 | cmdStr = "issu upgrade" |
| 5949 | handle = self.sendline( cmdStr ) |
| 5950 | assert handle is not None, "Error in sendline" |
| 5951 | assert "Command not found:" not in handle, handle |
| 5952 | assert "Unsupported command:" not in handle, handle |
| 5953 | if "Upgraded" in handle: |
| 5954 | return main.TRUE |
| 5955 | else: |
| 5956 | return main.FALSE |
| 5957 | except AssertionError: |
| 5958 | main.log.exception( "" ) |
| 5959 | return main.ERROR |
| 5960 | except TypeError: |
| 5961 | main.log.exception( self.name + ": Object not as expected" ) |
| 5962 | return main.ERROR |
| 5963 | except pexpect.EOF: |
| 5964 | main.log.error( self.name + ": EOF exception found" ) |
| 5965 | main.log.error( self.name + ": " + self.handle.before ) |
| 5966 | main.cleanAndExit() |
| 5967 | except Exception: |
| 5968 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5969 | main.cleanAndExit() |
| 5970 | |
| 5971 | def issuCommit( self ): |
| 5972 | """ |
| 5973 | Finalizes an In-Service Software Upgrade |
| 5974 | |
| 5975 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 5976 | """ |
| 5977 | try: |
| 5978 | cmdStr = "issu commit" |
| 5979 | handle = self.sendline( cmdStr ) |
| 5980 | assert handle is not None, "Error in sendline" |
| 5981 | assert "Command not found:" not in handle, handle |
| 5982 | assert "Unsupported command:" not in handle, handle |
| 5983 | # TODO: Check the version returned by this command |
| 5984 | if "Committed version" in handle: |
| 5985 | return main.TRUE |
| 5986 | else: |
| 5987 | return main.FALSE |
| 5988 | except AssertionError: |
| 5989 | main.log.exception( "" ) |
| 5990 | return main.ERROR |
| 5991 | except TypeError: |
| 5992 | main.log.exception( self.name + ": Object not as expected" ) |
| 5993 | return main.ERROR |
| 5994 | except pexpect.EOF: |
| 5995 | main.log.error( self.name + ": EOF exception found" ) |
| 5996 | main.log.error( self.name + ": " + self.handle.before ) |
| 5997 | main.cleanAndExit() |
| 5998 | except Exception: |
| 5999 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6000 | main.cleanAndExit() |
| 6001 | |
| 6002 | def issuRollback( self ): |
| 6003 | """ |
| 6004 | Rolls back an In-Service Software Upgrade |
| 6005 | |
| 6006 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6007 | """ |
| 6008 | try: |
| 6009 | cmdStr = "issu rollback" |
| 6010 | handle = self.sendline( cmdStr ) |
| 6011 | assert handle is not None, "Error in sendline" |
| 6012 | assert "Command not found:" not in handle, handle |
| 6013 | assert "Unsupported command:" not in handle, handle |
| 6014 | # TODO: Check the version returned by this command |
| 6015 | if "Rolled back to version" in handle: |
| 6016 | return main.TRUE |
| 6017 | else: |
| 6018 | return main.FALSE |
| 6019 | except AssertionError: |
| 6020 | main.log.exception( "" ) |
| 6021 | return main.ERROR |
| 6022 | except TypeError: |
| 6023 | main.log.exception( self.name + ": Object not as expected" ) |
| 6024 | return main.ERROR |
| 6025 | except pexpect.EOF: |
| 6026 | main.log.error( self.name + ": EOF exception found" ) |
| 6027 | main.log.error( self.name + ": " + self.handle.before ) |
| 6028 | main.cleanAndExit() |
| 6029 | except Exception: |
| 6030 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6031 | main.cleanAndExit() |
| 6032 | |
| 6033 | def issuReset( self ): |
| 6034 | """ |
| 6035 | Resets the In-Service Software Upgrade status after a rollback |
| 6036 | |
| 6037 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6038 | """ |
| 6039 | try: |
| 6040 | cmdStr = "issu reset" |
| 6041 | handle = self.sendline( cmdStr ) |
| 6042 | assert handle is not None, "Error in sendline" |
| 6043 | assert "Command not found:" not in handle, handle |
| 6044 | assert "Unsupported command:" not in handle, handle |
| 6045 | # TODO: Check the version returned by this command |
| 6046 | if "Reset version" in handle: |
| 6047 | return main.TRUE |
| 6048 | else: |
| 6049 | return main.FALSE |
| 6050 | except AssertionError: |
| 6051 | main.log.exception( "" ) |
| 6052 | return main.ERROR |
| 6053 | except TypeError: |
| 6054 | main.log.exception( self.name + ": Object not as expected" ) |
| 6055 | return main.ERROR |
| 6056 | except pexpect.EOF: |
| 6057 | main.log.error( self.name + ": EOF exception found" ) |
| 6058 | main.log.error( self.name + ": " + self.handle.before ) |
| 6059 | main.cleanAndExit() |
| 6060 | except Exception: |
| 6061 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6062 | main.cleanAndExit() |
| 6063 | |
| 6064 | def issuStatus( self ): |
| 6065 | """ |
| 6066 | Status of an In-Service Software Upgrade |
| 6067 | |
| 6068 | Returns the output of the cli command or None on Error |
| 6069 | """ |
| 6070 | try: |
| 6071 | cmdStr = "issu status" |
| 6072 | handle = self.sendline( cmdStr ) |
| 6073 | assert handle is not None, "Error in sendline" |
| 6074 | assert "Command not found:" not in handle, handle |
| 6075 | assert "Unsupported command:" not in handle, handle |
| 6076 | return handle |
| 6077 | except AssertionError: |
| 6078 | main.log.exception( "" ) |
| 6079 | return None |
| 6080 | except TypeError: |
| 6081 | main.log.exception( self.name + ": Object not as expected" ) |
| 6082 | return None |
| 6083 | except pexpect.EOF: |
| 6084 | main.log.error( self.name + ": EOF exception found" ) |
| 6085 | main.log.error( self.name + ": " + self.handle.before ) |
| 6086 | main.cleanAndExit() |
| 6087 | except Exception: |
| 6088 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6089 | main.cleanAndExit() |
| 6090 | |
| 6091 | def issuVersion( self ): |
| 6092 | """ |
| 6093 | Get the version of an In-Service Software Upgrade |
| 6094 | |
| 6095 | Returns the output of the cli command or None on Error |
| 6096 | """ |
| 6097 | try: |
| 6098 | cmdStr = "issu version" |
| 6099 | handle = self.sendline( cmdStr ) |
| 6100 | assert handle is not None, "Error in sendline" |
| 6101 | assert "Command not found:" not in handle, handle |
| 6102 | assert "Unsupported command:" not in handle, handle |
| 6103 | return handle |
| 6104 | except AssertionError: |
| 6105 | main.log.exception( "" ) |
| 6106 | return None |
| 6107 | except TypeError: |
| 6108 | main.log.exception( self.name + ": Object not as expected" ) |
| 6109 | return None |
| 6110 | except pexpect.EOF: |
| 6111 | main.log.error( self.name + ": EOF exception found" ) |
| 6112 | main.log.error( self.name + ": " + self.handle.before ) |
| 6113 | main.cleanAndExit() |
| 6114 | except Exception: |
| 6115 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6116 | main.cleanAndExit() |