root / lib / errors.py @ 9748ab35
History | View | Annotate | Download (7.9 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2006, 2007 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""Ganeti exception handling"""
|
23 |
|
24 |
|
25 |
class GenericError(Exception): |
26 |
"""Base exception for Ganeti.
|
27 |
|
28 |
"""
|
29 |
pass
|
30 |
|
31 |
|
32 |
class LVMError(GenericError): |
33 |
"""LVM-related exception.
|
34 |
|
35 |
This exception codifies problems with LVM setup.
|
36 |
|
37 |
"""
|
38 |
pass
|
39 |
|
40 |
|
41 |
class LockError(GenericError): |
42 |
"""Lock error exception.
|
43 |
|
44 |
This signifies problems in the locking subsystem.
|
45 |
|
46 |
"""
|
47 |
pass
|
48 |
|
49 |
|
50 |
class HypervisorError(GenericError): |
51 |
"""Hypervisor-related exception.
|
52 |
|
53 |
This is raised in case we can't communicate with the hypervisor
|
54 |
properly.
|
55 |
|
56 |
"""
|
57 |
pass
|
58 |
|
59 |
|
60 |
class ProgrammerError(GenericError): |
61 |
"""Programming-related error.
|
62 |
|
63 |
This is raised in cases we determine that the calling conventions
|
64 |
have been violated, meaning we got some desynchronisation between
|
65 |
parts of our code. It signifies a real programming bug.
|
66 |
|
67 |
"""
|
68 |
pass
|
69 |
|
70 |
|
71 |
class BlockDeviceError(GenericError): |
72 |
"""Block-device related exception.
|
73 |
|
74 |
This is raised in case we can't setup the instance's block devices
|
75 |
properly.
|
76 |
|
77 |
"""
|
78 |
pass
|
79 |
|
80 |
|
81 |
class ConfigurationError(GenericError): |
82 |
"""Configuration related exception.
|
83 |
|
84 |
Things like having an instance with a primary node that doesn't
|
85 |
exist in the config or such raise this exception.
|
86 |
|
87 |
"""
|
88 |
pass
|
89 |
|
90 |
|
91 |
class RemoteError(GenericError): |
92 |
"""Programming-related error on remote call.
|
93 |
|
94 |
This is raised when an unhandled error occurs in a call to a
|
95 |
remote node. It usually signifies a real programming bug.
|
96 |
|
97 |
"""
|
98 |
pass
|
99 |
|
100 |
|
101 |
class SignatureError(GenericError): |
102 |
"""Error authenticating a remote message.
|
103 |
|
104 |
This is raised when the hmac signature on a message doesn't verify correctly
|
105 |
to the message itself. It can happen because of network unreliability or
|
106 |
because of spurious traffic.
|
107 |
|
108 |
"""
|
109 |
pass
|
110 |
|
111 |
|
112 |
class ParameterError(GenericError): |
113 |
"""A passed parameter to a command is invalid.
|
114 |
|
115 |
This is raised when the parameter passed to a request function is
|
116 |
invalid. Correct code should have verified this before passing the
|
117 |
request structure.
|
118 |
|
119 |
The argument to this exception should be the parameter name.
|
120 |
|
121 |
"""
|
122 |
pass
|
123 |
|
124 |
|
125 |
class OpPrereqError(GenericError): |
126 |
"""Prerequisites for the OpCode are not fulfilled.
|
127 |
|
128 |
"""
|
129 |
|
130 |
|
131 |
class OpExecError(GenericError): |
132 |
"""Error during OpCode execution.
|
133 |
|
134 |
"""
|
135 |
|
136 |
|
137 |
class OpRetryError(OpExecError): |
138 |
"""Error during OpCode execution, action can be retried.
|
139 |
|
140 |
"""
|
141 |
|
142 |
|
143 |
class OpCodeUnknown(GenericError): |
144 |
"""Unknown opcode submitted.
|
145 |
|
146 |
This signifies a mismatch between the definitions on the client and
|
147 |
server side.
|
148 |
|
149 |
"""
|
150 |
|
151 |
|
152 |
class JobLost(GenericError): |
153 |
"""Submitted job lost.
|
154 |
|
155 |
The job was submitted but it cannot be found in the current job
|
156 |
list.
|
157 |
|
158 |
"""
|
159 |
|
160 |
|
161 |
class ResolverError(GenericError): |
162 |
"""Host name cannot be resolved.
|
163 |
|
164 |
This is not a normal situation for Ganeti, as we rely on having a
|
165 |
working resolver.
|
166 |
|
167 |
The non-resolvable hostname is available as the first element of the
|
168 |
args tuple; the other two elements of the tuple are the first two
|
169 |
args of the socket.gaierror exception (error code and description).
|
170 |
|
171 |
"""
|
172 |
|
173 |
|
174 |
class HooksFailure(GenericError): |
175 |
"""A generic hook failure.
|
176 |
|
177 |
This signifies usually a setup misconfiguration.
|
178 |
|
179 |
"""
|
180 |
|
181 |
|
182 |
class HooksAbort(HooksFailure): |
183 |
"""A required hook has failed.
|
184 |
|
185 |
This caused an abort of the operation in the initial phase. This
|
186 |
exception always has an attribute args which is a list of tuples of:
|
187 |
- node: the source node on which this hooks has failed
|
188 |
- script: the name of the script which aborted the run
|
189 |
|
190 |
"""
|
191 |
|
192 |
|
193 |
class UnitParseError(GenericError): |
194 |
"""Unable to parse size unit.
|
195 |
|
196 |
"""
|
197 |
|
198 |
|
199 |
class TypeEnforcementError(GenericError): |
200 |
"""Unable to enforce data type.
|
201 |
|
202 |
"""
|
203 |
|
204 |
|
205 |
class SshKeyError(GenericError): |
206 |
"""Invalid SSH key.
|
207 |
|
208 |
"""
|
209 |
|
210 |
|
211 |
class TagError(GenericError): |
212 |
"""Generic tag error.
|
213 |
|
214 |
The argument to this exception will show the exact error.
|
215 |
|
216 |
"""
|
217 |
|
218 |
|
219 |
class CommandError(GenericError): |
220 |
"""External command error.
|
221 |
|
222 |
"""
|
223 |
|
224 |
|
225 |
class StorageError(GenericError): |
226 |
"""Storage-related exception.
|
227 |
|
228 |
"""
|
229 |
|
230 |
|
231 |
class InotifyError(GenericError): |
232 |
"""Error raised when there is a failure setting up an inotify watcher.
|
233 |
|
234 |
"""
|
235 |
|
236 |
|
237 |
class QuitGanetiException(Exception): |
238 |
"""Signal that Ganeti that it must quit.
|
239 |
|
240 |
This is not necessarily an error (and thus not a subclass of
|
241 |
GenericError), but it's an exceptional circumstance and it is thus
|
242 |
treated. This instance should be instantiated with two values. The
|
243 |
first one will specify the return code to the caller, and the second
|
244 |
one will be the returned result (either as an error or as a normal
|
245 |
result). Usually only the leave cluster rpc call should return
|
246 |
status True (as there it's expected we quit), every other call will
|
247 |
return status False (as a critical error was encountered).
|
248 |
|
249 |
Examples::
|
250 |
|
251 |
# Return a result of "True" to the caller, but quit ganeti afterwards
|
252 |
raise QuitGanetiException(True, None)
|
253 |
# Send an error to the caller, and quit ganeti
|
254 |
raise QuitGanetiException(False, "Fatal safety violation, shutting down")
|
255 |
|
256 |
"""
|
257 |
|
258 |
|
259 |
class JobQueueError(GenericError): |
260 |
"""Job queue error.
|
261 |
|
262 |
"""
|
263 |
|
264 |
|
265 |
class JobQueueDrainError(JobQueueError): |
266 |
"""Job queue is marked for drain error.
|
267 |
|
268 |
This is raised when a job submission attempt is made but the queue
|
269 |
is marked for drain.
|
270 |
|
271 |
"""
|
272 |
|
273 |
|
274 |
class JobQueueFull(JobQueueError): |
275 |
"""Job queue full error.
|
276 |
|
277 |
Raised when job queue size reached its hard limit.
|
278 |
|
279 |
"""
|
280 |
|
281 |
|
282 |
class ConfdFatalError(GenericError): |
283 |
"""A fatal failure in Ganeti confd.
|
284 |
|
285 |
Events that compromise the ability of confd to proceed further.
|
286 |
(for example: inability to load the config file)
|
287 |
|
288 |
"""
|
289 |
|
290 |
|
291 |
class ConfdRequestError(GenericError): |
292 |
"""A request error in Ganeti confd.
|
293 |
|
294 |
Events that should make confd abort the current request and proceed serving
|
295 |
different ones.
|
296 |
|
297 |
"""
|
298 |
|
299 |
|
300 |
class ConfdMagicError(GenericError): |
301 |
"""A magic fourcc error in Ganeti confd.
|
302 |
|
303 |
Errors processing the fourcc in ganeti confd datagrams.
|
304 |
|
305 |
"""
|
306 |
|
307 |
|
308 |
class UdpDataSizeError(GenericError): |
309 |
"""UDP payload too big.
|
310 |
|
311 |
"""
|
312 |
|
313 |
|
314 |
# errors should be added above
|
315 |
|
316 |
|
317 |
def GetErrorClass(name): |
318 |
"""Return the class of an exception.
|
319 |
|
320 |
Given the class name, return the class itself.
|
321 |
|
322 |
@type name: str
|
323 |
@param name: the exception name
|
324 |
@rtype: class
|
325 |
@return: the actual class, or None if not found
|
326 |
|
327 |
"""
|
328 |
item = globals().get(name, None) |
329 |
if item is not None: |
330 |
if not (isinstance(item, type(Exception)) and |
331 |
issubclass(item, GenericError)):
|
332 |
item = None
|
333 |
return item
|
334 |
|
335 |
|
336 |
def EncodeException(err): |
337 |
"""Encodes an exception into a format that L{MaybeRaise} will recognise.
|
338 |
|
339 |
The passed L{err} argument will be formatted as a tuple (exception
|
340 |
name, arguments) that the MaybeRaise function will recognise.
|
341 |
|
342 |
@type err: GenericError child
|
343 |
@param err: usually a child of GenericError (but any exception
|
344 |
will be accepted)
|
345 |
@rtype: tuple
|
346 |
@return: tuple of (exception name, exception arguments)
|
347 |
|
348 |
"""
|
349 |
return (err.__class__.__name__, err.args)
|
350 |
|
351 |
|
352 |
def MaybeRaise(result): |
353 |
"""Is this looks like an encoded Ganeti exception, raise it.
|
354 |
|
355 |
This function tries to parse the passed argument and if it looks
|
356 |
like an encoding done by EncodeException, it will re-raise it.
|
357 |
|
358 |
"""
|
359 |
tlt = (tuple, list) |
360 |
if (isinstance(result, tlt) and len(result) == 2 and |
361 |
isinstance(result[1], tlt)): |
362 |
# custom ganeti errors
|
363 |
err_class = GetErrorClass(result[0])
|
364 |
if err_class is not None: |
365 |
raise err_class, tuple(result[1]) |