blob: 7bc4abc251de227d93891d8dce2c4cd780ef381d [file] [log] [blame]
Dennis Dmitriev6f59add2016-10-18 13:45:27 +03001# Copyright 2016 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15
16class UnexpectedExitCode(Exception):
17 def __init__(self, command, ec, expected_ec, stdout=None, stderr=None):
18 """Exception for unexpected exit code after executing shell/ssh command
19
20 :param command: str - executed command
21 :param ec: int - actual exit code
22 :param expected_ec: list of integers - expected exit codes
23 :param stdout: str
24 :param stderr: str
25 """
26 self.ec = ec
27 self.expected_ec = expected_ec
28 self.cmd = command
29 self.stdout = stdout
30 self.stderr = stderr
31 super(UnexpectedExitCode, self).__init__()
32
33 def __str__(self):
34 message = "Command '{cmd:s}' returned unexpected exit code {code:d}," \
35 " while waiting for {exp}".format(cmd=self.cmd,
36 code=self.ec,
37 exp=self.expected_ec)
38 if self.stdout:
39 message += "stdout: {}\n".format(self.stdout)
40 if self.stderr:
41 message += "stderr: {}\n".format(self.stderr)
42 return message
43
44
45class VariableNotSet(Exception):
46 def __init__(self, variable_name, expected_value):
47 self.variable_name = variable_name
48 self.expected_value = expected_value
49 super(VariableNotSet, self).__init__()
50
51 def __str__(self):
52 return "Variable {0} was not set in value {1}".format(
53 self.variable_name, self.expected_value)
54
55
56class DevopsConfigPathIsNotSet(ValueError):
57 def __str__(self):
58 return "Devops config/template path is not set!"
59
60
61class DevopsConfigTypeError(TypeError):
62 def __init__(self, type_name):
63 self.type_name = type_name
64 super(DevopsConfigTypeError, self).__init__()
65
66 def __str__(self):
67 return "Devops config should be dict instead of {0}".format(
68 self.type_name
69 )
70
71
72class DevopsConfigIsNone(ValueError):
73 def __str__(self):
74 return "Devops config is None!"
75
76
77class EnvironmentNameIsNotSet(ValueError):
78 def __str__(self):
79 return "Couldn't get environment name!"
80
81
82class EnvironmentDoesNotExist(BaseException):
83 def __init__(self, env_name):
84 super(EnvironmentDoesNotExist, self).__init__()
85 self.env_name = env_name
86
87 def __str__(self):
88 return "Environment {0} does not exist!".format(
89 self.env_name
90 )
91
92
93class EnvironmentAlreadyExists(BaseException):
94 def __init__(self, env_name):
95 super(EnvironmentAlreadyExists, self).__init__()
96 self.env_name = env_name
97
98 def __str__(self):
99 return "Environment {0} already exists!".format(
100 self.env_name
101 )
102
103
104class EnvironmentSnapshotMissing(BaseException):
105 def __init__(self, env_name, snapshot_name):
106 super(EnvironmentSnapshotMissing, self).__init__()
107 self.env_name = env_name
108 self.snapshot_name = snapshot_name
109
110 def __str__(self):
111 return ("Environment '{0}' doesn't have requested snapshot '{1}'! "
112 "Please create the snapshot manually or erase the environment."
113 .format(self.env_name, self.snapshot_name))
114
115
116class EnvironmentIsNotSet(BaseException):
117 def __str__(self):
118 return "Environment is not set!"
119
120
121class BaseImageIsNotSet(BaseException):
122 def __str__(self):
123 return "Base image for creating VMs is not set!"
Dennis Dmitriev2d643bc2017-12-04 12:23:47 +0200124
125
126class SaltPillarError(BaseException):
127 def __init__(self, minion_id, pillar, message=''):
128 super(SaltPillarError, self).__init__()
129 self.minion_id = minion_id
130 self.pillar = pillar
131 self.message = message
132
133 def __str__(self):
134 return ("Salt pillar '{0}' error on minion {1}: {2}"
135 .format(self.minion_id, self.pillar, self.message))
Dennis Dmitriev86085b42018-07-02 14:14:25 +0300136
137
138class EnvironmentNodeIsNotStarted(BaseException):
139 def __init__(self, node_name, message=''):
140 super(EnvironmentNodeIsNotStarted, self).__init__()
141 self.node_name = node_name
142 self.message = message
143
144 def __str__(self):
145 return ("Cloud-init failed on node {0} with error: \n{1}"
146 .format(self.node_name, self.message))