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 # 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"
47 class GenericError(Exception):
48 """Base exception for Ganeti.
54 class LVMError(GenericError):
55 """LVM-related exception.
57 This exception codifies problems with LVM setup.
63 class LockError(GenericError):
64 """Lock error exception.
66 This signifies problems in the locking subsystem.
72 class HypervisorError(GenericError):
73 """Hypervisor-related exception.
75 This is raised in case we can't communicate with the hypervisor
82 class ProgrammerError(GenericError):
83 """Programming-related error.
85 This is raised in cases we determine that the calling conventions
86 have been violated, meaning we got some desynchronisation between
87 parts of our code. It signifies a real programming bug.
93 class BlockDeviceError(GenericError):
94 """Block-device related exception.
96 This is raised in case we can't setup the instance's block devices
103 class ConfigurationError(GenericError):
104 """Configuration related exception.
106 Things like having an instance with a primary node that doesn't
107 exist in the config or such raise this exception.
113 class ReservationError(GenericError):
114 """Errors reserving a resource.
119 class RemoteError(GenericError):
120 """Programming-related error on remote call.
122 This is raised when an unhandled error occurs in a call to a
123 remote node. It usually signifies a real programming bug.
129 class SignatureError(GenericError):
130 """Error authenticating a remote message.
132 This is raised when the hmac signature on a message doesn't verify correctly
133 to the message itself. It can happen because of network unreliability or
134 because of spurious traffic.
140 class ParameterError(GenericError):
141 """A passed parameter to a command is invalid.
143 This is raised when the parameter passed to a request function is
144 invalid. Correct code should have verified this before passing the
147 The argument to this exception should be the parameter name.
153 class OpPrereqError(GenericError):
154 """Prerequisites for the OpCode are not fulfilled.
156 This exception will have either one or two arguments. For the
157 two-argument construction, the second argument should be one of the
163 class OpExecError(GenericError):
164 """Error during OpCode execution.
169 class OpCodeUnknown(GenericError):
170 """Unknown opcode submitted.
172 This signifies a mismatch between the definitions on the client and
178 class JobLost(GenericError):
179 """Submitted job lost.
181 The job was submitted but it cannot be found in the current job
187 class JobFileCorrupted(GenericError):
188 """Job file could not be properly decoded/restored.
193 class ResolverError(GenericError):
194 """Host name cannot be resolved.
196 This is not a normal situation for Ganeti, as we rely on having a
199 The non-resolvable hostname is available as the first element of the
200 args tuple; the other two elements of the tuple are the first two
201 args of the socket.gaierror exception (error code and description).
206 class HooksFailure(GenericError):
207 """A generic hook failure.
209 This signifies usually a setup misconfiguration.
214 class HooksAbort(HooksFailure):
215 """A required hook has failed.
217 This caused an abort of the operation in the initial phase. This
218 exception always has an attribute args which is a list of tuples of:
219 - node: the source node on which this hooks has failed
220 - script: the name of the script which aborted the run
225 class UnitParseError(GenericError):
226 """Unable to parse size unit.
231 class TypeEnforcementError(GenericError):
232 """Unable to enforce data type.
237 class SshKeyError(GenericError):
243 class TagError(GenericError):
244 """Generic tag error.
246 The argument to this exception will show the exact error.
251 class CommandError(GenericError):
252 """External command error.
257 class StorageError(GenericError):
258 """Storage-related exception.
263 class InotifyError(GenericError):
264 """Error raised when there is a failure setting up an inotify watcher.
269 class QuitGanetiException(Exception):
270 """Signal that Ganeti that it must quit.
272 This is not necessarily an error (and thus not a subclass of
273 GenericError), but it's an exceptional circumstance and it is thus
274 treated. This instance should be instantiated with two values. The
275 first one will specify the return code to the caller, and the second
276 one will be the returned result (either as an error or as a normal
277 result). Usually only the leave cluster rpc call should return
278 status True (as there it's expected we quit), every other call will
279 return status False (as a critical error was encountered).
283 # Return a result of "True" to the caller, but quit ganeti afterwards
284 raise QuitGanetiException(True, None)
285 # Send an error to the caller, and quit ganeti
286 raise QuitGanetiException(False, "Fatal safety violation, shutting down")
291 class JobQueueError(GenericError):
297 class JobQueueDrainError(JobQueueError):
298 """Job queue is marked for drain error.
300 This is raised when a job submission attempt is made but the queue
306 class JobQueueFull(JobQueueError):
307 """Job queue full error.
309 Raised when job queue size reached its hard limit.
314 class ConfdRequestError(GenericError):
315 """A request error in Ganeti confd.
317 Events that should make confd abort the current request and proceed serving
323 class ConfdMagicError(GenericError):
324 """A magic fourcc error in Ganeti confd.
326 Errors processing the fourcc in ganeti confd datagrams.
331 class ConfdClientError(GenericError):
332 """A magic fourcc error in Ganeti confd.
334 Errors in the confd client library.
339 class UdpDataSizeError(GenericError):
340 """UDP payload too big.
345 class NoCtypesError(GenericError):
346 """python ctypes module is not found in the system.
351 # errors should be added above
354 def GetErrorClass(name):
355 """Return the class of an exception.
357 Given the class name, return the class itself.
360 @param name: the exception name
362 @return: the actual class, or None if not found
365 item = globals().get(name, None)
367 if not (isinstance(item, type(Exception)) and
368 issubclass(item, GenericError)):
373 def EncodeException(err):
374 """Encodes an exception into a format that L{MaybeRaise} will recognise.
376 The passed L{err} argument will be formatted as a tuple (exception
377 name, arguments) that the MaybeRaise function will recognise.
379 @type err: GenericError child
380 @param err: usually a child of GenericError (but any exception
383 @return: tuple of (exception name, exception arguments)
386 return (err.__class__.__name__, err.args)
389 def MaybeRaise(result):
390 """If this looks like an encoded Ganeti exception, raise it.
392 This function tries to parse the passed argument and if it looks
393 like an encoding done by EncodeException, it will re-raise it.
397 if (isinstance(result, tlt) and len(result) == 2 and
398 isinstance(result[1], tlt)):
399 # custom ganeti errors
400 err_class = GetErrorClass(result[0])
401 if err_class is not None:
402 raise err_class, tuple(result[1])