4 # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 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.
26 from ganeti import compat
29 # OpPrereqError failure types
32 ECODE_RESOLVER = "resolver_error"
34 #: Not enough resources (iallocator failure, disk space, memory, etc.)
35 ECODE_NORES = "insufficient_resources"
37 #: Temporarily out of resources; operation can be tried again
38 ECODE_TEMP_NORES = "temp_insufficient_resources"
40 #: Wrong arguments (at syntax level)
41 ECODE_INVAL = "wrong_input"
44 ECODE_STATE = "wrong_state"
47 ECODE_NOENT = "unknown_entity"
49 #: Entity already exists
50 ECODE_EXISTS = "already_exists"
52 #: Resource not unique (e.g. MAC or IP duplication)
53 ECODE_NOTUNIQUE = "resource_not_unique"
55 #: Internal cluster error
56 ECODE_FAULT = "internal_error"
58 #: Environment error (e.g. node disk error)
59 ECODE_ENVIRON = "environment_error"
61 #: List of all failure types
62 ECODE_ALL = compat.UniqueFrozenset([
76 class GenericError(Exception):
77 """Base exception for Ganeti.
82 class LockError(GenericError):
83 """Lock error exception.
85 This signifies problems in the locking subsystem.
90 class PidFileLockError(LockError):
91 """PID file is already locked by another process.
96 class HypervisorError(GenericError):
97 """Hypervisor-related exception.
99 This is raised in case we can't communicate with the hypervisor
105 class ProgrammerError(GenericError):
106 """Programming-related error.
108 This is raised in cases we determine that the calling conventions
109 have been violated, meaning we got some desynchronisation between
110 parts of our code. It signifies a real programming bug.
115 class BlockDeviceError(GenericError):
116 """Block-device related exception.
118 This is raised in case we can't setup the instance's block devices
124 class ConfigurationError(GenericError):
125 """Configuration related exception.
127 Things like having an instance with a primary node that doesn't
128 exist in the config or such raise this exception.
133 class ConfigVersionMismatch(ConfigurationError):
134 """Version mismatch in the configuration file.
136 The error has two arguments: the expected and the actual found
142 class AddressPoolError(GenericError):
143 """Errors related to IP address pools.
148 class ReservationError(GenericError):
149 """Errors reserving a resource.
154 class RemoteError(GenericError):
155 """Programming-related error on remote call.
157 This is raised when an unhandled error occurs in a call to a
158 remote node. It usually signifies a real programming bug.
163 class SignatureError(GenericError):
164 """Error authenticating a remote message.
166 This is raised when the hmac signature on a message doesn't verify correctly
167 to the message itself. It can happen because of network unreliability or
168 because of spurious traffic.
173 class ParameterError(GenericError):
174 """A passed parameter to a command is invalid.
176 This is raised when the parameter passed to a request function is
177 invalid. Correct code should have verified this before passing the
180 The argument to this exception should be the parameter name.
185 class ResultValidationError(GenericError):
186 """The iallocation results fails validation.
191 class OpPrereqError(GenericError):
192 """Prerequisites for the OpCode are not fulfilled.
194 This exception has two arguments: an error message, and one of the
200 class OpExecError(GenericError):
201 """Error during OpCode execution.
206 class OpResultError(GenericError):
207 """Issue with OpCode result.
212 class OpCodeUnknown(GenericError):
213 """Unknown opcode submitted.
215 This signifies a mismatch between the definitions on the client and
221 class JobLost(GenericError):
222 """Submitted job lost.
224 The job was submitted but it cannot be found in the current job
230 class JobFileCorrupted(GenericError):
231 """Job file could not be properly decoded/restored.
236 class ResolverError(GenericError):
237 """Host name cannot be resolved.
239 This is not a normal situation for Ganeti, as we rely on having a
242 The non-resolvable hostname is available as the first element of the
243 args tuple; the other two elements of the tuple are the first two
244 args of the socket.gaierror exception (error code and description).
249 class HooksFailure(GenericError):
250 """A generic hook failure.
252 This signifies usually a setup misconfiguration.
257 class HooksAbort(HooksFailure):
258 """A required hook has failed.
260 This caused an abort of the operation in the initial phase. This
261 exception always has an attribute args which is a list of tuples of:
262 - node: the source node on which this hooks has failed
263 - script: the name of the script which aborted the run
268 class UnitParseError(GenericError):
269 """Unable to parse size unit.
274 class ParseError(GenericError):
275 """Generic parse error.
277 Raised when unable to parse user input.
282 class TypeEnforcementError(GenericError):
283 """Unable to enforce data type.
288 class X509CertError(GenericError):
289 """Invalid X509 certificate.
291 This error has two arguments: the certificate filename and the error cause.
296 class TagError(GenericError):
297 """Generic tag error.
299 The argument to this exception will show the exact error.
304 class CommandError(GenericError):
305 """External command error.
310 class StorageError(GenericError):
311 """Storage-related exception.
316 class InotifyError(GenericError):
317 """Error raised when there is a failure setting up an inotify watcher.
322 class QuitGanetiException(Exception):
323 """Signal Ganeti that it must quit.
325 This is not necessarily an error (and thus not a subclass of
326 GenericError), but it's an exceptional circumstance and it is thus
327 treated. This exception should be instantiated with two values. The
328 first one will specify the return code to the caller, and the second
329 one will be the returned result (either as an error or as a normal
330 result). Usually only the leave cluster rpc call should return
331 status True (as there it's expected we quit), every other call will
332 return status False (as a critical error was encountered).
336 # Return a result of "True" to the caller, but quit ganeti afterwards
337 raise QuitGanetiException(True, None)
338 # Send an error to the caller, and quit ganeti
339 raise QuitGanetiException(False, "Fatal safety violation, shutting down")
344 class JobQueueError(GenericError):
350 class JobQueueDrainError(JobQueueError):
351 """Job queue is marked for drain error.
353 This is raised when a job submission attempt is made but the queue
359 class JobQueueFull(JobQueueError):
360 """Job queue full error.
362 Raised when job queue size reached its hard limit.
367 class ConfdMagicError(GenericError):
368 """A magic fourcc error in Ganeti confd.
370 Errors processing the fourcc in ganeti confd datagrams.
375 class ConfdClientError(GenericError):
376 """A magic fourcc error in Ganeti confd.
378 Errors in the confd client library.
383 class UdpDataSizeError(GenericError):
384 """UDP payload too big.
389 class NoCtypesError(GenericError):
390 """python ctypes module is not found in the system.
395 class IPAddressError(GenericError):
396 """Generic IP address error.
401 class LuxiError(GenericError):
407 class QueryFilterParseError(ParseError):
408 """Error while parsing query filter.
410 This exception must be instantiated with two values. The first one is a
411 string with an error description, the second one is an instance of a subclass
412 of C{pyparsing.ParseBaseException} (used to display the exact error
416 def GetDetails(self):
417 """Returns a list of strings with details about the error.
421 (_, inner) = self.args
425 return [str(inner.line),
426 (" " * (inner.column - 1)) + "^",
430 class RapiTestResult(GenericError):
431 """Exception containing results from RAPI test utilities.
436 class FileStoragePathError(GenericError):
437 """Error from file storage path validation.
442 # errors should be added above
445 def GetErrorClass(name):
446 """Return the class of an exception.
448 Given the class name, return the class itself.
451 @param name: the exception name
453 @return: the actual class, or None if not found
456 item = globals().get(name, None)
458 if not (isinstance(item, type(Exception)) and
459 issubclass(item, GenericError)):
464 def EncodeException(err):
465 """Encodes an exception into a format that L{MaybeRaise} will recognise.
467 The passed L{err} argument will be formatted as a tuple (exception
468 name, arguments) that the MaybeRaise function will recognise.
470 @type err: GenericError child
471 @param err: usually a child of GenericError (but any exception
474 @return: tuple of (exception name, exception arguments)
477 return (err.__class__.__name__, err.args)
480 def GetEncodedError(result):
481 """If this looks like an encoded Ganeti exception, return it.
483 This function tries to parse the passed argument and if it looks
484 like an encoding done by EncodeException, it will return the class
485 object and arguments.
489 if (isinstance(result, tlt) and len(result) == 2 and
490 isinstance(result[1], tlt)):
491 # custom ganeti errors
492 errcls = GetErrorClass(result[0])
494 return (errcls, tuple(result[1]))
499 def MaybeRaise(result):
500 """If this looks like an encoded Ganeti exception, raise it.
502 This function tries to parse the passed argument and if it looks
503 like an encoding done by EncodeException, it will re-raise it.
506 error = GetEncodedError(result)
508 (errcls, args) = error
509 # pylint: disable=W0142