4 # Copyright (C) 2006, 2007, 2008, 2009, 2010 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 # OpPrereqError failure types
28 ECODE_RESOLVER = "resolver_error"
29 # not enough resources (iallocator failure, disk space, memory, etc.)
30 ECODE_NORES = "insufficient_resources"
31 # wrong arguments (at syntax level)
32 ECODE_INVAL = "wrong_input"
34 ECODE_STATE = "wrong_state"
36 ECODE_NOENT = "unknown_entity"
37 # entity already exists
38 ECODE_EXISTS = "already_exists"
39 # resource not unique (e.g. MAC or IP duplication)
40 ECODE_NOTUNIQUE = "resource_not_unique"
41 # internal cluster error
42 ECODE_FAULT = "internal_error"
43 # environment error (e.g. node disk error)
44 ECODE_ENVIRON = "environment_error"
46 #: List of all failure types
47 ECODE_ALL = frozenset([
60 class GenericError(Exception):
61 """Base exception for Ganeti.
67 class LVMError(GenericError):
68 """LVM-related exception.
70 This exception codifies problems with LVM setup.
76 class LockError(GenericError):
77 """Lock error exception.
79 This signifies problems in the locking subsystem.
85 class PidFileLockError(LockError):
86 """PID file is already locked by another process.
91 class HypervisorError(GenericError):
92 """Hypervisor-related exception.
94 This is raised in case we can't communicate with the hypervisor
101 class ProgrammerError(GenericError):
102 """Programming-related error.
104 This is raised in cases we determine that the calling conventions
105 have been violated, meaning we got some desynchronisation between
106 parts of our code. It signifies a real programming bug.
112 class BlockDeviceError(GenericError):
113 """Block-device related exception.
115 This is raised in case we can't setup the instance's block devices
122 class ConfigurationError(GenericError):
123 """Configuration related exception.
125 Things like having an instance with a primary node that doesn't
126 exist in the config or such raise this exception.
132 class ConfigVersionMismatch(ConfigurationError):
133 """Version mismatch in the configuration file.
135 The error has two arguments: the expected and the actual found
142 class ReservationError(GenericError):
143 """Errors reserving a resource.
148 class RemoteError(GenericError):
149 """Programming-related error on remote call.
151 This is raised when an unhandled error occurs in a call to a
152 remote node. It usually signifies a real programming bug.
158 class SignatureError(GenericError):
159 """Error authenticating a remote message.
161 This is raised when the hmac signature on a message doesn't verify correctly
162 to the message itself. It can happen because of network unreliability or
163 because of spurious traffic.
169 class ParameterError(GenericError):
170 """A passed parameter to a command is invalid.
172 This is raised when the parameter passed to a request function is
173 invalid. Correct code should have verified this before passing the
176 The argument to this exception should be the parameter name.
182 class OpPrereqError(GenericError):
183 """Prerequisites for the OpCode are not fulfilled.
185 This exception will have either one or two arguments. For the
186 two-argument construction, the second argument should be one of the
192 class OpExecError(GenericError):
193 """Error during OpCode execution.
198 class OpResultError(GenericError):
199 """Issue with OpCode result.
204 class OpCodeUnknown(GenericError):
205 """Unknown opcode submitted.
207 This signifies a mismatch between the definitions on the client and
213 class JobLost(GenericError):
214 """Submitted job lost.
216 The job was submitted but it cannot be found in the current job
222 class JobFileCorrupted(GenericError):
223 """Job file could not be properly decoded/restored.
228 class ResolverError(GenericError):
229 """Host name cannot be resolved.
231 This is not a normal situation for Ganeti, as we rely on having a
234 The non-resolvable hostname is available as the first element of the
235 args tuple; the other two elements of the tuple are the first two
236 args of the socket.gaierror exception (error code and description).
241 class HooksFailure(GenericError):
242 """A generic hook failure.
244 This signifies usually a setup misconfiguration.
249 class HooksAbort(HooksFailure):
250 """A required hook has failed.
252 This caused an abort of the operation in the initial phase. This
253 exception always has an attribute args which is a list of tuples of:
254 - node: the source node on which this hooks has failed
255 - script: the name of the script which aborted the run
260 class UnitParseError(GenericError):
261 """Unable to parse size unit.
266 class ParseError(GenericError):
267 """Generic parse error.
269 Raised when unable to parse user input.
274 class TypeEnforcementError(GenericError):
275 """Unable to enforce data type.
280 class SshKeyError(GenericError):
286 class TagError(GenericError):
287 """Generic tag error.
289 The argument to this exception will show the exact error.
294 class CommandError(GenericError):
295 """External command error.
300 class StorageError(GenericError):
301 """Storage-related exception.
306 class InotifyError(GenericError):
307 """Error raised when there is a failure setting up an inotify watcher.
312 class QuitGanetiException(Exception):
313 """Signal Ganeti that it must quit.
315 This is not necessarily an error (and thus not a subclass of
316 GenericError), but it's an exceptional circumstance and it is thus
317 treated. This instance should be instantiated with two values. The
318 first one will specify the return code to the caller, and the second
319 one will be the returned result (either as an error or as a normal
320 result). Usually only the leave cluster rpc call should return
321 status True (as there it's expected we quit), every other call will
322 return status False (as a critical error was encountered).
326 # Return a result of "True" to the caller, but quit ganeti afterwards
327 raise QuitGanetiException(True, None)
328 # Send an error to the caller, and quit ganeti
329 raise QuitGanetiException(False, "Fatal safety violation, shutting down")
334 class JobQueueError(GenericError):
340 class JobQueueDrainError(JobQueueError):
341 """Job queue is marked for drain error.
343 This is raised when a job submission attempt is made but the queue
349 class JobQueueFull(JobQueueError):
350 """Job queue full error.
352 Raised when job queue size reached its hard limit.
357 class ConfdRequestError(GenericError):
358 """A request error in Ganeti confd.
360 Events that should make confd abort the current request and proceed serving
366 class ConfdMagicError(GenericError):
367 """A magic fourcc error in Ganeti confd.
369 Errors processing the fourcc in ganeti confd datagrams.
374 class ConfdClientError(GenericError):
375 """A magic fourcc error in Ganeti confd.
377 Errors in the confd client library.
382 class UdpDataSizeError(GenericError):
383 """UDP payload too big.
388 class NoCtypesError(GenericError):
389 """python ctypes module is not found in the system.
394 class IPAddressError(GenericError):
395 """Generic IP address error.
400 class LuxiError(GenericError):
406 class QueryFilterParseError(ParseError):
407 """Error while parsing query filter.
410 def GetDetails(self):
411 """Returns a list of strings with details about the error.
415 (_, inner) = self.args
419 return [str(inner.line),
420 (" " * (inner.column - 1)) + "^",
424 # errors should be added above
427 def GetErrorClass(name):
428 """Return the class of an exception.
430 Given the class name, return the class itself.
433 @param name: the exception name
435 @return: the actual class, or None if not found
438 item = globals().get(name, None)
440 if not (isinstance(item, type(Exception)) and
441 issubclass(item, GenericError)):
446 def EncodeException(err):
447 """Encodes an exception into a format that L{MaybeRaise} will recognise.
449 The passed L{err} argument will be formatted as a tuple (exception
450 name, arguments) that the MaybeRaise function will recognise.
452 @type err: GenericError child
453 @param err: usually a child of GenericError (but any exception
456 @return: tuple of (exception name, exception arguments)
459 return (err.__class__.__name__, err.args)
462 def GetEncodedError(result):
463 """If this looks like an encoded Ganeti exception, return it.
465 This function tries to parse the passed argument and if it looks
466 like an encoding done by EncodeException, it will return the class
467 object and arguments.
471 if (isinstance(result, tlt) and len(result) == 2 and
472 isinstance(result[1], tlt)):
473 # custom ganeti errors
474 errcls = GetErrorClass(result[0])
476 return (errcls, tuple(result[1]))
481 def MaybeRaise(result):
482 """If this looks like an encoded Ganeti exception, raise it.
484 This function tries to parse the passed argument and if it looks
485 like an encoding done by EncodeException, it will re-raise it.
488 error = GetEncodedError(result)
490 (errcls, args) = error