andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 4 | OCT 13 2014 |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5 | Copyright 2014 Open Networking Foundation (ONF) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 6 | |
| 7 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 8 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 9 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 10 | |
| 11 | TestON is free software: you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 14 | (at your option) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 15 | |
| 16 | TestON is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 23 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 24 | |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 25 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 26 | This driver enters the onos> prompt to issue commands. |
| 27 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 28 | Please follow the coding style demonstrated by existing |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 29 | functions and document properly. |
| 30 | |
| 31 | If you are a contributor to the driver, please |
| 32 | list your email here for future contact: |
| 33 | |
| 34 | jhall@onlab.us |
| 35 | andrew@onlab.us |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 36 | shreya@onlab.us |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 37 | jeremyr@opennetworking.org |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 38 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 39 | import pexpect |
| 40 | import re |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 41 | import json |
| 42 | import types |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 43 | import time |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 44 | import os |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 45 | from drivers.common.clidriver import CLI |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 46 | from core.graph import Graph |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 47 | from cStringIO import StringIO |
| 48 | from itertools import izip |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 49 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 50 | class OnosCliDriver( CLI ): |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 51 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 52 | def __init__( self ): |
| 53 | """ |
| 54 | Initialize client |
| 55 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 56 | self.name = None |
| 57 | self.home = None |
| 58 | self.handle = None |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 59 | self.karafUser = None |
| 60 | self.karafPass = None |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 61 | self.karafTimeout = None |
| 62 | |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 63 | self.dockerPrompt = None |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 64 | self.graph = Graph() |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 65 | super( OnosCliDriver, self ).__init__() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 66 | |
| 67 | def connect( self, **connectargs ): |
| 68 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 69 | Creates ssh handle for ONOS cli. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 70 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 71 | try: |
| 72 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 73 | vars( self )[ key ] = connectargs[ key ] |
Author Name | e1c7998 | 2019-06-04 23:38:42 +0100 | [diff] [blame] | 74 | self.karafPrompt = self.user_name + "@root >" |
andrew@onlab.us | 658ec01 | 2015-03-11 15:13:09 -0700 | [diff] [blame] | 75 | self.home = "~/onos" |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 76 | for key in self.options: |
| 77 | if key == "home": |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 78 | self.home = self.options[ key ] |
| 79 | elif key == "karaf_username": |
| 80 | self.karafUser = self.options[ key ] |
| 81 | elif key == "karaf_password": |
| 82 | self.karafPass = self.options[ key ] |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 83 | elif key == "docker_prompt": |
| 84 | self.dockerPrompt = self.options[ key ] |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 85 | elif key == "karaf_timeout": |
| 86 | self.karafTimeout = self.options[ key ] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 87 | self.home = self.checkOptions( self.home, "~/onos" ) |
| 88 | self.karafUser = self.checkOptions( self.karafUser, self.user_name ) |
| 89 | self.karafPass = self.checkOptions( self.karafPass, self.pwd ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 90 | self.dockerPrompt = self.checkOptions( self.dockerPrompt, "~/onos#" ) |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 91 | self.karafTimeout = self.checkOptions( self.karafTimeout, 7200000 ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 92 | |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 93 | for key in self.options: |
| 94 | if key == 'onosIp': |
| 95 | self.onosIp = self.options[ 'onosIp' ] |
| 96 | break |
| 97 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 98 | self.name = self.options[ 'name' ] |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 99 | |
| 100 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 101 | if os.getenv( str( self.ip_address ) ) is not None: |
kelvin-onlab | a407429 | 2015-07-09 15:19:49 -0700 | [diff] [blame] | 102 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 103 | else: |
| 104 | main.log.info( self.name + |
| 105 | ": Trying to connect to " + |
| 106 | self.ip_address ) |
| 107 | |
| 108 | except KeyError: |
| 109 | main.log.info( "Invalid host name," + |
| 110 | " connecting to local host instead" ) |
| 111 | self.ip_address = 'localhost' |
| 112 | except Exception as inst: |
| 113 | main.log.error( "Uncaught exception: " + str( inst ) ) |
| 114 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 115 | self.handle = super( OnosCliDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 116 | user_name=self.user_name, |
| 117 | ip_address=self.ip_address, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 118 | port=self.port, |
| 119 | pwd=self.pwd, |
| 120 | home=self.home ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 121 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 122 | self.handle.sendline( "cd " + self.home ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 123 | self.handle.expect( self.prompt ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 124 | if self.handle: |
| 125 | return self.handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 126 | else: |
| 127 | main.log.info( "NO ONOS HANDLE" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 128 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 129 | except TypeError: |
| 130 | main.log.exception( self.name + ": Object not as expected" ) |
| 131 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 132 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 133 | main.log.error( self.name + ": EOF exception found" ) |
| 134 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 135 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 136 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 137 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 138 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 139 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 140 | def disconnect( self ): |
| 141 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 142 | Called when Test is complete to disconnect the ONOS handle. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 143 | """ |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 144 | response = main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 145 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 146 | if self.handle: |
| 147 | i = self.logout() |
| 148 | if i == main.TRUE: |
| 149 | self.handle.sendline( "" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 150 | for l in range( 3 ): |
| 151 | p = self.handle.expect( [ self.prompt, self.dockerPrompt ] ) |
| 152 | if p == 1: |
| 153 | self.inDocker = False |
| 154 | self.handle.sendline( "exit" ) |
| 155 | j = self.handle.expect( [ "closed", pexpect.TIMEOUT ], timeout=3 ) |
| 156 | if j == 0: |
| 157 | return response |
| 158 | response = main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 159 | except TypeError: |
| 160 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | d61331b | 2015-02-17 16:35:47 -0800 | [diff] [blame] | 161 | response = main.FALSE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 162 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 163 | main.log.error( self.name + ": EOF exception found" ) |
| 164 | main.log.error( self.name + ": " + self.handle.before ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 165 | except ValueError: |
Jon Hall | 1a77a1e | 2015-04-06 10:41:13 -0700 | [diff] [blame] | 166 | main.log.exception( "Exception in disconnect of " + self.name ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 167 | response = main.TRUE |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 168 | except Exception: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 169 | main.log.exception( self.name + ": disconnection failed from the host" ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 170 | response = main.FALSE |
| 171 | return response |
| 172 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 173 | def logout( self ): |
| 174 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 175 | Sends 'logout' command to ONOS cli |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 176 | Returns main.TRUE if exited CLI and |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 177 | main.FALSE on timeout (not guranteed you are disconnected) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 178 | None on TypeError |
| 179 | Exits test on unknown error or pexpect exits unexpectedly |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 180 | """ |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 181 | try: |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 182 | if self.handle: |
| 183 | self.handle.sendline( "" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 184 | i = self.handle.expect( [ self.karafPrompt, |
| 185 | self.Prompt(), |
| 186 | pexpect.TIMEOUT ], |
| 187 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 188 | timeout=10 ) |
| 189 | if i == 0: # In ONOS CLI |
| 190 | self.handle.sendline( "logout" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 191 | j = self.handle.expect( [ self.Prompt(), |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 192 | "Command not found:", |
| 193 | pexpect.TIMEOUT ] ) |
| 194 | if j == 0: # Successfully logged out |
| 195 | return main.TRUE |
| 196 | elif j == 1 or j == 2: |
| 197 | # ONOS didn't fully load, and logout command isn't working |
| 198 | # or the command timed out |
| 199 | self.handle.send( "\x04" ) # send ctrl-d |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 200 | try: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 201 | self.handle.expect( self.Prompt() ) |
Jon Hall | 64ab3bd | 2016-05-13 11:29:44 -0700 | [diff] [blame] | 202 | except pexpect.TIMEOUT: |
| 203 | main.log.error( "ONOS did not respond to 'logout' or CTRL-d" ) |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 204 | return main.TRUE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 205 | else: # some other output |
Jon Hall | bfe0000 | 2016-04-05 10:23:54 -0700 | [diff] [blame] | 206 | main.log.warn( "Unknown repsonse to logout command: '{}'", |
| 207 | repr( self.handle.before ) ) |
| 208 | return main.FALSE |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 209 | elif i == 1: # not in CLI |
| 210 | return main.TRUE |
steven30801 | e42f1fb | 2019-01-17 11:31:45 +0800 | [diff] [blame] | 211 | elif i == 2: # Timeout |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 212 | return main.FALSE |
| 213 | else: |
andrewonlab | 9627f43 | 2014-11-14 12:45:10 -0500 | [diff] [blame] | 214 | return main.TRUE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 215 | except TypeError: |
| 216 | main.log.exception( self.name + ": Object not as expected" ) |
| 217 | return None |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 218 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 219 | main.log.error( self.name + ": eof exception found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 220 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 221 | main.cleanAndExit() |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 222 | except ValueError: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 223 | main.log.error( self.name + |
| 224 | "ValueError exception in logout method" ) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 225 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 226 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 227 | main.cleanAndExit() |
andrewonlab | 38d2b4a | 2014-11-13 16:28:47 -0500 | [diff] [blame] | 228 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 229 | def setCell( self, cellname ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 230 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 231 | Calls 'cell <name>' to set the environment variables on ONOSbench |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 232 | |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 233 | Before issuing any cli commands, set the environment variable first. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 234 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 235 | try: |
| 236 | if not cellname: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 237 | main.log.error( "Must define cellname" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 238 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 239 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 240 | self.handle.sendline( "cell " + str( cellname ) ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 241 | # Expect the cellname in the ONOSCELL variable. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 242 | # Note that this variable name is subject to change |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 243 | # and that this driver will have to change accordingly |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 244 | self.handle.expect( str( cellname ) ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 245 | handleBefore = self.handle.before |
| 246 | handleAfter = self.handle.after |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 247 | # Get the rest of the handle |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 248 | self.handle.sendline( "" ) |
| 249 | self.handle.expect( self.prompt ) |
andrew@onlab.us | c400b11 | 2015-01-21 15:33:19 -0800 | [diff] [blame] | 250 | handleMore = self.handle.before |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 251 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 252 | main.log.info( "Cell call returned: " + handleBefore + |
| 253 | handleAfter + handleMore ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 254 | |
| 255 | return main.TRUE |
| 256 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 257 | except TypeError: |
| 258 | main.log.exception( self.name + ": Object not as expected" ) |
| 259 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 260 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 261 | main.log.error( self.name + ": eof exception found" ) |
| 262 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 263 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 264 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 265 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 266 | main.cleanAndExit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 267 | |
pingping-lin | 57a56ce | 2015-05-20 16:43:48 -0700 | [diff] [blame] | 268 | def startOnosCli( self, ONOSIp, karafTimeout="", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 269 | commandlineTimeout=10, onosStartTimeout=60, waitForStart=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 270 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 271 | karafTimeout is an optional argument. karafTimeout value passed |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 272 | by user would be used to set the current karaf shell idle timeout. |
| 273 | 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] | 274 | the subsequent login would reflect new idle timeout. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 275 | Below is an example to start a session with 60 seconds idle timeout |
| 276 | ( input value is in milliseconds ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 277 | |
Hari Krishna | 25d42f7 | 2015-01-05 15:08:28 -0800 | [diff] [blame] | 278 | tValue = "60000" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 279 | main.ONOScli1.startOnosCli( ONOSIp, karafTimeout=tValue ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 280 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 281 | Note: karafTimeout is left as str so that this could be read |
| 282 | and passed to startOnosCli from PARAMS file as str. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 283 | """ |
You Wang | f69ab39 | 2016-01-26 16:34:38 -0800 | [diff] [blame] | 284 | self.onosIp = ONOSIp |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 285 | try: |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 286 | # Check if we are already in the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 287 | self.handle.sendline( "" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 288 | x = self.handle.expect( [ self.Prompt(), self.karafPrompt ], commandlineTimeout ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 289 | if x == 1: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 290 | main.log.info( "ONOS cli is already running" ) |
andrewonlab | 48829f6 | 2014-11-17 13:49:01 -0500 | [diff] [blame] | 291 | return main.TRUE |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 292 | |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 293 | # Not in CLI so login |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 294 | if self.inDocker: |
| 295 | # The Docker does not have all the wrapper scripts |
| 296 | startCliCommand = "ssh -p 8101 -o StrictHostKeyChecking=no %s@localhost" % self.karafUser |
| 297 | elif waitForStart: |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 298 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 299 | startCliCommand = "onos-wait-for-start " + str( ONOSIp ) |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 300 | else: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 301 | startCliCommand = "onos " + str( ONOSIp ) |
| 302 | self.handle.sendline( startCliCommand ) |
| 303 | tries = 0 |
Jon Hall | f69e316 | 2020-09-01 09:08:44 -0700 | [diff] [blame] | 304 | timeoutSet = False |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 305 | while tries < 5: |
| 306 | i = self.handle.expect( [ |
| 307 | self.karafPrompt, |
| 308 | "Password:", |
| 309 | pexpect.TIMEOUT ], onosStartTimeout ) |
andrewonlab | 2a7ea9b | 2014-10-24 12:21:05 -0400 | [diff] [blame] | 310 | |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 311 | if i == 0: |
Jon Hall | f69e316 | 2020-09-01 09:08:44 -0700 | [diff] [blame] | 312 | if not karafTimeout or timeoutSet: |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 313 | main.log.info( str( ONOSIp ) + " CLI Started successfully" ) |
| 314 | return main.TRUE |
Hari Krishna | e36ef21 | 2015-01-04 14:09:13 -0800 | [diff] [blame] | 315 | if karafTimeout: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 316 | self.handle.sendline( |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 317 | "config:property-set -p org.apache.karaf.shell\ |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 318 | sshIdleTimeout " + |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 319 | str( karafTimeout ) ) |
| 320 | self.handle.expect( "closed by remote host" ) |
Jon Hall | f69e316 | 2020-09-01 09:08:44 -0700 | [diff] [blame] | 321 | self.handle.expect( self.Prompt() ) |
Jon Hall | 9b0de1f | 2020-08-24 15:38:04 -0700 | [diff] [blame] | 322 | self.handle.sendline( startCliCommand ) |
Jon Hall | f69e316 | 2020-09-01 09:08:44 -0700 | [diff] [blame] | 323 | timeoutSet = True |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 324 | elif i == 1: |
| 325 | main.log.info( str( ONOSIp ) + " CLI asking for password" ) |
| 326 | main.log.debug( "Sending %s" % self.karafPass ) |
| 327 | self.handle.sendline( self.karafPass ) |
andrewonlab | 3a7c3c7 | 2014-10-24 17:21:03 -0400 | [diff] [blame] | 328 | else: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 329 | # If failed, send ctrl+c to process and try again |
| 330 | main.log.info( "Starting CLI failed. Retrying..." ) |
Jon Hall | f69e316 | 2020-09-01 09:08:44 -0700 | [diff] [blame] | 331 | time.sleep( 5 ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 332 | self.handle.send( "\x03" ) |
| 333 | self.handle.sendline( startCliCommand ) |
| 334 | tries += 1 |
| 335 | main.log.error( "Connection to CLI " + str( ONOSIp ) + " timeout" ) |
| 336 | return main.FALSE |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 337 | except TypeError: |
| 338 | main.log.exception( self.name + ": Object not as expected" ) |
| 339 | return None |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 340 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 341 | main.log.error( self.name + ": EOF exception found" ) |
| 342 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 343 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 344 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 345 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 346 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 347 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 348 | def startCellCli( self, karafTimeout="", |
| 349 | commandlineTimeout=10, onosStartTimeout=60 ): |
| 350 | """ |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 351 | Start CLI on onos cell handle. |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 352 | |
| 353 | karafTimeout is an optional argument. karafTimeout value passed |
| 354 | by user would be used to set the current karaf shell idle timeout. |
| 355 | Note that when ever this property is modified the shell will exit and |
| 356 | the subsequent login would reflect new idle timeout. |
| 357 | Below is an example to start a session with 60 seconds idle timeout |
| 358 | ( input value is in milliseconds ): |
| 359 | |
| 360 | tValue = "60000" |
| 361 | |
| 362 | Note: karafTimeout is left as str so that this could be read |
| 363 | and passed to startOnosCli from PARAMS file as str. |
| 364 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 365 | |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 366 | try: |
| 367 | self.handle.sendline( "" ) |
| 368 | x = self.handle.expect( [ |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 369 | self.Prompt(), self.karafPrompt ], commandlineTimeout ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 370 | |
| 371 | if x == 1: |
| 372 | main.log.info( "ONOS cli is already running" ) |
| 373 | return main.TRUE |
| 374 | |
Jeremy Ronquillo | ec916a4 | 2018-02-02 13:05:57 -0800 | [diff] [blame] | 375 | # Wait for onos start ( onos-wait-for-start ) and enter onos cli |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 376 | self.handle.sendline( "/opt/onos/bin/onos" ) |
| 377 | i = self.handle.expect( [ |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 378 | self.karafPrompt, |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 379 | pexpect.TIMEOUT ], onosStartTimeout ) |
| 380 | |
| 381 | if i == 0: |
| 382 | main.log.info( self.name + " CLI Started successfully" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 383 | if karafTimeout: # FIXME: This doesn't look right |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 384 | self.handle.sendline( |
| 385 | "config:property-set -p org.apache.karaf.shell\ |
| 386 | sshIdleTimeout " + |
| 387 | karafTimeout ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 388 | self.handle.expect( self.Prompt() ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 389 | self.handle.sendline( "/opt/onos/bin/onos" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 390 | self.handle.expect( self.karafPrompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 391 | return main.TRUE |
| 392 | else: |
| 393 | # If failed, send ctrl+c to process and try again |
| 394 | main.log.info( "Starting CLI failed. Retrying..." ) |
| 395 | self.handle.send( "\x03" ) |
| 396 | self.handle.sendline( "/opt/onos/bin/onos" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 397 | i = self.handle.expect( [ self.karafPrompt, pexpect.TIMEOUT ], |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 398 | timeout=30 ) |
| 399 | if i == 0: |
| 400 | main.log.info( self.name + " CLI Started " + |
| 401 | "successfully after retry attempt" ) |
| 402 | if karafTimeout: |
| 403 | self.handle.sendline( |
| 404 | "config:property-set -p org.apache.karaf.shell\ |
| 405 | sshIdleTimeout " + |
| 406 | karafTimeout ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 407 | self.handle.expect( self.Prompt() ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 408 | self.handle.sendline( "/opt/onos/bin/onos" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 409 | self.handle.expect( self.karafPrompt ) |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 410 | return main.TRUE |
| 411 | else: |
| 412 | main.log.error( "Connection to CLI " + |
| 413 | self.name + " timeout" ) |
| 414 | return main.FALSE |
| 415 | |
| 416 | except TypeError: |
| 417 | main.log.exception( self.name + ": Object not as expected" ) |
| 418 | return None |
| 419 | except pexpect.EOF: |
| 420 | main.log.error( self.name + ": EOF exception found" ) |
| 421 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 422 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 423 | except Exception: |
| 424 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 425 | main.cleanAndExit() |
suibin zhang | 116647a | 2016-05-06 16:30:09 -0700 | [diff] [blame] | 426 | |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 427 | def log( self, cmdStr, level="", noExit=False ): |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 428 | """ |
| 429 | log the commands in the onos CLI. |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 430 | returns main.TRUE on success |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 431 | returns main.FALSE if Error occurred |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 432 | if noExit is True, TestON will not exit, but clean up |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 433 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 434 | Level defaults to INFO |
Pratik Parab | 3b2ab5a | 2017-02-14 13:15:14 -0800 | [diff] [blame] | 435 | if cmdStr has spaces then put quotes in the passed string |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 436 | """ |
| 437 | try: |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 438 | lvlStr = "" |
| 439 | if level: |
| 440 | lvlStr = "--level=" + level |
| 441 | |
kelvin-onlab | 338f551 | 2015-02-06 10:53:16 -0800 | [diff] [blame] | 442 | self.handle.sendline( "log:log " + lvlStr + " " + cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 443 | self.handle.expect( "log:log" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 444 | self.handle.expect( self.karafPrompt ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 445 | |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 446 | response = self.handle.before |
| 447 | if re.search( "Error", response ): |
Jon Hall | dac3eae | 2020-06-05 12:04:06 -0700 | [diff] [blame] | 448 | main.log.debug( response ) |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 449 | return main.FALSE |
| 450 | return main.TRUE |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 451 | except pexpect.TIMEOUT: |
| 452 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 453 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 454 | if noExit: |
| 455 | main.cleanup() |
| 456 | return None |
| 457 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 458 | main.cleanAndExit() |
kelvin-onlab | 9f54103 | 2015-02-04 16:19:53 -0800 | [diff] [blame] | 459 | except pexpect.EOF: |
| 460 | main.log.error( self.name + ": EOF exception found" ) |
| 461 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 462 | if noExit: |
| 463 | main.cleanup() |
| 464 | return None |
| 465 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 466 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 467 | except Exception: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 468 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 469 | if noExit: |
| 470 | main.cleanup() |
| 471 | return None |
| 472 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 473 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 474 | |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 475 | def clearBuffer( self, debug=False, timeout=10, noExit=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 476 | """ |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 477 | Test cli connection and clear any left over output in the buffer |
| 478 | Optional Arguments: |
| 479 | debug - Defaults to False. If True, will enable debug logging. |
| 480 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 481 | before a timeout. |
| 482 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 483 | """ |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 484 | try: |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 485 | # Try to reconnect if disconnected from cli |
| 486 | self.handle.sendline( "" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 487 | i = self.handle.expect( [ self.karafPrompt, |
| 488 | self.Prompt(), |
| 489 | pexpect.TIMEOUT ] ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 490 | response = self.handle.before |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 491 | if i == 1: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 492 | main.log.error( self.name + ": onos cli session closed. " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 493 | if self.onosIp: |
| 494 | main.log.warn( "Trying to reconnect " + self.onosIp ) |
| 495 | reconnectResult = self.startOnosCli( self.onosIp ) |
| 496 | if reconnectResult: |
| 497 | main.log.info( self.name + ": onos cli session reconnected." ) |
| 498 | else: |
| 499 | main.log.error( self.name + ": reconnection failed." ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 500 | if noExit: |
| 501 | return None |
| 502 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 503 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 504 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 505 | main.cleanAndExit() |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 506 | if i == 2: |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 507 | main.log.warn( "Timeout when testing cli responsiveness" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 508 | main.log.debug( "%s: %s" % ( self.name, self.handle.before ) ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 509 | self.handle.send( "\x03" ) # Send ctrl-c to clear previous output |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 510 | self.handle.expect( self.karafPrompt ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 511 | |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 512 | response += self.handle.before |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 513 | if debug: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 514 | main.log.debug( self.name + ": Raw output from sending ''" ) |
| 515 | main.log.debug( self.name + ": " + repr( response ) ) |
| 516 | except pexpect.TIMEOUT: |
| 517 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 518 | main.log.debug( "%s: %s" % ( self.name, self.handle.before ) ) |
You Wang | 141b43b | 2018-06-26 16:50:18 -0700 | [diff] [blame] | 519 | self.handle.send( "\x03" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 520 | self.handle.expect( self.karafPrompt ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 521 | return None |
| 522 | except pexpect.EOF: |
| 523 | main.log.error( self.name + ": EOF exception found" ) |
| 524 | main.log.error( self.name + ": " + self.handle.before ) |
| 525 | if noExit: |
| 526 | return None |
| 527 | else: |
| 528 | main.cleanAndExit() |
| 529 | except Exception: |
| 530 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 531 | if noExit: |
| 532 | return None |
| 533 | else: |
| 534 | main.cleanAndExit() |
| 535 | |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 536 | def sendline( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True, expectJson=False ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 537 | """ |
| 538 | A wrapper around pexpect's sendline/expect. Will return all the output from a given command |
| 539 | |
| 540 | Required Arguments: |
| 541 | cmdStr - String to send to the pexpect session |
| 542 | |
| 543 | Optional Arguments: |
| 544 | showResponse - Defaults to False. If True will log the response. |
| 545 | debug - Defaults to False. If True, will enable debug logging. |
| 546 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 547 | before a timeout. |
| 548 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
| 549 | closed channel, but instead return None |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 550 | relaxedRegex - Defaults to True. If there is a pipe in the command send, will only try to match the last part of the piped command. |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 551 | |
| 552 | Warning: There are no sanity checking to commands sent using this method. |
| 553 | |
| 554 | """ |
| 555 | try: |
| 556 | # Try to reconnect if disconnected from cli |
| 557 | self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit ) |
| 558 | if debug: |
| 559 | # NOTE: This adds an average of .4 seconds per call |
Jon Hall | 14a03b5 | 2016-05-11 12:07:30 -0700 | [diff] [blame] | 560 | logStr = "\"Sending CLI command: '" + cmdStr + "'\"" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 561 | self.log( logStr, noExit=noExit ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 562 | self.handle.sendline( cmdStr ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 563 | self.handle.expect( self.karafPrompt, timeout ) |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 564 | response = self.handle.before |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 565 | main.log.info( "Command '" + str( cmdStr ) + "' sent to " |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 566 | + self.name + "." ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 567 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 568 | main.log.debug( self.name + ": Raw output" ) |
| 569 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 570 | |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 571 | response = self.cleanOutput( response, debug=debug ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 572 | # Remove control codes from karaf 4.2.1 |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 573 | karafEscape = re.compile( r"('(0|1)~\'|\r\r\r\n\x1b\[A\x1b\[79C(x|\s)?|\x1b(>|=~?)|\x1b\[90m~)" ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 574 | response = karafEscape.sub( '', response ) |
| 575 | if debug: |
| 576 | main.log.debug( self.name + ": karafEscape output" ) |
| 577 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 578 | # Remove ANSI color control strings from output |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 579 | response = self.cleanOutput( response, debug ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 580 | |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 581 | # Remove ANSI color control strings from output |
Jon Hall | cf31d0f | 2018-12-13 11:18:48 -0800 | [diff] [blame] | 582 | # NOTE: karaf is sometimes adding a single character then two |
| 583 | # backspaces and sometimes adding 2 characters with 2 backspaces?? |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 584 | backspaceEscape = re.compile( r'((.|\s)\x08)' ) |
| 585 | unchanged = False |
| 586 | while not unchanged: |
| 587 | old = response |
| 588 | response = backspaceEscape.sub( '', response, count=1 ) |
| 589 | if debug: |
| 590 | main.log.debug( self.name + ": backspaceEscape output" ) |
| 591 | main.log.debug( self.name + ": " + repr( response ) ) |
| 592 | unchanged = old == response |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 593 | |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 594 | # Remove extra return chars that get added |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 595 | response = re.sub( r"\s\r", "", response ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 596 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 597 | main.log.debug( self.name + ": Removed extra returns " + |
| 598 | "from output" ) |
| 599 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 600 | |
| 601 | # Strip excess whitespace |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 602 | response = response.strip() |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 603 | if debug: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 604 | main.log.debug( self.name + ": parsed and stripped output" ) |
| 605 | main.log.debug( self.name + ": " + repr( response ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 606 | |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 607 | # parse for just the output, remove the cmd from response |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 608 | cmdPattern = cmdStr.strip() |
| 609 | main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) + |
| 610 | "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 611 | if relaxedRegex: |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 612 | cmdPattern = cmdPattern.split( '|' )[ -1 ].strip() |
| 613 | main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) + |
| 614 | "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 615 | # This was added because karaf 4.2 is stripping some characters from the command echo |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 616 | output = response.split( cmdPattern, 1 ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 617 | if expectJson: |
| 618 | main.log.warn( "Relaxed Regex: Searching for a json string amongst the output" ) |
| 619 | jsonPattern = r'\{.*\}' |
| 620 | match = re.search( jsonPattern, output[ 0 ] ) |
| 621 | if match: |
| 622 | output = [ '' , match.group( 0 ) ] # We expect a list with the second element to be the output |
Jon Hall | 39e3ffe | 2018-12-05 11:40:29 -0800 | [diff] [blame] | 623 | if len( output ) < 2: |
| 624 | main.log.warn( "Relaxing regex match to last 5 characters of the sent command" ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 625 | cmdPattern = cmdPattern[ -5: ] |
| 626 | main.log.debug( "REGEX PATTERN SET TO: " + repr( cmdPattern ) + |
| 627 | "\nSENT COMMAND STRING WAS: " + repr( cmdStr ) ) |
| 628 | output = response.split( cmdPattern, 1 ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 629 | else: |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 630 | output = response.split( cmdPattern, 1 ) |
| 631 | if len( output ) < 2: # TODO: Should we do this without the relaxedRegex flag? |
Jon Hall | 8c9dd1c | 2018-11-14 15:40:39 -0800 | [diff] [blame] | 632 | main.log.warn( "Relaxing regex match to last 5 characters of the sent command" ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 633 | output = response.split( cmdPattern[ -5: ], 1 ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 634 | if output: |
| 635 | if debug: |
| 636 | main.log.debug( self.name + ": split output" ) |
| 637 | for r in output: |
| 638 | main.log.debug( self.name + ": " + repr( r ) ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 639 | if len( output ) == 1: |
| 640 | main.log.error( "Could not remove sent command echo from output" ) |
| 641 | return output |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 642 | output = output[ 1 ].strip() |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 643 | if showResponse: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 644 | main.log.info( "Response from ONOS: {}".format( output ) ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 645 | self.clearBuffer( debug=debug, timeout=timeout, noExit=noExit ) |
GlennRC | 8587043 | 2015-11-23 11:45:51 -0800 | [diff] [blame] | 646 | return output |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 647 | except pexpect.TIMEOUT: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 648 | main.log.error( self.name + ": ONOS timeout" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 649 | if debug: |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 650 | main.log.debug( "%s: %s" % ( self.name, self.handle.before ) ) |
You Wang | 6b5e5ba | 2019-01-31 15:32:40 -0800 | [diff] [blame] | 651 | self.exitFromCmd( self.karafPrompt, 100 ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 652 | return None |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 653 | except IndexError: |
| 654 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 655 | main.log.debug( "response: {}".format( repr( response ) ) ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 656 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 657 | except TypeError: |
| 658 | main.log.exception( self.name + ": Object not as expected" ) |
| 659 | return None |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 660 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 661 | main.log.error( self.name + ": EOF exception found" ) |
| 662 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 663 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 664 | return None |
| 665 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 666 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 667 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 668 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 669 | if noExit: |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 670 | return None |
| 671 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 672 | main.cleanAndExit() |
andrewonlab | a18f6bf | 2014-10-13 19:31:54 -0400 | [diff] [blame] | 673 | |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 674 | def lineCount( self, cmdStr, showResponse=False, debug=False, timeout=10, noExit=False, relaxedRegex=True ): |
| 675 | """ |
| 676 | A wrapper around sendline(). Will return the number of lines returned or None on error |
| 677 | |
| 678 | Required Arguments: |
| 679 | cmdStr - String to send to the pexpect session |
| 680 | |
| 681 | Optional Arguments: |
| 682 | showResponse - Defaults to False. If True will log the response. |
| 683 | debug - Defaults to False. If True, will enable debug logging. |
| 684 | timeout - Defaults to 10. Amount of time in seconds for a command to return |
| 685 | before a timeout. |
| 686 | noExit - Defaults to False. If True, will not exit TestON in the event of a |
| 687 | closed channel, but instead return None |
| 688 | relaxedRegex - Defaults to True. If there is a pipe in the command send, will only try to match the last part of the piped command. |
| 689 | |
| 690 | Warning: There are no sanity checking to commands sent using this method. |
| 691 | |
| 692 | """ |
| 693 | try: |
| 694 | numLines = self.sendline( cmdStr, showResponse, debug, timeout, noExit, relaxedRegex ) |
You Wang | 0ce8e0c | 2019-02-22 12:22:26 -0800 | [diff] [blame] | 695 | parsed = re.search( "(\d+)", numLines ) |
Jon Hall | 8c9dd1c | 2018-11-14 15:40:39 -0800 | [diff] [blame] | 696 | if not parsed: |
| 697 | main.log.error( "Warning, output of karaf's wc may have changed" ) |
| 698 | return None |
| 699 | return parsed.group( 1 ) |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 700 | except IndexError: |
| 701 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | ce0d70b | 2018-12-11 11:01:32 -0800 | [diff] [blame] | 702 | main.log.debug( "response: {}".format( repr( numLines ) ) ) |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 703 | return None |
| 704 | except TypeError: |
| 705 | main.log.exception( self.name + ": Object not as expected" ) |
| 706 | return None |
| 707 | except Exception: |
| 708 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 709 | if noExit: |
| 710 | return None |
| 711 | else: |
| 712 | main.cleanAndExit() |
| 713 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 714 | # IMPORTANT NOTE: |
| 715 | # For all cli commands, naming convention should match |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 716 | # the cli command changing 'a:b' with 'aB'. |
| 717 | # Ex ) onos:topology > onosTopology |
| 718 | # onos:links > onosLinks |
| 719 | # feature:list > featureList |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 720 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 721 | def addNode( self, nodeId, ONOSIp, tcpPort="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 722 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 723 | Adds a new cluster node by ID and address information. |
| 724 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 725 | * nodeId |
| 726 | * ONOSIp |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 727 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 728 | * tcpPort |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 729 | """ |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 730 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 731 | cmdStr = "add-node " + str( nodeId ) + " " +\ |
| 732 | str( ONOSIp ) + " " + str( tcpPort ) |
| 733 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 734 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 735 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 736 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 737 | main.log.error( self.name + ": Error in adding node" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 738 | main.log.error( handle ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 739 | return main.FALSE |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 740 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 741 | main.log.info( "Node " + str( ONOSIp ) + " added" ) |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 742 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 743 | except AssertionError: |
| 744 | main.log.exception( "" ) |
| 745 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 746 | except TypeError: |
| 747 | main.log.exception( self.name + ": Object not as expected" ) |
| 748 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 749 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 750 | main.log.error( self.name + ": EOF exception found" ) |
| 751 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 752 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 753 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 754 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 755 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 756 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 757 | def removeNode( self, nodeId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 758 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 759 | Removes a cluster by ID |
| 760 | Issues command: 'remove-node [<node-id>]' |
| 761 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 762 | * nodeId |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 763 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 764 | try: |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 765 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 766 | cmdStr = "remove-node " + str( nodeId ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 767 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 768 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 769 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 770 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 771 | main.log.error( self.name + ": Error in removing node" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 772 | main.log.error( handle ) |
| 773 | return main.FALSE |
| 774 | else: |
| 775 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 776 | except AssertionError: |
| 777 | main.log.exception( "" ) |
| 778 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 779 | except TypeError: |
| 780 | main.log.exception( self.name + ": Object not as expected" ) |
| 781 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 782 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 783 | main.log.error( self.name + ": EOF exception found" ) |
| 784 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 785 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 786 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 787 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 788 | main.cleanAndExit() |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 789 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 790 | def nodes( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 791 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 792 | List the nodes currently visible |
| 793 | Issues command: 'nodes' |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 794 | Optional argument: |
| 795 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 796 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 797 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 798 | cmdStr = "nodes" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 799 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 800 | cmdStr += " -j" |
| 801 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 802 | assert output is not None, "Error in sendline" |
Jon Hall | e37bd1f | 2020-09-10 12:16:41 -0700 | [diff] [blame] | 803 | # "Command not found" or "Service org.onosproject.security.AuditService not found" |
| 804 | assert "not found" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 805 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 806 | except AssertionError: |
| 807 | main.log.exception( "" ) |
| 808 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 809 | except TypeError: |
| 810 | main.log.exception( self.name + ": Object not as expected" ) |
| 811 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 812 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 813 | main.log.error( self.name + ": EOF exception found" ) |
| 814 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 815 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 816 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 817 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 818 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 819 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 820 | def topology( self ): |
| 821 | """ |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 822 | Definition: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 823 | Returns the output of topology command. |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 824 | Return: |
| 825 | topology = current ONOS topology |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 826 | """ |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 827 | try: |
Hari Krishna | ef1bd4e | 2015-03-12 16:55:30 -0700 | [diff] [blame] | 828 | cmdStr = "topology -j" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 829 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 830 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 831 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 832 | main.log.info( cmdStr + " returned: " + str( handle ) ) |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 833 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 834 | except AssertionError: |
| 835 | main.log.exception( "" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 836 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 837 | except TypeError: |
| 838 | main.log.exception( self.name + ": Object not as expected" ) |
| 839 | return None |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 840 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 841 | main.log.error( self.name + ": EOF exception found" ) |
| 842 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 843 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 844 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 845 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 846 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 847 | |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 848 | def deviceRemove( self, deviceId ): |
| 849 | """ |
| 850 | Removes particular device from storage |
| 851 | |
| 852 | TODO: refactor this function |
| 853 | """ |
| 854 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 855 | cmdStr = "device-remove " + str( deviceId ) |
| 856 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 857 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 858 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 859 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 860 | main.log.error( self.name + ": Error in removing device" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 861 | main.log.error( handle ) |
| 862 | return main.FALSE |
| 863 | else: |
| 864 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 865 | except AssertionError: |
| 866 | main.log.exception( "" ) |
| 867 | return None |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 868 | except TypeError: |
| 869 | main.log.exception( self.name + ": Object not as expected" ) |
| 870 | return None |
| 871 | except pexpect.EOF: |
| 872 | main.log.error( self.name + ": EOF exception found" ) |
| 873 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 874 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 875 | except Exception: |
| 876 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 877 | main.cleanAndExit() |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 878 | |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 879 | def devices( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 880 | """ |
Jon Hall | 7b02d95 | 2014-10-17 20:14:54 -0400 | [diff] [blame] | 881 | Lists all infrastructure devices or switches |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 882 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 883 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 884 | """ |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 885 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 886 | cmdStr = "devices" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 887 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 888 | cmdStr += " -j" |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 889 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 890 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 891 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 892 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 893 | except AssertionError: |
| 894 | main.log.exception( "" ) |
| 895 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 896 | except TypeError: |
| 897 | main.log.exception( self.name + ": Object not as expected" ) |
| 898 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 899 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 900 | main.log.error( self.name + ": EOF exception found" ) |
| 901 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 902 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 903 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 904 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 905 | main.cleanAndExit() |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 906 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 907 | def balanceMasters( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 908 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 909 | This balances the devices across all controllers |
| 910 | by issuing command: 'onos> onos:balance-masters' |
| 911 | If required this could be extended to return devices balanced output. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 912 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 913 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 914 | cmdStr = "onos:balance-masters" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 915 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 916 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 917 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 918 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 919 | main.log.error( self.name + ": Error in balancing masters" ) |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 920 | main.log.error( handle ) |
| 921 | return main.FALSE |
| 922 | else: |
| 923 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 924 | except AssertionError: |
| 925 | main.log.exception( "" ) |
| 926 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 927 | except TypeError: |
| 928 | main.log.exception( self.name + ": Object not as expected" ) |
| 929 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 930 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 931 | main.log.error( self.name + ": EOF exception found" ) |
| 932 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 933 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 934 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 935 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 936 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 937 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 938 | def checkMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 939 | """ |
| 940 | Returns the output of the masters command. |
| 941 | Optional argument: |
| 942 | * jsonFormat - boolean indicating if you want output in json |
| 943 | """ |
| 944 | try: |
| 945 | cmdStr = "onos:masters" |
| 946 | if jsonFormat: |
| 947 | cmdStr += " -j" |
| 948 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 949 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 950 | assert "Command not found:" not in output, output |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 951 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 952 | except AssertionError: |
| 953 | main.log.exception( "" ) |
| 954 | return None |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 955 | except TypeError: |
| 956 | main.log.exception( self.name + ": Object not as expected" ) |
| 957 | return None |
| 958 | except pexpect.EOF: |
| 959 | main.log.error( self.name + ": EOF exception found" ) |
| 960 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 961 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 962 | except Exception: |
| 963 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 964 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 965 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 966 | def checkBalanceMasters( self, jsonFormat=True ): |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 967 | """ |
| 968 | Uses the master command to check that the devices' leadership |
| 969 | is evenly divided |
| 970 | |
| 971 | Dependencies: checkMasters() and summary() |
| 972 | |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 973 | Returns main.TRUE if the devices are balanced |
| 974 | Returns main.FALSE if the devices are unbalanced |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 975 | Exits on Exception |
| 976 | Returns None on TypeError |
| 977 | """ |
| 978 | try: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 979 | summaryOutput = self.summary() |
| 980 | totalDevices = json.loads( summaryOutput )[ "devices" ] |
| 981 | except ( TypeError, ValueError ): |
| 982 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summaryOutput ) ) |
| 983 | return None |
| 984 | try: |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 985 | totalOwnedDevices = 0 |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 986 | mastersOutput = self.checkMasters() |
| 987 | masters = json.loads( mastersOutput ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 988 | first = masters[ 0 ][ "size" ] |
| 989 | for master in masters: |
| 990 | totalOwnedDevices += master[ "size" ] |
| 991 | if master[ "size" ] > first + 1 or master[ "size" ] < first - 1: |
| 992 | main.log.error( "Mastership not balanced" ) |
| 993 | main.log.info( "\n" + self.checkMasters( False ) ) |
| 994 | return main.FALSE |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 995 | main.log.info( "Mastership balanced between " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 996 | str( len( masters ) ) + " masters" ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 997 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 998 | except ( TypeError, ValueError ): |
| 999 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, mastersOutput ) ) |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 1000 | return None |
| 1001 | except pexpect.EOF: |
| 1002 | main.log.error( self.name + ": EOF exception found" ) |
| 1003 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1004 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 1005 | except Exception: |
| 1006 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1007 | main.cleanAndExit() |
acsmars | 2495002 | 2015-07-30 18:00:43 -0700 | [diff] [blame] | 1008 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1009 | def links( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1010 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1011 | Lists all core links |
| 1012 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1013 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1014 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1015 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1016 | cmdStr = "links" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1017 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1018 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 1019 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1020 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1021 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1022 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1023 | except AssertionError: |
| 1024 | main.log.exception( "" ) |
| 1025 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1026 | except TypeError: |
| 1027 | main.log.exception( self.name + ": Object not as expected" ) |
| 1028 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1029 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1030 | main.log.error( self.name + ": EOF exception found" ) |
| 1031 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1032 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1033 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1034 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1035 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1036 | |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 1037 | def ports( self, jsonFormat=True, timeout=30 ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1038 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1039 | Lists all ports |
| 1040 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1041 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1042 | """ |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1043 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1044 | cmdStr = "ports" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1045 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1046 | cmdStr += " -j" |
You Wang | 3b9689a | 2018-08-30 12:24:00 -0700 | [diff] [blame] | 1047 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1048 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1049 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1050 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1051 | except AssertionError: |
| 1052 | main.log.exception( "" ) |
| 1053 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1054 | except TypeError: |
| 1055 | main.log.exception( self.name + ": Object not as expected" ) |
| 1056 | return None |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1057 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1058 | main.log.error( self.name + ": EOF exception found" ) |
| 1059 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1060 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1061 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1062 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1063 | main.cleanAndExit() |
Jon Hall | e821748 | 2014-10-17 13:49:14 -0400 | [diff] [blame] | 1064 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1065 | def roles( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1066 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1067 | Lists all devices and the controllers with roles assigned to them |
| 1068 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1069 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1070 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 1071 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1072 | cmdStr = "roles" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1073 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1074 | cmdStr += " -j" |
| 1075 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1076 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1077 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1078 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1079 | except AssertionError: |
| 1080 | main.log.exception( "" ) |
| 1081 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1082 | except TypeError: |
| 1083 | main.log.exception( self.name + ": Object not as expected" ) |
| 1084 | return None |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1085 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1086 | main.log.error( self.name + ": EOF exception found" ) |
| 1087 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1088 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1089 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1090 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1091 | main.cleanAndExit() |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1092 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1093 | def getRole( self, deviceId ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1094 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1095 | Given the a string containing the json representation of the "roles" |
| 1096 | cli command and a partial or whole device id, returns a json object |
| 1097 | containing the roles output for the first device whose id contains |
| 1098 | "device_id" |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1099 | |
| 1100 | Returns: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1101 | A dict of the role assignments for the given device or |
| 1102 | None if no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1103 | """ |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1104 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1105 | if deviceId is None: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1106 | return None |
| 1107 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1108 | rawRoles = self.roles() |
| 1109 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1110 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1111 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1112 | # print device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1113 | if str( deviceId ) in device[ 'id' ]: |
Jon Hall | 983a170 | 2014-10-28 18:44:22 -0400 | [diff] [blame] | 1114 | return device |
| 1115 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1116 | except ( TypeError, ValueError ): |
| 1117 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1118 | return None |
andrewonlab | 86dc308 | 2014-10-13 18:18:38 -0400 | [diff] [blame] | 1119 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1120 | main.log.error( self.name + ": EOF exception found" ) |
| 1121 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1122 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1123 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1124 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1125 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1126 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1127 | def rolesNotNull( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1128 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1129 | Iterates through each device and checks if there is a master assigned |
| 1130 | Returns: main.TRUE if each device has a master |
| 1131 | main.FALSE any device has no master |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1132 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1133 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1134 | rawRoles = self.roles() |
| 1135 | rolesJson = json.loads( rawRoles ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1136 | # search json for the device with id then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1137 | for device in rolesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1138 | # print device |
| 1139 | if device[ 'master' ] == "none": |
| 1140 | main.log.warn( "Device has no master: " + str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1141 | return main.FALSE |
| 1142 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1143 | except ( TypeError, ValueError ): |
| 1144 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawRoles ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1145 | return None |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1146 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1147 | main.log.error( self.name + ": EOF exception found" ) |
| 1148 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1149 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1150 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1151 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1152 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1153 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1154 | def paths( self, srcId, dstId ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1155 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1156 | Returns string of paths, and the cost. |
| 1157 | Issues command: onos:paths <src> <dst> |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1158 | """ |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1159 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1160 | cmdStr = "onos:paths " + str( srcId ) + " " + str( dstId ) |
| 1161 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1162 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1163 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1164 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1165 | main.log.error( self.name + ": Error in getting paths" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1166 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1167 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1168 | path = handle.split( ";" )[ 0 ] |
| 1169 | cost = handle.split( ";" )[ 1 ] |
| 1170 | return ( path, cost ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1171 | except AssertionError: |
| 1172 | main.log.exception( "" ) |
| 1173 | return ( handle, "Error" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1174 | except TypeError: |
| 1175 | main.log.exception( self.name + ": Object not as expected" ) |
| 1176 | return ( handle, "Error" ) |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1177 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1178 | main.log.error( self.name + ": EOF exception found" ) |
| 1179 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1180 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1181 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1182 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1183 | main.cleanAndExit() |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1184 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1185 | def hosts( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1186 | """ |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1187 | Lists all discovered hosts |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1188 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1189 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1190 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1191 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1192 | cmdStr = "hosts" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1193 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1194 | cmdStr += " -j" |
| 1195 | handle = self.sendline( cmdStr ) |
Jeremy | d9e4eb1 | 2016-04-13 12:09:06 -0700 | [diff] [blame] | 1196 | if handle: |
| 1197 | assert "Command not found:" not in handle, handle |
Jon Hall | baf5316 | 2015-12-17 17:04:34 -0800 | [diff] [blame] | 1198 | # TODO: Maybe make this less hardcoded |
| 1199 | # ConsistentMap Exceptions |
| 1200 | assert "org.onosproject.store.service" not in handle |
| 1201 | # Node not leader |
| 1202 | assert "java.lang.IllegalStateException" not in handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 1203 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1204 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1205 | main.log.exception( self.name + ": Error in processing '" + cmdStr + "' " + |
Jeremy Songster | 6949cea | 2016-04-19 18:13:18 -0700 | [diff] [blame] | 1206 | "command: " + str( handle ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1207 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1208 | except TypeError: |
| 1209 | main.log.exception( self.name + ": Object not as expected" ) |
| 1210 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1211 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1212 | main.log.error( self.name + ": EOF exception found" ) |
| 1213 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1214 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1215 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1216 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1217 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1218 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1219 | def getHost( self, mac ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1220 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1221 | Return the first host from the hosts api whose 'id' contains 'mac' |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1222 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1223 | 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] | 1224 | partial mac address |
| 1225 | |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1226 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1227 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1228 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1229 | if mac is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1230 | return None |
| 1231 | else: |
| 1232 | mac = mac |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1233 | rawHosts = self.hosts() |
| 1234 | hostsJson = json.loads( rawHosts ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1235 | # search json for the host with mac then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1236 | for host in hostsJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1237 | # print "%s in %s?" % ( mac, host[ 'id' ] ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1238 | if not host: |
| 1239 | pass |
| 1240 | elif mac in host[ 'id' ]: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1241 | return host |
| 1242 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1243 | except ( TypeError, ValueError ): |
| 1244 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawHosts ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1245 | return None |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1246 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1247 | main.log.error( self.name + ": EOF exception found" ) |
| 1248 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1249 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1250 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1251 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1252 | main.cleanAndExit() |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 1253 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1254 | def getHostsId( self, hostList ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1255 | """ |
| 1256 | Obtain list of hosts |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1257 | Issues command: 'onos> hosts' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1258 | |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1259 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1260 | * hostList: List of hosts obtained by Mininet |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1261 | IMPORTANT: |
| 1262 | This function assumes that you started your |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1263 | topology with the option '--mac'. |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1264 | Furthermore, it assumes that value of VLAN is '-1' |
| 1265 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1266 | Converts mininet hosts ( h1, h2, h3... ) into |
| 1267 | ONOS format ( 00:00:00:00:00:01/-1 , ... ) |
| 1268 | """ |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1269 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1270 | onosHostList = [] |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1271 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1272 | for host in hostList: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1273 | host = host.replace( "h", "" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1274 | hostHex = hex( int( host ) ).zfill( 12 ) |
| 1275 | hostHex = str( hostHex ).replace( 'x', '0' ) |
| 1276 | i = iter( str( hostHex ) ) |
| 1277 | hostHex = ":".join( a + b for a, b in zip( i, i ) ) |
| 1278 | hostHex = hostHex + "/-1" |
| 1279 | onosHostList.append( hostHex ) |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1280 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1281 | return onosHostList |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1282 | |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1283 | except TypeError: |
| 1284 | main.log.exception( self.name + ": Object not as expected" ) |
| 1285 | return None |
andrewonlab | 3f0a4af | 2014-10-17 12:25:14 -0400 | [diff] [blame] | 1286 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1287 | main.log.error( self.name + ": EOF exception found" ) |
| 1288 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1289 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1290 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1291 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1292 | main.cleanAndExit() |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 1293 | |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1294 | def verifyHostLocation( self, hostIp, location ): |
| 1295 | """ |
| 1296 | Description: |
| 1297 | Verify the host given is discovered in all locations expected |
| 1298 | Required: |
| 1299 | hostIp: IP address of the host |
| 1300 | location: expected location(s) of the given host. ex. "of:0000000000000005/8" |
| 1301 | Could be a string or list |
| 1302 | Returns: |
| 1303 | main.TRUE if host is discovered on all locations provided |
| 1304 | main.FALSE otherwise |
| 1305 | """ |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1306 | locations = [ location ] if isinstance( location, str ) else location |
| 1307 | assert isinstance( locations, list ), "Wrong type of location: {}".format( type( location ) ) |
| 1308 | try: |
| 1309 | hosts = self.hosts() |
| 1310 | hosts = json.loads( hosts ) |
| 1311 | targetHost = None |
| 1312 | for host in hosts: |
| 1313 | if hostIp in host[ "ipAddresses" ]: |
| 1314 | targetHost = host |
You Wang | fd80ab4 | 2018-05-10 17:21:53 -0700 | [diff] [blame] | 1315 | assert targetHost, "Not able to find host with IP {}".format( hostIp ) |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1316 | result = main.TRUE |
| 1317 | locationsDiscovered = [ loc[ "elementId" ] + "/" + loc[ "port" ] for loc in targetHost[ "locations" ] ] |
| 1318 | for loc in locations: |
| 1319 | discovered = False |
| 1320 | for locDiscovered in locationsDiscovered: |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1321 | locToMatch = locDiscovered if "/" in loc else locDiscovered.split( "/" )[0] |
| 1322 | if loc == locToMatch: |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1323 | main.log.debug( "Host {} discovered with location {}".format( hostIp, loc ) ) |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 1324 | discovered = True |
You Wang | bc898b8 | 2018-05-03 16:22:34 -0700 | [diff] [blame] | 1325 | break |
| 1326 | if discovered: |
| 1327 | locationsDiscovered.remove( locDiscovered ) |
| 1328 | else: |
| 1329 | main.log.warn( "Host {} not discovered with location {}".format( hostIp, loc ) ) |
| 1330 | result = main.FALSE |
| 1331 | if locationsDiscovered: |
| 1332 | main.log.warn( "Host {} is also discovered with location {}".format( hostIp, locationsDiscovered ) ) |
| 1333 | result = main.FALSE |
| 1334 | return result |
| 1335 | except KeyError: |
| 1336 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1337 | return None |
| 1338 | except pexpect.EOF: |
| 1339 | main.log.error( self.name + ": EOF exception found" ) |
| 1340 | main.log.error( self.name + ": " + self.handle.before ) |
| 1341 | main.cleanAndExit() |
| 1342 | except Exception: |
| 1343 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1344 | return None |
| 1345 | |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1346 | def verifyHostIp( self, hostList=[], prefix="" ): |
| 1347 | """ |
| 1348 | Description: |
| 1349 | Verify that all hosts have IP address assigned to them |
| 1350 | Optional: |
| 1351 | hostList: If specified, verifications only happen to the hosts |
| 1352 | in hostList |
| 1353 | prefix: at least one of the ip address assigned to the host |
| 1354 | needs to have the specified prefix |
| 1355 | Returns: |
| 1356 | main.TRUE if all hosts have specific IP address assigned; |
| 1357 | main.FALSE otherwise |
| 1358 | """ |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1359 | try: |
| 1360 | hosts = self.hosts() |
| 1361 | hosts = json.loads( hosts ) |
| 1362 | if not hostList: |
| 1363 | hostList = [ host[ "id" ] for host in hosts ] |
| 1364 | for host in hosts: |
| 1365 | hostId = host[ "id" ] |
| 1366 | if hostId not in hostList: |
| 1367 | continue |
| 1368 | ipList = host[ "ipAddresses" ] |
| 1369 | main.log.debug( self.name + ": IP list on host " + str( hostId ) + ": " + str( ipList ) ) |
| 1370 | if not ipList: |
| 1371 | main.log.warn( self.name + ": Failed to discover any IP addresses on host " + str( hostId ) ) |
| 1372 | else: |
| 1373 | if not any( ip.startswith( str( prefix ) ) for ip in ipList ): |
| 1374 | main.log.warn( self.name + ": None of the IPs on host " + str( hostId ) + " has prefix " + str( prefix ) ) |
| 1375 | else: |
| 1376 | main.log.debug( self.name + ": Found matching IP on host " + str( hostId ) ) |
| 1377 | hostList.remove( hostId ) |
| 1378 | if hostList: |
| 1379 | main.log.warn( self.name + ": failed to verify IP on following hosts: " + str( hostList) ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1380 | # Print info for debugging |
| 1381 | main.log.debug( self.name + ": hosts output: " + str( hosts ) ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 1382 | return main.FALSE |
| 1383 | else: |
| 1384 | return main.TRUE |
| 1385 | except KeyError: |
| 1386 | main.log.exception( self.name + ": host data not as expected: " + hosts ) |
| 1387 | return None |
| 1388 | except pexpect.EOF: |
| 1389 | main.log.error( self.name + ": EOF exception found" ) |
| 1390 | main.log.error( self.name + ": " + self.handle.before ) |
| 1391 | main.cleanAndExit() |
| 1392 | except Exception: |
| 1393 | main.log.exception( self.name + ": Uncaught exception" ) |
| 1394 | return None |
| 1395 | |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1396 | def addHostIntent( self, hostIdOne, hostIdTwo, vlanId="", setVlan="", encap="", bandwidth="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1397 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1398 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1399 | * hostIdOne: ONOS host id for host1 |
| 1400 | * hostIdTwo: ONOS host id for host2 |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1401 | Optional: |
| 1402 | * vlanId: specify a VLAN id for the intent |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1403 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1404 | * encap: specify an encapsulation type |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1405 | Description: |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1406 | Adds a host-to-host intent ( bidirectional ) by |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1407 | specifying the two hosts. |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1408 | Returns: |
| 1409 | A string of the intent id or None on Error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1410 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1411 | try: |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1412 | cmdStr = "add-host-intent " |
| 1413 | if vlanId: |
| 1414 | cmdStr += "-v " + str( vlanId ) + " " |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1415 | if setVlan: |
| 1416 | cmdStr += "--setVlan " + str( vlanId ) + " " |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1417 | if encap: |
| 1418 | cmdStr += "--encapsulation " + str( encap ) + " " |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 1419 | if bandwidth: |
| 1420 | cmdStr += "-b " + str( bandwidth ) + " " |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1421 | cmdStr += str( hostIdOne ) + " " + str( hostIdTwo ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1422 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1423 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1424 | assert "Command not found:" not in handle, handle |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1425 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1426 | main.log.error( self.name + ": Error in adding Host intent" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1427 | main.log.debug( "Response from ONOS was: " + repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1428 | return None |
Hari Krishna | ac4e178 | 2015-01-26 12:09:12 -0800 | [diff] [blame] | 1429 | else: |
| 1430 | main.log.info( "Host intent installed between " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1431 | str( hostIdOne ) + " and " + str( hostIdTwo ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1432 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1433 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1434 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1435 | else: |
| 1436 | main.log.error( "Error, intent ID not found" ) |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 1437 | main.log.debug( "Response from ONOS was: " + |
| 1438 | repr( handle ) ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1439 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1440 | except AssertionError: |
| 1441 | main.log.exception( "" ) |
| 1442 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1443 | except TypeError: |
| 1444 | main.log.exception( self.name + ": Object not as expected" ) |
| 1445 | return None |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1446 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1447 | main.log.error( self.name + ": EOF exception found" ) |
| 1448 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1449 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1450 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1451 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1452 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 1453 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1454 | def addOpticalIntent( self, ingressDevice, egressDevice ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1455 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1456 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1457 | * ingressDevice: device id of ingress device |
| 1458 | * egressDevice: device id of egress device |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1459 | Optional: |
| 1460 | TODO: Still needs to be implemented via dev side |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1461 | Description: |
| 1462 | Adds an optical intent by specifying an ingress and egress device |
| 1463 | Returns: |
| 1464 | A string of the intent id or None on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1465 | """ |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1466 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1467 | cmdStr = "add-optical-intent " + str( ingressDevice ) +\ |
| 1468 | " " + str( egressDevice ) |
| 1469 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1470 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1471 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1472 | # If error, return error message |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1473 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1474 | main.log.error( self.name + ": Error in adding Optical intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1475 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1476 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1477 | main.log.info( "Optical intent installed between " + |
| 1478 | str( ingressDevice ) + " and " + |
| 1479 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1480 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1481 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1482 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1483 | else: |
| 1484 | main.log.error( "Error, intent ID not found" ) |
| 1485 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1486 | except AssertionError: |
| 1487 | main.log.exception( "" ) |
| 1488 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1489 | except TypeError: |
| 1490 | main.log.exception( self.name + ": Object not as expected" ) |
| 1491 | return None |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1492 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1493 | main.log.error( self.name + ": EOF exception found" ) |
| 1494 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1495 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1496 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1497 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1498 | main.cleanAndExit() |
andrewonlab | 7b31d23 | 2014-10-24 13:31:47 -0400 | [diff] [blame] | 1499 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1500 | def addPointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1501 | self, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1502 | ingressDevice, |
| 1503 | egressDevice, |
| 1504 | portIngress="", |
| 1505 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1506 | ethType="", |
| 1507 | ethSrc="", |
| 1508 | ethDst="", |
| 1509 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1510 | lambdaAlloc=False, |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1511 | protected=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1512 | ipProto="", |
| 1513 | ipSrc="", |
| 1514 | ipDst="", |
| 1515 | tcpSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1516 | tcpDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1517 | vlanId="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1518 | setVlan="", |
| 1519 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1520 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1521 | Required: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1522 | * ingressDevice: device id of ingress device |
| 1523 | * egressDevice: device id of egress device |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1524 | Optional: |
| 1525 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1526 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1527 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 1528 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1529 | * lambdaAlloc: if True, intent will allocate lambda |
andrewonlab | 40ccd8b | 2014-11-06 16:23:34 -0500 | [diff] [blame] | 1530 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1531 | * ipProto: specify ip protocol |
andrewonlab | f77e0cb | 2014-11-11 17:17:59 -0500 | [diff] [blame] | 1532 | * ipSrc: specify ip source address |
| 1533 | * ipDst: specify ip destination address |
| 1534 | * tcpSrc: specify tcp source port |
| 1535 | * tcpDst: specify tcp destination port |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1536 | * vlanId: specify vlan ID |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1537 | * setVlan: specify a VLAN id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1538 | * encap: specify an Encapsulation type to use |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1539 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1540 | Adds a point-to-point intent ( uni-directional ) by |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1541 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1542 | Returns: |
| 1543 | A string of the intent id or None on error |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1544 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1545 | NOTE: This function may change depending on the |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1546 | options developers provide for point-to-point |
| 1547 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1548 | """ |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1549 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1550 | cmd = "add-point-intent" |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1551 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1552 | if ethType: |
| 1553 | cmd += " --ethType " + str( ethType ) |
| 1554 | if ethSrc: |
| 1555 | cmd += " --ethSrc " + str( ethSrc ) |
| 1556 | if ethDst: |
| 1557 | cmd += " --ethDst " + str( ethDst ) |
| 1558 | if bandwidth: |
| 1559 | cmd += " --bandwidth " + str( bandwidth ) |
| 1560 | if lambdaAlloc: |
| 1561 | cmd += " --lambda " |
| 1562 | if ipProto: |
| 1563 | cmd += " --ipProto " + str( ipProto ) |
| 1564 | if ipSrc: |
| 1565 | cmd += " --ipSrc " + str( ipSrc ) |
| 1566 | if ipDst: |
| 1567 | cmd += " --ipDst " + str( ipDst ) |
| 1568 | if tcpSrc: |
| 1569 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1570 | if tcpDst: |
| 1571 | cmd += " --tcpDst " + str( tcpDst ) |
| 1572 | if vlanId: |
| 1573 | cmd += " -v " + str( vlanId ) |
| 1574 | if setVlan: |
| 1575 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1576 | if encap: |
| 1577 | cmd += " --encapsulation " + str( encap ) |
alison | da15727 | 2016-12-22 01:13:21 -0800 | [diff] [blame] | 1578 | if protected: |
| 1579 | cmd += " --protect " |
andrewonlab | 289e4b7 | 2014-10-21 21:24:18 -0400 | [diff] [blame] | 1580 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1581 | # Check whether the user appended the port |
| 1582 | # or provided it as an input |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1583 | if "/" in ingressDevice: |
| 1584 | cmd += " " + str( ingressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1585 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1586 | if not portIngress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1587 | main.log.error( "You must specify the ingress port" ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1588 | # TODO: perhaps more meaningful return |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1589 | # Would it make sense to throw an exception and exit |
| 1590 | # the test? |
| 1591 | return None |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1592 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1593 | cmd += " " + \ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1594 | str( ingressDevice ) + "/" +\ |
| 1595 | str( portIngress ) + " " |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1596 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1597 | if "/" in egressDevice: |
| 1598 | cmd += " " + str( egressDevice ) |
andrewonlab | 36af382 | 2014-11-18 17:48:18 -0500 | [diff] [blame] | 1599 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1600 | if not portEgress: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1601 | main.log.error( "You must specify the egress port" ) |
| 1602 | return None |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1603 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1604 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1605 | str( egressDevice ) + "/" +\ |
| 1606 | str( portEgress ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1607 | |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1608 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1609 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1610 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1611 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1612 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1613 | main.log.error( self.name + ": Error in adding point-to-point intent" ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1614 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1615 | else: |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1616 | # TODO: print out all the options in this message? |
| 1617 | main.log.info( "Point-to-point intent installed between " + |
| 1618 | str( ingressDevice ) + " and " + |
| 1619 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1620 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1621 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1622 | return match.group()[ 3:-1 ] |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1623 | else: |
| 1624 | main.log.error( "Error, intent ID not found" ) |
| 1625 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1626 | except AssertionError: |
| 1627 | main.log.exception( "" ) |
| 1628 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1629 | except TypeError: |
| 1630 | main.log.exception( self.name + ": Object not as expected" ) |
| 1631 | return None |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1632 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1633 | main.log.error( self.name + ": EOF exception found" ) |
| 1634 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1635 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1636 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1637 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1638 | main.cleanAndExit() |
andrewonlab | 4dbb4d8 | 2014-10-17 18:22:31 -0400 | [diff] [blame] | 1639 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1640 | def addMultipointToSinglepointIntent( |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1641 | self, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1642 | ingressDeviceList, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1643 | egressDevice, |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1644 | portIngressList=None, |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1645 | portEgress="", |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1646 | ethType="", |
| 1647 | ethSrc="", |
| 1648 | ethDst="", |
| 1649 | bandwidth="", |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1650 | lambdaAlloc=False, |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1651 | ipProto="", |
| 1652 | ipSrc="", |
| 1653 | ipDst="", |
| 1654 | tcpSrc="", |
| 1655 | tcpDst="", |
| 1656 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1657 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1658 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1659 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1660 | partial=False, |
| 1661 | encap="" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1662 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1663 | Note: |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1664 | This function assumes the format of all ingress devices |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1665 | is same. That is, all ingress devices include port numbers |
| 1666 | with a "/" or all ingress devices could specify device |
| 1667 | ids and port numbers seperately. |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1668 | Required: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1669 | * ingressDeviceList: List of device ids of ingress device |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1670 | ( Atleast 2 ingress devices required in the list ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1671 | * egressDevice: device id of egress device |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1672 | Optional: |
| 1673 | * ethType: specify ethType |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1674 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1675 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1676 | * bandwidth: specify bandwidth capacity of link |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1677 | * lambdaAlloc: if True, intent will allocate lambda |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1678 | for the specified intent |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1679 | * ipProto: specify ip protocol |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1680 | * ipSrc: specify ip source address |
| 1681 | * ipDst: specify ip destination address |
| 1682 | * tcpSrc: specify tcp source port |
| 1683 | * tcpDst: specify tcp destination port |
| 1684 | * setEthSrc: action to Rewrite Source MAC Address |
| 1685 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1686 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1687 | * setVlan: specify VLAN Id treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1688 | * encap: specify a type of encapsulation |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1689 | Description: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1690 | Adds a multipoint-to-singlepoint intent ( uni-directional ) by |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1691 | specifying device id's and optional fields |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1692 | Returns: |
| 1693 | A string of the intent id or None on error |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1694 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1695 | NOTE: This function may change depending on the |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 1696 | options developers provide for multipoint-to-singlepoint |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1697 | intent via cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1698 | """ |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1699 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1700 | cmd = "add-multi-to-single-intent" |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1701 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1702 | if ethType: |
| 1703 | cmd += " --ethType " + str( ethType ) |
| 1704 | if ethSrc: |
| 1705 | cmd += " --ethSrc " + str( ethSrc ) |
| 1706 | if ethDst: |
| 1707 | cmd += " --ethDst " + str( ethDst ) |
| 1708 | if bandwidth: |
| 1709 | cmd += " --bandwidth " + str( bandwidth ) |
| 1710 | if lambdaAlloc: |
| 1711 | cmd += " --lambda " |
| 1712 | if ipProto: |
| 1713 | cmd += " --ipProto " + str( ipProto ) |
| 1714 | if ipSrc: |
| 1715 | cmd += " --ipSrc " + str( ipSrc ) |
| 1716 | if ipDst: |
| 1717 | cmd += " --ipDst " + str( ipDst ) |
| 1718 | if tcpSrc: |
| 1719 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1720 | if tcpDst: |
| 1721 | cmd += " --tcpDst " + str( tcpDst ) |
| 1722 | if setEthSrc: |
| 1723 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1724 | if setEthDst: |
| 1725 | cmd += " --setEthDst " + str( setEthDst ) |
| 1726 | if vlanId: |
| 1727 | cmd += " -v " + str( vlanId ) |
| 1728 | if setVlan: |
| 1729 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1730 | if partial: |
| 1731 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1732 | if encap: |
| 1733 | cmd += " --encapsulation " + str( encap ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1734 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1735 | # Check whether the user appended the port |
| 1736 | # or provided it as an input |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1737 | |
| 1738 | if portIngressList is None: |
| 1739 | for ingressDevice in ingressDeviceList: |
| 1740 | if "/" in ingressDevice: |
| 1741 | cmd += " " + str( ingressDevice ) |
| 1742 | else: |
| 1743 | main.log.error( "You must specify " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 1744 | "the ingress port" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1745 | # TODO: perhaps more meaningful return |
| 1746 | return main.FALSE |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1747 | else: |
Jon Hall | 71ce4e7 | 2015-03-23 14:05:58 -0700 | [diff] [blame] | 1748 | if len( ingressDeviceList ) == len( portIngressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1749 | for ingressDevice, portIngress in zip( ingressDeviceList, |
| 1750 | portIngressList ): |
shahshreya | 70622b1 | 2015-03-19 17:19:00 -0700 | [diff] [blame] | 1751 | cmd += " " + \ |
| 1752 | str( ingressDevice ) + "/" +\ |
| 1753 | str( portIngress ) + " " |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1754 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1755 | main.log.error( "Device list and port list does not " + |
| 1756 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1757 | return main.FALSE |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1758 | if "/" in egressDevice: |
| 1759 | cmd += " " + str( egressDevice ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1760 | else: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1761 | if not portEgress: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1762 | main.log.error( "You must specify " + |
| 1763 | "the egress port" ) |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1764 | return main.FALSE |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 1765 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1766 | cmd += " " +\ |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 1767 | str( egressDevice ) + "/" +\ |
| 1768 | str( portEgress ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1769 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1770 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1771 | assert "Command not found:" not in handle, handle |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1772 | # If error, return error message |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 1773 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1774 | main.log.error( self.name + ": Error in adding multipoint-to-singlepoint " + |
kelvin-onlab | fb52166 | 2015-02-27 09:52:40 -0800 | [diff] [blame] | 1775 | "intent" ) |
| 1776 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1777 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1778 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1779 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1780 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1781 | else: |
| 1782 | main.log.error( "Error, intent ID not found" ) |
| 1783 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1784 | except AssertionError: |
| 1785 | main.log.exception( "" ) |
| 1786 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1787 | except TypeError: |
| 1788 | main.log.exception( self.name + ": Object not as expected" ) |
| 1789 | return None |
| 1790 | except pexpect.EOF: |
| 1791 | main.log.error( self.name + ": EOF exception found" ) |
| 1792 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1793 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1794 | except Exception: |
| 1795 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1796 | main.cleanAndExit() |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1797 | |
| 1798 | def addSinglepointToMultipointIntent( |
| 1799 | self, |
| 1800 | ingressDevice, |
| 1801 | egressDeviceList, |
| 1802 | portIngress="", |
| 1803 | portEgressList=None, |
| 1804 | ethType="", |
| 1805 | ethSrc="", |
| 1806 | ethDst="", |
| 1807 | bandwidth="", |
| 1808 | lambdaAlloc=False, |
| 1809 | ipProto="", |
| 1810 | ipSrc="", |
| 1811 | ipDst="", |
| 1812 | tcpSrc="", |
| 1813 | tcpDst="", |
| 1814 | setEthSrc="", |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1815 | setEthDst="", |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1816 | vlanId="", |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1817 | setVlan="", |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1818 | partial=False, |
| 1819 | encap="" ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1820 | """ |
| 1821 | Note: |
| 1822 | This function assumes the format of all egress devices |
| 1823 | is same. That is, all egress devices include port numbers |
| 1824 | with a "/" or all egress devices could specify device |
| 1825 | ids and port numbers seperately. |
| 1826 | Required: |
| 1827 | * EgressDeviceList: List of device ids of egress device |
| 1828 | ( Atleast 2 eress devices required in the list ) |
| 1829 | * ingressDevice: device id of ingress device |
| 1830 | Optional: |
| 1831 | * ethType: specify ethType |
| 1832 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1833 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1834 | * bandwidth: specify bandwidth capacity of link |
| 1835 | * lambdaAlloc: if True, intent will allocate lambda |
| 1836 | for the specified intent |
| 1837 | * ipProto: specify ip protocol |
| 1838 | * ipSrc: specify ip source address |
| 1839 | * ipDst: specify ip destination address |
| 1840 | * tcpSrc: specify tcp source port |
| 1841 | * tcpDst: specify tcp destination port |
| 1842 | * setEthSrc: action to Rewrite Source MAC Address |
| 1843 | * setEthDst: action to Rewrite Destination MAC Address |
Jeremy Songster | 832f9e9 | 2016-05-05 14:30:49 -0700 | [diff] [blame] | 1844 | * vlanId: specify vlan Id |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1845 | * setVlan: specify VLAN ID treatment |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1846 | * encap: specify an encapsulation type |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1847 | Description: |
| 1848 | Adds a singlepoint-to-multipoint intent ( uni-directional ) by |
| 1849 | specifying device id's and optional fields |
| 1850 | Returns: |
| 1851 | A string of the intent id or None on error |
| 1852 | |
| 1853 | NOTE: This function may change depending on the |
| 1854 | options developers provide for singlepoint-to-multipoint |
| 1855 | intent via cli |
| 1856 | """ |
| 1857 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1858 | cmd = "add-single-to-multi-intent" |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1859 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 1860 | if ethType: |
| 1861 | cmd += " --ethType " + str( ethType ) |
| 1862 | if ethSrc: |
| 1863 | cmd += " --ethSrc " + str( ethSrc ) |
| 1864 | if ethDst: |
| 1865 | cmd += " --ethDst " + str( ethDst ) |
| 1866 | if bandwidth: |
| 1867 | cmd += " --bandwidth " + str( bandwidth ) |
| 1868 | if lambdaAlloc: |
| 1869 | cmd += " --lambda " |
| 1870 | if ipProto: |
| 1871 | cmd += " --ipProto " + str( ipProto ) |
| 1872 | if ipSrc: |
| 1873 | cmd += " --ipSrc " + str( ipSrc ) |
| 1874 | if ipDst: |
| 1875 | cmd += " --ipDst " + str( ipDst ) |
| 1876 | if tcpSrc: |
| 1877 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 1878 | if tcpDst: |
| 1879 | cmd += " --tcpDst " + str( tcpDst ) |
| 1880 | if setEthSrc: |
| 1881 | cmd += " --setEthSrc " + str( setEthSrc ) |
| 1882 | if setEthDst: |
| 1883 | cmd += " --setEthDst " + str( setEthDst ) |
| 1884 | if vlanId: |
| 1885 | cmd += " -v " + str( vlanId ) |
| 1886 | if setVlan: |
| 1887 | cmd += " --setVlan " + str( setVlan ) |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 1888 | if partial: |
| 1889 | cmd += " --partial" |
Jeremy Songster | c032f16 | 2016-08-04 17:14:49 -0700 | [diff] [blame] | 1890 | if encap: |
| 1891 | cmd += " --encapsulation " + str( encap ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1892 | |
| 1893 | # Check whether the user appended the port |
| 1894 | # or provided it as an input |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1895 | |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1896 | if "/" in ingressDevice: |
| 1897 | cmd += " " + str( ingressDevice ) |
| 1898 | else: |
| 1899 | if not portIngress: |
| 1900 | main.log.error( "You must specify " + |
| 1901 | "the Ingress port" ) |
| 1902 | return main.FALSE |
| 1903 | |
| 1904 | cmd += " " +\ |
| 1905 | str( ingressDevice ) + "/" +\ |
| 1906 | str( portIngress ) |
| 1907 | |
| 1908 | if portEgressList is None: |
| 1909 | for egressDevice in egressDeviceList: |
| 1910 | if "/" in egressDevice: |
| 1911 | cmd += " " + str( egressDevice ) |
| 1912 | else: |
| 1913 | main.log.error( "You must specify " + |
| 1914 | "the egress port" ) |
| 1915 | # TODO: perhaps more meaningful return |
| 1916 | return main.FALSE |
| 1917 | else: |
| 1918 | if len( egressDeviceList ) == len( portEgressList ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1919 | for egressDevice, portEgress in zip( egressDeviceList, |
| 1920 | portEgressList ): |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1921 | cmd += " " + \ |
| 1922 | str( egressDevice ) + "/" +\ |
| 1923 | str( portEgress ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1924 | else: |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 1925 | main.log.error( "Device list and port list does not " + |
| 1926 | "have the same length" ) |
kelvin-onlab | 3814381 | 2015-04-01 15:03:01 -0700 | [diff] [blame] | 1927 | return main.FALSE |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1928 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 1929 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1930 | assert "Command not found:" not in handle, handle |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1931 | # If error, return error message |
| 1932 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 1933 | main.log.error( self.name + ": Error in adding singlepoint-to-multipoint " + |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1934 | "intent" ) |
shahshreya | c2f9707 | 2015-03-19 17:04:29 -0700 | [diff] [blame] | 1935 | return None |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1936 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1937 | match = re.search( 'id=0x([\da-f]+),', handle ) |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1938 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1939 | return match.group()[ 3:-1 ] |
kelvin-onlab | b940821 | 2015-04-01 13:34:04 -0700 | [diff] [blame] | 1940 | else: |
| 1941 | main.log.error( "Error, intent ID not found" ) |
| 1942 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 1943 | except AssertionError: |
| 1944 | main.log.exception( "" ) |
| 1945 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1946 | except TypeError: |
| 1947 | main.log.exception( self.name + ": Object not as expected" ) |
| 1948 | return None |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1949 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 1950 | main.log.error( self.name + ": EOF exception found" ) |
| 1951 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1952 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 1953 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 1954 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1955 | main.cleanAndExit() |
shahshreya | d0c8043 | 2014-12-04 16:56:05 -0800 | [diff] [blame] | 1956 | |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1957 | def addMplsIntent( |
| 1958 | self, |
| 1959 | ingressDevice, |
| 1960 | egressDevice, |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1961 | ingressPort="", |
| 1962 | egressPort="", |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1963 | ethType="", |
| 1964 | ethSrc="", |
| 1965 | ethDst="", |
| 1966 | bandwidth="", |
| 1967 | lambdaAlloc=False, |
| 1968 | ipProto="", |
| 1969 | ipSrc="", |
| 1970 | ipDst="", |
| 1971 | tcpSrc="", |
| 1972 | tcpDst="", |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 1973 | ingressLabel="", |
Hari Krishna | dfff667 | 2015-04-13 17:53:27 -0700 | [diff] [blame] | 1974 | egressLabel="", |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1975 | priority="" ): |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 1976 | """ |
| 1977 | Required: |
| 1978 | * ingressDevice: device id of ingress device |
| 1979 | * egressDevice: device id of egress device |
| 1980 | Optional: |
| 1981 | * ethType: specify ethType |
| 1982 | * ethSrc: specify ethSrc ( i.e. src mac addr ) |
| 1983 | * ethDst: specify ethDst ( i.e. dst mac addr ) |
| 1984 | * bandwidth: specify bandwidth capacity of link |
| 1985 | * lambdaAlloc: if True, intent will allocate lambda |
| 1986 | for the specified intent |
| 1987 | * ipProto: specify ip protocol |
| 1988 | * ipSrc: specify ip source address |
| 1989 | * ipDst: specify ip destination address |
| 1990 | * tcpSrc: specify tcp source port |
| 1991 | * tcpDst: specify tcp destination port |
| 1992 | * ingressLabel: Ingress MPLS label |
| 1993 | * egressLabel: Egress MPLS label |
| 1994 | Description: |
| 1995 | Adds MPLS intent by |
| 1996 | specifying device id's and optional fields |
| 1997 | Returns: |
| 1998 | A string of the intent id or None on error |
| 1999 | |
| 2000 | NOTE: This function may change depending on the |
| 2001 | options developers provide for MPLS |
| 2002 | intent via cli |
| 2003 | """ |
| 2004 | try: |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 2005 | cmd = "add-mpls-intent" |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2006 | |
Jeremy Songster | ff55367 | 2016-05-12 17:06:23 -0700 | [diff] [blame] | 2007 | if ethType: |
| 2008 | cmd += " --ethType " + str( ethType ) |
| 2009 | if ethSrc: |
| 2010 | cmd += " --ethSrc " + str( ethSrc ) |
| 2011 | if ethDst: |
| 2012 | cmd += " --ethDst " + str( ethDst ) |
| 2013 | if bandwidth: |
| 2014 | cmd += " --bandwidth " + str( bandwidth ) |
| 2015 | if lambdaAlloc: |
| 2016 | cmd += " --lambda " |
| 2017 | if ipProto: |
| 2018 | cmd += " --ipProto " + str( ipProto ) |
| 2019 | if ipSrc: |
| 2020 | cmd += " --ipSrc " + str( ipSrc ) |
| 2021 | if ipDst: |
| 2022 | cmd += " --ipDst " + str( ipDst ) |
| 2023 | if tcpSrc: |
| 2024 | cmd += " --tcpSrc " + str( tcpSrc ) |
| 2025 | if tcpDst: |
| 2026 | cmd += " --tcpDst " + str( tcpDst ) |
| 2027 | if ingressLabel: |
| 2028 | cmd += " --ingressLabel " + str( ingressLabel ) |
| 2029 | if egressLabel: |
| 2030 | cmd += " --egressLabel " + str( egressLabel ) |
| 2031 | if priority: |
| 2032 | cmd += " --priority " + str( priority ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2033 | |
| 2034 | # Check whether the user appended the port |
| 2035 | # or provided it as an input |
| 2036 | if "/" in ingressDevice: |
| 2037 | cmd += " " + str( ingressDevice ) |
| 2038 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2039 | if not ingressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2040 | main.log.error( "You must specify the ingress port" ) |
| 2041 | return None |
| 2042 | |
| 2043 | cmd += " " + \ |
| 2044 | str( ingressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2045 | str( ingressPort ) + " " |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2046 | |
| 2047 | if "/" in egressDevice: |
| 2048 | cmd += " " + str( egressDevice ) |
| 2049 | else: |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2050 | if not egressPort: |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2051 | main.log.error( "You must specify the egress port" ) |
| 2052 | return None |
| 2053 | |
| 2054 | cmd += " " +\ |
| 2055 | str( egressDevice ) + "/" +\ |
Hari Krishna | 87a17f1 | 2015-04-13 17:42:23 -0700 | [diff] [blame] | 2056 | str( egressPort ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2057 | |
| 2058 | handle = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2059 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2060 | assert "Command not found:" not in handle, handle |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2061 | # If error, return error message |
| 2062 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2063 | main.log.error( self.name + ": Error in adding mpls intent" ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2064 | return None |
| 2065 | else: |
| 2066 | # TODO: print out all the options in this message? |
| 2067 | main.log.info( "MPLS intent installed between " + |
| 2068 | str( ingressDevice ) + " and " + |
| 2069 | str( egressDevice ) ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2070 | match = re.search( 'id=0x([\da-f]+),', handle ) |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2071 | if match: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2072 | return match.group()[ 3:-1 ] |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2073 | else: |
| 2074 | main.log.error( "Error, intent ID not found" ) |
| 2075 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2076 | except AssertionError: |
| 2077 | main.log.exception( "" ) |
| 2078 | return None |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2079 | except TypeError: |
| 2080 | main.log.exception( self.name + ": Object not as expected" ) |
| 2081 | return None |
| 2082 | except pexpect.EOF: |
| 2083 | main.log.error( self.name + ": EOF exception found" ) |
| 2084 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2085 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2086 | except Exception: |
| 2087 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2088 | main.cleanAndExit() |
Hari Krishna | 9e23260 | 2015-04-13 17:29:08 -0700 | [diff] [blame] | 2089 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2090 | def removeIntent( self, intentId, app='org.onosproject.cli', |
| 2091 | purge=False, sync=False ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2092 | """ |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2093 | Remove intent for specified application id and intent id |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2094 | Optional args:- |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2095 | -s or --sync: Waits for the removal before returning |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 2096 | -p or --purge: Purge the intent from the store after removal |
| 2097 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2098 | Returns: |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 2099 | main.FALSE on error and |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2100 | cli output otherwise |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2101 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2102 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2103 | cmdStr = "remove-intent" |
shahshreya | 1c818fc | 2015-02-26 13:44:08 -0800 | [diff] [blame] | 2104 | if purge: |
| 2105 | cmdStr += " -p" |
| 2106 | if sync: |
| 2107 | cmdStr += " -s" |
| 2108 | |
| 2109 | cmdStr += " " + app + " " + str( intentId ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2110 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2111 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2112 | assert "Command not found:" not in handle, handle |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2113 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2114 | main.log.error( self.name + ": Error in removing intent" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2115 | return main.FALSE |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2116 | else: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2117 | # TODO: Should this be main.TRUE |
| 2118 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2119 | except AssertionError: |
| 2120 | main.log.exception( "" ) |
| 2121 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2122 | except TypeError: |
| 2123 | main.log.exception( self.name + ": Object not as expected" ) |
| 2124 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2125 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2126 | main.log.error( self.name + ": EOF exception found" ) |
| 2127 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2128 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2129 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2130 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2131 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2132 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2133 | def removeAllIntents( self, purge=False, sync=False, app='org.onosproject.cli', timeout=30 ): |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2134 | """ |
| 2135 | Description: |
| 2136 | Remove all the intents |
| 2137 | Optional args:- |
| 2138 | -s or --sync: Waits for the removal before returning |
| 2139 | -p or --purge: Purge the intent from the store after removal |
| 2140 | Returns: |
| 2141 | Returns main.TRUE if all intents are removed, otherwise returns |
| 2142 | main.FALSE; Returns None for exception |
| 2143 | """ |
| 2144 | try: |
| 2145 | cmdStr = "remove-intent" |
| 2146 | if purge: |
| 2147 | cmdStr += " -p" |
| 2148 | if sync: |
| 2149 | cmdStr += " -s" |
| 2150 | |
| 2151 | cmdStr += " " + app |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 2152 | handle = self.sendline( cmdStr, timeout=timeout ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2153 | assert handle is not None, "Error in sendline" |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2154 | assert "Command not found:" not in handle, handle |
| 2155 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2156 | main.log.error( self.name + ": Error in removing intent" ) |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2157 | return main.FALSE |
| 2158 | else: |
| 2159 | return main.TRUE |
| 2160 | except AssertionError: |
| 2161 | main.log.exception( "" ) |
| 2162 | return None |
| 2163 | except TypeError: |
| 2164 | main.log.exception( self.name + ": Object not as expected" ) |
| 2165 | return None |
| 2166 | except pexpect.EOF: |
| 2167 | main.log.error( self.name + ": EOF exception found" ) |
| 2168 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2169 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2170 | except Exception: |
| 2171 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2172 | main.cleanAndExit() |
Jeremy | 42df2e7 | 2016-02-23 16:37:46 -0800 | [diff] [blame] | 2173 | |
Hari Krishna | acabd5a | 2015-07-01 17:10:19 -0700 | [diff] [blame] | 2174 | def purgeWithdrawnIntents( self ): |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2175 | """ |
| 2176 | Purges all WITHDRAWN Intents |
| 2177 | """ |
| 2178 | try: |
| 2179 | cmdStr = "purge-intents" |
| 2180 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2181 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2182 | assert "Command not found:" not in handle, handle |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2183 | if re.search( "Error", handle ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2184 | main.log.error( self.name + ": Error in purging intents" ) |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2185 | return main.FALSE |
| 2186 | else: |
| 2187 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2188 | except AssertionError: |
| 2189 | main.log.exception( "" ) |
| 2190 | return None |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2191 | except TypeError: |
| 2192 | main.log.exception( self.name + ": Object not as expected" ) |
| 2193 | return None |
| 2194 | except pexpect.EOF: |
| 2195 | main.log.error( self.name + ": EOF exception found" ) |
| 2196 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2197 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2198 | except Exception: |
| 2199 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2200 | main.cleanAndExit() |
Hari Krishna | 0ce0e15 | 2015-06-23 09:55:29 -0700 | [diff] [blame] | 2201 | |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 2202 | def wipeout( self ): |
| 2203 | """ |
| 2204 | Wipe out the flows,intents,links,devices,hosts, and groups from the ONOS. |
| 2205 | """ |
| 2206 | try: |
| 2207 | cmdStr = "wipe-out please" |
| 2208 | handle = self.sendline( cmdStr, timeout=60 ) |
| 2209 | assert handle is not None, "Error in sendline" |
| 2210 | assert "Command not found:" not in handle, handle |
| 2211 | return main.TRUE |
| 2212 | except AssertionError: |
| 2213 | main.log.exception( "" ) |
| 2214 | return None |
| 2215 | except TypeError: |
| 2216 | main.log.exception( self.name + ": Object not as expected" ) |
| 2217 | return None |
| 2218 | except pexpect.EOF: |
| 2219 | main.log.error( self.name + ": EOF exception found" ) |
| 2220 | main.log.error( self.name + ": " + self.handle.before ) |
| 2221 | main.cleanAndExit() |
| 2222 | except Exception: |
| 2223 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 2224 | main.cleanAndExit() |
| 2225 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2226 | def routes( self, jsonFormat=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2227 | """ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2228 | NOTE: This method should be used after installing application: |
| 2229 | onos-app-sdnip |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2230 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2231 | * jsonFormat: enable output formatting in json |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2232 | Description: |
| 2233 | Obtain all routes in the system |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2234 | """ |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2235 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2236 | cmdStr = "routes" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2237 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2238 | cmdStr += " -j" |
| 2239 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2240 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2241 | assert "Command not found:" not in handle, handle |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2242 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2243 | except AssertionError: |
| 2244 | main.log.exception( "" ) |
| 2245 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2246 | except TypeError: |
| 2247 | main.log.exception( self.name + ": Object not as expected" ) |
| 2248 | return None |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2249 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2250 | main.log.error( self.name + ": EOF exception found" ) |
| 2251 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2252 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2253 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2254 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2255 | main.cleanAndExit() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2256 | |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2257 | def ipv4RouteNumber( self ): |
| 2258 | """ |
| 2259 | NOTE: This method should be used after installing application: |
| 2260 | onos-app-sdnip |
| 2261 | Description: |
| 2262 | Obtain the total IPv4 routes number in the system |
| 2263 | """ |
| 2264 | try: |
Pratik Parab | 5796357 | 2017-05-09 11:37:54 -0700 | [diff] [blame] | 2265 | cmdStr = "routes -j" |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2266 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2267 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2268 | assert "Command not found:" not in handle, handle |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2269 | jsonResult = json.loads( handle ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2270 | return len( jsonResult[ 'routes4' ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2271 | except AssertionError: |
| 2272 | main.log.exception( "" ) |
| 2273 | return None |
| 2274 | except ( TypeError, ValueError ): |
| 2275 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2276 | return None |
| 2277 | except pexpect.EOF: |
| 2278 | main.log.error( self.name + ": EOF exception found" ) |
| 2279 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2280 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2281 | except Exception: |
| 2282 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2283 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2284 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2285 | # =============Function to check Bandwidth allocation======== |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2286 | def allocations( self, jsonFormat = True ): |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2287 | """ |
| 2288 | Description: |
| 2289 | Obtain Bandwidth Allocation Information from ONOS cli. |
| 2290 | """ |
| 2291 | try: |
| 2292 | cmdStr = "allocations" |
| 2293 | if jsonFormat: |
| 2294 | cmdStr += " -j" |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 2295 | handle = self.sendline( cmdStr, timeout=300 ) |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2296 | assert handle is not None, "Error in sendline" |
| 2297 | assert "Command not found:" not in handle, handle |
| 2298 | return handle |
| 2299 | except AssertionError: |
| 2300 | main.log.exception( "" ) |
| 2301 | return None |
| 2302 | except ( TypeError, ValueError ): |
| 2303 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
| 2304 | return None |
| 2305 | except pexpect.EOF: |
| 2306 | main.log.error( self.name + ": EOF exception found" ) |
| 2307 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2308 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2309 | except Exception: |
| 2310 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2311 | main.cleanAndExit() |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2312 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2313 | def intents( self, jsonFormat = True, summary = False, **intentargs ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2314 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2315 | Description: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2316 | Obtain intents from the ONOS cli. |
| 2317 | Optional: |
| 2318 | * jsonFormat: Enable output formatting in json, default to True |
| 2319 | * summary: Whether only output the intent summary, defaults to False |
| 2320 | * type: Only output a certain type of intent. This options is valid |
| 2321 | only when jsonFormat is True and summary is True. |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2322 | """ |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2323 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2324 | cmdStr = "intents" |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2325 | if summary: |
| 2326 | cmdStr += " -s" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2327 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2328 | cmdStr += " -j" |
Shreya Chowdhary | 6fbb96c | 2017-05-02 16:20:19 -0700 | [diff] [blame] | 2329 | handle = self.sendline( cmdStr, timeout=300 ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2330 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2331 | assert "Command not found:" not in handle, handle |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2332 | args = utilities.parse_args( [ "TYPE" ], **intentargs ) |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2333 | if "TYPE" in args.keys(): |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2334 | intentType = args[ "TYPE" ] |
acsmars | 5b5fbaf | 2015-09-18 10:38:20 -0700 | [diff] [blame] | 2335 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2336 | intentType = "" |
| 2337 | # IF we want the summary of a specific intent type |
| 2338 | if jsonFormat and summary and ( intentType != "" ): |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2339 | jsonResult = json.loads( handle ) |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2340 | if intentType in jsonResult.keys(): |
| 2341 | return jsonResult[ intentType ] |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2342 | else: |
Jon Hall | ff566d5 | 2016-01-15 14:45:36 -0800 | [diff] [blame] | 2343 | main.log.error( "unknown TYPE, returning all types of intents" ) |
pingping-lin | 8244a3b | 2015-09-16 13:36:56 -0700 | [diff] [blame] | 2344 | return handle |
| 2345 | else: |
| 2346 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2347 | except AssertionError: |
| 2348 | main.log.exception( "" ) |
| 2349 | return None |
| 2350 | except ( TypeError, ValueError ): |
| 2351 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, handle ) ) |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2352 | return None |
| 2353 | except pexpect.EOF: |
| 2354 | main.log.error( self.name + ": EOF exception found" ) |
| 2355 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2356 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2357 | except Exception: |
| 2358 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2359 | main.cleanAndExit() |
pingping-lin | 54b0337 | 2015-08-13 14:43:10 -0700 | [diff] [blame] | 2360 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2361 | def getIntentState( self, intentsId, intentsJson=None ): |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2362 | """ |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2363 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2364 | Gets intent state. Accepts a single intent ID (string type) or a |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2365 | list of intent IDs. |
| 2366 | Parameters: |
| 2367 | intentsId: intent ID, both string type and list type are acceptable |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2368 | intentsJson: parsed json object from the onos:intents api |
You Wang | fdcbfc4 | 2016-05-16 12:16:53 -0700 | [diff] [blame] | 2369 | Returns: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2370 | 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] | 2371 | accepted. |
| 2372 | Returns a list of dictionaries if a list of intent IDs is accepted, |
| 2373 | and each dictionary maps 'id' to the Intent ID and 'state' to |
| 2374 | corresponding intent state. |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2375 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2376 | |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2377 | try: |
| 2378 | state = "State is Undefined" |
| 2379 | if not intentsJson: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2380 | rawJson = self.intents() |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2381 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2382 | rawJson = intentsJson |
| 2383 | parsedIntentsJson = json.loads( rawJson ) |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2384 | if isinstance( intentsId, types.StringType ): |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2385 | for intent in parsedIntentsJson: |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2386 | if intentsId == intent[ 'id' ]: |
| 2387 | state = intent[ 'state' ] |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2388 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2389 | main.log.info( "Cannot find intent ID" + str( intentsId ) + |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2390 | " in the list" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2391 | return state |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2392 | elif isinstance( intentsId, types.ListType ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2393 | dictList = [] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2394 | for i in xrange( len( intentsId ) ): |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2395 | stateDict = {} |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2396 | for intent in parsedIntentsJson: |
| 2397 | if intentsId[ i ] == intent[ 'id' ]: |
| 2398 | stateDict[ 'state' ] = intent[ 'state' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2399 | stateDict[ 'id' ] = intentsId[ i ] |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2400 | dictList.append( stateDict ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2401 | break |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 2402 | if len( intentsId ) != len( dictList ): |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2403 | main.log.warn( "Could not find all intents in ONOS output" ) |
| 2404 | main.log.debug( "expected ids: {} \n ONOS intents: {}".format( intentsId, parsedIntentsJson ) ) |
kelvin-onlab | 07dbd01 | 2015-03-04 16:29:39 -0800 | [diff] [blame] | 2405 | return dictList |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2406 | else: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2407 | main.log.info( "Invalid type for intentsId argument" ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2408 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2409 | except ( TypeError, ValueError ): |
| 2410 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2411 | return None |
| 2412 | except pexpect.EOF: |
| 2413 | main.log.error( self.name + ": EOF exception found" ) |
| 2414 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2415 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2416 | except Exception: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 2417 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2418 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 2419 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2420 | def checkIntentState( self, intentsId, expectedState='INSTALLED' ): |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2421 | """ |
| 2422 | Description: |
| 2423 | Check intents state |
| 2424 | Required: |
| 2425 | intentsId - List of intents ID to be checked |
| 2426 | Optional: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2427 | expectedState - Check the expected state(s) of each intents |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2428 | state in the list. |
| 2429 | *NOTE: You can pass in a list of expected state, |
| 2430 | Eg: expectedState = [ 'INSTALLED' , 'INSTALLING' ] |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2431 | Return: |
Jon Hall | 5315808 | 2017-05-18 11:17:00 -0700 | [diff] [blame] | 2432 | Returns main.TRUE only if all intent are the same as expected states, |
| 2433 | otherwise returns main.FALSE. |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2434 | """ |
| 2435 | try: |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2436 | returnValue = main.TRUE |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2437 | # Generating a dictionary: intent id as a key and state as value |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2438 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2439 | # intentsDict = self.getIntentState( intentsId ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2440 | intentsDict = [] |
| 2441 | for intent in json.loads( self.intents() ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2442 | if isinstance( intentsId, types.StringType ) \ |
| 2443 | and intent.get( 'id' ) == intentsId: |
| 2444 | intentsDict.append( intent ) |
| 2445 | elif isinstance( intentsId, types.ListType ) \ |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2446 | and any( intent.get( 'id' ) == ids for ids in intentsId ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2447 | intentsDict.append( intent ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 2448 | |
| 2449 | if not intentsDict: |
Jon Hall | ae04e62 | 2016-01-27 10:38:05 -0800 | [diff] [blame] | 2450 | main.log.info( self.name + ": There is something wrong " + |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2451 | "getting intents state" ) |
| 2452 | return main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2453 | |
| 2454 | if isinstance( expectedState, types.StringType ): |
| 2455 | for intents in intentsDict: |
| 2456 | if intents.get( 'state' ) != expectedState: |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2457 | main.log.debug( self.name + " : Intent ID - " + |
| 2458 | intents.get( 'id' ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2459 | " actual state = " + |
| 2460 | intents.get( 'state' ) |
| 2461 | + " does not equal expected state = " |
| 2462 | + expectedState ) |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 2463 | returnValue = main.FALSE |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2464 | elif isinstance( expectedState, types.ListType ): |
| 2465 | for intents in intentsDict: |
| 2466 | if not any( state == intents.get( 'state' ) for state in |
| 2467 | expectedState ): |
| 2468 | main.log.debug( self.name + " : Intent ID - " + |
| 2469 | intents.get( 'id' ) + |
| 2470 | " actual state = " + |
| 2471 | intents.get( 'state' ) + |
| 2472 | " does not equal expected states = " |
| 2473 | + str( expectedState ) ) |
| 2474 | returnValue = main.FALSE |
| 2475 | |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2476 | if returnValue == main.TRUE: |
| 2477 | main.log.info( self.name + ": All " + |
| 2478 | str( len( intentsDict ) ) + |
kelvin-onlab | f512e94 | 2015-06-08 19:42:59 -0700 | [diff] [blame] | 2479 | " intents are in " + str( expectedState ) + |
| 2480 | " state" ) |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2481 | return returnValue |
| 2482 | except TypeError: |
| 2483 | main.log.exception( self.name + ": Object not as expected" ) |
| 2484 | return None |
| 2485 | except pexpect.EOF: |
| 2486 | main.log.error( self.name + ": EOF exception found" ) |
| 2487 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2488 | main.cleanAndExit() |
kelvin-onlab | c2dcd3f | 2015-04-09 16:40:02 -0700 | [diff] [blame] | 2489 | except Exception: |
| 2490 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2491 | main.cleanAndExit() |
andrewonlab | e674534 | 2014-10-17 14:29:13 -0400 | [diff] [blame] | 2492 | |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2493 | def compareBandwidthAllocations( self, expectedAllocations ): |
| 2494 | """ |
| 2495 | Description: |
| 2496 | Compare the allocated bandwidth with the given allocations |
| 2497 | Required: |
| 2498 | expectedAllocations - The expected ONOS output of the allocations command |
| 2499 | Return: |
| 2500 | Returns main.TRUE only if all intent are the same as expected states, |
| 2501 | otherwise returns main.FALSE. |
| 2502 | """ |
| 2503 | # FIXME: Convert these string comparisons to object comparisons |
| 2504 | try: |
| 2505 | returnValue = main.TRUE |
| 2506 | bandwidthFailed = False |
| 2507 | rawAlloc = self.allocations() |
| 2508 | expectedFormat = StringIO( expectedAllocations ) |
| 2509 | ONOSOutput = StringIO( rawAlloc ) |
| 2510 | main.log.debug( "ONOSOutput: {}\nexpected output: {}".format( str( ONOSOutput ), |
| 2511 | str( expectedFormat ) ) ) |
| 2512 | |
| 2513 | for actual, expected in izip( ONOSOutput, expectedFormat ): |
| 2514 | actual = actual.rstrip() |
| 2515 | expected = expected.rstrip() |
| 2516 | main.log.debug( "Expect: {}\nactual: {}".format( expected, actual ) ) |
| 2517 | if actual != expected and 'allocated' in actual and 'allocated' in expected: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2518 | marker1 = actual.find( 'allocated' ) |
| 2519 | m1 = actual[ :marker1 ] |
| 2520 | marker2 = expected.find( 'allocated' ) |
| 2521 | m2 = expected[ :marker2 ] |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2522 | if m1 != m2: |
| 2523 | bandwidthFailed = True |
| 2524 | elif actual != expected and 'allocated' not in actual and 'allocated' not in expected: |
| 2525 | bandwidthFailed = True |
| 2526 | expectedFormat.close() |
| 2527 | ONOSOutput.close() |
| 2528 | |
| 2529 | if bandwidthFailed: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2530 | main.log.error( "Bandwidth not allocated correctly using Intents!!" ) |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2531 | returnValue = main.FALSE |
| 2532 | return returnValue |
| 2533 | except TypeError: |
| 2534 | main.log.exception( self.name + ": Object not as expected" ) |
| 2535 | return None |
| 2536 | except pexpect.EOF: |
| 2537 | main.log.error( self.name + ": EOF exception found" ) |
| 2538 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2539 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2540 | except Exception: |
| 2541 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2542 | main.cleanAndExit() |
Jon Hall | f539eb9 | 2017-05-22 17:18:42 -0700 | [diff] [blame] | 2543 | |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2544 | def compareIntent( self, intentDict ): |
| 2545 | """ |
| 2546 | Description: |
| 2547 | Compare the intent ids and states provided in the argument with all intents in ONOS |
| 2548 | Return: |
| 2549 | Returns main.TRUE if the two sets of intents match exactly, otherwise main.FALSE |
| 2550 | Arguments: |
| 2551 | intentDict: a dictionary which maps intent ids to intent states |
| 2552 | """ |
| 2553 | try: |
| 2554 | intentsRaw = self.intents() |
| 2555 | intentsJson = json.loads( intentsRaw ) |
| 2556 | intentDictONOS = {} |
| 2557 | for intent in intentsJson: |
| 2558 | intentDictONOS[ intent[ 'id' ] ] = intent[ 'state' ] |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2559 | returnValue = main.TRUE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2560 | if len( intentDict ) != len( intentDictONOS ): |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2561 | 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] | 2562 | str( len( intentDict ) ) + " expected and " + |
| 2563 | str( len( intentDictONOS ) ) + " actual" ) |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2564 | returnValue = main.FALSE |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2565 | for intentID in intentDict.keys(): |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2566 | if intentID not in intentDictONOS.keys(): |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2567 | main.log.debug( self.name + ": intent ID - " + intentID + " is not in ONOS" ) |
| 2568 | returnValue = main.FALSE |
You Wang | 58d0445 | 2016-09-21 15:13:05 -0700 | [diff] [blame] | 2569 | else: |
| 2570 | if intentDict[ intentID ] != intentDictONOS[ intentID ]: |
| 2571 | main.log.debug( self.name + ": intent ID - " + intentID + |
| 2572 | " expected state is " + intentDict[ intentID ] + |
| 2573 | " but actual state is " + intentDictONOS[ intentID ] ) |
| 2574 | returnValue = main.FALSE |
| 2575 | intentDictONOS.pop( intentID ) |
| 2576 | if len( intentDictONOS ) > 0: |
| 2577 | returnValue = main.FALSE |
| 2578 | for intentID in intentDictONOS.keys(): |
| 2579 | 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] | 2580 | if returnValue == main.TRUE: |
| 2581 | main.log.info( self.name + ": all intent IDs and states match that in ONOS" ) |
| 2582 | return returnValue |
You Wang | 1be9a51 | 2016-05-26 16:54:17 -0700 | [diff] [blame] | 2583 | except KeyError: |
| 2584 | main.log.exception( self.name + ": KeyError exception found" ) |
| 2585 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2586 | except ( TypeError, ValueError ): |
| 2587 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intentsRaw ) ) |
You Wang | 8556037 | 2016-05-18 10:44:33 -0700 | [diff] [blame] | 2588 | return main.ERROR |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2589 | except pexpect.EOF: |
| 2590 | main.log.error( self.name + ": EOF exception found" ) |
| 2591 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2592 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2593 | except Exception: |
| 2594 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2595 | main.cleanAndExit() |
You Wang | 66518af | 2016-05-16 15:32:59 -0700 | [diff] [blame] | 2596 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2597 | def checkIntentSummary( self, timeout=60, noExit=True ): |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2598 | """ |
| 2599 | Description: |
| 2600 | Check the number of installed intents. |
| 2601 | Optional: |
| 2602 | timeout - the timeout for pexcept |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2603 | noExit - If noExit, TestON will not exit if any except. |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2604 | Return: |
| 2605 | Returns main.TRUE only if the number of all installed intents are the same as total intents number |
| 2606 | , otherwise, returns main.FALSE. |
| 2607 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2608 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2609 | try: |
| 2610 | cmd = "intents -s -j" |
| 2611 | |
| 2612 | # Check response if something wrong |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2613 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2614 | if response is None: |
YPZhang | 0584d43 | 2016-06-21 15:20:13 -0700 | [diff] [blame] | 2615 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2616 | response = json.loads( response ) |
| 2617 | |
| 2618 | # get total and installed number, see if they are match |
| 2619 | allState = response.get( 'all' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2620 | if allState.get( 'total' ) == allState.get( 'installed' ): |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2621 | main.log.info( 'Total Intents: {} Installed Intents: {}'.format( |
| 2622 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2623 | return main.TRUE |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 2624 | main.log.info( 'Verified Intents failed Expected intents: {} installed intents: {}'.format( |
| 2625 | allState.get( 'total' ), allState.get( 'installed' ) ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2626 | return main.FALSE |
| 2627 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2628 | except ( TypeError, ValueError ): |
| 2629 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2630 | return None |
| 2631 | except pexpect.EOF: |
| 2632 | main.log.error( self.name + ": EOF exception found" ) |
| 2633 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2634 | if noExit: |
| 2635 | return main.FALSE |
| 2636 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2637 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2638 | except pexpect.TIMEOUT: |
| 2639 | main.log.error( self.name + ": ONOS timeout" ) |
| 2640 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2641 | except Exception: |
| 2642 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2643 | if noExit: |
| 2644 | return main.FALSE |
| 2645 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2646 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2647 | |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2648 | def flows( self, state="any", jsonFormat=True, timeout=60, noExit=False, noCore=False, device=""): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2649 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2650 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2651 | * jsonFormat: enable output formatting in json |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2652 | * noCore: suppress core flows |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2653 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2654 | Obtain flows currently installed |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 2655 | """ |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2656 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2657 | cmdStr = "flows" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2658 | if jsonFormat: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2659 | cmdStr += " -j" |
Jeremy Songster | 306ed7a | 2016-07-19 10:59:07 -0700 | [diff] [blame] | 2660 | if noCore: |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 2661 | cmdStr += " -n" |
| 2662 | cmdStr += " " + state |
| 2663 | cmdStr += " " + device |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2664 | handle = self.sendline( cmdStr, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2665 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2666 | assert "Command not found:" not in handle, handle |
| 2667 | if re.search( "Error:", handle ): |
| 2668 | main.log.error( self.name + ": flows() response: " + |
| 2669 | str( handle ) ) |
| 2670 | return handle |
| 2671 | except AssertionError: |
| 2672 | main.log.exception( "" ) |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2673 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2674 | except TypeError: |
| 2675 | main.log.exception( self.name + ": Object not as expected" ) |
| 2676 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2677 | except pexpect.TIMEOUT: |
| 2678 | main.log.error( self.name + ": ONOS timeout" ) |
| 2679 | return None |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2680 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2681 | main.log.error( self.name + ": EOF exception found" ) |
| 2682 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2683 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2684 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2685 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2686 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2687 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2688 | def checkFlowCount( self, min=0, timeout=60 ): |
Flavio Castro | a1286fe | 2016-07-25 14:48:51 -0700 | [diff] [blame] | 2689 | count = self.getTotalFlowsNum( timeout=timeout ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2690 | count = int( count ) if count else 0 |
steven30801 | eccfe21 | 2019-01-24 13:00:42 +0800 | [diff] [blame] | 2691 | main.log.debug( "found {} flows".format( count ) ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 2692 | return count if ( count >= min ) else False |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2693 | |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2694 | def checkFlowsState( self, isPENDING=True, timeout=60, noExit=False ): |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2695 | """ |
| 2696 | Description: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2697 | Check the if all the current flows are in ADDED state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2698 | We check PENDING_ADD, PENDING_REMOVE, REMOVED, and FAILED flows, |
| 2699 | if the count of those states is 0, which means all current flows |
| 2700 | are in ADDED state, and return main.TRUE otherwise return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2701 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2702 | * isPENDING: whether the PENDING_ADD is also a correct status |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2703 | Return: |
| 2704 | returnValue - Returns main.TRUE only if all flows are in |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2705 | ADDED state or PENDING_ADD if the isPENDING |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2706 | parameter is set true, return main.FALSE otherwise. |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2707 | """ |
| 2708 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2709 | states = [ "PENDING_ADD", "PENDING_REMOVE", "REMOVED", "FAILED" ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2710 | checkedStates = [] |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2711 | statesCount = [ 0, 0, 0, 0 ] |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2712 | for s in states: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2713 | rawFlows = self.flows( state=s, timeout = timeout ) |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2714 | if rawFlows: |
| 2715 | # if we didn't get flows or flows function return None, we should return |
| 2716 | # main.Flase |
| 2717 | checkedStates.append( json.loads( rawFlows ) ) |
| 2718 | else: |
| 2719 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2720 | for i in range( len( states ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2721 | for c in checkedStates[ i ]: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2722 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2723 | statesCount[ i ] += int( c.get( "flowCount" ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2724 | except TypeError: |
| 2725 | main.log.exception( "Json object not as expected" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2726 | main.log.info( states[ i ] + " flows: " + str( statesCount[ i ] ) ) |
kelvin-onlab | f2ec6e0 | 2015-05-27 14:15:28 -0700 | [diff] [blame] | 2727 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2728 | # We want to count PENDING_ADD if isPENDING is true |
| 2729 | if isPENDING: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2730 | if statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2731 | return main.FALSE |
pingping-lin | bab7f8a | 2015-09-21 17:33:36 -0700 | [diff] [blame] | 2732 | else: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2733 | if statesCount[ 0 ] + statesCount[ 1 ] + statesCount[ 2 ] + statesCount[ 3 ] > 0: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2734 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2735 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2736 | except ( TypeError, ValueError ): |
| 2737 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawFlows ) ) |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2738 | return None |
Jeremy Songster | 9385d41 | 2016-06-02 17:57:36 -0700 | [diff] [blame] | 2739 | |
YPZhang | 240842b | 2016-05-17 12:00:50 -0700 | [diff] [blame] | 2740 | except AssertionError: |
| 2741 | main.log.exception( "" ) |
| 2742 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2743 | except pexpect.TIMEOUT: |
| 2744 | main.log.error( self.name + ": ONOS timeout" ) |
| 2745 | return None |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2746 | except pexpect.EOF: |
| 2747 | main.log.error( self.name + ": EOF exception found" ) |
| 2748 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2749 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2750 | except Exception: |
| 2751 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2752 | main.cleanAndExit() |
kelvin-onlab | 4df89f2 | 2015-04-13 18:10:23 -0700 | [diff] [blame] | 2753 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2754 | def pushTestIntents( self, ingress, egress, batchSize, offset="", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2755 | options="", timeout=10, background = False, noExit=False, getResponse=False ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2756 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2757 | Description: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2758 | Push a number of intents in a batch format to |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2759 | a specific point-to-point intent definition |
| 2760 | Required: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2761 | * ingress: specify source dpid |
| 2762 | * egress: specify destination dpid |
| 2763 | * batchSize: specify number of intents to push |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2764 | Optional: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2765 | * offset: the keyOffset is where the next batch of intents |
| 2766 | will be installed |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2767 | * noExit: If set to True, TestON will not exit if any error when issus command |
| 2768 | * getResponse: If set to True, function will return ONOS response. |
| 2769 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2770 | Returns: If failed to push test intents, it will returen None, |
| 2771 | if successful, return true. |
| 2772 | Timeout expection will return None, |
| 2773 | TypeError will return false |
| 2774 | other expections will exit() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2775 | """ |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2776 | try: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2777 | if background: |
| 2778 | back = "&" |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2779 | else: |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2780 | back = "" |
| 2781 | cmd = "push-test-intents {} {} {} {} {} {}".format( options, |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2782 | ingress, |
| 2783 | egress, |
| 2784 | batchSize, |
| 2785 | offset, |
| 2786 | back ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2787 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2788 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2789 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2790 | main.log.info( response ) |
YPZhang | b34b7e1 | 2016-06-14 14:28:19 -0700 | [diff] [blame] | 2791 | if getResponse: |
| 2792 | return response |
| 2793 | |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2794 | # TODO: We should handle if there is failure in installation |
| 2795 | return main.TRUE |
| 2796 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2797 | except AssertionError: |
| 2798 | main.log.exception( "" ) |
| 2799 | return None |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2800 | except pexpect.TIMEOUT: |
| 2801 | main.log.error( self.name + ": ONOS timeout" ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2802 | return None |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2803 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2804 | main.log.error( self.name + ": EOF exception found" ) |
| 2805 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2806 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 2807 | except TypeError: |
| 2808 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2809 | return None |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2810 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2811 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2812 | main.cleanAndExit() |
andrewonlab | 87852b0 | 2014-11-19 18:44:19 -0500 | [diff] [blame] | 2813 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 2814 | def getTotalFlowsNum( self, timeout=60, noExit=False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2815 | """ |
| 2816 | Description: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2817 | Get the number of ADDED flows. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2818 | Return: |
YPZhang | f6f14a0 | 2016-01-28 15:17:31 -0800 | [diff] [blame] | 2819 | The number of ADDED flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2820 | Or return None if any exceptions |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2821 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2822 | |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2823 | try: |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2824 | # get total added flows number |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2825 | cmd = "flows -c added" |
| 2826 | rawFlows = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
| 2827 | if rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2828 | rawFlows = rawFlows.split( "\n" ) |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2829 | totalFlows = 0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2830 | for l in rawFlows: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2831 | totalFlows += int( l.split( "Count=" )[ 1 ] ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2832 | else: |
You Wang | 68568b1 | 2019-03-04 11:49:57 -0800 | [diff] [blame] | 2833 | main.log.warn( "Response not as expected!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2834 | return None |
| 2835 | return totalFlows |
YPZhang | e3109a7 | 2016-02-02 11:25:37 -0800 | [diff] [blame] | 2836 | |
You Wang | d3097f7 | 2018-12-12 11:56:03 -0800 | [diff] [blame] | 2837 | except IndexError: |
| 2838 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
| 2839 | main.log.debug( "rawFlows: {}".format( rawFlows ) ) |
| 2840 | return None |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2841 | except ( TypeError, ValueError ): |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2842 | main.log.exception( "{}: Object not as expected!".format( self.name ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2843 | return None |
| 2844 | except pexpect.EOF: |
| 2845 | main.log.error( self.name + ": EOF exception found" ) |
| 2846 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2847 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2848 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2849 | return None |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2850 | except pexpect.TIMEOUT: |
| 2851 | main.log.error( self.name + ": ONOS timeout" ) |
| 2852 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2853 | except Exception: |
| 2854 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2855 | if not noExit: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2856 | main.cleanAndExit() |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2857 | return None |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2858 | |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 2859 | def getTotalIntentsNum( self, timeout=60, noExit = False ): |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2860 | """ |
| 2861 | Description: |
| 2862 | Get the total number of intents, include every states. |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2863 | Optional: |
| 2864 | noExit - If noExit, TestON will not exit if any except. |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2865 | Return: |
| 2866 | The number of intents |
| 2867 | """ |
| 2868 | try: |
| 2869 | cmd = "summary -j" |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2870 | response = self.sendline( cmd, timeout=timeout, noExit=noExit ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 2871 | if response is None: |
| 2872 | return -1 |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2873 | response = json.loads( response ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2874 | return int( response.get( "intents" ) ) |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 2875 | except ( TypeError, ValueError ): |
| 2876 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, response ) ) |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2877 | return None |
| 2878 | except pexpect.EOF: |
| 2879 | main.log.error( self.name + ": EOF exception found" ) |
| 2880 | main.log.error( self.name + ": " + self.handle.before ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2881 | if noExit: |
| 2882 | return -1 |
| 2883 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2884 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2885 | except Exception: |
| 2886 | main.log.exception( self.name + ": Uncaught exception!" ) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 2887 | if noExit: |
| 2888 | return -1 |
| 2889 | else: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2890 | main.cleanAndExit() |
YPZhang | b5d3f83 | 2016-01-23 22:54:26 -0800 | [diff] [blame] | 2891 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2892 | def intentsEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2893 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 2894 | Description:Returns topology metrics |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2895 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2896 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2897 | """ |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2898 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2899 | cmdStr = "intents-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2900 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2901 | cmdStr += " -j" |
| 2902 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2903 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2904 | assert "Command not found:" not in handle, handle |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2905 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2906 | except AssertionError: |
| 2907 | main.log.exception( "" ) |
| 2908 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2909 | except TypeError: |
| 2910 | main.log.exception( self.name + ": Object not as expected" ) |
| 2911 | return None |
andrewonlab | 0dbb6ec | 2014-11-06 13:46:55 -0500 | [diff] [blame] | 2912 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2913 | main.log.error( self.name + ": EOF exception found" ) |
| 2914 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2915 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2916 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2917 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2918 | main.cleanAndExit() |
Shreya Shah | 0f01c81 | 2014-10-26 20:15:28 -0400 | [diff] [blame] | 2919 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2920 | def topologyEventsMetrics( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2921 | """ |
| 2922 | Description:Returns topology metrics |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2923 | Optional: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2924 | * jsonFormat: enable json formatting of output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2925 | """ |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2926 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2927 | cmdStr = "topology-events-metrics" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2928 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2929 | cmdStr += " -j" |
| 2930 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 2931 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2932 | assert "Command not found:" not in handle, handle |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2933 | if handle: |
| 2934 | return handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2935 | elif jsonFormat: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 2936 | # Return empty json |
jenkins | 7ead5a8 | 2015-03-13 10:28:21 -0700 | [diff] [blame] | 2937 | return '{}' |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 2938 | else: |
| 2939 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 2940 | except AssertionError: |
| 2941 | main.log.exception( "" ) |
| 2942 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2943 | except TypeError: |
| 2944 | main.log.exception( self.name + ": Object not as expected" ) |
| 2945 | return None |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2946 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2947 | main.log.error( self.name + ": EOF exception found" ) |
| 2948 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2949 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2950 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2951 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2952 | main.cleanAndExit() |
andrewonlab | 867212a | 2014-10-22 20:13:38 -0400 | [diff] [blame] | 2953 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2954 | # Wrapper functions **************** |
| 2955 | # Wrapper functions use existing driver |
| 2956 | # functions and extends their use case. |
| 2957 | # For example, we may use the output of |
| 2958 | # a normal driver function, and parse it |
| 2959 | # using a wrapper function |
andrewonlab | c2d05aa | 2014-10-13 16:51:10 -0400 | [diff] [blame] | 2960 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2961 | def getAllIntentsId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2962 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2963 | Description: |
| 2964 | Obtain all intent id's in a list |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2965 | """ |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2966 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2967 | # Obtain output of intents function |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 2968 | intentsStr = self.intents( jsonFormat=True ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 2969 | if intentsStr is None: |
| 2970 | raise TypeError |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2971 | # Convert to a dictionary |
| 2972 | intents = json.loads( intentsStr ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2973 | intentIdList = [] |
Jon Hall | 6021e06 | 2017-01-30 11:10:06 -0800 | [diff] [blame] | 2974 | for intent in intents: |
| 2975 | intentIdList.append( intent[ 'id' ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 2976 | return intentIdList |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2977 | except TypeError: |
| 2978 | main.log.exception( self.name + ": Object not as expected" ) |
| 2979 | return None |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2980 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2981 | main.log.error( self.name + ": EOF exception found" ) |
| 2982 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2983 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 2984 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 2985 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 2986 | main.cleanAndExit() |
andrewonlab | 9a50dfe | 2014-10-17 17:22:31 -0400 | [diff] [blame] | 2987 | |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2988 | def flowAddedCount( self, deviceId, core=False ): |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2989 | """ |
| 2990 | Determine the number of flow rules for the given device id that are |
| 2991 | in the added state |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2992 | Params: |
| 2993 | core: if True, only return the number of core flows added |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 2994 | """ |
| 2995 | try: |
You Wang | 3c27625 | 2016-09-21 15:21:36 -0700 | [diff] [blame] | 2996 | if core: |
| 2997 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 2998 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 2999 | else: |
| 3000 | cmdStr = "flows any " + str( deviceId ) + " | " +\ |
| 3001 | "grep 'state=ADDED' | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3002 | handle = self.lineCount( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3003 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3004 | assert "Command not found:" not in handle, handle |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 3005 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3006 | except AssertionError: |
| 3007 | main.log.exception( "" ) |
| 3008 | return None |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 3009 | except pexpect.EOF: |
| 3010 | main.log.error( self.name + ": EOF exception found" ) |
| 3011 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3012 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3013 | except Exception: |
Jon Hall | 30b82fa | 2015-03-04 17:15:43 -0800 | [diff] [blame] | 3014 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3015 | main.cleanAndExit() |
andrewonlab | 95ce832 | 2014-10-13 14:12:04 -0400 | [diff] [blame] | 3016 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3017 | def groupAddedCount( self, deviceId, core=False ): |
| 3018 | """ |
| 3019 | Determine the number of group rules for the given device id that are |
| 3020 | in the added state |
| 3021 | Params: |
| 3022 | core: if True, only return the number of core groups added |
| 3023 | """ |
| 3024 | try: |
| 3025 | if core: |
| 3026 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 3027 | "grep 'state=ADDED' | grep org.onosproject.core | wc -l" |
| 3028 | else: |
| 3029 | cmdStr = "groups any " + str( deviceId ) + " | " +\ |
| 3030 | "grep 'state=ADDED' | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3031 | handle = self.lineCount( cmdStr ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3032 | assert handle is not None, "Error in sendline" |
| 3033 | assert "Command not found:" not in handle, handle |
| 3034 | return handle |
| 3035 | except AssertionError: |
| 3036 | main.log.exception( "" ) |
| 3037 | return None |
| 3038 | except pexpect.EOF: |
| 3039 | main.log.error( self.name + ": EOF exception found" ) |
| 3040 | main.log.error( self.name + ": " + self.handle.before ) |
| 3041 | main.cleanAndExit() |
| 3042 | except Exception: |
| 3043 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3044 | main.cleanAndExit() |
| 3045 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 3046 | def addStaticRoute( self, subnet, intf): |
| 3047 | """ |
| 3048 | Adds a static route to onos. |
| 3049 | Params: |
| 3050 | subnet: The subnet reaching through this route |
| 3051 | intf: The interface this route is reachable through |
| 3052 | """ |
| 3053 | try: |
| 3054 | cmdStr = "route-add " + subnet + " " + intf |
| 3055 | handle = self.sendline( cmdStr ) |
| 3056 | assert handle is not None, "Error in sendline" |
| 3057 | assert "Command not found:" not in handle, handle |
| 3058 | return handle |
| 3059 | except AssertionError: |
| 3060 | main.log.exception( "" ) |
| 3061 | return None |
| 3062 | except pexpect.EOF: |
| 3063 | main.log.error( self.name + ": EOF exception found" ) |
| 3064 | main.log.error( self.name + ": " + self.handle.before ) |
| 3065 | main.cleanAndExit() |
| 3066 | except Exception: |
| 3067 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3068 | main.cleanAndExit() |
| 3069 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3070 | def checkGroupAddedCount( self, deviceId, expectedGroupCount=0, core=False, comparison=0): |
| 3071 | """ |
| 3072 | Description: |
| 3073 | Check whether the number of groups for the given device id that |
| 3074 | are in ADDED state is bigger than minGroupCount. |
| 3075 | Required: |
| 3076 | * deviceId: device id to check the number of added group rules |
| 3077 | Optional: |
| 3078 | * minGroupCount: the number of groups to compare |
| 3079 | * core: if True, only check the number of core groups added |
| 3080 | * comparison: if 0, compare with greater than minFlowCount |
| 3081 | * if 1, compare with equal to minFlowCount |
| 3082 | Return: |
| 3083 | Returns the number of groups if it is bigger than minGroupCount, |
| 3084 | returns main.FALSE otherwise. |
| 3085 | """ |
| 3086 | count = self.groupAddedCount( deviceId, core ) |
| 3087 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 3088 | main.log.debug( "found {} groups".format( count ) ) |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3089 | return count if ((count > expectedGroupCount) if (comparison == 0) else (count == expectedGroupCount)) else main.FALSE |
| 3090 | |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3091 | def getGroups( self, deviceId, groupType="any" ): |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3092 | """ |
| 3093 | Retrieve groups from a specific device. |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3094 | deviceId: Id of the device from which we retrieve groups |
| 3095 | groupType: Type of group |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3096 | """ |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3097 | try: |
You Wang | c02f3be | 2018-05-18 12:14:23 -0700 | [diff] [blame] | 3098 | groupCmd = "groups -t {0} any {1}".format( groupType, deviceId ) |
| 3099 | handle = self.sendline( groupCmd ) |
Andreas Pantelopoulos | df5061f | 2018-05-15 11:46:59 -0700 | [diff] [blame] | 3100 | assert handle is not None, "Error in sendline" |
| 3101 | assert "Command not found:" not in handle, handle |
| 3102 | return handle |
| 3103 | except AssertionError: |
| 3104 | main.log.exception( "" ) |
| 3105 | return None |
| 3106 | except TypeError: |
| 3107 | main.log.exception( self.name + ": Object not as expected" ) |
| 3108 | return None |
| 3109 | except pexpect.EOF: |
| 3110 | main.log.error( self.name + ": EOF exception found" ) |
| 3111 | main.log.error( self.name + ": " + self.handle.before ) |
| 3112 | main.cleanAndExit() |
| 3113 | except Exception: |
| 3114 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 3115 | main.cleanAndExit() |
| 3116 | |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3117 | def checkFlowAddedCount( self, deviceId, expectedFlowCount=0, core=False, comparison=0): |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3118 | """ |
| 3119 | Description: |
| 3120 | Check whether the number of flow rules for the given device id that |
| 3121 | are in ADDED state is bigger than minFlowCount. |
| 3122 | Required: |
| 3123 | * deviceId: device id to check the number of added flow rules |
| 3124 | Optional: |
| 3125 | * minFlowCount: the number of flow rules to compare |
| 3126 | * core: if True, only check the number of core flows added |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 3127 | * comparison: if 0, compare with greater than minFlowCount |
| 3128 | * if 1, compare with equal to minFlowCount |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 3129 | Return: |
| 3130 | Returns the number of flow rules if it is bigger than minFlowCount, |
| 3131 | returns main.FALSE otherwise. |
| 3132 | """ |
| 3133 | count = self.flowAddedCount( deviceId, core ) |
| 3134 | count = int( count ) if count else 0 |
Jon Hall | 9677ed3 | 2018-04-24 11:16:23 -0700 | [diff] [blame] | 3135 | main.log.debug( "found {} flows".format( count ) ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3136 | 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] | 3137 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3138 | def getAllDevicesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3139 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3140 | Use 'devices' function to obtain list of all devices |
| 3141 | and parse the result to obtain a list of all device |
| 3142 | id's. Returns this list. Returns empty list if no |
| 3143 | devices exist |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3144 | List is ordered sequentially |
| 3145 | |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3146 | This function may be useful if you are not sure of the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3147 | device id, and wish to execute other commands using |
andrewonlab | 3e15ead | 2014-10-15 14:21:34 -0400 | [diff] [blame] | 3148 | the ids. By obtaining the list of device ids on the fly, |
| 3149 | you can iterate through the list to get mastership, etc. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3150 | """ |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3151 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3152 | # Call devices and store result string |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3153 | devicesStr = self.devices( jsonFormat=False ) |
| 3154 | idList = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3155 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3156 | if not devicesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3157 | main.log.info( "There are no devices to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3158 | return idList |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3159 | |
| 3160 | # Split the string into list by comma |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3161 | deviceList = devicesStr.split( "," ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3162 | # Get temporary list of all arguments with string 'id=' |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3163 | tempList = [ dev for dev in deviceList if "id=" in dev ] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3164 | # Split list further into arguments before and after string |
| 3165 | # 'id='. Get the latter portion ( the actual device id ) and |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3166 | # append to idList |
| 3167 | for arg in tempList: |
| 3168 | idList.append( arg.split( "id=" )[ 1 ] ) |
| 3169 | return idList |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3170 | |
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 |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [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() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3181 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3182 | def getAllNodesId( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3183 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3184 | Uses 'nodes' function to obtain list of all nodes |
| 3185 | and parse the result of nodes to obtain just the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3186 | node id's. |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3187 | Returns: |
| 3188 | list of node id's |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3189 | """ |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3190 | try: |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3191 | nodesStr = self.nodes( jsonFormat=True ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3192 | idList = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3193 | # Sample nodesStr output |
Jon Hall | bd18278 | 2016-03-28 16:42:22 -0700 | [diff] [blame] | 3194 | # id=local, address=127.0.0.1:9876, state=READY * |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3195 | if not nodesStr: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3196 | main.log.info( "There are no nodes to get id from" ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3197 | return idList |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3198 | nodesJson = json.loads( nodesStr ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3199 | idList = [ node.get( 'id' ) for node in nodesJson ] |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3200 | return idList |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3201 | except ( TypeError, ValueError ): |
| 3202 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, nodesStr ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3203 | return None |
andrewonlab | 7c21157 | 2014-10-15 16:45:20 -0400 | [diff] [blame] | 3204 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3205 | main.log.error( self.name + ": EOF exception found" ) |
| 3206 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3207 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3208 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3209 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3210 | main.cleanAndExit() |
andrewonlab | 7e4d2d3 | 2014-10-15 13:23:21 -0400 | [diff] [blame] | 3211 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3212 | def getDevice( self, dpid=None ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3213 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3214 | Return the first device from the devices api whose 'id' contains 'dpid' |
| 3215 | Return None if there is no match |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3216 | """ |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3217 | try: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3218 | if dpid is None: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3219 | return None |
| 3220 | else: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3221 | dpid = dpid.replace( ':', '' ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3222 | rawDevices = self.devices() |
| 3223 | devicesJson = json.loads( rawDevices ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3224 | # search json for the device with dpid then return the device |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3225 | for device in devicesJson: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3226 | # print "%s in %s?" % ( dpid, device[ 'id' ] ) |
| 3227 | if dpid in device[ 'id' ]: |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3228 | return device |
| 3229 | return None |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3230 | except ( TypeError, ValueError ): |
| 3231 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawDevices ) ) |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3232 | return None |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3233 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3234 | main.log.error( self.name + ": EOF exception found" ) |
| 3235 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3236 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3237 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3238 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3239 | main.cleanAndExit() |
Jon Hall | a91c4dc | 2014-10-22 12:57:04 -0400 | [diff] [blame] | 3240 | |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3241 | def getTopology( self, topologyOutput ): |
| 3242 | """ |
| 3243 | Definition: |
| 3244 | Loads a json topology output |
| 3245 | Return: |
| 3246 | topology = current ONOS topology |
| 3247 | """ |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3248 | try: |
| 3249 | # either onos:topology or 'topology' will work in CLI |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3250 | topology = json.loads( topologyOutput ) |
Jeremy Songster | bc2d8ac | 2016-05-04 11:25:42 -0700 | [diff] [blame] | 3251 | main.log.debug( topology ) |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3252 | return topology |
You Wang | d3cb2ce | 2016-05-16 14:01:24 -0700 | [diff] [blame] | 3253 | except ( TypeError, ValueError ): |
| 3254 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, topologyOutput ) ) |
| 3255 | return None |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3256 | except pexpect.EOF: |
| 3257 | main.log.error( self.name + ": EOF exception found" ) |
| 3258 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3259 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3260 | except Exception: |
| 3261 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3262 | main.cleanAndExit() |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3263 | |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3264 | def checkStatus( self, numoswitch, numolink = -1, numoctrl = -1, numoSCCs=1, logLevel="info" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3265 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3266 | Checks the number of switches & links that ONOS sees against the |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3267 | supplied values. By default this will report to main.log, but the |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3268 | log level can be specific. |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3269 | |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3270 | Params: numoswitch = expected number of switches |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3271 | numolink = expected number of links |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3272 | numoctrl = expected number of controllers |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3273 | numoSCCs = Number of expected SCCs |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3274 | logLevel = level to log to. |
| 3275 | Currently accepts 'info', 'warn' and 'report' |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3276 | |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3277 | Returns: main.TRUE if the number of switches and links are correct, |
| 3278 | main.FALSE if the number of switches and links is incorrect, |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3279 | and main.ERROR otherwise |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3280 | """ |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3281 | try: |
You Wang | 1331025 | 2016-07-31 10:56:14 -0700 | [diff] [blame] | 3282 | summary = self.summary() |
| 3283 | summary = json.loads( summary ) |
Flavio Castro | f5b3f87 | 2016-06-23 17:52:31 -0700 | [diff] [blame] | 3284 | except ( TypeError, ValueError ): |
| 3285 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, summary ) ) |
| 3286 | return main.ERROR |
| 3287 | try: |
| 3288 | topology = self.getTopology( self.topology() ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 3289 | if topology == {} or topology is None or summary == {} or summary is None: |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3290 | return main.ERROR |
| 3291 | output = "" |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3292 | # Is the number of switches is what we expected |
| 3293 | devices = topology.get( 'devices', False ) |
| 3294 | links = topology.get( 'links', False ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3295 | nodes = summary.get( 'nodes', False ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3296 | SCCs = summary.get( 'SCC(s)', False ) |
| 3297 | if devices is False or links is False or nodes is False or SCCs is False: |
| 3298 | main.log.warn( "Issues parsing topology and summary output" ) |
| 3299 | main.log.debug( topology ) |
| 3300 | main.log.debug( summary ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3301 | return main.ERROR |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3302 | switchCheck = ( int( devices ) == int( numoswitch ) ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3303 | if not switchCheck: |
| 3304 | main.log.debug( "switch Check Failed" ) |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3305 | linkCheck = ( int( links ) == int( numolink ) ) or int( numolink ) == -1 |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3306 | if not linkCheck: |
| 3307 | main.log.debug( "link Check Failed" ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3308 | nodeCheck = ( int( nodes ) == int( numoctrl ) ) or int( numoctrl ) == -1 |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3309 | if not nodeCheck: |
| 3310 | main.log.debug( "node Check Failed" ) |
| 3311 | SCCsCheck = ( int( SCCs ) == int( numoSCCs ) ) or int( numoSCCs ) == -1 |
| 3312 | if not SCCsCheck: |
| 3313 | main.log.debug( "SCCs Check Failed" ) |
| 3314 | if switchCheck and linkCheck and nodeCheck and SCCsCheck: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3315 | # We expected the correct numbers |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3316 | output = output + "The number of links, switches, nodes, and SCCs match "\ |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3317 | + "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3318 | result = main.TRUE |
| 3319 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3320 | output = output + \ |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3321 | "The number of links, switches, nodes, and SCCs does not match " + \ |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3322 | "what was expected" |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3323 | result = main.FALSE |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3324 | output = output + "\n ONOS sees %i devices " % int( devices ) |
| 3325 | output = output + "(%i expected) " % int( numoswitch ) |
| 3326 | if int( numolink ) >= 0: |
Pier | 6a0c4de | 2018-03-18 16:01:30 -0700 | [diff] [blame] | 3327 | output = output + "and %i links " % int( links ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3328 | output = output + "(%i expected) " % int( numolink ) |
| 3329 | if int( numoctrl ) >= 0: |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 3330 | output = output + "and %i controllers " % int( nodes ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3331 | output = output + "(%i expected) " % int( numoctrl ) |
| 3332 | if int( numoSCCs ) >= 0: |
| 3333 | output = output + "and %i SCCs " % int( SCCs ) |
| 3334 | output = output + "(%i expected)" % int( numoSCCs ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3335 | if logLevel == "report": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3336 | main.log.report( output ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3337 | elif logLevel == "warn": |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3338 | main.log.warn( output ) |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3339 | else: |
You Wang | 2413987 | 2016-05-03 11:48:47 -0700 | [diff] [blame] | 3340 | main.log.info( output ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 3341 | main.TOPOOUTPUT = output |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3342 | return result |
Jon Hall | 42db6dc | 2014-10-24 19:03:48 -0400 | [diff] [blame] | 3343 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3344 | main.log.error( self.name + ": EOF exception found" ) |
| 3345 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3346 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3347 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3348 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3349 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3350 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3351 | def deviceRole( self, deviceId, onosNode, role="master" ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3352 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3353 | Calls the device-role cli command. |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3354 | deviceId must be the id of a device as seen in the onos devices command |
| 3355 | 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] | 3356 | role must be either master, standby, or none |
| 3357 | |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3358 | Returns: |
| 3359 | main.TRUE or main.FALSE based on argument verification and |
| 3360 | main.ERROR if command returns and error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3361 | """ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3362 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3363 | if role.lower() == "master" or role.lower() == "standby" or\ |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3364 | role.lower() == "none": |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3365 | cmdStr = "device-role " +\ |
| 3366 | str( deviceId ) + " " +\ |
| 3367 | str( onosNode ) + " " +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3368 | str( role ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3369 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3370 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3371 | assert "Command not found:" not in handle, handle |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3372 | if re.search( "Error", handle ): |
| 3373 | # end color output to escape any colours |
| 3374 | # from the cli |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3375 | main.log.error( self.name + ": " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3376 | handle + '\033[0m' ) |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3377 | return main.ERROR |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3378 | return main.TRUE |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3379 | else: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3380 | main.log.error( "Invalid 'role' given to device_role(). " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3381 | "Value was '" + str( role ) + "'." ) |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3382 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3383 | except AssertionError: |
| 3384 | main.log.exception( "" ) |
| 3385 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3386 | except TypeError: |
| 3387 | main.log.exception( self.name + ": Object not as expected" ) |
| 3388 | return None |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3389 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3390 | main.log.error( self.name + ": EOF exception found" ) |
| 3391 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3392 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3393 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3394 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3395 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3396 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3397 | def clusters( self, jsonFormat=True ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3398 | """ |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3399 | Lists all topology clusters |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 3400 | Optional argument: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3401 | * jsonFormat - boolean indicating if you want output in json |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3402 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3403 | try: |
Jon Hall | 0dd0995 | 2018-04-19 09:59:11 -0700 | [diff] [blame] | 3404 | cmdStr = "topo-clusters" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3405 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3406 | cmdStr += " -j" |
| 3407 | handle = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3408 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3409 | assert "Command not found:" not in handle, handle |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3410 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3411 | except AssertionError: |
| 3412 | main.log.exception( "" ) |
| 3413 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3414 | except TypeError: |
| 3415 | main.log.exception( self.name + ": Object not as expected" ) |
| 3416 | return None |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3417 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3418 | main.log.error( self.name + ": EOF exception found" ) |
| 3419 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3420 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3421 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3422 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3423 | main.cleanAndExit() |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 3424 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3425 | def electionTestLeader( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3426 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3427 | CLI command to get the current leader for the Election test application |
| 3428 | NOTE: Requires installation of the onos-app-election feature |
| 3429 | Returns: Node IP of the leader if one exists |
| 3430 | None if none exists |
| 3431 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3432 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3433 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3434 | cmdStr = "election-test-leader" |
| 3435 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3436 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3437 | assert "Command not found:" not in response, response |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3438 | # Leader |
| 3439 | leaderPattern = "The\scurrent\sleader\sfor\sthe\sElection\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3440 | "app\sis\s(?P<node>.+)\." |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3441 | nodeSearch = re.search( leaderPattern, response ) |
| 3442 | if nodeSearch: |
| 3443 | node = nodeSearch.group( 'node' ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3444 | main.log.info( "Election-test-leader on " + str( self.name ) + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3445 | " found " + node + " as the leader" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3446 | return node |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3447 | # no leader |
| 3448 | nullPattern = "There\sis\scurrently\sno\sleader\selected\sfor\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3449 | "the\sElection\sapp" |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3450 | nullSearch = re.search( nullPattern, response ) |
| 3451 | if nullSearch: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3452 | main.log.info( "Election-test-leader found no leader on " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3453 | self.name ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3454 | return None |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3455 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3456 | main.log.error( self.name + ": Error in electionTestLeader on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3457 | ": " + "unexpected response" ) |
| 3458 | main.log.error( repr( response ) ) |
| 3459 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3460 | except AssertionError: |
| 3461 | main.log.exception( "" ) |
| 3462 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3463 | except TypeError: |
| 3464 | main.log.exception( self.name + ": Object not as expected" ) |
| 3465 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3466 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3467 | main.log.error( self.name + ": EOF exception found" ) |
| 3468 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3469 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3470 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3471 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3472 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3473 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3474 | def electionTestRun( self ): |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3475 | """ |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3476 | CLI command to run for leadership of the Election test application. |
| 3477 | NOTE: Requires installation of the onos-app-election feature |
| 3478 | Returns: Main.TRUE on success |
| 3479 | Main.FALSE on error |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3480 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3481 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3482 | cmdStr = "election-test-run" |
| 3483 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3484 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3485 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3486 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3487 | successPattern = "Entering\sleadership\selections\sfor\sthe\s" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3488 | "Election\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3489 | search = re.search( successPattern, response ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3490 | if search: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3491 | main.log.info( self.name + " entering leadership elections " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3492 | "for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3493 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3494 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3495 | main.log.error( self.name + ": Error in electionTestRun on " + self.name + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3496 | ": " + "unexpected response" ) |
| 3497 | main.log.error( repr( response ) ) |
| 3498 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3499 | except AssertionError: |
| 3500 | main.log.exception( "" ) |
| 3501 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3502 | except TypeError: |
| 3503 | main.log.exception( self.name + ": Object not as expected" ) |
| 3504 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3505 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3506 | main.log.error( self.name + ": EOF exception found" ) |
| 3507 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3508 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3509 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3510 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3511 | main.cleanAndExit() |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3512 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3513 | def electionTestWithdraw( self ): |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3514 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3515 | * CLI command to withdraw the local node from leadership election for |
| 3516 | * the Election test application. |
| 3517 | #NOTE: Requires installation of the onos-app-election feature |
| 3518 | Returns: Main.TRUE on success |
| 3519 | Main.FALSE on error |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3520 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3521 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3522 | cmdStr = "election-test-withdraw" |
| 3523 | response = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3524 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3525 | assert "Command not found:" not in response, response |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3526 | # success |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3527 | successPattern = "Withdrawing\sfrom\sleadership\selections\sfor" +\ |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3528 | "\sthe\sElection\sapp." |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3529 | if re.search( successPattern, response ): |
| 3530 | main.log.info( self.name + " withdrawing from leadership " + |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3531 | "elections for the Election app." ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3532 | return main.TRUE |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3533 | # error |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3534 | main.log.error( self.name + ": Error in electionTestWithdraw on " + |
Jon Hall | 97cf84a | 2016-06-20 13:35:58 -0700 | [diff] [blame] | 3535 | self.name + ": " + "unexpected response" ) |
| 3536 | main.log.error( repr( response ) ) |
| 3537 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3538 | except AssertionError: |
| 3539 | main.log.exception( "" ) |
| 3540 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3541 | except TypeError: |
| 3542 | main.log.exception( self.name + ": Object not as expected" ) |
| 3543 | return main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 3544 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3545 | main.log.error( self.name + ": EOF exception found" ) |
| 3546 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3547 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3548 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3549 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3550 | main.cleanAndExit() |
Jon Hall | 1c9e873 | 2014-10-27 19:29:27 -0400 | [diff] [blame] | 3551 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3552 | def getDevicePortsEnabledCount( self, dpid ): |
| 3553 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3554 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3555 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3556 | try: |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3557 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3558 | cmdStr = "onos:ports -e " + dpid + " | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3559 | output = self.lineCount( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3560 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3561 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3562 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3563 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3564 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3565 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3566 | except AssertionError: |
| 3567 | main.log.exception( "" ) |
| 3568 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3569 | except TypeError: |
| 3570 | main.log.exception( self.name + ": Object not as expected" ) |
| 3571 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3572 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3573 | main.log.error( self.name + ": EOF exception found" ) |
| 3574 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3575 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3576 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3577 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3578 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3579 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3580 | def getDeviceLinksActiveCount( self, dpid ): |
| 3581 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3582 | Get the count of all enabled ports on a particular device/switch |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3583 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3584 | try: |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3585 | dpid = str( dpid ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3586 | cmdStr = "onos:links " + dpid + " | grep ACTIVE | wc -l" |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 3587 | output = self.lineCount( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3588 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3589 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3590 | if re.search( "No such device", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3591 | main.log.error( self.name + ": Error in getting ports " ) |
kelvin-onlab | 898a6c6 | 2015-01-16 14:13:53 -0800 | [diff] [blame] | 3592 | return ( output, "Error " ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3593 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3594 | except AssertionError: |
| 3595 | main.log.exception( "" ) |
| 3596 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3597 | except TypeError: |
| 3598 | main.log.exception( self.name + ": Object not as expected" ) |
| 3599 | return ( output, "Error " ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3600 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3601 | main.log.error( self.name + ": EOF exception found" ) |
| 3602 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3603 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3604 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3605 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3606 | main.cleanAndExit() |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3607 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3608 | def getAllIntentIds( self ): |
| 3609 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3610 | Return a list of all Intent IDs |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3611 | """ |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3612 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 3613 | cmdStr = "onos:intents | grep id=" |
| 3614 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3615 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3616 | assert "Command not found:" not in output, output |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3617 | if re.search( "Error", output ): |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3618 | main.log.error( self.name + ": Error in getting ports" ) |
Jon Hall | e3f39ff | 2015-01-13 11:50:53 -0800 | [diff] [blame] | 3619 | return ( output, "Error" ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3620 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3621 | except AssertionError: |
| 3622 | main.log.exception( "" ) |
| 3623 | return None |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3624 | except TypeError: |
| 3625 | main.log.exception( self.name + ": Object not as expected" ) |
| 3626 | return ( output, "Error" ) |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3627 | except pexpect.EOF: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 3628 | main.log.error( self.name + ": EOF exception found" ) |
| 3629 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3630 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3631 | except Exception: |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3632 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3633 | main.cleanAndExit() |
Jon Hall | d4d4b37 | 2015-01-28 16:02:41 -0800 | [diff] [blame] | 3634 | |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3635 | def intentSummary( self ): |
| 3636 | """ |
Jon Hall | efbd979 | 2015-03-05 16:11:36 -0800 | [diff] [blame] | 3637 | Returns a dictionary containing the current intent states and the count |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3638 | """ |
| 3639 | try: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3640 | intents = self.intents( ) |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3641 | states = [] |
Jon Hall | 5aa168b | 2015-03-23 14:23:09 -0700 | [diff] [blame] | 3642 | for intent in json.loads( intents ): |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3643 | states.append( intent.get( 'state', None ) ) |
| 3644 | out = [ ( i, states.count( i ) ) for i in set( states ) ] |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3645 | main.log.info( dict( out ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3646 | return dict( out ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3647 | except ( TypeError, ValueError ): |
| 3648 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, intents ) ) |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3649 | return None |
| 3650 | except pexpect.EOF: |
| 3651 | main.log.error( self.name + ": EOF exception found" ) |
| 3652 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3653 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 3654 | except Exception: |
Jon Hall | 7350995 | 2015-02-24 16:42:56 -0800 | [diff] [blame] | 3655 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3656 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3657 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3658 | def leaders( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3659 | """ |
| 3660 | Returns the output of the leaders command. |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3661 | Optional argument: |
| 3662 | * jsonFormat - boolean indicating if you want output in json |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3663 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3664 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3665 | cmdStr = "onos:leaders" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3666 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3667 | cmdStr += " -j" |
| 3668 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3669 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3670 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3671 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3672 | except AssertionError: |
| 3673 | main.log.exception( "" ) |
| 3674 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3675 | except TypeError: |
| 3676 | main.log.exception( self.name + ": Object not as expected" ) |
| 3677 | return None |
Hari Krishna | a43d4e9 | 2014-12-19 13:22:40 -0800 | [diff] [blame] | 3678 | except pexpect.EOF: |
| 3679 | main.log.error( self.name + ": EOF exception found" ) |
| 3680 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3681 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3682 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3683 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3684 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3685 | |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3686 | def leaderCandidates( self, jsonFormat=True ): |
| 3687 | """ |
| 3688 | Returns the output of the leaders -c command. |
| 3689 | Optional argument: |
| 3690 | * jsonFormat - boolean indicating if you want output in json |
| 3691 | """ |
| 3692 | try: |
| 3693 | cmdStr = "onos:leaders -c" |
| 3694 | if jsonFormat: |
| 3695 | cmdStr += " -j" |
| 3696 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3697 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3698 | assert "Command not found:" not in output, output |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3699 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3700 | except AssertionError: |
| 3701 | main.log.exception( "" ) |
| 3702 | return None |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3703 | except TypeError: |
| 3704 | main.log.exception( self.name + ": Object not as expected" ) |
| 3705 | return None |
| 3706 | except pexpect.EOF: |
| 3707 | main.log.error( self.name + ": EOF exception found" ) |
| 3708 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3709 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3710 | except Exception: |
| 3711 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3712 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3713 | |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3714 | def specificLeaderCandidate( self, topic ): |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3715 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3716 | Returns a list in format [leader,candidate1,candidate2,...] for a given |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3717 | topic parameter and an empty list if the topic doesn't exist |
| 3718 | If no leader is elected leader in the returned list will be "none" |
| 3719 | Returns None if there is a type error processing the json object |
| 3720 | """ |
| 3721 | try: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 3722 | cmdStr = "onos:leaders -j" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3723 | rawOutput = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3724 | assert rawOutput is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3725 | assert "Command not found:" not in rawOutput, rawOutput |
| 3726 | output = json.loads( rawOutput ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3727 | results = [] |
| 3728 | for dict in output: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3729 | if dict[ "topic" ] == topic: |
| 3730 | leader = dict[ "leader" ] |
| 3731 | candidates = re.split( ", ", dict[ "candidates" ][ 1:-1 ] ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3732 | results.append( leader ) |
| 3733 | results.extend( candidates ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3734 | return results |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3735 | except AssertionError: |
| 3736 | main.log.exception( "" ) |
| 3737 | return None |
| 3738 | except ( TypeError, ValueError ): |
| 3739 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawOutput ) ) |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3740 | return None |
| 3741 | except pexpect.EOF: |
| 3742 | main.log.error( self.name + ": EOF exception found" ) |
| 3743 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3744 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3745 | except Exception: |
| 3746 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3747 | main.cleanAndExit() |
acsmars | a4a4d1e | 2015-07-10 16:01:24 -0700 | [diff] [blame] | 3748 | |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3749 | def pendingMap( self, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3750 | """ |
| 3751 | Returns the output of the intent Pending map. |
| 3752 | """ |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3753 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3754 | cmdStr = "onos:intents -p" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3755 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3756 | cmdStr += " -j" |
| 3757 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3758 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3759 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3760 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3761 | except AssertionError: |
| 3762 | main.log.exception( "" ) |
| 3763 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3764 | except TypeError: |
| 3765 | main.log.exception( self.name + ": Object not as expected" ) |
| 3766 | return None |
| 3767 | except pexpect.EOF: |
| 3768 | main.log.error( self.name + ": EOF exception found" ) |
| 3769 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3770 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3771 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3772 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3773 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3774 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3775 | def partitions( self, candidates=False, jsonFormat=True ): |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3776 | """ |
| 3777 | Returns the output of the raft partitions command for ONOS. |
| 3778 | """ |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3779 | # Sample JSON |
| 3780 | # { |
| 3781 | # "leader": "tcp://10.128.30.11:7238", |
| 3782 | # "members": [ |
| 3783 | # "tcp://10.128.30.11:7238", |
| 3784 | # "tcp://10.128.30.17:7238", |
| 3785 | # "tcp://10.128.30.13:7238", |
| 3786 | # ], |
| 3787 | # "name": "p1", |
| 3788 | # "term": 3 |
| 3789 | # }, |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3790 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3791 | cmdStr = "onos:partitions" |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 3792 | if candidates: |
| 3793 | cmdStr += " -c" |
Jon Hall | 61282e3 | 2015-03-19 11:34:11 -0700 | [diff] [blame] | 3794 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3795 | cmdStr += " -j" |
| 3796 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3797 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3798 | assert "Command not found:" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3799 | return output |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3800 | except AssertionError: |
| 3801 | main.log.exception( "" ) |
| 3802 | return None |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3803 | except TypeError: |
| 3804 | main.log.exception( self.name + ": Object not as expected" ) |
| 3805 | return None |
| 3806 | except pexpect.EOF: |
| 3807 | main.log.error( self.name + ": EOF exception found" ) |
| 3808 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3809 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3810 | except Exception: |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3811 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3812 | main.cleanAndExit() |
Jon Hall | 6360493 | 2015-02-26 17:09:50 -0800 | [diff] [blame] | 3813 | |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3814 | def apps( self, summary=False, active=False, jsonFormat=True ): |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3815 | """ |
| 3816 | Returns the output of the apps command for ONOS. This command lists |
| 3817 | information about installed ONOS applications |
| 3818 | """ |
| 3819 | # Sample JSON object |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3820 | # [{"name":"org.onosproject.openflow","id":0,"version":"1.2.0", |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3821 | # "description":"ONOS OpenFlow protocol southbound providers", |
| 3822 | # "origin":"ON.Lab","permissions":"[]","featuresRepo":"", |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 3823 | # "features":"[onos-openflow]","state":"ACTIVE"}] |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3824 | try: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3825 | cmdStr = "onos:apps" |
Jon Hall | f03ae76 | 2019-01-22 13:25:27 -0800 | [diff] [blame] | 3826 | expectJson = False |
Jon Hall | e9f909e | 2016-09-23 10:43:12 -0700 | [diff] [blame] | 3827 | if summary: |
| 3828 | cmdStr += " -s" |
| 3829 | if active: |
| 3830 | cmdStr += " -a" |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3831 | if jsonFormat: |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3832 | cmdStr += " -j" |
Jon Hall | f03ae76 | 2019-01-22 13:25:27 -0800 | [diff] [blame] | 3833 | expectJson = True |
| 3834 | output = self.sendline( cmdStr, expectJson=expectJson ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 3835 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3836 | assert "Command not found:" not in output, output |
| 3837 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 3838 | return output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3839 | # FIXME: look at specific exceptions/Errors |
| 3840 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3841 | main.log.exception( self.name + ": Error in processing onos:app command." ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3842 | return None |
| 3843 | except TypeError: |
| 3844 | main.log.exception( self.name + ": Object not as expected" ) |
| 3845 | return None |
| 3846 | except pexpect.EOF: |
| 3847 | main.log.error( self.name + ": EOF exception found" ) |
| 3848 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3849 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3850 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3851 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3852 | main.cleanAndExit() |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3853 | |
You Wang | cdc51fe | 2018-08-12 17:14:56 -0700 | [diff] [blame] | 3854 | def appStatus( self, appName ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3855 | """ |
| 3856 | Uses the onos:apps cli command to return the status of an application. |
| 3857 | Returns: |
| 3858 | "ACTIVE" - If app is installed and activated |
| 3859 | "INSTALLED" - If app is installed and deactivated |
| 3860 | "UNINSTALLED" - If app is not installed |
| 3861 | None - on error |
| 3862 | """ |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3863 | try: |
| 3864 | if not isinstance( appName, types.StringType ): |
| 3865 | main.log.error( self.name + ".appStatus(): appName must be" + |
| 3866 | " a string" ) |
| 3867 | return None |
| 3868 | output = self.apps( jsonFormat=True ) |
| 3869 | appsJson = json.loads( output ) |
| 3870 | state = None |
| 3871 | for app in appsJson: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3872 | if appName == app.get( 'name' ): |
| 3873 | state = app.get( 'state' ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3874 | break |
| 3875 | if state == "ACTIVE" or state == "INSTALLED": |
| 3876 | return state |
| 3877 | elif state is None: |
You Wang | 0d9f2c0 | 2018-08-10 14:56:32 -0700 | [diff] [blame] | 3878 | main.log.warn( "{} app not found".format( appName ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3879 | return "UNINSTALLED" |
| 3880 | elif state: |
| 3881 | main.log.error( "Unexpected state from 'onos:apps': " + |
| 3882 | str( state ) ) |
| 3883 | return state |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 3884 | except ( TypeError, ValueError ): |
| 3885 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3886 | return None |
| 3887 | except pexpect.EOF: |
| 3888 | main.log.error( self.name + ": EOF exception found" ) |
| 3889 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3890 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3891 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3892 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3893 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3894 | |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3895 | def app( self, appName, option ): |
| 3896 | """ |
| 3897 | Interacts with the app command for ONOS. This command manages |
| 3898 | application inventory. |
| 3899 | """ |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3900 | try: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3901 | # Validate argument types |
| 3902 | valid = True |
| 3903 | if not isinstance( appName, types.StringType ): |
| 3904 | main.log.error( self.name + ".app(): appName must be a " + |
| 3905 | "string" ) |
| 3906 | valid = False |
| 3907 | if not isinstance( option, types.StringType ): |
| 3908 | main.log.error( self.name + ".app(): option must be a string" ) |
| 3909 | valid = False |
| 3910 | if not valid: |
| 3911 | return main.FALSE |
| 3912 | # Validate Option |
| 3913 | option = option.lower() |
| 3914 | # NOTE: Install may become a valid option |
| 3915 | if option == "activate": |
| 3916 | pass |
| 3917 | elif option == "deactivate": |
| 3918 | pass |
| 3919 | elif option == "uninstall": |
| 3920 | pass |
| 3921 | else: |
| 3922 | # Invalid option |
| 3923 | main.log.error( "The ONOS app command argument only takes " + |
| 3924 | "the values: (activate|deactivate|uninstall)" + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3925 | "; was given '" + option + "'" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3926 | return main.FALSE |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3927 | cmdStr = "onos:app " + option + " " + appName |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3928 | output = self.sendline( cmdStr ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3929 | assert output is not None, "Error in sendline" |
| 3930 | assert "Command not found:" not in output, output |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3931 | if "Error executing command" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3932 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3933 | str( output ) ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3934 | return main.FALSE |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3935 | elif "No such application" in output: |
| 3936 | main.log.error( "The application '" + appName + |
| 3937 | "' is not installed in ONOS" ) |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3938 | return main.FALSE |
| 3939 | elif "Command not found:" in output: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 3940 | main.log.error( self.name + ": Error in processing onos:app command: " + |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3941 | str( output ) ) |
| 3942 | return main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3943 | elif "Unsupported command:" in output: |
| 3944 | main.log.error( "Incorrect command given to 'app': " + |
| 3945 | str( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3946 | # NOTE: we may need to add more checks here |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3947 | # else: Command was successful |
Jon Hall | 08f61bc | 2015-04-13 16:00:30 -0700 | [diff] [blame] | 3948 | # main.log.debug( "app response: " + repr( output ) ) |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3949 | return main.TRUE |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 3950 | except AssertionError: |
| 3951 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 3952 | return main.ERROR |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3953 | except TypeError: |
| 3954 | main.log.exception( self.name + ": Object not as expected" ) |
| 3955 | return main.ERROR |
| 3956 | except pexpect.EOF: |
| 3957 | main.log.error( self.name + ": EOF exception found" ) |
| 3958 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3959 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 3960 | except Exception: |
Jon Hall | be37960 | 2015-03-24 13:39:32 -0700 | [diff] [blame] | 3961 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 3962 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3963 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3964 | def activateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3965 | """ |
| 3966 | Activate an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3967 | appName is the hierarchical app name, not the feature name |
| 3968 | If check is True, method will check the status of the app after the |
| 3969 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3970 | Returns main.TRUE if the command was successfully sent |
| 3971 | main.FALSE if the cli responded with an error or given |
| 3972 | incorrect input |
| 3973 | """ |
| 3974 | try: |
| 3975 | if not isinstance( appName, types.StringType ): |
| 3976 | main.log.error( self.name + ".activateApp(): appName must be" + |
| 3977 | " a string" ) |
| 3978 | return main.FALSE |
| 3979 | status = self.appStatus( appName ) |
| 3980 | if status == "INSTALLED": |
| 3981 | response = self.app( appName, "activate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3982 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 3983 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3984 | status = self.appStatus( appName ) |
| 3985 | if status == "ACTIVE": |
| 3986 | return main.TRUE |
| 3987 | else: |
Jon Hall | 050e1bd | 2015-03-30 13:33:02 -0700 | [diff] [blame] | 3988 | main.log.debug( "The state of application " + |
| 3989 | appName + " is " + status ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 3990 | time.sleep( 1 ) |
| 3991 | return main.FALSE |
| 3992 | else: # not 'check' or command didn't succeed |
| 3993 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 3994 | elif status == "ACTIVE": |
| 3995 | return main.TRUE |
| 3996 | elif status == "UNINSTALLED": |
| 3997 | main.log.error( self.name + ": Tried to activate the " + |
| 3998 | "application '" + appName + "' which is not " + |
| 3999 | "installed." ) |
| 4000 | else: |
| 4001 | main.log.error( "Unexpected return value from appStatus: " + |
| 4002 | str( status ) ) |
| 4003 | return main.ERROR |
| 4004 | except TypeError: |
| 4005 | main.log.exception( self.name + ": Object not as expected" ) |
| 4006 | return main.ERROR |
| 4007 | except pexpect.EOF: |
| 4008 | main.log.error( self.name + ": EOF exception found" ) |
| 4009 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4010 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4011 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4012 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4013 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4014 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4015 | def deactivateApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4016 | """ |
| 4017 | Deactivate an app that is already activated in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4018 | appName is the hierarchical app name, not the feature name |
| 4019 | If check is True, method will check the status of the app after the |
| 4020 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4021 | Returns main.TRUE if the command was successfully sent |
| 4022 | main.FALSE if the cli responded with an error or given |
| 4023 | incorrect input |
| 4024 | """ |
| 4025 | try: |
| 4026 | if not isinstance( appName, types.StringType ): |
| 4027 | main.log.error( self.name + ".deactivateApp(): appName must " + |
| 4028 | "be a string" ) |
| 4029 | return main.FALSE |
| 4030 | status = self.appStatus( appName ) |
| 4031 | if status == "INSTALLED": |
| 4032 | return main.TRUE |
| 4033 | elif status == "ACTIVE": |
| 4034 | response = self.app( appName, "deactivate" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4035 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4036 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4037 | status = self.appStatus( appName ) |
| 4038 | if status == "INSTALLED": |
| 4039 | return main.TRUE |
| 4040 | else: |
| 4041 | time.sleep( 1 ) |
| 4042 | return main.FALSE |
| 4043 | else: # not check or command didn't succeed |
| 4044 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4045 | elif status == "UNINSTALLED": |
| 4046 | main.log.warn( self.name + ": Tried to deactivate the " + |
| 4047 | "application '" + appName + "' which is not " + |
| 4048 | "installed." ) |
| 4049 | return main.TRUE |
| 4050 | else: |
| 4051 | main.log.error( "Unexpected return value from appStatus: " + |
| 4052 | str( status ) ) |
| 4053 | return main.ERROR |
| 4054 | except TypeError: |
| 4055 | main.log.exception( self.name + ": Object not as expected" ) |
| 4056 | return main.ERROR |
| 4057 | except pexpect.EOF: |
| 4058 | main.log.error( self.name + ": EOF exception found" ) |
| 4059 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4060 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4061 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4062 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4063 | main.cleanAndExit() |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4064 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4065 | def uninstallApp( self, appName, check=True ): |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4066 | """ |
| 4067 | Uninstall an app that is already installed in ONOS |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4068 | appName is the hierarchical app name, not the feature name |
| 4069 | If check is True, method will check the status of the app after the |
| 4070 | command is issued |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4071 | Returns main.TRUE if the command was successfully sent |
| 4072 | main.FALSE if the cli responded with an error or given |
| 4073 | incorrect input |
| 4074 | """ |
| 4075 | # TODO: check with Thomas about the state machine for apps |
| 4076 | try: |
| 4077 | if not isinstance( appName, types.StringType ): |
| 4078 | main.log.error( self.name + ".uninstallApp(): appName must " + |
| 4079 | "be a string" ) |
| 4080 | return main.FALSE |
| 4081 | status = self.appStatus( appName ) |
| 4082 | if status == "INSTALLED": |
| 4083 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4084 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4085 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4086 | status = self.appStatus( appName ) |
| 4087 | if status == "UNINSTALLED": |
| 4088 | return main.TRUE |
| 4089 | else: |
| 4090 | time.sleep( 1 ) |
| 4091 | return main.FALSE |
| 4092 | else: # not check or command didn't succeed |
| 4093 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4094 | elif status == "ACTIVE": |
| 4095 | main.log.warn( self.name + ": Tried to uninstall the " + |
| 4096 | "application '" + appName + "' which is " + |
| 4097 | "currently active." ) |
| 4098 | response = self.app( appName, "uninstall" ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4099 | if check and response == main.TRUE: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4100 | for i in range( 10 ): # try 10 times then give up |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4101 | status = self.appStatus( appName ) |
| 4102 | if status == "UNINSTALLED": |
| 4103 | return main.TRUE |
| 4104 | else: |
| 4105 | time.sleep( 1 ) |
| 4106 | return main.FALSE |
| 4107 | else: # not check or command didn't succeed |
| 4108 | return response |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4109 | elif status == "UNINSTALLED": |
| 4110 | return main.TRUE |
| 4111 | else: |
| 4112 | main.log.error( "Unexpected return value from appStatus: " + |
| 4113 | str( status ) ) |
| 4114 | return main.ERROR |
| 4115 | except TypeError: |
| 4116 | main.log.exception( self.name + ": Object not as expected" ) |
| 4117 | return main.ERROR |
| 4118 | except pexpect.EOF: |
| 4119 | main.log.error( self.name + ": EOF exception found" ) |
| 4120 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4121 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4122 | except Exception: |
Jon Hall | 146f152 | 2015-03-24 15:33:24 -0700 | [diff] [blame] | 4123 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4124 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4125 | |
| 4126 | def appIDs( self, jsonFormat=True ): |
| 4127 | """ |
| 4128 | Show the mappings between app id and app names given by the 'app-ids' |
| 4129 | cli command |
| 4130 | """ |
| 4131 | try: |
| 4132 | cmdStr = "app-ids" |
| 4133 | if jsonFormat: |
| 4134 | cmdStr += " -j" |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4135 | output = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4136 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4137 | assert "Command not found:" not in output, output |
| 4138 | assert "Error executing command" not in output, output |
Jon Hall | c6358dd | 2015-04-10 12:44:28 -0700 | [diff] [blame] | 4139 | return output |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4140 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4141 | main.log.exception( self.name + ": Error in processing onos:app-ids command." ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4142 | return None |
| 4143 | except TypeError: |
| 4144 | main.log.exception( self.name + ": Object not as expected" ) |
| 4145 | return None |
| 4146 | except pexpect.EOF: |
| 4147 | main.log.error( self.name + ": EOF exception found" ) |
| 4148 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4149 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4150 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4151 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4152 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4153 | |
| 4154 | def appToIDCheck( self ): |
| 4155 | """ |
| 4156 | This method will check that each application's ID listed in 'apps' is |
| 4157 | the same as the ID listed in 'app-ids'. The check will also check that |
| 4158 | there are no duplicate IDs issued. Note that an app ID should be |
| 4159 | a globaly unique numerical identifier for app/app-like features. Once |
| 4160 | an ID is registered, the ID is never freed up so that if an app is |
| 4161 | reinstalled it will have the same ID. |
| 4162 | |
| 4163 | Returns: main.TRUE if the check passes and |
| 4164 | main.FALSE if the check fails or |
| 4165 | main.ERROR if there is some error in processing the test |
| 4166 | """ |
| 4167 | try: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4168 | # Grab IDs |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4169 | rawJson = self.appIDs( jsonFormat=True ) |
| 4170 | if rawJson: |
| 4171 | ids = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4172 | else: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4173 | main.log.error( "app-ids returned nothing: " + repr( rawJson ) ) |
| 4174 | return main.FALSE |
| 4175 | |
| 4176 | # Grab Apps |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4177 | rawJson = self.apps( jsonFormat=True ) |
| 4178 | if rawJson: |
| 4179 | apps = json.loads( rawJson ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4180 | else: |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4181 | main.log.error( "apps returned nothing:" + repr( rawJson ) ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4182 | return main.FALSE |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4183 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4184 | result = main.TRUE |
| 4185 | for app in apps: |
| 4186 | appID = app.get( 'id' ) |
| 4187 | if appID is None: |
| 4188 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4189 | result = main.FALSE |
| 4190 | appName = app.get( 'name' ) |
| 4191 | if appName is None: |
| 4192 | main.log.error( "Error parsing app: " + str( app ) ) |
| 4193 | result = main.FALSE |
| 4194 | # get the entry in ids that has the same appID |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4195 | current = filter( lambda item: item[ 'id' ] == appID, ids ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4196 | if not current: # if ids doesn't have this id |
| 4197 | result = main.FALSE |
| 4198 | main.log.error( "'app-ids' does not have the ID for " + |
| 4199 | str( appName ) + " that apps does." ) |
Jon Hall | b9d381e | 2018-02-05 12:02:10 -0800 | [diff] [blame] | 4200 | main.log.debug( "apps command returned: " + str( app ) + |
| 4201 | "; app-ids has: " + str( ids ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4202 | elif len( current ) > 1: |
| 4203 | # there is more than one app with this ID |
| 4204 | result = main.FALSE |
| 4205 | # We will log this later in the method |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4206 | elif not current[ 0 ][ 'name' ] == appName: |
| 4207 | currentName = current[ 0 ][ 'name' ] |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4208 | result = main.FALSE |
| 4209 | main.log.error( "'app-ids' has " + str( currentName ) + |
| 4210 | " registered under id:" + str( appID ) + |
| 4211 | " but 'apps' has " + str( appName ) ) |
| 4212 | else: |
| 4213 | pass # id and name match! |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4214 | |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4215 | # now make sure that app-ids has no duplicates |
| 4216 | idsList = [] |
| 4217 | namesList = [] |
| 4218 | for item in ids: |
| 4219 | idsList.append( item[ 'id' ] ) |
| 4220 | namesList.append( item[ 'name' ] ) |
| 4221 | if len( idsList ) != len( set( idsList ) ) or\ |
| 4222 | len( namesList ) != len( set( namesList ) ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4223 | main.log.error( "'app-ids' has some duplicate entries: \n" |
| 4224 | + json.dumps( ids, |
| 4225 | sort_keys=True, |
| 4226 | indent=4, |
| 4227 | separators=( ',', ': ' ) ) ) |
| 4228 | result = main.FALSE |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4229 | return result |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4230 | except ( TypeError, ValueError ): |
| 4231 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, rawJson ) ) |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4232 | return main.ERROR |
| 4233 | except pexpect.EOF: |
| 4234 | main.log.error( self.name + ": EOF exception found" ) |
| 4235 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4236 | main.cleanAndExit() |
Jon Hall | 77ba41c | 2015-04-06 10:25:40 -0700 | [diff] [blame] | 4237 | except Exception: |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4238 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4239 | main.cleanAndExit() |
Jon Hall | bd16b92 | 2015-03-26 17:53:15 -0700 | [diff] [blame] | 4240 | |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4241 | def getCfg( self, component=None, propName=None, short=False, |
| 4242 | jsonFormat=True ): |
| 4243 | """ |
| 4244 | Get configuration settings from onos cli |
| 4245 | Optional arguments: |
| 4246 | component - Optionally only list configurations for a specific |
| 4247 | component. If None, all components with configurations |
| 4248 | are displayed. Case Sensitive string. |
| 4249 | propName - If component is specified, propName option will show |
| 4250 | only this specific configuration from that component. |
| 4251 | Case Sensitive string. |
| 4252 | jsonFormat - Returns output as json. Note that this will override |
| 4253 | the short option |
| 4254 | short - Short, less verbose, version of configurations. |
| 4255 | This is overridden by the json option |
| 4256 | returns: |
| 4257 | Output from cli as a string or None on error |
| 4258 | """ |
| 4259 | try: |
| 4260 | baseStr = "cfg" |
| 4261 | cmdStr = " get" |
| 4262 | componentStr = "" |
| 4263 | if component: |
| 4264 | componentStr += " " + component |
| 4265 | if propName: |
| 4266 | componentStr += " " + propName |
| 4267 | if jsonFormat: |
| 4268 | baseStr += " -j" |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4269 | expectJson = True |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4270 | elif short: |
| 4271 | baseStr += " -s" |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4272 | expectJson = False |
| 4273 | output = self.sendline( baseStr + cmdStr + componentStr, expectJson=expectJson ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4274 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4275 | assert "Command not found:" not in output, output |
| 4276 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4277 | return output |
| 4278 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4279 | main.log.exception( self.name + ": Error in processing 'cfg get' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4280 | return None |
| 4281 | except TypeError: |
| 4282 | main.log.exception( self.name + ": Object not as expected" ) |
| 4283 | return None |
| 4284 | except pexpect.EOF: |
| 4285 | main.log.error( self.name + ": EOF exception found" ) |
| 4286 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4287 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4288 | except Exception: |
| 4289 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4290 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4291 | |
| 4292 | def setCfg( self, component, propName, value=None, check=True ): |
| 4293 | """ |
| 4294 | Set/Unset configuration settings from ONOS cli |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4295 | Required arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4296 | component - The case sensitive name of the component whose |
| 4297 | property is to be set |
| 4298 | propName - The case sensitive name of the property to be set/unset |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4299 | Optional arguments: |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4300 | 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] | 4301 | property and revert it to it's default value(if applicable) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4302 | check - Boolean, Check whether the option was successfully set this |
| 4303 | only applies when a value is given. |
| 4304 | returns: |
| 4305 | main.TRUE on success or main.FALSE on failure. If check is False, |
| 4306 | will return main.TRUE unless there is an error |
| 4307 | """ |
| 4308 | try: |
| 4309 | baseStr = "cfg" |
| 4310 | cmdStr = " set " + str( component ) + " " + str( propName ) |
| 4311 | if value is not None: |
| 4312 | cmdStr += " " + str( value ) |
| 4313 | output = self.sendline( baseStr + cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4314 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4315 | assert "Command not found:" not in output, output |
| 4316 | assert "Error executing command" not in output, output |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4317 | if value and check: |
| 4318 | results = self.getCfg( component=str( component ), |
| 4319 | propName=str( propName ), |
| 4320 | jsonFormat=True ) |
| 4321 | # Check if current value is what we just set |
| 4322 | try: |
| 4323 | jsonOutput = json.loads( results ) |
| 4324 | current = jsonOutput[ 'value' ] |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4325 | except ( TypeError, ValueError ): |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4326 | main.log.exception( "Error parsing cfg output" ) |
| 4327 | main.log.error( "output:" + repr( results ) ) |
| 4328 | return main.FALSE |
| 4329 | if current == str( value ): |
| 4330 | return main.TRUE |
| 4331 | return main.FALSE |
| 4332 | return main.TRUE |
| 4333 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4334 | main.log.exception( self.name + ": Error in processing 'cfg set' command." ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4335 | return main.FALSE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4336 | except ( TypeError, ValueError ): |
| 4337 | main.log.exception( "{}: Object not as expected: {!r}".format( self.name, results ) ) |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4338 | return main.FALSE |
| 4339 | except pexpect.EOF: |
| 4340 | main.log.error( self.name + ": EOF exception found" ) |
| 4341 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4342 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4343 | except Exception: |
| 4344 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4345 | main.cleanAndExit() |
Jon Hall | fb760a0 | 2015-04-13 15:35:03 -0700 | [diff] [blame] | 4346 | |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4347 | def distPrimitivesSend( self, cmd ): |
| 4348 | """ |
| 4349 | Function to handle sending cli commands for the distributed primitives test app |
| 4350 | |
| 4351 | This command will catch some exceptions and retry the command on some |
| 4352 | specific store exceptions. |
| 4353 | |
| 4354 | Required arguments: |
| 4355 | cmd - The command to send to the cli |
| 4356 | returns: |
| 4357 | string containing the cli output |
| 4358 | None on Error |
| 4359 | """ |
| 4360 | try: |
| 4361 | output = self.sendline( cmd ) |
| 4362 | try: |
| 4363 | assert output is not None, "Error in sendline" |
| 4364 | # TODO: Maybe make this less hardcoded |
| 4365 | # ConsistentMap Exceptions |
| 4366 | assert "org.onosproject.store.service" not in output |
| 4367 | # Node not leader |
| 4368 | assert "java.lang.IllegalStateException" not in output |
| 4369 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4370 | main.log.error( self.name + ": Error in processing '" + cmd + "' " + |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4371 | "command: " + str( output ) ) |
| 4372 | retryTime = 30 # Conservative time, given by Madan |
| 4373 | main.log.info( "Waiting " + str( retryTime ) + |
| 4374 | "seconds before retrying." ) |
| 4375 | time.sleep( retryTime ) # Due to change in mastership |
| 4376 | output = self.sendline( cmd ) |
| 4377 | assert output is not None, "Error in sendline" |
| 4378 | assert "Command not found:" not in output, output |
| 4379 | assert "Error executing command" not in output, output |
| 4380 | main.log.info( self.name + ": " + output ) |
| 4381 | return output |
| 4382 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4383 | main.log.exception( self.name + ": Error in processing '" + cmd + "' command." ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4384 | return None |
| 4385 | except TypeError: |
| 4386 | main.log.exception( self.name + ": Object not as expected" ) |
| 4387 | return None |
| 4388 | except pexpect.EOF: |
| 4389 | main.log.error( self.name + ": EOF exception found" ) |
| 4390 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4391 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4392 | except Exception: |
| 4393 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4394 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4395 | |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4396 | def setTestAdd( self, setName, values ): |
| 4397 | """ |
| 4398 | CLI command to add elements to a distributed set. |
| 4399 | Arguments: |
| 4400 | setName - The name of the set to add to. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4401 | values - The value(s) to add to the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4402 | Example usages: |
| 4403 | setTestAdd( "set1", "a b c" ) |
| 4404 | setTestAdd( "set2", "1" ) |
| 4405 | returns: |
| 4406 | main.TRUE on success OR |
| 4407 | main.FALSE if elements were already in the set OR |
| 4408 | main.ERROR on error |
| 4409 | """ |
| 4410 | try: |
| 4411 | cmdStr = "set-test-add " + str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4412 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4413 | positiveMatch = "\[(.*)\] was added to the set " + str( setName ) |
| 4414 | negativeMatch = "\[(.*)\] was already in set " + str( setName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4415 | if re.search( positiveMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4416 | return main.TRUE |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 4417 | elif re.search( negativeMatch, output ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4418 | return main.FALSE |
| 4419 | else: |
| 4420 | main.log.error( self.name + ": setTestAdd did not" + |
| 4421 | " match expected output" ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4422 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4423 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4424 | except TypeError: |
| 4425 | main.log.exception( self.name + ": Object not as expected" ) |
| 4426 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4427 | except Exception: |
| 4428 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4429 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4430 | |
| 4431 | def setTestRemove( self, setName, values, clear=False, retain=False ): |
| 4432 | """ |
| 4433 | CLI command to remove elements from a distributed set. |
| 4434 | Required arguments: |
| 4435 | setName - The name of the set to remove from. |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4436 | values - The value(s) to remove from the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4437 | Optional arguments: |
| 4438 | clear - Clear all elements from the set |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4439 | retain - Retain only the given values. (intersection of the |
| 4440 | original set and the given set) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4441 | returns: |
| 4442 | main.TRUE on success OR |
| 4443 | main.FALSE if the set was not changed OR |
| 4444 | main.ERROR on error |
| 4445 | """ |
| 4446 | try: |
| 4447 | cmdStr = "set-test-remove " |
| 4448 | if clear: |
| 4449 | cmdStr += "-c " + str( setName ) |
| 4450 | elif retain: |
| 4451 | cmdStr += "-r " + str( setName ) + " " + str( values ) |
| 4452 | else: |
| 4453 | cmdStr += str( setName ) + " " + str( values ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4454 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4455 | if clear: |
| 4456 | pattern = "Set " + str( setName ) + " cleared" |
| 4457 | if re.search( pattern, output ): |
| 4458 | return main.TRUE |
| 4459 | elif retain: |
| 4460 | positivePattern = str( setName ) + " was pruned to contain " +\ |
| 4461 | "only elements of set \[(.*)\]" |
| 4462 | negativePattern = str( setName ) + " was not changed by " +\ |
| 4463 | "retaining only elements of the set " +\ |
| 4464 | "\[(.*)\]" |
| 4465 | if re.search( positivePattern, output ): |
| 4466 | return main.TRUE |
| 4467 | elif re.search( negativePattern, output ): |
| 4468 | return main.FALSE |
| 4469 | else: |
| 4470 | positivePattern = "\[(.*)\] was removed from the set " +\ |
| 4471 | str( setName ) |
| 4472 | if ( len( values.split() ) == 1 ): |
| 4473 | negativePattern = "\[(.*)\] was not in set " +\ |
| 4474 | str( setName ) |
| 4475 | else: |
| 4476 | negativePattern = "No element of \[(.*)\] was in set " +\ |
| 4477 | str( setName ) |
| 4478 | if re.search( positivePattern, output ): |
| 4479 | return main.TRUE |
| 4480 | elif re.search( negativePattern, output ): |
| 4481 | return main.FALSE |
| 4482 | main.log.error( self.name + ": setTestRemove did not" + |
| 4483 | " match expected output" ) |
| 4484 | main.log.debug( self.name + " expected: " + pattern ) |
| 4485 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4486 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4487 | except TypeError: |
| 4488 | main.log.exception( self.name + ": Object not as expected" ) |
| 4489 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4490 | except Exception: |
| 4491 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4492 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4493 | |
| 4494 | def setTestGet( self, setName, values="" ): |
| 4495 | """ |
| 4496 | CLI command to get the elements in a distributed set. |
| 4497 | Required arguments: |
| 4498 | setName - The name of the set to remove from. |
| 4499 | Optional arguments: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4500 | values - The value(s) to check if in the set, space seperated. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4501 | returns: |
| 4502 | main.ERROR on error OR |
| 4503 | A list of elements in the set if no optional arguments are |
| 4504 | supplied OR |
| 4505 | A tuple containing the list then: |
| 4506 | main.FALSE if the given values are not in the set OR |
| 4507 | main.TRUE if the given values are in the set OR |
| 4508 | """ |
| 4509 | try: |
| 4510 | values = str( values ).strip() |
| 4511 | setName = str( setName ).strip() |
| 4512 | length = len( values.split() ) |
| 4513 | containsCheck = None |
| 4514 | # Patterns to match |
| 4515 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4516 | pattern = "Items in set " + setName + ":\r\n" + setPattern |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4517 | containsTrue = "Set " + setName + " contains the value " + values |
| 4518 | containsFalse = "Set " + setName + " did not contain the value " +\ |
| 4519 | values |
| 4520 | containsAllTrue = "Set " + setName + " contains the the subset " +\ |
| 4521 | setPattern |
| 4522 | containsAllFalse = "Set " + setName + " did not contain the the" +\ |
| 4523 | " subset " + setPattern |
| 4524 | |
| 4525 | cmdStr = "set-test-get " |
| 4526 | cmdStr += setName + " " + values |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4527 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4528 | if length == 0: |
| 4529 | match = re.search( pattern, output ) |
| 4530 | else: # if given values |
| 4531 | if length == 1: # Contains output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4532 | patternTrue = pattern + "\r\n" + containsTrue |
| 4533 | patternFalse = pattern + "\r\n" + containsFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4534 | else: # ContainsAll output |
Jon Hall | 54b994f | 2016-12-05 10:48:59 -0800 | [diff] [blame] | 4535 | patternTrue = pattern + "\r\n" + containsAllTrue |
| 4536 | patternFalse = pattern + "\r\n" + containsAllFalse |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4537 | matchTrue = re.search( patternTrue, output ) |
| 4538 | matchFalse = re.search( patternFalse, output ) |
| 4539 | if matchTrue: |
| 4540 | containsCheck = main.TRUE |
| 4541 | match = matchTrue |
| 4542 | elif matchFalse: |
| 4543 | containsCheck = main.FALSE |
| 4544 | match = matchFalse |
| 4545 | else: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 4546 | main.log.error( self.name + " setTestGet did not match " + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4547 | "expected output" ) |
| 4548 | main.log.debug( self.name + " expected: " + pattern ) |
| 4549 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4550 | match = None |
| 4551 | if match: |
| 4552 | setMatch = match.group( 1 ) |
| 4553 | if setMatch == '': |
| 4554 | setList = [] |
| 4555 | else: |
| 4556 | setList = setMatch.split( ", " ) |
| 4557 | if length > 0: |
| 4558 | return ( setList, containsCheck ) |
| 4559 | else: |
| 4560 | return setList |
| 4561 | else: # no match |
| 4562 | main.log.error( self.name + ": setTestGet did not" + |
| 4563 | " match expected output" ) |
| 4564 | main.log.debug( self.name + " expected: " + pattern ) |
| 4565 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4566 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4567 | except TypeError: |
| 4568 | main.log.exception( self.name + ": Object not as expected" ) |
| 4569 | return main.ERROR |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4570 | except Exception: |
| 4571 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4572 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4573 | |
| 4574 | def setTestSize( self, setName ): |
| 4575 | """ |
| 4576 | CLI command to get the elements in a distributed set. |
| 4577 | Required arguments: |
| 4578 | setName - The name of the set to remove from. |
| 4579 | returns: |
Jon Hall | feff308 | 2015-05-19 10:23:26 -0700 | [diff] [blame] | 4580 | The integer value of the size returned or |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4581 | None on error |
| 4582 | """ |
| 4583 | try: |
| 4584 | # TODO: Should this check against the number of elements returned |
| 4585 | # and then return true/false based on that? |
| 4586 | setName = str( setName ).strip() |
| 4587 | # Patterns to match |
| 4588 | setPattern = "\[(.*)\]" |
Jon Hall | 6725383 | 2016-12-05 09:47:13 -0800 | [diff] [blame] | 4589 | pattern = "There are (\d+) items in set " + setName + ":\r\n" +\ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4590 | setPattern |
| 4591 | cmdStr = "set-test-get -s " |
| 4592 | cmdStr += setName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4593 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4594 | if output: |
| 4595 | match = re.search( pattern, output ) |
| 4596 | if match: |
| 4597 | setSize = int( match.group( 1 ) ) |
| 4598 | setMatch = match.group( 2 ) |
| 4599 | if len( setMatch.split() ) == setSize: |
| 4600 | main.log.info( "The size returned by " + self.name + |
| 4601 | " matches the number of elements in " + |
| 4602 | "the returned set" ) |
| 4603 | else: |
| 4604 | main.log.error( "The size returned by " + self.name + |
| 4605 | " does not match the number of " + |
| 4606 | "elements in the returned set." ) |
| 4607 | return setSize |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4608 | else: # no match |
| 4609 | main.log.error( self.name + ": setTestGet did not" + |
| 4610 | " match expected output" ) |
| 4611 | main.log.debug( self.name + " expected: " + pattern ) |
| 4612 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4613 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4614 | except TypeError: |
| 4615 | main.log.exception( self.name + ": Object not as expected" ) |
| 4616 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4617 | except Exception: |
| 4618 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4619 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4620 | |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4621 | def counters( self, jsonFormat=True ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4622 | """ |
| 4623 | Command to list the various counters in the system. |
| 4624 | returns: |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4625 | if jsonFormat, a string of the json object returned by the cli |
| 4626 | command |
| 4627 | if not jsonFormat, the normal string output of the cli command |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4628 | None on error |
| 4629 | """ |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4630 | try: |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4631 | cmdStr = "counters" |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4632 | if jsonFormat: |
| 4633 | cmdStr += " -j" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4634 | output = self.sendline( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4635 | main.log.debug( self.name + ": Counters unparsed: " + output ) |
| 4636 | output = output.split( "\r\n" )[ -1 ] |
| 4637 | main.log.debug( self.name + ": Counters parsed: " + output ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4638 | assert output is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4639 | assert "Command not found:" not in output, output |
| 4640 | assert "Error executing command" not in output, output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4641 | main.log.info( self.name + ": " + output ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4642 | return output |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4643 | except AssertionError: |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 4644 | main.log.exception( self.name + ": Error in processing 'counters' command." ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4645 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4646 | except TypeError: |
| 4647 | main.log.exception( self.name + ": Object not as expected" ) |
Jon Hall | 80daded | 2015-05-27 16:07:00 -0700 | [diff] [blame] | 4648 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4649 | except pexpect.EOF: |
| 4650 | main.log.error( self.name + ": EOF exception found" ) |
| 4651 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4652 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4653 | except Exception: |
| 4654 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4655 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4656 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4657 | def counterTestAddAndGet( self, counter, delta=1 ): |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4658 | """ |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4659 | CLI command to add a delta to then get a distributed counter. |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4660 | Required arguments: |
| 4661 | counter - The name of the counter to increment. |
| 4662 | Optional arguments: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4663 | delta - The long to add to the counter |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4664 | returns: |
| 4665 | integer value of the counter or |
| 4666 | None on Error |
| 4667 | """ |
| 4668 | try: |
| 4669 | counter = str( counter ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4670 | delta = int( delta ) |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4671 | cmdStr = "counter-test-increment " |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4672 | cmdStr += counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4673 | if delta != 1: |
| 4674 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4675 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4676 | pattern = counter + " was updated to (-?\d+)" |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4677 | match = re.search( pattern, output ) |
| 4678 | if match: |
| 4679 | return int( match.group( 1 ) ) |
| 4680 | else: |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4681 | main.log.error( self.name + ": counterTestAddAndGet did not" + |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4682 | " match expected output." ) |
| 4683 | main.log.debug( self.name + " expected: " + pattern ) |
| 4684 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4685 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4686 | except TypeError: |
| 4687 | main.log.exception( self.name + ": Object not as expected" ) |
| 4688 | return None |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4689 | except Exception: |
| 4690 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4691 | main.cleanAndExit() |
Jon Hall | 390696c | 2015-05-05 17:13:41 -0700 | [diff] [blame] | 4692 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4693 | def counterTestGetAndAdd( self, counter, delta=1 ): |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4694 | """ |
| 4695 | CLI command to get a distributed counter then add a delta to it. |
| 4696 | Required arguments: |
| 4697 | counter - The name of the counter to increment. |
| 4698 | Optional arguments: |
| 4699 | delta - The long to add to the counter |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4700 | returns: |
| 4701 | integer value of the counter or |
| 4702 | None on Error |
| 4703 | """ |
| 4704 | try: |
| 4705 | counter = str( counter ) |
| 4706 | delta = int( delta ) |
| 4707 | cmdStr = "counter-test-increment -g " |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4708 | cmdStr += counter |
| 4709 | if delta != 1: |
| 4710 | cmdStr += " " + str( delta ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4711 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4712 | pattern = counter + " was updated to (-?\d+)" |
| 4713 | match = re.search( pattern, output ) |
| 4714 | if match: |
| 4715 | return int( match.group( 1 ) ) |
| 4716 | else: |
| 4717 | main.log.error( self.name + ": counterTestGetAndAdd did not" + |
| 4718 | " match expected output." ) |
| 4719 | main.log.debug( self.name + " expected: " + pattern ) |
| 4720 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4721 | return None |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4722 | except TypeError: |
| 4723 | main.log.exception( self.name + ": Object not as expected" ) |
| 4724 | return None |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4725 | except Exception: |
| 4726 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4727 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4728 | |
| 4729 | def valueTestGet( self, valueName ): |
| 4730 | """ |
| 4731 | CLI command to get the value of an atomic value. |
| 4732 | Required arguments: |
| 4733 | valueName - The name of the value to get. |
| 4734 | returns: |
| 4735 | string value of the value or |
| 4736 | None on Error |
| 4737 | """ |
| 4738 | try: |
| 4739 | valueName = str( valueName ) |
| 4740 | cmdStr = "value-test " |
| 4741 | operation = "get" |
| 4742 | cmdStr = "value-test {} {}".format( valueName, |
| 4743 | operation ) |
| 4744 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 4745 | main.log.debug( self.name + ": value test unparsed: " + output ) |
| 4746 | output = output.split( "\r\n" )[ -1 ] |
| 4747 | main.log.debug( self.name + ": value test parsed: " + output ) |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4748 | pattern = "(\w+)" |
| 4749 | match = re.search( pattern, output ) |
| 4750 | if match: |
| 4751 | return match.group( 1 ) |
| 4752 | else: |
| 4753 | main.log.error( self.name + ": valueTestGet did not" + |
| 4754 | " match expected output." ) |
| 4755 | main.log.debug( self.name + " expected: " + pattern ) |
| 4756 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4757 | return None |
| 4758 | except TypeError: |
| 4759 | main.log.exception( self.name + ": Object not as expected" ) |
| 4760 | return None |
| 4761 | except Exception: |
| 4762 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4763 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4764 | |
| 4765 | def valueTestSet( self, valueName, newValue ): |
| 4766 | """ |
| 4767 | CLI command to set the value of an atomic value. |
| 4768 | Required arguments: |
| 4769 | valueName - The name of the value to set. |
| 4770 | newValue - The value to assign to the given value. |
| 4771 | returns: |
| 4772 | main.TRUE on success or |
| 4773 | main.ERROR on Error |
| 4774 | """ |
| 4775 | try: |
| 4776 | valueName = str( valueName ) |
| 4777 | newValue = str( newValue ) |
| 4778 | operation = "set" |
| 4779 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4780 | operation, |
| 4781 | newValue ) |
| 4782 | output = self.distPrimitivesSend( cmdStr ) |
| 4783 | if output is not None: |
| 4784 | return main.TRUE |
| 4785 | else: |
| 4786 | return main.ERROR |
| 4787 | except TypeError: |
| 4788 | main.log.exception( self.name + ": Object not as expected" ) |
| 4789 | return main.ERROR |
| 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() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4793 | |
| 4794 | def valueTestCompareAndSet( self, valueName, oldValue, newValue ): |
| 4795 | """ |
| 4796 | CLI command to compareAndSet the value of an atomic value. |
| 4797 | Required arguments: |
| 4798 | valueName - The name of the value. |
| 4799 | oldValue - Compare the current value of the atomic value to this |
| 4800 | newValue - If the value equals oldValue, set the value to newValue |
| 4801 | returns: |
| 4802 | main.TRUE on success or |
| 4803 | main.FALSE on failure or |
| 4804 | main.ERROR on Error |
| 4805 | """ |
| 4806 | try: |
| 4807 | valueName = str( valueName ) |
| 4808 | oldValue = str( oldValue ) |
| 4809 | newValue = str( newValue ) |
| 4810 | operation = "compareAndSet" |
| 4811 | cmdStr = "value-test {} {} {} {}".format( valueName, |
| 4812 | operation, |
| 4813 | oldValue, |
| 4814 | newValue ) |
| 4815 | output = self.distPrimitivesSend( cmdStr ) |
| 4816 | pattern = "(\w+)" |
| 4817 | match = re.search( pattern, output ) |
| 4818 | if match: |
| 4819 | result = match.group( 1 ) |
| 4820 | if result == "true": |
| 4821 | return main.TRUE |
| 4822 | elif result == "false": |
| 4823 | return main.FALSE |
| 4824 | else: |
| 4825 | main.log.error( self.name + ": valueTestCompareAndSet did not" + |
| 4826 | " match expected output." ) |
| 4827 | main.log.debug( self.name + " expected: " + pattern ) |
| 4828 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4829 | return main.ERROR |
| 4830 | except TypeError: |
| 4831 | main.log.exception( self.name + ": Object not as expected" ) |
| 4832 | return main.ERROR |
| 4833 | except Exception: |
| 4834 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4835 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4836 | |
| 4837 | def valueTestGetAndSet( self, valueName, newValue ): |
| 4838 | """ |
| 4839 | CLI command to getAndSet the value of an atomic value. |
| 4840 | Required arguments: |
| 4841 | valueName - The name of the value to get. |
| 4842 | newValue - The value to assign to the given value |
| 4843 | returns: |
| 4844 | string value of the value or |
| 4845 | None on Error |
| 4846 | """ |
| 4847 | try: |
| 4848 | valueName = str( valueName ) |
| 4849 | cmdStr = "value-test " |
| 4850 | operation = "getAndSet" |
| 4851 | cmdStr += valueName + " " + operation |
| 4852 | cmdStr = "value-test {} {} {}".format( valueName, |
| 4853 | operation, |
| 4854 | newValue ) |
| 4855 | output = self.distPrimitivesSend( cmdStr ) |
| 4856 | pattern = "(\w+)" |
| 4857 | match = re.search( pattern, output ) |
| 4858 | if match: |
| 4859 | return match.group( 1 ) |
| 4860 | else: |
| 4861 | main.log.error( self.name + ": valueTestGetAndSet did not" + |
| 4862 | " match expected output." ) |
| 4863 | main.log.debug( self.name + " expected: " + pattern ) |
| 4864 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4865 | return None |
| 4866 | except TypeError: |
| 4867 | main.log.exception( self.name + ": Object not as expected" ) |
| 4868 | return None |
| 4869 | except Exception: |
| 4870 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4871 | main.cleanAndExit() |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4872 | |
| 4873 | def valueTestDestroy( self, valueName ): |
| 4874 | """ |
| 4875 | CLI command to destroy an atomic value. |
| 4876 | Required arguments: |
| 4877 | valueName - The name of the value to destroy. |
| 4878 | returns: |
| 4879 | main.TRUE on success or |
| 4880 | main.ERROR on Error |
| 4881 | """ |
| 4882 | try: |
| 4883 | valueName = str( valueName ) |
| 4884 | cmdStr = "value-test " |
| 4885 | operation = "destroy" |
| 4886 | cmdStr += valueName + " " + operation |
| 4887 | output = self.distPrimitivesSend( cmdStr ) |
| 4888 | if output is not None: |
| 4889 | return main.TRUE |
| 4890 | else: |
| 4891 | return main.ERROR |
| 4892 | except TypeError: |
| 4893 | main.log.exception( self.name + ": Object not as expected" ) |
| 4894 | return main.ERROR |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4895 | except Exception: |
| 4896 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4897 | main.cleanAndExit() |
Jon Hall | e1a3b75 | 2015-07-22 13:02:46 -0700 | [diff] [blame] | 4898 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4899 | def summary( self, jsonFormat=True, timeout=30 ): |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4900 | """ |
| 4901 | Description: Execute summary command in onos |
| 4902 | Returns: json object ( summary -j ), returns main.FALSE if there is |
| 4903 | no output |
| 4904 | |
| 4905 | """ |
| 4906 | try: |
| 4907 | cmdStr = "summary" |
| 4908 | if jsonFormat: |
| 4909 | cmdStr += " -j" |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 4910 | handle = self.sendline( cmdStr, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 4911 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4912 | assert "Command not found:" not in handle, handle |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4913 | assert "Error:" not in handle, handle |
Devin Lim | a7cfdbd | 2017-09-29 15:02:22 -0700 | [diff] [blame] | 4914 | assert "Error executing" not in handle, handle |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4915 | if not handle: |
| 4916 | main.log.error( self.name + ": There is no output in " + |
| 4917 | "summary command" ) |
| 4918 | return main.FALSE |
| 4919 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4920 | except AssertionError: |
Jon Hall | 6e70975 | 2016-02-01 13:38:46 -0800 | [diff] [blame] | 4921 | main.log.exception( "{} Error in summary output:".format( self.name ) ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 4922 | return None |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4923 | except TypeError: |
| 4924 | main.log.exception( self.name + ": Object not as expected" ) |
| 4925 | return None |
| 4926 | except pexpect.EOF: |
| 4927 | main.log.error( self.name + ": EOF exception found" ) |
| 4928 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4929 | main.cleanAndExit() |
kelvin-onlab | a297c4d | 2015-06-01 13:53:55 -0700 | [diff] [blame] | 4930 | except Exception: |
| 4931 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4932 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4933 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4934 | def transactionalMapGet( self, keyName ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4935 | """ |
| 4936 | CLI command to get the value of a key in a consistent map using |
| 4937 | transactions. This a test function and can only get keys from the |
| 4938 | test map hard coded into the cli command |
| 4939 | Required arguments: |
| 4940 | keyName - The name of the key to get |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4941 | returns: |
| 4942 | The string value of the key or |
| 4943 | None on Error |
| 4944 | """ |
| 4945 | try: |
| 4946 | keyName = str( keyName ) |
| 4947 | cmdStr = "transactional-map-test-get " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4948 | cmdStr += keyName |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4949 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4950 | pattern = "Key-value pair \(" + keyName + ", (?P<value>.+)\) found." |
| 4951 | if "Key " + keyName + " not found." in output: |
Jon Hall | 9bfadd2 | 2016-05-11 14:48:07 -0700 | [diff] [blame] | 4952 | main.log.warn( output ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4953 | return None |
| 4954 | else: |
| 4955 | match = re.search( pattern, output ) |
| 4956 | if match: |
| 4957 | return match.groupdict()[ 'value' ] |
| 4958 | else: |
| 4959 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 4960 | " match expected output." ) |
| 4961 | main.log.debug( self.name + " expected: " + pattern ) |
| 4962 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 4963 | return None |
| 4964 | except TypeError: |
| 4965 | main.log.exception( self.name + ": Object not as expected" ) |
| 4966 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4967 | except Exception: |
| 4968 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 4969 | main.cleanAndExit() |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4970 | |
Jon Hall | 935db19 | 2016-04-19 00:22:04 -0700 | [diff] [blame] | 4971 | def transactionalMapPut( self, numKeys, value ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4972 | """ |
| 4973 | CLI command to put a value into 'numKeys' number of keys in a |
| 4974 | consistent map using transactions. This a test function and can only |
| 4975 | put into keys named 'Key#' of the test map hard coded into the cli command |
| 4976 | Required arguments: |
| 4977 | numKeys - Number of keys to add the value to |
| 4978 | value - The string value to put into the keys |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4979 | returns: |
| 4980 | A dictionary whose keys are the name of the keys put into the map |
| 4981 | and the values of the keys are dictionaries whose key-values are |
| 4982 | 'value': value put into map and optionaly |
| 4983 | 'oldValue': Previous value in the key or |
| 4984 | None on Error |
| 4985 | |
| 4986 | Example output |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4987 | { 'Key1': {'oldValue': 'oldTestValue', 'value': 'Testing'}, |
| 4988 | 'Key2': {'value': 'Testing'} } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4989 | """ |
| 4990 | try: |
| 4991 | numKeys = str( numKeys ) |
| 4992 | value = str( value ) |
| 4993 | cmdStr = "transactional-map-test-put " |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4994 | cmdStr += numKeys + " " + value |
Jon Hall | 7a6ebfd | 2017-03-13 10:58:58 -0700 | [diff] [blame] | 4995 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 4996 | newPattern = 'Created Key (?P<key>(\w)+) with value (?P<value>(.)+)\.' |
| 4997 | updatedPattern = "Put (?P<value>(.)+) into key (?P<key>(\w)+)\. The old value was (?P<oldValue>(.)+)\." |
| 4998 | results = {} |
| 4999 | for line in output.splitlines(): |
| 5000 | new = re.search( newPattern, line ) |
| 5001 | updated = re.search( updatedPattern, line ) |
| 5002 | if new: |
| 5003 | results[ new.groupdict()[ 'key' ] ] = { 'value': new.groupdict()[ 'value' ] } |
| 5004 | elif updated: |
| 5005 | results[ updated.groupdict()[ 'key' ] ] = { 'value': updated.groupdict()[ 'value' ], |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5006 | 'oldValue': updated.groupdict()[ 'oldValue' ] } |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 5007 | else: |
| 5008 | main.log.error( self.name + ": transactionlMapGet did not" + |
| 5009 | " match expected output." ) |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5010 | main.log.debug( "{} expected: {!r} or {!r}".format( self.name, |
| 5011 | newPattern, |
| 5012 | updatedPattern ) ) |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 5013 | main.log.debug( self.name + " actual: " + repr( output ) ) |
| 5014 | return results |
Jon Hall | 0e24037 | 2018-05-02 11:21:57 -0700 | [diff] [blame] | 5015 | except ( TypeError, AttributeError ): |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 5016 | main.log.exception( self.name + ": Object not as expected" ) |
| 5017 | return None |
Jon Hall | 2a5002c | 2015-08-21 16:49:11 -0700 | [diff] [blame] | 5018 | except Exception: |
| 5019 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5020 | main.cleanAndExit() |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5021 | |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 5022 | def maps( self, jsonFormat=True ): |
| 5023 | """ |
| 5024 | Description: Returns result of onos:maps |
| 5025 | Optional: |
| 5026 | * jsonFormat: enable json formatting of output |
| 5027 | """ |
| 5028 | try: |
| 5029 | cmdStr = "maps" |
| 5030 | if jsonFormat: |
| 5031 | cmdStr += " -j" |
| 5032 | handle = self.sendline( cmdStr ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5033 | assert handle is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5034 | assert "Command not found:" not in handle, handle |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 5035 | return handle |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5036 | except AssertionError: |
| 5037 | main.log.exception( "" ) |
| 5038 | return None |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 5039 | except TypeError: |
| 5040 | main.log.exception( self.name + ": Object not as expected" ) |
| 5041 | return None |
| 5042 | except pexpect.EOF: |
| 5043 | main.log.error( self.name + ": EOF exception found" ) |
| 5044 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5045 | main.cleanAndExit() |
acsmars | daea66c | 2015-09-03 11:44:06 -0700 | [diff] [blame] | 5046 | except Exception: |
| 5047 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5048 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5049 | |
| 5050 | def getSwController( self, uri, jsonFormat=True ): |
| 5051 | """ |
| 5052 | Descrition: Gets the controller information from the device |
| 5053 | """ |
| 5054 | try: |
| 5055 | cmd = "device-controllers " |
| 5056 | if jsonFormat: |
| 5057 | cmd += "-j " |
| 5058 | response = self.sendline( cmd + uri ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5059 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5060 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5061 | return response |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5062 | except AssertionError: |
| 5063 | main.log.exception( "" ) |
| 5064 | return None |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5065 | except TypeError: |
| 5066 | main.log.exception( self.name + ": Object not as expected" ) |
| 5067 | return None |
| 5068 | except pexpect.EOF: |
| 5069 | main.log.error( self.name + ": EOF exception found" ) |
| 5070 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5071 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5072 | except Exception: |
| 5073 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5074 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5075 | |
| 5076 | def setSwController( self, uri, ip, proto="tcp", port="6653", jsonFormat=True ): |
| 5077 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5078 | Descrition: sets the controller(s) for the specified device |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5079 | |
| 5080 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5081 | Required: uri - String: The uri of the device(switch). |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5082 | ip - String or List: The ip address of the controller. |
| 5083 | This parameter can be formed in a couple of different ways. |
| 5084 | VALID: |
| 5085 | 10.0.0.1 - just the ip address |
| 5086 | tcp:10.0.0.1 - the protocol and the ip address |
| 5087 | tcp:10.0.0.1:6653 - the protocol and port can be specified, |
| 5088 | so that you can add controllers with different |
| 5089 | protocols and ports |
| 5090 | INVALID: |
| 5091 | 10.0.0.1:6653 - this is not supported by ONOS |
| 5092 | |
| 5093 | Optional: proto - The type of connection e.g. tcp, ssl. If a list of ips are given |
| 5094 | port - The port number. |
| 5095 | jsonFormat - If set ONOS will output in json NOTE: This is currently not supported |
| 5096 | |
| 5097 | Returns: main.TRUE if ONOS returns without any errors, otherwise returns main.FALSE |
| 5098 | """ |
| 5099 | try: |
| 5100 | cmd = "device-setcontrollers" |
| 5101 | |
| 5102 | if jsonFormat: |
| 5103 | cmd += " -j" |
| 5104 | cmd += " " + uri |
| 5105 | if isinstance( ip, str ): |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5106 | ip = [ ip ] |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5107 | for item in ip: |
| 5108 | if ":" in item: |
| 5109 | sitem = item.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5110 | if len( sitem ) == 3: |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5111 | cmd += " " + item |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5112 | elif "." in sitem[ 1 ]: |
| 5113 | cmd += " {}:{}".format( item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5114 | else: |
| 5115 | main.log.error( "Malformed entry: " + item ) |
| 5116 | raise TypeError |
| 5117 | else: |
| 5118 | cmd += " {}:{}:{}".format( proto, item, port ) |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5119 | response = self.sendline( cmd ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5120 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5121 | assert "Command not found:" not in response, response |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5122 | if "Error" in response: |
| 5123 | main.log.error( response ) |
| 5124 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5125 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5126 | except AssertionError: |
| 5127 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5128 | return main.FALSE |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5129 | except TypeError: |
| 5130 | main.log.exception( self.name + ": Object not as expected" ) |
| 5131 | return main.FALSE |
| 5132 | except pexpect.EOF: |
| 5133 | main.log.error( self.name + ": EOF exception found" ) |
| 5134 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5135 | main.cleanAndExit() |
GlennRC | 050596c | 2015-11-18 17:06:41 -0800 | [diff] [blame] | 5136 | except Exception: |
| 5137 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5138 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5139 | |
| 5140 | def removeDevice( self, device ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5141 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5142 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5143 | Remove a device from ONOS by passing the uri of the device(s). |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5144 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5145 | 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] | 5146 | Returns: |
| 5147 | Returns main.FALSE if an exception is thrown or an error is present |
| 5148 | in the response. Otherwise, returns main.TRUE. |
| 5149 | NOTE: |
| 5150 | 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] | 5151 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5152 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5153 | if isinstance( device, str ): |
You Wang | 823f502 | 2016-08-18 15:24:41 -0700 | [diff] [blame] | 5154 | deviceStr = device |
| 5155 | device = [] |
| 5156 | device.append( deviceStr ) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5157 | |
| 5158 | for d in device: |
| 5159 | time.sleep( 1 ) |
| 5160 | response = self.sendline( "device-remove {}".format( d ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5161 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5162 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5163 | if "Error" in response: |
| 5164 | main.log.warn( "Error for device: {}\nResponse: {}".format( d, response ) ) |
| 5165 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5166 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5167 | except AssertionError: |
| 5168 | main.log.exception( "" ) |
| 5169 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5170 | except TypeError: |
| 5171 | main.log.exception( self.name + ": Object not as expected" ) |
| 5172 | return main.FALSE |
| 5173 | except pexpect.EOF: |
| 5174 | main.log.error( self.name + ": EOF exception found" ) |
| 5175 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5176 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5177 | except Exception: |
| 5178 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5179 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5180 | |
| 5181 | def removeHost( self, host ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5182 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5183 | Description: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5184 | Remove a host from ONOS by passing the id of the host(s) |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5185 | Parameters: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5186 | 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] | 5187 | Returns: |
| 5188 | Returns main.FALSE if an exception is thrown or an error is present |
| 5189 | in the response. Otherwise, returns main.TRUE. |
| 5190 | NOTE: |
| 5191 | 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] | 5192 | ''' |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5193 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5194 | if isinstance( host, str ): |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5195 | host = list( host ) |
| 5196 | |
| 5197 | for h in host: |
| 5198 | time.sleep( 1 ) |
| 5199 | response = self.sendline( "host-remove {}".format( h ) ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5200 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5201 | assert "Command not found:" not in response, response |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5202 | if "Error" in response: |
| 5203 | main.log.warn( "Error for host: {}\nResponse: {}".format( h, response ) ) |
| 5204 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5205 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5206 | except AssertionError: |
| 5207 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5208 | return main.FALSE |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5209 | except TypeError: |
| 5210 | main.log.exception( self.name + ": Object not as expected" ) |
| 5211 | return main.FALSE |
| 5212 | except pexpect.EOF: |
| 5213 | main.log.error( self.name + ": EOF exception found" ) |
| 5214 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5215 | main.cleanAndExit() |
GlennRC | 20fc652 | 2015-12-23 23:26:57 -0800 | [diff] [blame] | 5216 | except Exception: |
| 5217 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5218 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5219 | |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5220 | def link( self, begin, end, state, timeout=30, showResponse=True ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5221 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5222 | Description: |
| 5223 | Bring link down or up in the null-provider. |
| 5224 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5225 | begin - (string) One end of a device or switch. |
| 5226 | end - (string) the other end of the device or switch |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5227 | returns: |
| 5228 | main.TRUE if no exceptions were thrown and no Errors are |
| 5229 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5230 | ''' |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5231 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5232 | cmd = "null-link null:{} null:{} {}".format( begin, end, state ) |
YPZhang | febf730 | 2016-05-24 16:45:56 -0700 | [diff] [blame] | 5233 | response = self.sendline( cmd, showResponse=showResponse, timeout=timeout ) |
Jon Hall | a495f56 | 2016-05-16 18:03:26 -0700 | [diff] [blame] | 5234 | assert response is not None, "Error in sendline" |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5235 | assert "Command not found:" not in response, response |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5236 | if "Error" in response or "Failure" in response: |
| 5237 | main.log.error( response ) |
| 5238 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5239 | return main.TRUE |
Jon Hall | c679355 | 2016-01-19 14:18:37 -0800 | [diff] [blame] | 5240 | except AssertionError: |
| 5241 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5242 | return main.FALSE |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5243 | except TypeError: |
| 5244 | main.log.exception( self.name + ": Object not as expected" ) |
| 5245 | return main.FALSE |
| 5246 | except pexpect.EOF: |
| 5247 | main.log.error( self.name + ": EOF exception found" ) |
| 5248 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5249 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5250 | except Exception: |
| 5251 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5252 | main.cleanAndExit() |
GlennRC | ed77124 | 2016-01-13 17:02:47 -0800 | [diff] [blame] | 5253 | |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5254 | def portstate( self, dpid, port, state ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5255 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5256 | Description: |
| 5257 | Changes the state of port in an OF switch by means of the |
| 5258 | PORTSTATUS OF messages. |
| 5259 | params: |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5260 | dpid - (string) Datapath ID of the device. Ex: 'of:0000000000000102' |
| 5261 | port - (string) target port in the device. Ex: '2' |
| 5262 | state - (string) target state (enable or disable) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5263 | returns: |
| 5264 | main.TRUE if no exceptions were thrown and no Errors are |
| 5265 | present in the resoponse. Otherwise, returns main.FALSE |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5266 | ''' |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5267 | try: |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5268 | state = state.lower() |
| 5269 | assert state == 'enable' or state == 'disable', "Unknown state" |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5270 | cmd = "portstate {} {} {}".format( dpid, port, state ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5271 | response = self.sendline( cmd, showResponse=True ) |
| 5272 | assert response is not None, "Error in sendline" |
| 5273 | assert "Command not found:" not in response, response |
| 5274 | if "Error" in response or "Failure" in response: |
| 5275 | main.log.error( response ) |
| 5276 | return main.FALSE |
| 5277 | return main.TRUE |
| 5278 | except AssertionError: |
| 5279 | main.log.exception( "" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5280 | return main.FALSE |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5281 | except TypeError: |
| 5282 | main.log.exception( self.name + ": Object not as expected" ) |
| 5283 | return main.FALSE |
| 5284 | except pexpect.EOF: |
| 5285 | main.log.error( self.name + ": EOF exception found" ) |
| 5286 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5287 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5288 | except Exception: |
| 5289 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5290 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5291 | |
| 5292 | def logSet( self, level="INFO", app="org.onosproject" ): |
| 5293 | """ |
| 5294 | Set the logging level to lvl for a specific app |
| 5295 | returns main.TRUE on success |
| 5296 | returns main.FALSE if Error occurred |
| 5297 | if noExit is True, TestON will not exit, but clean up |
| 5298 | Available level: DEBUG, TRACE, INFO, WARN, ERROR |
| 5299 | Level defaults to INFO |
| 5300 | """ |
| 5301 | try: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5302 | self.handle.sendline( "log:set %s %s" % ( level, app ) ) |
Jon Hall | 6c9e2da | 2018-11-06 12:01:23 -0800 | [diff] [blame] | 5303 | self.handle.expect( self.karafPrompt ) |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5304 | |
| 5305 | response = self.handle.before |
| 5306 | if re.search( "Error", response ): |
| 5307 | return main.FALSE |
| 5308 | return main.TRUE |
| 5309 | except pexpect.TIMEOUT: |
| 5310 | main.log.exception( self.name + ": TIMEOUT exception found" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5311 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5312 | except pexpect.EOF: |
| 5313 | main.log.error( self.name + ": EOF exception found" ) |
| 5314 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5315 | main.cleanAndExit() |
Flavio Castro | 82ee2f6 | 2016-06-07 15:04:12 -0700 | [diff] [blame] | 5316 | except Exception: |
| 5317 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5318 | main.cleanAndExit() |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5319 | |
| 5320 | def getGraphDict( self, timeout=60, includeHost=False ): |
| 5321 | """ |
| 5322 | Return a dictionary which describes the latest network topology data as a |
| 5323 | graph. |
| 5324 | An example of the dictionary: |
| 5325 | { vertex1: { 'edges': ..., 'name': ..., 'protocol': ... }, |
| 5326 | vertex2: { 'edges': ..., 'name': ..., 'protocol': ... } } |
| 5327 | Each vertex should at least have an 'edges' attribute which describes the |
| 5328 | adjacency information. The value of 'edges' attribute is also represented by |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5329 | 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] | 5330 | list of attributes. |
| 5331 | An example of the edges dictionary: |
| 5332 | 'edges': { vertex2: { 'port': ..., 'weight': ... }, |
| 5333 | vertex3: { 'port': ..., 'weight': ... } } |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5334 | If includeHost == True, all hosts (and host-switch links) will be included |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5335 | in topology data. |
| 5336 | """ |
| 5337 | graphDict = {} |
| 5338 | try: |
| 5339 | links = self.links() |
| 5340 | links = json.loads( links ) |
| 5341 | devices = self.devices() |
| 5342 | devices = json.loads( devices ) |
| 5343 | idToDevice = {} |
| 5344 | for device in devices: |
| 5345 | idToDevice[ device[ 'id' ] ] = device |
| 5346 | if includeHost: |
| 5347 | hosts = self.hosts() |
| 5348 | # FIXME: support 'includeHost' argument |
| 5349 | for link in links: |
| 5350 | nodeA = link[ 'src' ][ 'device' ] |
| 5351 | nodeB = link[ 'dst' ][ 'device' ] |
| 5352 | assert idToDevice[ nodeA ][ 'available' ] and idToDevice[ nodeB ][ 'available' ] |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5353 | if nodeA not in graphDict.keys(): |
| 5354 | graphDict[ nodeA ] = { 'edges': {}, |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5355 | 'dpid': idToDevice[ nodeA ][ 'id' ][ 3: ], |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5356 | 'type': idToDevice[ nodeA ][ 'type' ], |
| 5357 | 'available': idToDevice[ nodeA ][ 'available' ], |
| 5358 | 'role': idToDevice[ nodeA ][ 'role' ], |
| 5359 | 'mfr': idToDevice[ nodeA ][ 'mfr' ], |
| 5360 | 'hw': idToDevice[ nodeA ][ 'hw' ], |
| 5361 | 'sw': idToDevice[ nodeA ][ 'sw' ], |
| 5362 | 'serial': idToDevice[ nodeA ][ 'serial' ], |
| 5363 | 'chassisId': idToDevice[ nodeA ][ 'chassisId' ], |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5364 | 'annotations': idToDevice[ nodeA ][ 'annotations' ]} |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5365 | else: |
| 5366 | # Assert nodeB is not connected to any current links of nodeA |
You Wang | 7d14d64 | 2019-01-23 15:10:08 -0800 | [diff] [blame] | 5367 | # assert nodeB not in graphDict[ nodeA ][ 'edges' ].keys() |
| 5368 | pass |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5369 | graphDict[ nodeA ][ 'edges' ][ nodeB ] = { 'port': link[ 'src' ][ 'port' ], |
| 5370 | 'type': link[ 'type' ], |
| 5371 | 'state': link[ 'state' ] } |
You Wang | db8cd0a | 2016-05-26 15:19:45 -0700 | [diff] [blame] | 5372 | return graphDict |
| 5373 | except ( TypeError, ValueError ): |
| 5374 | main.log.exception( self.name + ": Object not as expected" ) |
| 5375 | return None |
| 5376 | except KeyError: |
| 5377 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5378 | return None |
| 5379 | except AssertionError: |
| 5380 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5381 | return None |
| 5382 | except pexpect.EOF: |
| 5383 | main.log.error( self.name + ": EOF exception found" ) |
| 5384 | main.log.error( self.name + ": " + self.handle.before ) |
| 5385 | return None |
| 5386 | except Exception: |
| 5387 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5388 | return None |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5389 | |
| 5390 | def getIntentPerfSummary( self ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5391 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5392 | Send command to check intent-perf summary |
| 5393 | Returns: dictionary for intent-perf summary |
| 5394 | if something wrong, function will return None |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5395 | ''' |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5396 | cmd = "intent-perf -s" |
| 5397 | respDic = {} |
| 5398 | resp = self.sendline( cmd ) |
You Wang | b5a55f7 | 2017-03-03 12:51:05 -0800 | [diff] [blame] | 5399 | assert resp is not None, "Error in sendline" |
| 5400 | assert "Command not found:" not in resp, resp |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5401 | try: |
| 5402 | # Generate the dictionary to return |
| 5403 | for l in resp.split( "\n" ): |
| 5404 | # Delete any white space in line |
| 5405 | temp = re.sub( r'\s+', '', l ) |
| 5406 | temp = temp.split( ":" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5407 | respDic[ temp[ 0 ] ] = temp[ 1 ] |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5408 | |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5409 | except ( TypeError, ValueError ): |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5410 | main.log.exception( self.name + ": Object not as expected" ) |
| 5411 | return None |
| 5412 | except KeyError: |
| 5413 | main.log.exception( self.name + ": KeyError exception found" ) |
| 5414 | return None |
| 5415 | except AssertionError: |
| 5416 | main.log.exception( self.name + ": AssertionError exception found" ) |
| 5417 | return None |
| 5418 | except pexpect.EOF: |
| 5419 | main.log.error( self.name + ": EOF exception found" ) |
| 5420 | main.log.error( self.name + ": " + self.handle.before ) |
| 5421 | return None |
| 5422 | except Exception: |
| 5423 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 5424 | return None |
| 5425 | return respDic |
| 5426 | |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5427 | def logSearch( self, mode='all', searchTerm='', startLine='', logNum=1 ): |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5428 | """ |
| 5429 | Searches the latest ONOS log file for the given search term and |
| 5430 | return a list that contains all the lines that have the search term. |
YPZhang | cbc2a06 | 2016-07-11 10:55:44 -0700 | [diff] [blame] | 5431 | |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5432 | Arguments: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5433 | searchTerm: |
| 5434 | The string to grep from the ONOS log. |
| 5435 | startLine: |
| 5436 | The term that decides which line is the start to search the searchTerm in |
| 5437 | the karaf log. For now, startTerm only works in 'first' mode. |
| 5438 | logNum: |
| 5439 | In some extreme cases, one karaf log is not big enough to contain all the |
| 5440 | information.Because of this, search mutiply logs is necessary to capture |
| 5441 | the right result. logNum is the number of karaf logs that we need to search |
| 5442 | the searchTerm. |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5443 | mode: |
| 5444 | all: return all the strings that contain the search term |
| 5445 | last: return the last string that contains the search term |
| 5446 | first: return the first string that contains the search term |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5447 | num: return the number of times that the searchTerm appears in the log |
| 5448 | total: return how many lines in karaf log |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5449 | """ |
| 5450 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5451 | assert isinstance( searchTerm, str ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5452 | # Build the log paths string |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5453 | logPath = '/opt/onos/log/karaf.log.' |
| 5454 | logPaths = '/opt/onos/log/karaf.log' |
| 5455 | for i in range( 1, logNum ): |
| 5456 | logPaths = logPath + str( i ) + " " + logPaths |
| 5457 | cmd = "cat " + logPaths |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5458 | if startLine: |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 5459 | # 100000000 is just a extreme large number to make sure this function can |
| 5460 | # grep all the lines after startLine |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5461 | cmd = cmd + " | grep -A 100000000 \'" + startLine + "\'" |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5462 | if mode == 'all': |
| 5463 | cmd = cmd + " | grep \'" + searchTerm + "\'" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5464 | elif mode == 'last': |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5465 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | tail -n 1" |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5466 | elif mode == 'first': |
| 5467 | cmd = cmd + " | grep \'" + searchTerm + "\'" + " | head -n 1" |
| 5468 | elif mode == 'num': |
You Wang | d91a70f | 2019-01-03 15:28:10 -0800 | [diff] [blame] | 5469 | cmd = cmd + " | grep \'" + searchTerm + "\' | wc -l" |
| 5470 | num = self.lineCount( cmd ) |
Chiyu Cheng | b8c2c84 | 2016-10-05 12:40:49 -0700 | [diff] [blame] | 5471 | return num |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5472 | elif mode == 'total': |
Jon Hall | d5a94fb | 2018-11-13 14:32:23 -0800 | [diff] [blame] | 5473 | totalLines = self.lineCount( "cat /opt/onos/log/karaf.log | wc -l" ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5474 | return int( totalLines ) |
You Wang | 6d301d4 | 2017-04-21 10:49:33 -0700 | [diff] [blame] | 5475 | else: |
| 5476 | main.log.error( self.name + " unsupported mode" ) |
| 5477 | return main.ERROR |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5478 | before = self.sendline( cmd ) |
| 5479 | before = before.splitlines() |
| 5480 | # make sure the returned list only contains the search term |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5481 | returnLines = [ line for line in before if searchTerm in line ] |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5482 | return returnLines |
| 5483 | except AssertionError: |
| 5484 | main.log.error( self.name + " searchTerm is not string type" ) |
| 5485 | return None |
| 5486 | except pexpect.EOF: |
| 5487 | main.log.error( self.name + ": EOF exception found" ) |
| 5488 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5489 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5490 | except pexpect.TIMEOUT: |
| 5491 | main.log.error( self.name + ": TIMEOUT exception found" ) |
| 5492 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5493 | main.cleanAndExit() |
chengchiyu | 08303a0 | 2016-09-08 17:40:26 -0700 | [diff] [blame] | 5494 | except Exception: |
| 5495 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5496 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5497 | |
| 5498 | def vplsShow( self, jsonFormat=True ): |
| 5499 | """ |
| 5500 | Description: Returns result of onos:vpls show, which should list the |
| 5501 | configured VPLS networks and the assigned interfaces. |
| 5502 | Optional: |
| 5503 | * jsonFormat: enable json formatting of output |
| 5504 | Returns: |
| 5505 | The output of the command or None on error. |
| 5506 | """ |
| 5507 | try: |
| 5508 | cmdStr = "vpls show" |
| 5509 | if jsonFormat: |
| 5510 | raise NotImplementedError |
| 5511 | cmdStr += " -j" |
| 5512 | handle = self.sendline( cmdStr ) |
| 5513 | assert handle is not None, "Error in sendline" |
| 5514 | assert "Command not found:" not in handle, handle |
| 5515 | return handle |
| 5516 | except AssertionError: |
| 5517 | main.log.exception( "" ) |
| 5518 | return None |
| 5519 | except TypeError: |
| 5520 | main.log.exception( self.name + ": Object not as expected" ) |
| 5521 | return None |
| 5522 | except pexpect.EOF: |
| 5523 | main.log.error( self.name + ": EOF exception found" ) |
| 5524 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5525 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5526 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5527 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5528 | return None |
| 5529 | except Exception: |
| 5530 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5531 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5532 | |
| 5533 | def parseVplsShow( self ): |
| 5534 | """ |
| 5535 | Parse the cli output of 'vpls show' into json output. This is required |
| 5536 | as there is currently no json output available. |
| 5537 | """ |
| 5538 | try: |
| 5539 | output = [] |
| 5540 | raw = self.vplsShow( jsonFormat=False ) |
| 5541 | namePat = "VPLS name: (?P<name>\w+)" |
| 5542 | interfacesPat = "Associated interfaces: \[(?P<interfaces>.*)\]" |
| 5543 | encapPat = "Encapsulation: (?P<encap>\w+)" |
| 5544 | pattern = "\s+".join( [ namePat, interfacesPat, encapPat ] ) |
| 5545 | mIter = re.finditer( pattern, raw ) |
| 5546 | for match in mIter: |
| 5547 | item = {} |
| 5548 | item[ 'name' ] = match.group( 'name' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5549 | ifaces = match.group( 'interfaces' ).split( ', ' ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5550 | if ifaces == [ "" ]: |
| 5551 | ifaces = [] |
| 5552 | item[ 'interfaces' ] = ifaces |
| 5553 | encap = match.group( 'encap' ) |
| 5554 | if encap != 'NONE': |
| 5555 | item[ 'encapsulation' ] = encap.lower() |
| 5556 | output.append( item ) |
| 5557 | return output |
| 5558 | except Exception: |
| 5559 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5560 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5561 | |
| 5562 | def vplsList( self, jsonFormat=True ): |
| 5563 | """ |
| 5564 | Description: Returns result of onos:vpls list, which should list the |
| 5565 | configured VPLS networks. |
| 5566 | Optional: |
| 5567 | * jsonFormat: enable json formatting of output |
| 5568 | """ |
| 5569 | try: |
| 5570 | cmdStr = "vpls list" |
| 5571 | if jsonFormat: |
| 5572 | raise NotImplementedError |
| 5573 | cmdStr += " -j" |
| 5574 | handle = self.sendline( cmdStr ) |
| 5575 | assert handle is not None, "Error in sendline" |
| 5576 | assert "Command not found:" not in handle, handle |
| 5577 | return handle |
| 5578 | except AssertionError: |
| 5579 | main.log.exception( "" ) |
| 5580 | return None |
| 5581 | except TypeError: |
| 5582 | main.log.exception( self.name + ": Object not as expected" ) |
| 5583 | return None |
| 5584 | except pexpect.EOF: |
| 5585 | main.log.error( self.name + ": EOF exception found" ) |
| 5586 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5587 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5588 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5589 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5590 | return None |
| 5591 | except Exception: |
| 5592 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5593 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5594 | |
| 5595 | def vplsCreate( self, network ): |
| 5596 | """ |
| 5597 | CLI command to create a new VPLS network. |
| 5598 | Required arguments: |
| 5599 | network - String name of the network to create. |
| 5600 | returns: |
| 5601 | main.TRUE on success and main.FALSE on failure |
| 5602 | """ |
| 5603 | try: |
| 5604 | network = str( network ) |
| 5605 | cmdStr = "vpls create " |
| 5606 | cmdStr += network |
| 5607 | output = self.sendline( cmdStr ) |
| 5608 | assert output is not None, "Error in sendline" |
| 5609 | assert "Command not found:" not in output, output |
| 5610 | assert "Error executing command" not in output, output |
| 5611 | assert "VPLS already exists:" not in output, output |
| 5612 | return main.TRUE |
| 5613 | except AssertionError: |
| 5614 | main.log.exception( "" ) |
| 5615 | return main.FALSE |
| 5616 | except TypeError: |
| 5617 | main.log.exception( self.name + ": Object not as expected" ) |
| 5618 | return main.FALSE |
| 5619 | except pexpect.EOF: |
| 5620 | main.log.error( self.name + ": EOF exception found" ) |
| 5621 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5622 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5623 | except Exception: |
| 5624 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5625 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5626 | |
| 5627 | def vplsDelete( self, network ): |
| 5628 | """ |
| 5629 | CLI command to delete a VPLS network. |
| 5630 | Required arguments: |
| 5631 | network - Name of the network to delete. |
| 5632 | returns: |
| 5633 | main.TRUE on success and main.FALSE on failure |
| 5634 | """ |
| 5635 | try: |
| 5636 | network = str( network ) |
| 5637 | cmdStr = "vpls delete " |
| 5638 | cmdStr += network |
| 5639 | output = self.sendline( cmdStr ) |
| 5640 | assert output is not None, "Error in sendline" |
| 5641 | assert "Command not found:" not in output, output |
| 5642 | assert "Error executing command" not in output, output |
| 5643 | assert " not found" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5644 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5645 | return main.TRUE |
| 5646 | except AssertionError: |
| 5647 | main.log.exception( "" ) |
| 5648 | return main.FALSE |
| 5649 | except TypeError: |
| 5650 | main.log.exception( self.name + ": Object not as expected" ) |
| 5651 | return main.FALSE |
| 5652 | except pexpect.EOF: |
| 5653 | main.log.error( self.name + ": EOF exception found" ) |
| 5654 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5655 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5656 | except Exception: |
| 5657 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5658 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5659 | |
| 5660 | def vplsAddIface( self, network, iface ): |
| 5661 | """ |
| 5662 | CLI command to add an interface to a VPLS network. |
| 5663 | Required arguments: |
| 5664 | network - Name of the network to add the interface to. |
| 5665 | iface - The ONOS name for an interface. |
| 5666 | returns: |
| 5667 | main.TRUE on success and main.FALSE on failure |
| 5668 | """ |
| 5669 | try: |
| 5670 | network = str( network ) |
| 5671 | iface = str( iface ) |
| 5672 | cmdStr = "vpls add-if " |
| 5673 | cmdStr += network + " " + iface |
| 5674 | output = self.sendline( cmdStr ) |
| 5675 | assert output is not None, "Error in sendline" |
| 5676 | assert "Command not found:" not in output, output |
| 5677 | assert "Error executing command" not in output, output |
| 5678 | assert "already associated to network" not in output, output |
| 5679 | assert "Interface cannot be added." not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5680 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5681 | return main.TRUE |
| 5682 | except AssertionError: |
| 5683 | main.log.exception( "" ) |
| 5684 | return main.FALSE |
| 5685 | except TypeError: |
| 5686 | main.log.exception( self.name + ": Object not as expected" ) |
| 5687 | return main.FALSE |
| 5688 | except pexpect.EOF: |
| 5689 | main.log.error( self.name + ": EOF exception found" ) |
| 5690 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5691 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5692 | except Exception: |
| 5693 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5694 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5695 | |
| 5696 | def vplsRemIface( self, network, iface ): |
| 5697 | """ |
| 5698 | CLI command to remove an interface from a VPLS network. |
| 5699 | Required arguments: |
| 5700 | network - Name of the network to remove the interface from. |
| 5701 | iface - Name of the interface to remove. |
| 5702 | returns: |
| 5703 | main.TRUE on success and main.FALSE on failure |
| 5704 | """ |
| 5705 | try: |
| 5706 | iface = str( iface ) |
| 5707 | cmdStr = "vpls rem-if " |
| 5708 | cmdStr += network + " " + iface |
| 5709 | output = self.sendline( cmdStr ) |
| 5710 | assert output is not None, "Error in sendline" |
| 5711 | assert "Command not found:" not in output, output |
| 5712 | assert "Error executing command" not in output, output |
| 5713 | assert "is not configured" not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5714 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5715 | return main.TRUE |
| 5716 | except AssertionError: |
| 5717 | main.log.exception( "" ) |
| 5718 | return main.FALSE |
| 5719 | except TypeError: |
| 5720 | main.log.exception( self.name + ": Object not as expected" ) |
| 5721 | return main.FALSE |
| 5722 | except pexpect.EOF: |
| 5723 | main.log.error( self.name + ": EOF exception found" ) |
| 5724 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5725 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5726 | except Exception: |
| 5727 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5728 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5729 | |
| 5730 | def vplsClean( self ): |
| 5731 | """ |
| 5732 | Description: Clears the VPLS app configuration. |
| 5733 | Returns: main.TRUE on success and main.FALSE on failure |
| 5734 | """ |
| 5735 | try: |
| 5736 | cmdStr = "vpls clean" |
| 5737 | handle = self.sendline( cmdStr ) |
| 5738 | assert handle is not None, "Error in sendline" |
| 5739 | assert "Command not found:" not in handle, handle |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5740 | assert "still updating" not in handle, handle |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5741 | return handle |
| 5742 | except AssertionError: |
| 5743 | main.log.exception( "" ) |
| 5744 | return main.FALSE |
| 5745 | except TypeError: |
| 5746 | main.log.exception( self.name + ": Object not as expected" ) |
| 5747 | return main.FALSE |
| 5748 | except pexpect.EOF: |
| 5749 | main.log.error( self.name + ": EOF exception found" ) |
| 5750 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5751 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5752 | except Exception: |
| 5753 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5754 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5755 | |
| 5756 | def vplsSetEncap( self, network, encapType ): |
| 5757 | """ |
| 5758 | CLI command to add an interface to a VPLS network. |
| 5759 | Required arguments: |
| 5760 | network - Name of the network to create. |
| 5761 | encapType - Type of encapsulation. |
| 5762 | returns: |
| 5763 | main.TRUE on success and main.FALSE on failure |
| 5764 | """ |
| 5765 | try: |
| 5766 | network = str( network ) |
| 5767 | encapType = str( encapType ).upper() |
| 5768 | assert encapType in [ "MPLS", "VLAN", "NONE" ], "Incorrect type" |
| 5769 | cmdStr = "vpls set-encap " |
| 5770 | cmdStr += network + " " + encapType |
| 5771 | output = self.sendline( cmdStr ) |
| 5772 | assert output is not None, "Error in sendline" |
| 5773 | assert "Command not found:" not in output, output |
| 5774 | assert "Error executing command" not in output, output |
| 5775 | assert "already associated to network" not in output, output |
| 5776 | assert "Encapsulation type " not in output, output |
Jon Hall | cf97cf1 | 2017-06-06 09:37:51 -0700 | [diff] [blame] | 5777 | assert "still updating" not in output, output |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5778 | return main.TRUE |
| 5779 | except AssertionError: |
| 5780 | main.log.exception( "" ) |
| 5781 | return main.FALSE |
| 5782 | except TypeError: |
| 5783 | main.log.exception( self.name + ": Object not as expected" ) |
| 5784 | return main.FALSE |
| 5785 | except pexpect.EOF: |
| 5786 | main.log.error( self.name + ": EOF exception found" ) |
| 5787 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5788 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5789 | except Exception: |
| 5790 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5791 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5792 | |
| 5793 | def interfaces( self, jsonFormat=True ): |
| 5794 | """ |
| 5795 | Description: Returns result of interfaces command. |
| 5796 | Optional: |
| 5797 | * jsonFormat: enable json formatting of output |
| 5798 | Returns: |
| 5799 | The output of the command or None on error. |
| 5800 | """ |
| 5801 | try: |
| 5802 | cmdStr = "interfaces" |
| 5803 | if jsonFormat: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5804 | raise NotImplementedError |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5805 | cmdStr += " -j" |
| 5806 | handle = self.sendline( cmdStr ) |
| 5807 | assert handle is not None, "Error in sendline" |
| 5808 | assert "Command not found:" not in handle, handle |
| 5809 | return handle |
| 5810 | except AssertionError: |
| 5811 | main.log.exception( "" ) |
| 5812 | return None |
| 5813 | except TypeError: |
| 5814 | main.log.exception( self.name + ": Object not as expected" ) |
| 5815 | return None |
| 5816 | except pexpect.EOF: |
| 5817 | main.log.error( self.name + ": EOF exception found" ) |
| 5818 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5819 | main.cleanAndExit() |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5820 | except NotImplementedError: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5821 | main.log.exception( self.name + ": Json output not supported" ) |
Jon Hall | 2c8959e | 2016-12-16 12:17:34 -0800 | [diff] [blame] | 5822 | return None |
| 5823 | except Exception: |
| 5824 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5825 | main.cleanAndExit() |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5826 | |
| 5827 | def getTimeStampFromLog( self, mode, searchTerm, splitTerm_before, splitTerm_after, startLine='', logNum=1 ): |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5828 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5829 | Get the timestamp of searchTerm from karaf log. |
| 5830 | |
| 5831 | Arguments: |
| 5832 | splitTerm_before and splitTerm_after: |
| 5833 | |
| 5834 | The terms that split the string that contains the timeStamp of |
| 5835 | searchTerm. For example, if that string is "xxxxxxxcreationTime = |
| 5836 | 1419510501xxxxxx", then the splitTerm_before is "CreationTime = " |
| 5837 | and the splitTerm_after is "x" |
| 5838 | |
| 5839 | others: |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5840 | Please look at the "logsearch" Function in onosclidriver.py |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 5841 | ''' |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5842 | if logNum < 0: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5843 | main.log.error( "Get wrong log number ") |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5844 | return main.ERROR |
| 5845 | lines = self.logSearch( mode=mode, searchTerm=searchTerm, startLine=startLine, logNum=logNum ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5846 | if len( lines ) == 0: |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5847 | main.log.warn( "Captured timestamp string is empty" ) |
| 5848 | return main.ERROR |
| 5849 | lines = lines[ 0 ] |
| 5850 | try: |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 5851 | assert isinstance( lines, str ) |
Chiyu Cheng | ec63bde | 2016-11-17 18:11:36 -0800 | [diff] [blame] | 5852 | # get the target value |
| 5853 | line = lines.split( splitTerm_before ) |
| 5854 | key = line[ 1 ].split( splitTerm_after ) |
| 5855 | return int( key[ 0 ] ) |
| 5856 | except IndexError: |
| 5857 | main.log.warn( "Index Error!" ) |
| 5858 | return main.ERROR |
| 5859 | except AssertionError: |
| 5860 | main.log.warn( "Search Term Not Found " ) |
| 5861 | return main.ERROR |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5862 | |
| 5863 | def workQueueAdd( self, queueName, value ): |
| 5864 | """ |
| 5865 | CLI command to add a string to the specified Work Queue. |
| 5866 | This function uses the distributed primitives test app, which |
| 5867 | gives some cli access to distributed primitives for testing |
| 5868 | purposes only. |
| 5869 | |
| 5870 | Required arguments: |
| 5871 | queueName - The name of the queue to add to |
| 5872 | value - The value to add to the queue |
| 5873 | returns: |
| 5874 | main.TRUE on success, main.FALSE on failure and |
| 5875 | main.ERROR on error. |
| 5876 | """ |
| 5877 | try: |
| 5878 | queueName = str( queueName ) |
| 5879 | value = str( value ) |
| 5880 | prefix = "work-queue-test" |
| 5881 | operation = "add" |
| 5882 | cmdStr = " ".join( [ prefix, queueName, operation, value ] ) |
| 5883 | output = self.distPrimitivesSend( cmdStr ) |
| 5884 | if "Invalid operation name" in output: |
| 5885 | main.log.warn( output ) |
| 5886 | return main.ERROR |
| 5887 | elif "Done" in output: |
| 5888 | return main.TRUE |
| 5889 | except TypeError: |
| 5890 | main.log.exception( self.name + ": Object not as expected" ) |
| 5891 | return main.ERROR |
| 5892 | except Exception: |
| 5893 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5894 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5895 | |
| 5896 | def workQueueAddMultiple( self, queueName, value1, value2 ): |
| 5897 | """ |
| 5898 | CLI command to add two strings to the specified Work Queue. |
| 5899 | This function uses the distributed primitives test app, which |
| 5900 | gives some cli access to distributed primitives for testing |
| 5901 | purposes only. |
| 5902 | |
| 5903 | Required arguments: |
| 5904 | queueName - The name of the queue to add to |
| 5905 | value1 - The first value to add to the queue |
| 5906 | value2 - The second value to add to the queue |
| 5907 | returns: |
| 5908 | main.TRUE on success, main.FALSE on failure and |
| 5909 | main.ERROR on error. |
| 5910 | """ |
| 5911 | try: |
| 5912 | queueName = str( queueName ) |
| 5913 | value1 = str( value1 ) |
| 5914 | value2 = str( value2 ) |
| 5915 | prefix = "work-queue-test" |
| 5916 | operation = "addMultiple" |
| 5917 | cmdStr = " ".join( [ prefix, queueName, operation, value1, value2 ] ) |
| 5918 | output = self.distPrimitivesSend( cmdStr ) |
| 5919 | if "Invalid operation name" in output: |
| 5920 | main.log.warn( output ) |
| 5921 | return main.ERROR |
| 5922 | elif "Done" in output: |
| 5923 | return main.TRUE |
| 5924 | except TypeError: |
| 5925 | main.log.exception( self.name + ": Object not as expected" ) |
| 5926 | return main.ERROR |
| 5927 | except Exception: |
| 5928 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5929 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5930 | |
| 5931 | def workQueueTakeAndComplete( self, queueName, number=1 ): |
| 5932 | """ |
| 5933 | CLI command to take a value from the specified Work Queue and compelte it. |
| 5934 | This function uses the distributed primitives test app, which |
| 5935 | gives some cli access to distributed primitives for testing |
| 5936 | purposes only. |
| 5937 | |
| 5938 | Required arguments: |
| 5939 | queueName - The name of the queue to add to |
| 5940 | number - The number of items to take and complete |
| 5941 | returns: |
| 5942 | main.TRUE on success, main.FALSE on failure and |
| 5943 | main.ERROR on error. |
| 5944 | """ |
| 5945 | try: |
| 5946 | queueName = str( queueName ) |
| 5947 | number = str( int( number ) ) |
| 5948 | prefix = "work-queue-test" |
| 5949 | operation = "takeAndComplete" |
| 5950 | cmdStr = " ".join( [ prefix, queueName, operation, number ] ) |
| 5951 | output = self.distPrimitivesSend( cmdStr ) |
| 5952 | if "Invalid operation name" in output: |
| 5953 | main.log.warn( output ) |
| 5954 | return main.ERROR |
| 5955 | elif "Done" in output: |
| 5956 | return main.TRUE |
| 5957 | except TypeError: |
| 5958 | main.log.exception( self.name + ": Object not as expected" ) |
| 5959 | return main.ERROR |
| 5960 | except Exception: |
| 5961 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5962 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5963 | |
| 5964 | def workQueueDestroy( self, queueName ): |
| 5965 | """ |
| 5966 | CLI command to destroy the specified Work Queue. |
| 5967 | This function uses the distributed primitives test app, which |
| 5968 | gives some cli access to distributed primitives for testing |
| 5969 | purposes only. |
| 5970 | |
| 5971 | Required arguments: |
| 5972 | queueName - The name of the queue to add to |
| 5973 | returns: |
| 5974 | main.TRUE on success, main.FALSE on failure and |
| 5975 | main.ERROR on error. |
| 5976 | """ |
| 5977 | try: |
| 5978 | queueName = str( queueName ) |
| 5979 | prefix = "work-queue-test" |
| 5980 | operation = "destroy" |
| 5981 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 5982 | output = self.distPrimitivesSend( cmdStr ) |
| 5983 | if "Invalid operation name" in output: |
| 5984 | main.log.warn( output ) |
| 5985 | return main.ERROR |
| 5986 | return main.TRUE |
| 5987 | except TypeError: |
| 5988 | main.log.exception( self.name + ": Object not as expected" ) |
| 5989 | return main.ERROR |
| 5990 | except Exception: |
| 5991 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 5992 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 5993 | |
| 5994 | def workQueueTotalPending( self, queueName ): |
| 5995 | """ |
| 5996 | CLI command to get the Total Pending items of the specified Work Queue. |
| 5997 | This function uses the distributed primitives test app, which |
| 5998 | gives some cli access to distributed primitives for testing |
| 5999 | purposes only. |
| 6000 | |
| 6001 | Required arguments: |
| 6002 | queueName - The name of the queue to add to |
| 6003 | returns: |
| 6004 | The number of Pending items in the specified work queue or |
| 6005 | None on error |
| 6006 | """ |
| 6007 | try: |
| 6008 | queueName = str( queueName ) |
| 6009 | prefix = "work-queue-test" |
| 6010 | operation = "totalPending" |
| 6011 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 6012 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 6013 | main.log.debug( self.name + ": work queue unparsed: " + output ) |
| 6014 | output = output.split( "\r\n" )[ -1 ] |
| 6015 | main.log.debug( self.name + ": work queue parsed: " + output ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6016 | pattern = r'\d+' |
| 6017 | if "Invalid operation name" in output: |
| 6018 | main.log.warn( output ) |
| 6019 | return None |
| 6020 | else: |
| 6021 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 6022 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6023 | except ( AttributeError, TypeError ): |
| 6024 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 6025 | return None |
| 6026 | except Exception: |
| 6027 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 6028 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6029 | |
| 6030 | def workQueueTotalCompleted( self, queueName ): |
| 6031 | """ |
| 6032 | CLI command to get the Total Completed items of the specified Work Queue. |
| 6033 | This function uses the distributed primitives test app, which |
| 6034 | gives some cli access to distributed primitives for testing |
| 6035 | purposes only. |
| 6036 | |
| 6037 | Required arguments: |
| 6038 | queueName - The name of the queue to add to |
| 6039 | returns: |
| 6040 | The number of complete items in the specified work queue or |
| 6041 | None on error |
| 6042 | """ |
| 6043 | try: |
| 6044 | queueName = str( queueName ) |
| 6045 | prefix = "work-queue-test" |
| 6046 | operation = "totalCompleted" |
| 6047 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 6048 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 6049 | main.log.debug( self.name + ": work queue unparsed: " + output ) |
| 6050 | output = output.split( "\r\n" )[ -1 ] |
| 6051 | main.log.debug( self.name + ": work queue parsed: " + output ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6052 | pattern = r'\d+' |
| 6053 | if "Invalid operation name" in output: |
| 6054 | main.log.warn( output ) |
| 6055 | return None |
| 6056 | else: |
| 6057 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 6058 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6059 | except ( AttributeError, TypeError ): |
| 6060 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 6061 | return None |
| 6062 | except Exception: |
| 6063 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 6064 | main.cleanAndExit() |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6065 | |
| 6066 | def workQueueTotalInProgress( self, queueName ): |
| 6067 | """ |
| 6068 | CLI command to get the Total In Progress items of the specified Work Queue. |
| 6069 | This function uses the distributed primitives test app, which |
| 6070 | gives some cli access to distributed primitives for testing |
| 6071 | purposes only. |
| 6072 | |
| 6073 | Required arguments: |
| 6074 | queueName - The name of the queue to add to |
| 6075 | returns: |
| 6076 | The number of In Progress items in the specified work queue or |
| 6077 | None on error |
| 6078 | """ |
| 6079 | try: |
| 6080 | queueName = str( queueName ) |
| 6081 | prefix = "work-queue-test" |
| 6082 | operation = "totalInProgress" |
| 6083 | cmdStr = " ".join( [ prefix, queueName, operation ] ) |
| 6084 | output = self.distPrimitivesSend( cmdStr ) |
Jon Hall | 22e94ce | 2019-01-15 14:52:17 -0800 | [diff] [blame] | 6085 | main.log.debug( self.name + ": work queue unparsed: " + output ) |
| 6086 | output = output.split( "\r\n" )[ -1 ] |
| 6087 | main.log.debug( self.name + ": work queue parsed: " + output ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6088 | pattern = r'\d+' |
| 6089 | if "Invalid operation name" in output: |
| 6090 | main.log.warn( output ) |
| 6091 | return None |
| 6092 | else: |
| 6093 | match = re.search( pattern, output ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 6094 | return match.group( 0 ) |
Jon Hall | e0f0b34 | 2017-04-18 11:43:47 -0700 | [diff] [blame] | 6095 | except ( AttributeError, TypeError ): |
| 6096 | main.log.exception( self.name + ": Object not as expected; " + str( output ) ) |
| 6097 | return None |
| 6098 | except Exception: |
| 6099 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 6100 | main.cleanAndExit() |
Jeremy Ronquillo | 818bc7c | 2017-08-09 17:14:53 +0000 | [diff] [blame] | 6101 | |
| 6102 | def events( self, args='-a' ): |
| 6103 | """ |
| 6104 | Description: Returns events -a command output |
| 6105 | Optional: |
| 6106 | add other arguments |
| 6107 | """ |
| 6108 | try: |
| 6109 | cmdStr = "events" |
| 6110 | if args: |
| 6111 | cmdStr += " " + args |
| 6112 | handle = self.sendline( cmdStr ) |
| 6113 | assert handle is not None, "Error in sendline" |
| 6114 | assert "Command not found:" not in handle, handle |
| 6115 | return handle |
| 6116 | except AssertionError: |
| 6117 | main.log.exception( "" ) |
| 6118 | return None |
| 6119 | except TypeError: |
| 6120 | main.log.exception( self.name + ": Object not as expected" ) |
| 6121 | return None |
| 6122 | except pexpect.EOF: |
| 6123 | main.log.error( self.name + ": EOF exception found" ) |
| 6124 | main.log.error( self.name + ": " + self.handle.before ) |
| 6125 | main.cleanAndExit() |
| 6126 | except Exception: |
| 6127 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6128 | main.cleanAndExit() |
| 6129 | |
| 6130 | def getMaster( self, deviceID ): |
| 6131 | """ |
| 6132 | Description: Obtains current master using "roles" command for a specific deviceID |
| 6133 | """ |
| 6134 | try: |
| 6135 | return str( self.getRole( deviceID )[ 'master' ] ) |
| 6136 | except AssertionError: |
| 6137 | main.log.exception( "" ) |
| 6138 | return None |
| 6139 | except TypeError: |
| 6140 | main.log.exception( self.name + ": Object not as expected" ) |
| 6141 | return None |
| 6142 | except pexpect.EOF: |
| 6143 | main.log.error( self.name + ": EOF exception found" ) |
| 6144 | main.log.error( self.name + ": " + self.handle.before ) |
| 6145 | main.cleanAndExit() |
| 6146 | except Exception: |
| 6147 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | e6fe3c4 | 2017-10-18 16:28:40 -0700 | [diff] [blame] | 6148 | main.cleanAndExit() |
Jon Hall | a478b85 | 2017-12-04 15:00:15 -0800 | [diff] [blame] | 6149 | |
| 6150 | def issu( self ): |
| 6151 | """ |
| 6152 | Short summary of In-Service Software Upgrade status |
| 6153 | |
| 6154 | Returns the output of the cli command or None on Error |
| 6155 | """ |
| 6156 | try: |
| 6157 | cmdStr = "issu" |
| 6158 | handle = self.sendline( cmdStr ) |
| 6159 | assert handle is not None, "Error in sendline" |
| 6160 | assert "Command not found:" not in handle, handle |
| 6161 | assert "Unsupported command:" not in handle, handle |
| 6162 | return handle |
| 6163 | except AssertionError: |
| 6164 | main.log.exception( "" ) |
| 6165 | return None |
| 6166 | except TypeError: |
| 6167 | main.log.exception( self.name + ": Object not as expected" ) |
| 6168 | return None |
| 6169 | except pexpect.EOF: |
| 6170 | main.log.error( self.name + ": EOF exception found" ) |
| 6171 | main.log.error( self.name + ": " + self.handle.before ) |
| 6172 | main.cleanAndExit() |
| 6173 | except Exception: |
| 6174 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6175 | main.cleanAndExit() |
| 6176 | |
| 6177 | def issuInit( self ): |
| 6178 | """ |
| 6179 | Initiates an In-Service Software Upgrade |
| 6180 | |
| 6181 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6182 | """ |
| 6183 | try: |
| 6184 | cmdStr = "issu init" |
| 6185 | handle = self.sendline( cmdStr ) |
| 6186 | assert handle is not None, "Error in sendline" |
| 6187 | assert "Command not found:" not in handle, handle |
| 6188 | assert "Unsupported command:" not in handle, handle |
| 6189 | if "Initialized" in handle: |
| 6190 | return main.TRUE |
| 6191 | else: |
| 6192 | return main.FALSE |
| 6193 | except AssertionError: |
| 6194 | main.log.exception( "" ) |
| 6195 | return main.ERROR |
| 6196 | except TypeError: |
| 6197 | main.log.exception( self.name + ": Object not as expected" ) |
| 6198 | return main.ERROR |
| 6199 | except pexpect.EOF: |
| 6200 | main.log.error( self.name + ": EOF exception found" ) |
| 6201 | main.log.error( self.name + ": " + self.handle.before ) |
| 6202 | main.cleanAndExit() |
| 6203 | except Exception: |
| 6204 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6205 | main.cleanAndExit() |
| 6206 | |
| 6207 | def issuUpgrade( self ): |
| 6208 | """ |
| 6209 | Transitions stores to upgraded nodes |
| 6210 | |
| 6211 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6212 | """ |
| 6213 | try: |
| 6214 | cmdStr = "issu upgrade" |
| 6215 | handle = self.sendline( cmdStr ) |
| 6216 | assert handle is not None, "Error in sendline" |
| 6217 | assert "Command not found:" not in handle, handle |
| 6218 | assert "Unsupported command:" not in handle, handle |
| 6219 | if "Upgraded" in handle: |
| 6220 | return main.TRUE |
| 6221 | else: |
| 6222 | return main.FALSE |
| 6223 | except AssertionError: |
| 6224 | main.log.exception( "" ) |
| 6225 | return main.ERROR |
| 6226 | except TypeError: |
| 6227 | main.log.exception( self.name + ": Object not as expected" ) |
| 6228 | return main.ERROR |
| 6229 | except pexpect.EOF: |
| 6230 | main.log.error( self.name + ": EOF exception found" ) |
| 6231 | main.log.error( self.name + ": " + self.handle.before ) |
| 6232 | main.cleanAndExit() |
| 6233 | except Exception: |
| 6234 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6235 | main.cleanAndExit() |
| 6236 | |
| 6237 | def issuCommit( self ): |
| 6238 | """ |
| 6239 | Finalizes an In-Service Software Upgrade |
| 6240 | |
| 6241 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6242 | """ |
| 6243 | try: |
| 6244 | cmdStr = "issu commit" |
| 6245 | handle = self.sendline( cmdStr ) |
| 6246 | assert handle is not None, "Error in sendline" |
| 6247 | assert "Command not found:" not in handle, handle |
| 6248 | assert "Unsupported command:" not in handle, handle |
| 6249 | # TODO: Check the version returned by this command |
| 6250 | if "Committed version" in handle: |
| 6251 | return main.TRUE |
| 6252 | else: |
| 6253 | return main.FALSE |
| 6254 | except AssertionError: |
| 6255 | main.log.exception( "" ) |
| 6256 | return main.ERROR |
| 6257 | except TypeError: |
| 6258 | main.log.exception( self.name + ": Object not as expected" ) |
| 6259 | return main.ERROR |
| 6260 | except pexpect.EOF: |
| 6261 | main.log.error( self.name + ": EOF exception found" ) |
| 6262 | main.log.error( self.name + ": " + self.handle.before ) |
| 6263 | main.cleanAndExit() |
| 6264 | except Exception: |
| 6265 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6266 | main.cleanAndExit() |
| 6267 | |
| 6268 | def issuRollback( self ): |
| 6269 | """ |
| 6270 | Rolls back an In-Service Software Upgrade |
| 6271 | |
| 6272 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6273 | """ |
| 6274 | try: |
| 6275 | cmdStr = "issu rollback" |
| 6276 | handle = self.sendline( cmdStr ) |
| 6277 | assert handle is not None, "Error in sendline" |
| 6278 | assert "Command not found:" not in handle, handle |
| 6279 | assert "Unsupported command:" not in handle, handle |
| 6280 | # TODO: Check the version returned by this command |
| 6281 | if "Rolled back to version" in handle: |
| 6282 | return main.TRUE |
| 6283 | else: |
| 6284 | return main.FALSE |
| 6285 | except AssertionError: |
| 6286 | main.log.exception( "" ) |
| 6287 | return main.ERROR |
| 6288 | except TypeError: |
| 6289 | main.log.exception( self.name + ": Object not as expected" ) |
| 6290 | return main.ERROR |
| 6291 | except pexpect.EOF: |
| 6292 | main.log.error( self.name + ": EOF exception found" ) |
| 6293 | main.log.error( self.name + ": " + self.handle.before ) |
| 6294 | main.cleanAndExit() |
| 6295 | except Exception: |
| 6296 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6297 | main.cleanAndExit() |
| 6298 | |
| 6299 | def issuReset( self ): |
| 6300 | """ |
| 6301 | Resets the In-Service Software Upgrade status after a rollback |
| 6302 | |
| 6303 | Returns main.TRUE on success, main.ERROR on error, else main.FALSE |
| 6304 | """ |
| 6305 | try: |
| 6306 | cmdStr = "issu reset" |
| 6307 | handle = self.sendline( cmdStr ) |
| 6308 | assert handle is not None, "Error in sendline" |
| 6309 | assert "Command not found:" not in handle, handle |
| 6310 | assert "Unsupported command:" not in handle, handle |
| 6311 | # TODO: Check the version returned by this command |
| 6312 | if "Reset version" in handle: |
| 6313 | return main.TRUE |
| 6314 | else: |
| 6315 | return main.FALSE |
| 6316 | except AssertionError: |
| 6317 | main.log.exception( "" ) |
| 6318 | return main.ERROR |
| 6319 | except TypeError: |
| 6320 | main.log.exception( self.name + ": Object not as expected" ) |
| 6321 | return main.ERROR |
| 6322 | except pexpect.EOF: |
| 6323 | main.log.error( self.name + ": EOF exception found" ) |
| 6324 | main.log.error( self.name + ": " + self.handle.before ) |
| 6325 | main.cleanAndExit() |
| 6326 | except Exception: |
| 6327 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6328 | main.cleanAndExit() |
| 6329 | |
| 6330 | def issuStatus( self ): |
| 6331 | """ |
| 6332 | Status of an In-Service Software Upgrade |
| 6333 | |
| 6334 | Returns the output of the cli command or None on Error |
| 6335 | """ |
| 6336 | try: |
| 6337 | cmdStr = "issu status" |
| 6338 | handle = self.sendline( cmdStr ) |
| 6339 | assert handle is not None, "Error in sendline" |
| 6340 | assert "Command not found:" not in handle, handle |
| 6341 | assert "Unsupported command:" not in handle, handle |
| 6342 | return handle |
| 6343 | except AssertionError: |
| 6344 | main.log.exception( "" ) |
| 6345 | return None |
| 6346 | except TypeError: |
| 6347 | main.log.exception( self.name + ": Object not as expected" ) |
| 6348 | return None |
| 6349 | except pexpect.EOF: |
| 6350 | main.log.error( self.name + ": EOF exception found" ) |
| 6351 | main.log.error( self.name + ": " + self.handle.before ) |
| 6352 | main.cleanAndExit() |
| 6353 | except Exception: |
| 6354 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6355 | main.cleanAndExit() |
| 6356 | |
| 6357 | def issuVersion( self ): |
| 6358 | """ |
| 6359 | Get the version of an In-Service Software Upgrade |
| 6360 | |
| 6361 | Returns the output of the cli command or None on Error |
| 6362 | """ |
| 6363 | try: |
| 6364 | cmdStr = "issu version" |
| 6365 | handle = self.sendline( cmdStr ) |
| 6366 | assert handle is not None, "Error in sendline" |
| 6367 | assert "Command not found:" not in handle, handle |
| 6368 | assert "Unsupported command:" not in handle, handle |
| 6369 | return handle |
| 6370 | except AssertionError: |
| 6371 | main.log.exception( "" ) |
| 6372 | return None |
| 6373 | except TypeError: |
| 6374 | main.log.exception( self.name + ": Object not as expected" ) |
| 6375 | return None |
| 6376 | except pexpect.EOF: |
| 6377 | main.log.error( self.name + ": EOF exception found" ) |
| 6378 | main.log.error( self.name + ": " + self.handle.before ) |
| 6379 | main.cleanAndExit() |
| 6380 | except Exception: |
| 6381 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6382 | main.cleanAndExit() |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6383 | |
| 6384 | def mcastJoin( self, sIP, groupIP, sPort, dPorts ): |
| 6385 | """ |
| 6386 | Create a multicast route by calling 'mcast-join' command |
| 6387 | sIP: source IP of the multicast route |
| 6388 | groupIP: group IP of the multicast route |
| 6389 | sPort: source port (e.g. of:0000000000000001/3 ) of the multicast route |
| 6390 | dPorts: a list of destination ports of the multicast route |
| 6391 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6392 | """ |
| 6393 | try: |
| 6394 | cmdStr = "mcast-join" |
| 6395 | cmdStr += " " + str( sIP ) |
| 6396 | cmdStr += " " + str( groupIP ) |
| 6397 | cmdStr += " " + str( sPort ) |
| 6398 | assert isinstance( dPorts, list ) |
| 6399 | for dPort in dPorts: |
| 6400 | cmdStr += " " + str( dPort ) |
| 6401 | handle = self.sendline( cmdStr ) |
| 6402 | assert handle is not None, "Error in sendline" |
| 6403 | assert "Command not found:" not in handle, handle |
| 6404 | assert "Unsupported command:" not in handle, handle |
| 6405 | assert "Error executing command" not in handle, handle |
| 6406 | if "Added the mcast route" in handle: |
| 6407 | return main.TRUE |
| 6408 | else: |
| 6409 | return main.FALSE |
| 6410 | except AssertionError: |
| 6411 | main.log.exception( "" ) |
| 6412 | return None |
| 6413 | except TypeError: |
| 6414 | main.log.exception( self.name + ": Object not as expected" ) |
| 6415 | return None |
| 6416 | except pexpect.EOF: |
| 6417 | main.log.error( self.name + ": EOF exception found" ) |
| 6418 | main.log.error( self.name + ": " + self.handle.before ) |
| 6419 | main.cleanAndExit() |
| 6420 | except Exception: |
| 6421 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6422 | main.cleanAndExit() |
| 6423 | |
| 6424 | def mcastDelete( self, sIP, groupIP, dPorts ): |
| 6425 | """ |
| 6426 | Delete a multicast route by calling 'mcast-delete' command |
| 6427 | sIP: source IP of the multicast route |
| 6428 | groupIP: group IP of the multicast route |
| 6429 | dPorts: a list of destination ports of the multicast route |
| 6430 | Returns main.TRUE if mcast route is deleted; Otherwise main.FALSE |
| 6431 | """ |
| 6432 | try: |
| 6433 | cmdStr = "mcast-delete" |
| 6434 | cmdStr += " " + str( sIP ) |
| 6435 | cmdStr += " " + str( groupIP ) |
| 6436 | assert isinstance( dPorts, list ) |
| 6437 | for dPort in dPorts: |
| 6438 | cmdStr += " " + str( dPort ) |
| 6439 | handle = self.sendline( cmdStr ) |
| 6440 | assert handle is not None, "Error in sendline" |
| 6441 | assert "Command not found:" not in handle, handle |
| 6442 | assert "Unsupported command:" not in handle, handle |
| 6443 | assert "Error executing command" not in handle, handle |
| 6444 | if "Updated the mcast route" in handle: |
| 6445 | return main.TRUE |
| 6446 | else: |
| 6447 | return main.FALSE |
| 6448 | except AssertionError: |
| 6449 | main.log.exception( "" ) |
| 6450 | return None |
| 6451 | except TypeError: |
| 6452 | main.log.exception( self.name + ": Object not as expected" ) |
| 6453 | return None |
| 6454 | except pexpect.EOF: |
| 6455 | main.log.error( self.name + ": EOF exception found" ) |
| 6456 | main.log.error( self.name + ": " + self.handle.before ) |
| 6457 | main.cleanAndExit() |
| 6458 | except Exception: |
| 6459 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6460 | main.cleanAndExit() |
| 6461 | |
| 6462 | def mcastHostJoin( self, sAddr, gAddr, srcs, sinks ): |
| 6463 | """ |
| 6464 | Create a multicast route by calling 'mcast-host-join' command |
| 6465 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6466 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6467 | srcs: a list of HostId of the sources e.g. ["00:AA:00:00:00:01/None"] |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6468 | sinks: a list of HostId of the sinks e.g. ["00:AA:00:00:01:05/40"] |
| 6469 | Returns main.TRUE if mcast route is added; Otherwise main.FALSE |
| 6470 | """ |
| 6471 | try: |
| 6472 | cmdStr = "mcast-host-join" |
| 6473 | cmdStr += " -sAddr " + str( sAddr ) |
| 6474 | cmdStr += " -gAddr " + str( gAddr ) |
| 6475 | assert isinstance( srcs, list ) |
| 6476 | for src in srcs: |
| 6477 | cmdStr += " -srcs " + str( src ) |
| 6478 | assert isinstance( sinks, list ) |
| 6479 | for sink in sinks: |
| 6480 | cmdStr += " -sinks " + str( sink ) |
| 6481 | handle = self.sendline( cmdStr ) |
| 6482 | assert handle is not None, "Error in sendline" |
| 6483 | assert "Command not found:" not in handle, handle |
| 6484 | assert "Unsupported command:" not in handle, handle |
| 6485 | assert "Error executing command" not in handle, handle |
| 6486 | if "Added the mcast route" in handle: |
| 6487 | return main.TRUE |
| 6488 | else: |
| 6489 | return main.FALSE |
| 6490 | except AssertionError: |
| 6491 | main.log.exception( "" ) |
| 6492 | return None |
| 6493 | except TypeError: |
| 6494 | main.log.exception( self.name + ": Object not as expected" ) |
| 6495 | return None |
| 6496 | except pexpect.EOF: |
| 6497 | main.log.error( self.name + ": EOF exception found" ) |
| 6498 | main.log.error( self.name + ": " + self.handle.before ) |
| 6499 | main.cleanAndExit() |
| 6500 | except Exception: |
| 6501 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6502 | main.cleanAndExit() |
| 6503 | |
| 6504 | def mcastHostDelete( self, sAddr, gAddr, host=None ): |
| 6505 | """ |
| 6506 | Delete multicast sink(s) by calling 'mcast-host-delete' command |
| 6507 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6508 | gAddr: specifies multicast group address |
You Wang | c02d835 | 2018-04-17 16:42:10 -0700 | [diff] [blame] | 6509 | host: HostId of the sink e.g. "00:AA:00:00:01:05/40", |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6510 | will delete the route if not specified |
| 6511 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6512 | """ |
| 6513 | try: |
| 6514 | cmdStr = "mcast-host-delete" |
| 6515 | cmdStr += " -sAddr " + str( sAddr ) |
| 6516 | cmdStr += " -gAddr " + str( gAddr ) |
| 6517 | if host: |
| 6518 | cmdStr += " -h " + str( host ) |
| 6519 | handle = self.sendline( cmdStr ) |
| 6520 | assert handle is not None, "Error in sendline" |
| 6521 | assert "Command not found:" not in handle, handle |
| 6522 | assert "Unsupported command:" not in handle, handle |
| 6523 | assert "Error executing command" not in handle, handle |
| 6524 | if "Updated the mcast route" in handle: |
| 6525 | return main.TRUE |
| 6526 | elif "Deleted the mcast route" in handle: |
| 6527 | return main.TRUE |
| 6528 | else: |
| 6529 | return main.FALSE |
| 6530 | except AssertionError: |
| 6531 | main.log.exception( "" ) |
| 6532 | return None |
| 6533 | except TypeError: |
| 6534 | main.log.exception( self.name + ": Object not as expected" ) |
| 6535 | return None |
| 6536 | except pexpect.EOF: |
| 6537 | main.log.error( self.name + ": EOF exception found" ) |
| 6538 | main.log.error( self.name + ": " + self.handle.before ) |
| 6539 | main.cleanAndExit() |
| 6540 | except Exception: |
| 6541 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6542 | main.cleanAndExit() |
| 6543 | |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6544 | def mcastSinkDelete( self, sAddr, gAddr, sink=None ): |
| 6545 | """ |
| 6546 | Delete multicast sink(s) by calling 'mcast-sink-delete' command |
| 6547 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6548 | gAddr: specifies multicast group address |
| 6549 | host: HostId of the sink e.g. "00:AA:00:00:01:05/40", |
| 6550 | will delete the route if not specified |
| 6551 | Returns main.TRUE if the mcast sink is deleted; Otherwise main.FALSE |
| 6552 | """ |
| 6553 | try: |
| 6554 | cmdStr = "mcast-sink-delete" |
| 6555 | cmdStr += " -sAddr " + str( sAddr ) |
| 6556 | cmdStr += " -gAddr " + str( gAddr ) |
| 6557 | if sink: |
| 6558 | cmdStr += " -s " + str( sink ) |
| 6559 | handle = self.sendline( cmdStr ) |
| 6560 | assert handle is not None, "Error in sendline" |
| 6561 | assert "Command not found:" not in handle, handle |
| 6562 | assert "Unsupported command:" not in handle, handle |
| 6563 | assert "Error executing command" not in handle, handle |
| 6564 | if "Updated the mcast route" in handle: |
| 6565 | return main.TRUE |
| 6566 | elif "Deleted the mcast route" in handle: |
| 6567 | return main.TRUE |
| 6568 | else: |
| 6569 | return main.FALSE |
| 6570 | except AssertionError: |
| 6571 | main.log.exception( "" ) |
| 6572 | return None |
| 6573 | except TypeError: |
| 6574 | main.log.exception( self.name + ": Object not as expected" ) |
| 6575 | return None |
| 6576 | except pexpect.EOF: |
| 6577 | main.log.error( self.name + ": EOF exception found" ) |
| 6578 | main.log.error( self.name + ": " + self.handle.before ) |
| 6579 | main.cleanAndExit() |
| 6580 | except Exception: |
| 6581 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6582 | main.cleanAndExit() |
| 6583 | |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6584 | def mcastSourceDelete( self, sAddr, gAddr, srcs=None ): |
| 6585 | """ |
| 6586 | Delete multicast src(s) by calling 'mcast-source-delete' command |
| 6587 | sAddr: we can provide * for ASM or a specific address for SSM |
| 6588 | gAddr: specifies multicast group address |
You Wang | 547893e | 2018-05-08 13:34:59 -0700 | [diff] [blame] | 6589 | srcs: a list of host IDs of the sources e.g. ["00:AA:00:00:01:05/40"], |
You Wang | e24d627 | 2018-03-27 21:18:50 -0700 | [diff] [blame] | 6590 | will delete the route if not specified |
| 6591 | Returns main.TRUE if mcast sink is deleted; Otherwise main.FALSE |
| 6592 | """ |
| 6593 | try: |
| 6594 | cmdStr = "mcast-source-delete" |
| 6595 | cmdStr += " -sAddr " + str( sAddr ) |
| 6596 | cmdStr += " -gAddr " + str( gAddr ) |
| 6597 | if srcs: |
| 6598 | assert isinstance( srcs, list ) |
| 6599 | for src in srcs: |
| 6600 | cmdStr += " -src " + str( src ) |
| 6601 | handle = self.sendline( cmdStr ) |
| 6602 | assert handle is not None, "Error in sendline" |
| 6603 | assert "Command not found:" not in handle, handle |
| 6604 | assert "Unsupported command:" not in handle, handle |
| 6605 | assert "Error executing command" not in handle, handle |
| 6606 | if "Updated the mcast route" in handle: |
| 6607 | return main.TRUE |
| 6608 | elif "Deleted the mcast route" in handle: |
| 6609 | return main.TRUE |
| 6610 | else: |
| 6611 | return main.FALSE |
| 6612 | except AssertionError: |
| 6613 | main.log.exception( "" ) |
| 6614 | return None |
| 6615 | except TypeError: |
| 6616 | main.log.exception( self.name + ": Object not as expected" ) |
| 6617 | return None |
| 6618 | except pexpect.EOF: |
| 6619 | main.log.error( self.name + ": EOF exception found" ) |
| 6620 | main.log.error( self.name + ": " + self.handle.before ) |
| 6621 | main.cleanAndExit() |
| 6622 | except Exception: |
| 6623 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6624 | main.cleanAndExit() |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6625 | |
| 6626 | def netcfg( self, jsonFormat=True, args="" ): |
| 6627 | """ |
| 6628 | Run netcfg cli command with given args |
| 6629 | """ |
| 6630 | try: |
| 6631 | cmdStr = "netcfg" |
| 6632 | if jsonFormat: |
| 6633 | cmdStr = cmdStr + " -j" |
| 6634 | if args: |
| 6635 | cmdStr = cmdStr + " " + str( args ) |
| 6636 | handle = self.sendline( cmdStr ) |
| 6637 | assert handle is not None, "Error in sendline" |
| 6638 | assert "Command not found:" not in handle, handle |
| 6639 | assert "Unsupported command:" not in handle, handle |
| 6640 | assert "Error executing command" not in handle, handle |
| 6641 | return handle |
| 6642 | except AssertionError: |
| 6643 | main.log.exception( "" ) |
| 6644 | return None |
| 6645 | except TypeError: |
| 6646 | main.log.exception( self.name + ": Object not as expected" ) |
| 6647 | return None |
| 6648 | except pexpect.EOF: |
| 6649 | main.log.error( self.name + ": EOF exception found" ) |
| 6650 | main.log.error( self.name + ": " + self.handle.before ) |
| 6651 | main.cleanAndExit() |
| 6652 | except Exception: |
| 6653 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6654 | main.cleanAndExit() |
| 6655 | |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6656 | def composeT3Command( self, sAddr, dAddr, ipv6=False, verbose=True, simple=False ): |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6657 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6658 | Compose and return a list of t3-troubleshoot cli commands for given source and destination addresses |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6659 | Options: |
| 6660 | sAddr: IP address of the source host |
| 6661 | dAddr: IP address of the destination host |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6662 | ipv6: True if hosts are IPv6 |
| 6663 | verbose: return verbose t3 output if True |
| 6664 | simple: compose command for t3-troubleshoot-simple if True |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6665 | """ |
| 6666 | try: |
| 6667 | # Collect information of both hosts from onos |
| 6668 | hosts = self.hosts() |
| 6669 | hosts = json.loads( hosts ) |
| 6670 | sHost = None |
| 6671 | dHost = None |
| 6672 | for host in hosts: |
| 6673 | if sAddr in host[ "ipAddresses" ]: |
| 6674 | sHost = host |
| 6675 | elif dAddr in host[ "ipAddresses" ]: |
| 6676 | dHost = host |
| 6677 | if sHost and dHost: |
| 6678 | break |
| 6679 | assert sHost, "Not able to find host with IP {}".format( sAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6680 | cmdList = [] |
You Wang | 5d9527b | 2018-05-29 17:08:54 -0700 | [diff] [blame] | 6681 | if simple: |
| 6682 | assert dHost, "Not able to find host with IP {}".format( dAddr ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6683 | cmdStr = "t3-troubleshoot-simple" |
| 6684 | if verbose: |
| 6685 | cmdStr += " -vv" |
| 6686 | if ipv6: |
| 6687 | cmdStr += " -et ipv6" |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6688 | cmdStr += " {}/{} {}/{}".format( sHost[ "mac" ], sHost[ "vlan" ], dHost[ "mac" ], dHost[ "vlan" ] ) |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6689 | cmdList.append( cmdStr ) |
You Wang | 0fa76e7 | 2018-05-18 11:33:25 -0700 | [diff] [blame] | 6690 | else: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6691 | for location in sHost[ "locations" ]: |
| 6692 | cmdStr = "t3-troubleshoot" |
| 6693 | if verbose: |
| 6694 | cmdStr += " -vv" |
| 6695 | if ipv6: |
| 6696 | cmdStr += " -et ipv6" |
| 6697 | cmdStr += " -s " + str( sAddr ) |
| 6698 | cmdStr += " -sp " + str( location[ "elementId" ] ) + "/" + str( location[ "port" ] ) |
| 6699 | cmdStr += " -sm " + str( sHost[ "mac" ] ) |
| 6700 | if sHost[ "vlan" ] != "None": |
| 6701 | cmdStr += " -vid " + sHost[ "vlan" ] |
| 6702 | cmdStr += " -d " + str( dAddr ) |
| 6703 | netcfg = self.netcfg( args="devices {}".format( location[ "elementId" ] ) ) |
| 6704 | netcfg = json.loads( netcfg ) |
| 6705 | assert netcfg, "Failed to get netcfg" |
| 6706 | cmdStr += " -dm " + str( netcfg[ "segmentrouting" ][ "routerMac" ] ) |
| 6707 | cmdList.append( cmdStr ) |
| 6708 | return cmdList |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6709 | except AssertionError: |
| 6710 | main.log.exception( "" ) |
| 6711 | return None |
| 6712 | except ( KeyError, TypeError ): |
| 6713 | main.log.exception( self.name + ": Object not as expected" ) |
| 6714 | return None |
| 6715 | except Exception: |
| 6716 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6717 | main.cleanAndExit() |
| 6718 | |
| 6719 | def t3( self, sAddr, dAddr, ipv6=False ): |
| 6720 | """ |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6721 | Run t3-troubleshoot cli commands for all posible routes given source and destination addresses |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6722 | Options: |
| 6723 | sAddr: IP address of the source host |
| 6724 | dAddr: IP address of the destination host |
| 6725 | """ |
| 6726 | try: |
You Wang | 54b1d67 | 2018-06-11 16:44:13 -0700 | [diff] [blame] | 6727 | cmdList = self.composeT3Command( sAddr, dAddr, ipv6 ) |
| 6728 | assert cmdList is not None, "composeT3Command returned None" |
| 6729 | t3Output = "" |
| 6730 | for cmdStr in cmdList: |
| 6731 | handle = self.sendline( cmdStr ) |
| 6732 | assert handle is not None, "Error in sendline" |
| 6733 | assert "Command not found:" not in handle, handle |
| 6734 | assert "Unsupported command:" not in handle, handle |
| 6735 | assert "Error executing command" not in handle, handle |
| 6736 | assert "Tracing packet" in handle |
| 6737 | t3Output += handle |
| 6738 | return t3Output |
You Wang | 5da39c8 | 2018-04-26 22:55:08 -0700 | [diff] [blame] | 6739 | except AssertionError: |
| 6740 | main.log.exception( "" ) |
| 6741 | return None |
| 6742 | except pexpect.EOF: |
| 6743 | main.log.error( self.name + ": EOF exception found" ) |
| 6744 | main.log.error( self.name + ": " + self.handle.before ) |
| 6745 | main.cleanAndExit() |
| 6746 | except Exception: |
| 6747 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6748 | main.cleanAndExit() |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 6749 | |
| 6750 | def prepareForCLI( self, debug=True, maxRetries=120 ): |
| 6751 | """ |
| 6752 | Prepare docker container to connect to onos cli |
| 6753 | """ |
| 6754 | try: |
| 6755 | # Wait for log files to be created |
| 6756 | ready = 0 |
| 6757 | retries = 0 |
| 6758 | while not ready and retries < maxRetries: |
| 6759 | retries += 1 |
| 6760 | self.handle.sendline( "ls -al /root/onos/apache-karaf-*/data/log" ) |
| 6761 | ready = self.handle.expect( [ "No such file or directory", self.dockerPrompt ] ) |
| 6762 | main.log.debug( "%s: %s" % ( self.name, self.handle.before ) ) |
| 6763 | if not ready: |
| 6764 | self.handle.expect( self.dockerPrompt ) |
| 6765 | time.sleep( 1 ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 6766 | |
| 6767 | cmdList = [] |
| 6768 | cmdList.append( "apt-get update" ) |
| 6769 | cmdList.append( "apt-get install -y openssh-server" ) |
| 6770 | # Some built in scripts are hardcoded |
| 6771 | cmdList.append( "ln -s /root/onos /opt/onos" ) |
| 6772 | cmdList.append( "ln -s /root/onos/apache-karaf-*/data/log /opt/onos/log" ) |
| 6773 | cmdList.append( "ls -al /opt/onos" ) |
| 6774 | output = "" |
| 6775 | for cmdStr in cmdList: |
| 6776 | self.handle.sendline( cmdStr ) |
Jon Hall | 3957026 | 2020-11-17 12:18:19 -0800 | [diff] [blame^] | 6777 | self.handle.expect( self.dockerPrompt, timeout=120 ) |
Jon Hall | 3c0114c | 2020-08-11 15:07:42 -0700 | [diff] [blame] | 6778 | self.handle.sendline( "" ) |
| 6779 | self.handle.expect( self.dockerPrompt ) |
| 6780 | handle = self.handle.before |
| 6781 | assert "command not found" not in handle, handle |
| 6782 | assert "No such file or directory" not in handle, handle |
| 6783 | output += handle |
| 6784 | if debug: |
| 6785 | main.log.debug( "%s: %s" % ( self.name, output ) ) |
| 6786 | return output |
| 6787 | except AssertionError: |
| 6788 | main.log.exception( "" ) |
| 6789 | return None |
| 6790 | except pexpect.EOF: |
| 6791 | main.log.error( self.name + ": EOF exception found" ) |
| 6792 | main.log.error( self.name + ": " + self.handle.before ) |
| 6793 | main.cleanAndExit() |
| 6794 | except Exception: |
| 6795 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6796 | main.cleanAndExit() |
| 6797 | |
| 6798 | def onosSecureSSH( self, userName="onos", userPWD="rocks" ): |
| 6799 | """ |
| 6800 | Enables secure access to ONOS console |
| 6801 | by removing default users & keys. |
| 6802 | |
| 6803 | bin/onos-user-password onos rocks |
| 6804 | |
| 6805 | Returns: main.TRUE on success and main.FALSE on failure |
| 6806 | """ |
| 6807 | |
| 6808 | try: |
| 6809 | self.handle.sendline( "" ) |
| 6810 | self.handle.expect( self.dockerPrompt ) |
| 6811 | |
| 6812 | self.handle.sendline( "[ ! -f ~/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' -q" ) |
| 6813 | self.handle.expect( self.dockerPrompt ) |
| 6814 | main.log.debug( "%s: %s%s" % ( self.name, self.handle.before, self.handle.after ) ) |
| 6815 | |
| 6816 | self.handle.sendline( "bin/onos-user-key $(id -un) $(cut -d\\\\ -f2 ~/.ssh/id_rsa.pub)" ) |
| 6817 | self.handle.expect( pexpect.TIMEOUT, timeout=10 ) |
| 6818 | main.log.debug( "%s: %s" % ( self.name, self.handle.before ) ) |
| 6819 | |
| 6820 | self.handle.sendline( "bin/onos-user-password %s %s" % ( userName, userPWD ) ) |
| 6821 | i = self.handle.expect( [ "usage", |
| 6822 | self.dockerPrompt, |
| 6823 | pexpect.TIMEOUT ] ) |
| 6824 | if i == 0: |
| 6825 | # malformed command |
| 6826 | main.log.warn( self.name + ": Could not parse onos-user-password command" ) |
| 6827 | self.handle.expect( self.dockerPrompt ) |
| 6828 | return main.FALSE |
| 6829 | elif i == 1: |
| 6830 | # Process started |
| 6831 | main.log.info( self.name + ": SSH password added for user " + userName ) |
| 6832 | return main.TRUE |
| 6833 | elif i == 2: |
| 6834 | # timeout |
| 6835 | main.log.error( self.name + ": Failed to secure onos ssh " ) |
| 6836 | main.log.debug( "%s: %s" % ( self.name, self.handle.before ) ) |
| 6837 | except pexpect.EOF: |
| 6838 | main.log.error( self.name + ": EOF exception found" ) |
| 6839 | main.log.error( self.name + ": " + self.handle.before ) |
| 6840 | main.cleanAndExit() |
| 6841 | except Exception: |
| 6842 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 6843 | main.cleanAndExit() |