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"""
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.
66 class LockError(GenericError):
67 """Lock error exception.
69 This signifies problems in the locking subsystem.
74 class PidFileLockError(LockError):
75 """PID file is already locked by another process.
80 class HypervisorError(GenericError):
81 """Hypervisor-related exception.
83 This is raised in case we can't communicate with the hypervisor
89 class ProgrammerError(GenericError):
90 """Programming-related error.
92 This is raised in cases we determine that the calling conventions
93 have been violated, meaning we got some desynchronisation between
94 parts of our code. It signifies a real programming bug.
99 class BlockDeviceError(GenericError):
100 """Block-device related exception.
102 This is raised in case we can't setup the instance's block devices
108 class ConfigurationError(GenericError):
109 """Configuration related exception.
111 Things like having an instance with a primary node that doesn't
112 exist in the config or such raise this exception.
117 class ConfigVersionMismatch(ConfigurationError):
118 """Version mismatch in the configuration file.
120 The error has two arguments: the expected and the actual found
126 class AddressPoolError(GenericError):
127 """Errors related to IP address pools.
132 class ReservationError(GenericError):
133 """Errors reserving a resource.
138 class RemoteError(GenericError):
139 """Programming-related error on remote call.
141 This is raised when an unhandled error occurs in a call to a
142 remote node. It usually signifies a real programming bug.
147 class SignatureError(GenericError):
148 """Error authenticating a remote message.
150 This is raised when the hmac signature on a message doesn't verify correctly
151 to the message itself. It can happen because of network unreliability or
152 because of spurious traffic.
157 class ParameterError(GenericError):
158 """A passed parameter to a command is invalid.
160 This is raised when the parameter passed to a request function is
161 invalid. Correct code should have verified this before passing the
164 The argument to this exception should be the parameter name.
169 class ResultValidationError(GenericError):
170 """The iallocation results fails validation.
175 class OpPrereqError(GenericError):
176 """Prerequisites for the OpCode are not fulfilled.
178 This exception has two arguments: an error message, and one of the
184 class OpExecError(GenericError):
185 """Error during OpCode execution.
190 class OpResultError(GenericError):
191 """Issue with OpCode result.
196 class OpCodeUnknown(GenericError):
197 """Unknown opcode submitted.
199 This signifies a mismatch between the definitions on the client and
205 class JobLost(GenericError):
206 """Submitted job lost.
208 The job was submitted but it cannot be found in the current job
214 class JobFileCorrupted(GenericError):
215 """Job file could not be properly decoded/restored.
220 class ResolverError(GenericError):
221 """Host name cannot be resolved.
223 This is not a normal situation for Ganeti, as we rely on having a
226 The non-resolvable hostname is available as the first element of the
227 args tuple; the other two elements of the tuple are the first two
228 args of the socket.gaierror exception (error code and description).
233 class HooksFailure(GenericError):
234 """A generic hook failure.
236 This signifies usually a setup misconfiguration.
241 class HooksAbort(HooksFailure):
242 """A required hook has failed.
244 This caused an abort of the operation in the initial phase. This
245 exception always has an attribute args which is a list of tuples of:
246 - node: the source node on which this hooks has failed
247 - script: the name of the script which aborted the run
252 class UnitParseError(GenericError):
253 """Unable to parse size unit.
258 class ParseError(GenericError):
259 """Generic parse error.
261 Raised when unable to parse user input.
266 class TypeEnforcementError(GenericError):
267 """Unable to enforce data type.
272 class X509CertError(GenericError):
273 """Invalid X509 certificate.
275 This error has two arguments: the certificate filename and the error cause.
280 class TagError(GenericError):
281 """Generic tag error.
283 The argument to this exception will show the exact error.
288 class CommandError(GenericError):
289 """External command error.
294 class StorageError(GenericError):
295 """Storage-related exception.
300 class InotifyError(GenericError):
301 """Error raised when there is a failure setting up an inotify watcher.
306 class QuitGanetiException(Exception):
307 """Signal Ganeti that it must quit.
309 This is not necessarily an error (and thus not a subclass of
310 GenericError), but it's an exceptional circumstance and it is thus
311 treated. This exception should be instantiated with two values. The
312 first one will specify the return code to the caller, and the second
313 one will be the returned result (either as an error or as a normal
314 result). Usually only the leave cluster rpc call should return
315 status True (as there it's expected we quit), every other call will
316 return status False (as a critical error was encountered).
320 # Return a result of "True" to the caller, but quit ganeti afterwards
321 raise QuitGanetiException(True, None)
322 # Send an error to the caller, and quit ganeti
323 raise QuitGanetiException(False, "Fatal safety violation, shutting down")
328 class JobQueueError(GenericError):
334 class JobQueueDrainError(JobQueueError):
335 """Job queue is marked for drain error.
337 This is raised when a job submission attempt is made but the queue
343 class JobQueueFull(JobQueueError):
344 """Job queue full error.
346 Raised when job queue size reached its hard limit.
351 class ConfdMagicError(GenericError):
352 """A magic fourcc error in Ganeti confd.
354 Errors processing the fourcc in ganeti confd datagrams.
359 class ConfdClientError(GenericError):
360 """A magic fourcc error in Ganeti confd.
362 Errors in the confd client library.
367 class UdpDataSizeError(GenericError):
368 """UDP payload too big.
373 class NoCtypesError(GenericError):
374 """python ctypes module is not found in the system.
379 class IPAddressError(GenericError):
380 """Generic IP address error.
385 class LuxiError(GenericError):
391 class QueryFilterParseError(ParseError):
392 """Error while parsing query filter.
394 This exception must be instantiated with two values. The first one is a
395 string with an error description, the second one is an instance of a subclass
396 of C{pyparsing.ParseBaseException} (used to display the exact error
400 def GetDetails(self):
401 """Returns a list of strings with details about the error.
405 (_, inner) = self.args
409 return [str(inner.line),
410 (" " * (inner.column - 1)) + "^",
414 class RapiTestResult(GenericError):
415 """Exception containing results from RAPI test utilities.
420 class FileStoragePathError(GenericError):
421 """Error from file storage path validation.
426 # errors should be added above
429 def GetErrorClass(name):
430 """Return the class of an exception.
432 Given the class name, return the class itself.
435 @param name: the exception name
437 @return: the actual class, or None if not found
440 item = globals().get(name, None)
442 if not (isinstance(item, type(Exception)) and
443 issubclass(item, GenericError)):
448 def EncodeException(err):
449 """Encodes an exception into a format that L{MaybeRaise} will recognise.
451 The passed L{err} argument will be formatted as a tuple (exception
452 name, arguments) that the MaybeRaise function will recognise.
454 @type err: GenericError child
455 @param err: usually a child of GenericError (but any exception
458 @return: tuple of (exception name, exception arguments)
461 return (err.__class__.__name__, err.args)
464 def GetEncodedError(result):
465 """If this looks like an encoded Ganeti exception, return it.
467 This function tries to parse the passed argument and if it looks
468 like an encoding done by EncodeException, it will return the class
469 object and arguments.
473 if (isinstance(result, tlt) and len(result) == 2 and
474 isinstance(result[1], tlt)):
475 # custom ganeti errors
476 errcls = GetErrorClass(result[0])
478 return (errcls, tuple(result[1]))
483 def MaybeRaise(result):
484 """If this looks like an encoded Ganeti exception, raise it.
486 This function tries to parse the passed argument and if it looks
487 like an encoding done by EncodeException, it will re-raise it.
490 error = GetEncodedError(result)
492 (errcls, args) = error
493 # pylint: disable=W0142