blob: 398bc1c8a390d869324c222bd9814e8de2c6cd4d [file] [log] [blame]
Maru Newbyb096d9f2015-03-09 18:54:54 +00001# 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 Migliaccio023d7f82016-02-25 12:21:24 -080016from tempest.lib import exceptions
Maru Newbyb096d9f2015-03-09 18:54:54 +000017
Federico Ressi0e04f8f2018-10-24 12:19:05 +020018from neutron_tempest_plugin.common import utils
Maru Newbyb096d9f2015-03-09 18:54:54 +000019
20
Federico Ressi0e04f8f2018-10-24 12:19:05 +020021class 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
38class InvalidConfiguration(NeutronTempestPluginException):
Maru Newbyb096d9f2015-03-09 18:54:54 +000039 message = "Invalid Configuration"
40
41
Federico Ressi0e04f8f2018-10-24 12:19:05 +020042class InvalidCredentials(NeutronTempestPluginException):
Maru Newbyb096d9f2015-03-09 18:54:54 +000043 message = "Invalid Credentials"
44
45
Federico Ressi0e04f8f2018-10-24 12:19:05 +020046class InvalidServiceTag(NeutronTempestPluginException):
Maru Newbyb096d9f2015-03-09 18:54:54 +000047 message = "Invalid service tag"
Federico Ressi498a7f42018-10-22 17:44:11 +020048
49
50class SSHScriptException(exceptions.TempestException):
51 """Base class for SSH client execute_script() exceptions"""
52
53
Federico Ressi0e04f8f2018-10-24 12:19:05 +020054class ShellError(NeutronTempestPluginException):
55 pass
Federico Ressi498a7f42018-10-22 17:44:11 +020056
57
Federico Ressi0e04f8f2018-10-24 12:19:05 +020058class 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
67class SSHScriptFailed(ShellCommandFailed):
68 message = ("Command %(command)r failed, exit status: %(exit_status)d, "
69 "host: %(host)r\n"
Federico Ressi498a7f42018-10-22 17:44:11 +020070 "script:\n%(script)s\n"
71 "stderr:\n%(stderr)s\n"
Federico Ressi0e04f8f2018-10-24 12:19:05 +020072 "stdout:\n%(stdout)s")
73
74
75class 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
84class 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
95exceptions.SSHExecCommandFailed = utils.override_class(
96 exceptions.SSHExecCommandFailed, ShellCommandFailed)
97
98# Above code created a new SSHExecCommandFailed class based on top
Slawek Kaplonski86620da2020-02-06 10:41:36 +010099# of ShellCommandFailed
Federico Ressi0e04f8f2018-10-24 12:19:05 +0200100assert issubclass(exceptions.SSHExecCommandFailed, ShellCommandFailed)