Maru Newby | b096d9f | 2015-03-09 18:54:54 +0000 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Armando Migliaccio | 023d7f8 | 2016-02-25 12:21:24 -0800 | [diff] [blame] | 16 | from tempest.lib import exceptions |
Maru Newby | b096d9f | 2015-03-09 18:54:54 +0000 | [diff] [blame] | 17 | |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 18 | from neutron_tempest_plugin.common import utils |
Maru Newby | b096d9f | 2015-03-09 18:54:54 +0000 | [diff] [blame] | 19 | |
| 20 | |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 21 | class NeutronTempestPluginException(exceptions.TempestException): |
| 22 | |
| 23 | def __init__(self, **kwargs): |
| 24 | super(NeutronTempestPluginException, self).__init__(**kwargs) |
| 25 | self._properties = kwargs |
| 26 | |
| 27 | def __getattr__(self, name): |
| 28 | try: |
| 29 | return self._properties[name] |
| 30 | except KeyError: |
| 31 | pass |
| 32 | |
| 33 | msg = ("AttributeError: {!r} object has no attribute {!r}").format( |
| 34 | self, name) |
| 35 | raise AttributeError(msg) |
| 36 | |
| 37 | |
| 38 | class InvalidConfiguration(NeutronTempestPluginException): |
Maru Newby | b096d9f | 2015-03-09 18:54:54 +0000 | [diff] [blame] | 39 | message = "Invalid Configuration" |
| 40 | |
| 41 | |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 42 | class InvalidCredentials(NeutronTempestPluginException): |
Maru Newby | b096d9f | 2015-03-09 18:54:54 +0000 | [diff] [blame] | 43 | message = "Invalid Credentials" |
| 44 | |
| 45 | |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 46 | class InvalidServiceTag(NeutronTempestPluginException): |
Maru Newby | b096d9f | 2015-03-09 18:54:54 +0000 | [diff] [blame] | 47 | message = "Invalid service tag" |
Federico Ressi | 498a7f4 | 2018-10-22 17:44:11 +0200 | [diff] [blame] | 48 | |
| 49 | |
| 50 | class SSHScriptException(exceptions.TempestException): |
| 51 | """Base class for SSH client execute_script() exceptions""" |
| 52 | |
| 53 | |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 54 | class ShellError(NeutronTempestPluginException): |
| 55 | pass |
Federico Ressi | 498a7f4 | 2018-10-22 17:44:11 +0200 | [diff] [blame] | 56 | |
| 57 | |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 58 | class ShellCommandFailed(ShellError): |
| 59 | """Raised when shell command exited with non-zero status |
| 60 | |
| 61 | """ |
| 62 | message = ("Command %(command)r failed, exit status: %(exit_status)d, " |
| 63 | "stderr:\n%(stderr)s\n" |
| 64 | "stdout:\n%(stdout)s") |
| 65 | |
| 66 | |
| 67 | class SSHScriptFailed(ShellCommandFailed): |
| 68 | message = ("Command %(command)r failed, exit status: %(exit_status)d, " |
| 69 | "host: %(host)r\n" |
Federico Ressi | 498a7f4 | 2018-10-22 17:44:11 +0200 | [diff] [blame] | 70 | "script:\n%(script)s\n" |
| 71 | "stderr:\n%(stderr)s\n" |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 72 | "stdout:\n%(stdout)s") |
| 73 | |
| 74 | |
| 75 | class ShellTimeoutExpired(ShellError): |
| 76 | """Raised when shell command timeouts and has been killed before exiting |
| 77 | |
| 78 | """ |
| 79 | message = ("Command '%(command)s' timed out: %(timeout)d, " |
| 80 | "stderr:\n%(stderr)s\n" |
| 81 | "stdout:\n%(stdout)s") |
| 82 | |
| 83 | |
| 84 | class SSHScriptTimeoutExpired(ShellTimeoutExpired): |
| 85 | message = ("Command '%(command)s', timed out: %(timeout)d " |
| 86 | "host: %(host)r\n" |
| 87 | "script:\n%(script)s\n" |
| 88 | "stderr:\n%(stderr)s\n" |
| 89 | "stdout:\n%(stdout)s") |
| 90 | |
| 91 | |
| 92 | # Patch SSHExecCommandFailed exception to make sure we can access to fields |
| 93 | # command, exit_status, STDOUT and STDERR when SSH client reports command |
| 94 | # failure |
| 95 | exceptions.SSHExecCommandFailed = utils.override_class( |
| 96 | exceptions.SSHExecCommandFailed, ShellCommandFailed) |
| 97 | |
| 98 | # Above code created a new SSHExecCommandFailed class based on top |
Slawek Kaplonski | 86620da | 2020-02-06 10:41:36 +0100 | [diff] [blame] | 99 | # of ShellCommandFailed |
Federico Ressi | 0e04f8f | 2018-10-24 12:19:05 +0200 | [diff] [blame] | 100 | assert issubclass(exceptions.SSHExecCommandFailed, ShellCommandFailed) |