4 # Copyright (C) 2006, 2007 Google Inc.
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.
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.
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
22 """Ganeti exception handling"""
25 class GenericError(Exception):
26 """Base exception for Ganeti.
32 class LVMError(GenericError):
33 """LVM-related exception.
35 This exception codifies problems with LVM setup.
41 class LockError(GenericError):
42 """Lock error exception.
44 This signifies problems in the locking subsystem.
50 class HypervisorError(GenericError):
51 """Hypervisor-related exception.
53 This is raised in case we can't communicate with the hypervisor
60 class ProgrammerError(GenericError):
61 """Programming-related error.
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.
71 class BlockDeviceError(GenericError):
72 """Block-device related exception.
74 This is raised in case we can't setup the instance's block devices
81 class ConfigurationError(GenericError):
82 """Configuration related exception.
84 Things like having an instance with a primary node that doesn't
85 exist in the config or such raise this exception.
91 class RemoteError(GenericError):
92 """Programming-related error on remote call.
94 This is raised when an unhandled error occurs in a call to a
95 remote node. It usually signifies a real programming bug.
101 class SignatureError(GenericError):
102 """Error authenticating a remote message.
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.
112 class ParameterError(GenericError):
113 """A passed parameter to a command is invalid.
115 This is raised when the parameter passed to a request function is
116 invalid. Correct code should have verified this before passing the
119 The argument to this exception should be the parameter name.
125 class OpPrereqError(GenericError):
126 """Prerequisites for the OpCode are not fulfilled.
131 class OpExecError(GenericError):
132 """Error during OpCode execution.
137 class OpCodeUnknown(GenericError):
138 """Unknown opcode submitted.
140 This signifies a mismatch between the definitions on the client and
146 class JobLost(GenericError):
147 """Submitted job lost.
149 The job was submitted but it cannot be found in the current job
155 class ResolverError(GenericError):
156 """Host name cannot be resolved.
158 This is not a normal situation for Ganeti, as we rely on having a
161 The non-resolvable hostname is available as the first element of the
162 args tuple; the other two elements of the tuple are the first two
163 args of the socket.gaierror exception (error code and description).
168 class HooksFailure(GenericError):
169 """A generic hook failure.
171 This signifies usually a setup misconfiguration.
176 class HooksAbort(HooksFailure):
177 """A required hook has failed.
179 This caused an abort of the operation in the initial phase. This
180 exception always has an attribute args which is a list of tuples of:
181 - node: the source node on which this hooks has failed
182 - script: the name of the script which aborted the run
187 class UnitParseError(GenericError):
188 """Unable to parse size unit.
193 class TypeEnforcementError(GenericError):
194 """Unable to enforce data type.
199 class SshKeyError(GenericError):
205 class TagError(GenericError):
206 """Generic tag error.
208 The argument to this exception will show the exact error.
213 class CommandError(GenericError):
214 """External command error.
219 class StorageError(GenericError):
220 """Storage-related exception.
225 class InotifyError(GenericError):
226 """Error raised when there is a failure setting up an inotify watcher.
231 class QuitGanetiException(Exception):
232 """Signal that Ganeti that it must quit.
234 This is not necessarily an error (and thus not a subclass of
235 GenericError), but it's an exceptional circumstance and it is thus
236 treated. This instance should be instantiated with two values. The
237 first one will specify the return code to the caller, and the second
238 one will be the returned result (either as an error or as a normal
239 result). Usually only the leave cluster rpc call should return
240 status True (as there it's expected we quit), every other call will
241 return status False (as a critical error was encountered).
245 # Return a result of "True" to the caller, but quit ganeti afterwards
246 raise QuitGanetiException(True, None)
247 # Send an error to the caller, and quit ganeti
248 raise QuitGanetiException(False, "Fatal safety violation, shutting down")
253 class JobQueueError(GenericError):
259 class JobQueueDrainError(JobQueueError):
260 """Job queue is marked for drain error.
262 This is raised when a job submission attempt is made but the queue
268 class JobQueueFull(JobQueueError):
269 """Job queue full error.
271 Raised when job queue size reached its hard limit.
276 class ConfdFatalError(GenericError):
277 """A fatal failure in Ganeti confd.
279 Events that compromise the ability of confd to proceed further.
280 (for example: inability to load the config file)
285 class ConfdRequestError(GenericError):
286 """A request error in Ganeti confd.
288 Events that should make confd abort the current request and proceed serving
294 class ConfdMagicError(GenericError):
295 """A magic fourcc error in Ganeti confd.
297 Errors processing the fourcc in ganeti confd datagrams.
302 class ConfdClientError(GenericError):
303 """A magic fourcc error in Ganeti confd.
305 Errors in the confd client library.
310 class UdpDataSizeError(GenericError):
311 """UDP payload too big.
316 # errors should be added above
319 def GetErrorClass(name):
320 """Return the class of an exception.
322 Given the class name, return the class itself.
325 @param name: the exception name
327 @return: the actual class, or None if not found
330 item = globals().get(name, None)
332 if not (isinstance(item, type(Exception)) and
333 issubclass(item, GenericError)):
338 def EncodeException(err):
339 """Encodes an exception into a format that L{MaybeRaise} will recognise.
341 The passed L{err} argument will be formatted as a tuple (exception
342 name, arguments) that the MaybeRaise function will recognise.
344 @type err: GenericError child
345 @param err: usually a child of GenericError (but any exception
348 @return: tuple of (exception name, exception arguments)
351 return (err.__class__.__name__, err.args)
354 def MaybeRaise(result):
355 """Is this looks like an encoded Ganeti exception, raise it.
357 This function tries to parse the passed argument and if it looks
358 like an encoding done by EncodeException, it will re-raise it.
362 if (isinstance(result, tlt) and len(result) == 2 and
363 isinstance(result[1], tlt)):
364 # custom ganeti errors
365 err_class = GetErrorClass(result[0])
366 if err_class is not None:
367 raise err_class, tuple(result[1])