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 LVMError(GenericError):
67 """LVM-related exception.
69 This exception codifies problems with LVM setup.
74 class LockError(GenericError):
75 """Lock error exception.
77 This signifies problems in the locking subsystem.
82 class PidFileLockError(LockError):
83 """PID file is already locked by another process.
88 class HypervisorError(GenericError):
89 """Hypervisor-related exception.
91 This is raised in case we can't communicate with the hypervisor
97 class ProgrammerError(GenericError):
98 """Programming-related error.
100 This is raised in cases we determine that the calling conventions
101 have been violated, meaning we got some desynchronisation between
102 parts of our code. It signifies a real programming bug.
107 class BlockDeviceError(GenericError):
108 """Block-device related exception.
110 This is raised in case we can't setup the instance's block devices
116 class ConfigurationError(GenericError):
117 """Configuration related exception.
119 Things like having an instance with a primary node that doesn't
120 exist in the config or such raise this exception.
125 class ConfigVersionMismatch(ConfigurationError):
126 """Version mismatch in the configuration file.
128 The error has two arguments: the expected and the actual found
134 class ReservationError(GenericError):
135 """Errors reserving a resource.
140 class RemoteError(GenericError):
141 """Programming-related error on remote call.
143 This is raised when an unhandled error occurs in a call to a
144 remote node. It usually signifies a real programming bug.
149 class SignatureError(GenericError):
150 """Error authenticating a remote message.
152 This is raised when the hmac signature on a message doesn't verify correctly
153 to the message itself. It can happen because of network unreliability or
154 because of spurious traffic.
159 class ParameterError(GenericError):
160 """A passed parameter to a command is invalid.
162 This is raised when the parameter passed to a request function is
163 invalid. Correct code should have verified this before passing the
166 The argument to this exception should be the parameter name.
171 class OpPrereqError(GenericError):
172 """Prerequisites for the OpCode are not fulfilled.
174 This exception will have either one or two arguments. For the
175 two-argument construction, the second argument should be one of the
181 class OpExecError(GenericError):
182 """Error during OpCode execution.
187 class OpResultError(GenericError):
188 """Issue with OpCode result.
193 class OpCodeUnknown(GenericError):
194 """Unknown opcode submitted.
196 This signifies a mismatch between the definitions on the client and
202 class JobLost(GenericError):
203 """Submitted job lost.
205 The job was submitted but it cannot be found in the current job
211 class JobFileCorrupted(GenericError):
212 """Job file could not be properly decoded/restored.
217 class ResolverError(GenericError):
218 """Host name cannot be resolved.
220 This is not a normal situation for Ganeti, as we rely on having a
223 The non-resolvable hostname is available as the first element of the
224 args tuple; the other two elements of the tuple are the first two
225 args of the socket.gaierror exception (error code and description).
230 class HooksFailure(GenericError):
231 """A generic hook failure.
233 This signifies usually a setup misconfiguration.
238 class HooksAbort(HooksFailure):
239 """A required hook has failed.
241 This caused an abort of the operation in the initial phase. This
242 exception always has an attribute args which is a list of tuples of:
243 - node: the source node on which this hooks has failed
244 - script: the name of the script which aborted the run
249 class UnitParseError(GenericError):
250 """Unable to parse size unit.
255 class ParseError(GenericError):
256 """Generic parse error.
258 Raised when unable to parse user input.
263 class TypeEnforcementError(GenericError):
264 """Unable to enforce data type.
269 class SshKeyError(GenericError):
275 class X509CertError(GenericError):
276 """Invalid X509 certificate.
278 This error has two arguments: the certificate filename and the error cause.
283 class TagError(GenericError):
284 """Generic tag error.
286 The argument to this exception will show the exact error.
291 class CommandError(GenericError):
292 """External command error.
297 class StorageError(GenericError):
298 """Storage-related exception.
303 class InotifyError(GenericError):
304 """Error raised when there is a failure setting up an inotify watcher.
309 class QuitGanetiException(Exception):
310 """Signal Ganeti that it must quit.
312 This is not necessarily an error (and thus not a subclass of
313 GenericError), but it's an exceptional circumstance and it is thus
314 treated. This instance should be instantiated with two values. The
315 first one will specify the return code to the caller, and the second
316 one will be the returned result (either as an error or as a normal
317 result). Usually only the leave cluster rpc call should return
318 status True (as there it's expected we quit), every other call will
319 return status False (as a critical error was encountered).
323 # Return a result of "True" to the caller, but quit ganeti afterwards
324 raise QuitGanetiException(True, None)
325 # Send an error to the caller, and quit ganeti
326 raise QuitGanetiException(False, "Fatal safety violation, shutting down")
331 class JobQueueError(GenericError):
337 class JobQueueDrainError(JobQueueError):
338 """Job queue is marked for drain error.
340 This is raised when a job submission attempt is made but the queue
346 class JobQueueFull(JobQueueError):
347 """Job queue full error.
349 Raised when job queue size reached its hard limit.
354 class ConfdRequestError(GenericError):
355 """A request error in Ganeti confd.
357 Events that should make confd abort the current request and proceed serving
363 class ConfdMagicError(GenericError):
364 """A magic fourcc error in Ganeti confd.
366 Errors processing the fourcc in ganeti confd datagrams.
371 class ConfdClientError(GenericError):
372 """A magic fourcc error in Ganeti confd.
374 Errors in the confd client library.
379 class UdpDataSizeError(GenericError):
380 """UDP payload too big.
385 class NoCtypesError(GenericError):
386 """python ctypes module is not found in the system.
391 class IPAddressError(GenericError):
392 """Generic IP address error.
397 class LuxiError(GenericError):
403 class QueryFilterParseError(ParseError):
404 """Error while parsing query filter.
407 def GetDetails(self):
408 """Returns a list of strings with details about the error.
412 (_, inner) = self.args
416 return [str(inner.line),
417 (" " * (inner.column - 1)) + "^",
421 class RapiTestResult(GenericError):
422 """Exception containing results from RAPI test utilities.
427 # errors should be added above
430 def GetErrorClass(name):
431 """Return the class of an exception.
433 Given the class name, return the class itself.
436 @param name: the exception name
438 @return: the actual class, or None if not found
441 item = globals().get(name, None)
443 if not (isinstance(item, type(Exception)) and
444 issubclass(item, GenericError)):
449 def EncodeException(err):
450 """Encodes an exception into a format that L{MaybeRaise} will recognise.
452 The passed L{err} argument will be formatted as a tuple (exception
453 name, arguments) that the MaybeRaise function will recognise.
455 @type err: GenericError child
456 @param err: usually a child of GenericError (but any exception
459 @return: tuple of (exception name, exception arguments)
462 return (err.__class__.__name__, err.args)
465 def GetEncodedError(result):
466 """If this looks like an encoded Ganeti exception, return it.
468 This function tries to parse the passed argument and if it looks
469 like an encoding done by EncodeException, it will return the class
470 object and arguments.
474 if (isinstance(result, tlt) and len(result) == 2 and
475 isinstance(result[1], tlt)):
476 # custom ganeti errors
477 errcls = GetErrorClass(result[0])
479 return (errcls, tuple(result[1]))
484 def MaybeRaise(result):
485 """If this looks like an encoded Ganeti exception, raise it.
487 This function tries to parse the passed argument and if it looks
488 like an encoding done by EncodeException, it will re-raise it.
491 error = GetEncodedError(result)
493 (errcls, args) = error
494 # pylint: disable=W0142