Statistics
| Branch: | Tag: | Revision:

root / lib / errors.py @ 5c983ee5

History | View | Annotate | Download (8.7 kB)

1 2f31098c Iustin Pop
#
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 a8083063 Iustin Pop
# Copyright (C) 2006, 2007 Google Inc.
5 a8083063 Iustin Pop
#
6 a8083063 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a8083063 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a8083063 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a8083063 Iustin Pop
# (at your option) any later version.
10 a8083063 Iustin Pop
#
11 a8083063 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a8083063 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a8083063 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a8083063 Iustin Pop
# General Public License for more details.
15 a8083063 Iustin Pop
#
16 a8083063 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a8083063 Iustin Pop
# along with this program; if not, write to the Free Software
18 a8083063 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a8083063 Iustin Pop
# 02110-1301, USA.
20 a8083063 Iustin Pop
21 a8083063 Iustin Pop
22 a8083063 Iustin Pop
"""Ganeti exception handling"""
23 a8083063 Iustin Pop
24 a8083063 Iustin Pop
25 5c983ee5 Iustin Pop
# OpPrereqError failure types
26 5c983ee5 Iustin Pop
27 5c983ee5 Iustin Pop
# not enough resources (iallocator failure, disk space, memory, etc.)
28 5c983ee5 Iustin Pop
ECODE_NORES = "insufficient_resources"
29 5c983ee5 Iustin Pop
# wrong arguments (at syntax level)
30 5c983ee5 Iustin Pop
ECODE_INVAL = "wrong_input"
31 5c983ee5 Iustin Pop
# wrong entity state
32 5c983ee5 Iustin Pop
ECODE_STATE = "wrong_state"
33 5c983ee5 Iustin Pop
# entity not found
34 5c983ee5 Iustin Pop
ECODE_NOENT = "unknown_entity"
35 5c983ee5 Iustin Pop
# entity already exists
36 5c983ee5 Iustin Pop
ECODE_EXISTS = "already_exists"
37 5c983ee5 Iustin Pop
# resource not unique (e.g. MAC or IP duplication)
38 5c983ee5 Iustin Pop
ECODE_NOTUNIQUE = "resource_not_unique"
39 5c983ee5 Iustin Pop
# internal cluster error
40 5c983ee5 Iustin Pop
ECODE_FAULT = "internal_error"
41 5c983ee5 Iustin Pop
# environment error (e.g. node disk error)
42 5c983ee5 Iustin Pop
ECODE_ENVIRON = "environment_error"
43 5c983ee5 Iustin Pop
44 5c983ee5 Iustin Pop
45 a8083063 Iustin Pop
class GenericError(Exception):
46 a8083063 Iustin Pop
  """Base exception for Ganeti.
47 a8083063 Iustin Pop

48 a8083063 Iustin Pop
  """
49 a8083063 Iustin Pop
  pass
50 a8083063 Iustin Pop
51 a8083063 Iustin Pop
52 a8083063 Iustin Pop
class LVMError(GenericError):
53 a8083063 Iustin Pop
  """LVM-related exception.
54 a8083063 Iustin Pop

55 a8083063 Iustin Pop
  This exception codifies problems with LVM setup.
56 a8083063 Iustin Pop

57 a8083063 Iustin Pop
  """
58 a8083063 Iustin Pop
  pass
59 a8083063 Iustin Pop
60 a8083063 Iustin Pop
61 a8083063 Iustin Pop
class LockError(GenericError):
62 a8083063 Iustin Pop
  """Lock error exception.
63 a8083063 Iustin Pop

64 a8083063 Iustin Pop
  This signifies problems in the locking subsystem.
65 a8083063 Iustin Pop

66 a8083063 Iustin Pop
  """
67 a8083063 Iustin Pop
  pass
68 a8083063 Iustin Pop
69 a8083063 Iustin Pop
70 a8083063 Iustin Pop
class HypervisorError(GenericError):
71 a8083063 Iustin Pop
  """Hypervisor-related exception.
72 a8083063 Iustin Pop

73 a8083063 Iustin Pop
  This is raised in case we can't communicate with the hypervisor
74 a8083063 Iustin Pop
  properly.
75 a8083063 Iustin Pop

76 a8083063 Iustin Pop
  """
77 a8083063 Iustin Pop
  pass
78 a8083063 Iustin Pop
79 a8083063 Iustin Pop
80 a8083063 Iustin Pop
class ProgrammerError(GenericError):
81 a8083063 Iustin Pop
  """Programming-related error.
82 a8083063 Iustin Pop

83 a8083063 Iustin Pop
  This is raised in cases we determine that the calling conventions
84 a8083063 Iustin Pop
  have been violated, meaning we got some desynchronisation between
85 a8083063 Iustin Pop
  parts of our code. It signifies a real programming bug.
86 a8083063 Iustin Pop

87 a8083063 Iustin Pop
  """
88 a8083063 Iustin Pop
  pass
89 a8083063 Iustin Pop
90 a8083063 Iustin Pop
91 a8083063 Iustin Pop
class BlockDeviceError(GenericError):
92 a8083063 Iustin Pop
  """Block-device related exception.
93 a8083063 Iustin Pop

94 a8083063 Iustin Pop
  This is raised in case we can't setup the instance's block devices
95 a8083063 Iustin Pop
  properly.
96 a8083063 Iustin Pop

97 a8083063 Iustin Pop
  """
98 a8083063 Iustin Pop
  pass
99 a8083063 Iustin Pop
100 a8083063 Iustin Pop
101 a8083063 Iustin Pop
class ConfigurationError(GenericError):
102 a8083063 Iustin Pop
  """Configuration related exception.
103 a8083063 Iustin Pop

104 a8083063 Iustin Pop
  Things like having an instance with a primary node that doesn't
105 a8083063 Iustin Pop
  exist in the config or such raise this exception.
106 a8083063 Iustin Pop

107 a8083063 Iustin Pop
  """
108 a8083063 Iustin Pop
  pass
109 a8083063 Iustin Pop
110 a8083063 Iustin Pop
111 a8083063 Iustin Pop
class RemoteError(GenericError):
112 a8083063 Iustin Pop
  """Programming-related error on remote call.
113 a8083063 Iustin Pop

114 a8083063 Iustin Pop
  This is raised when an unhandled error occurs in a call to a
115 a8083063 Iustin Pop
  remote node.  It usually signifies a real programming bug.
116 a8083063 Iustin Pop

117 a8083063 Iustin Pop
  """
118 a8083063 Iustin Pop
  pass
119 a8083063 Iustin Pop
120 a8083063 Iustin Pop
121 f4a2f532 Guido Trotter
class SignatureError(GenericError):
122 f4a2f532 Guido Trotter
  """Error authenticating a remote message.
123 f4a2f532 Guido Trotter

124 f4a2f532 Guido Trotter
  This is raised when the hmac signature on a message doesn't verify correctly
125 f4a2f532 Guido Trotter
  to the message itself. It can happen because of network unreliability or
126 f4a2f532 Guido Trotter
  because of spurious traffic.
127 f4a2f532 Guido Trotter

128 f4a2f532 Guido Trotter
  """
129 f4a2f532 Guido Trotter
  pass
130 f4a2f532 Guido Trotter
131 f4a2f532 Guido Trotter
132 a8083063 Iustin Pop
class ParameterError(GenericError):
133 a8083063 Iustin Pop
  """A passed parameter to a command is invalid.
134 a8083063 Iustin Pop

135 a8083063 Iustin Pop
  This is raised when the parameter passed to a request function is
136 a8083063 Iustin Pop
  invalid. Correct code should have verified this before passing the
137 a8083063 Iustin Pop
  request structure.
138 a8083063 Iustin Pop

139 a8083063 Iustin Pop
  The argument to this exception should be the parameter name.
140 a8083063 Iustin Pop

141 a8083063 Iustin Pop
  """
142 a8083063 Iustin Pop
  pass
143 a8083063 Iustin Pop
144 a8083063 Iustin Pop
145 a8083063 Iustin Pop
class OpPrereqError(GenericError):
146 a8083063 Iustin Pop
  """Prerequisites for the OpCode are not fulfilled.
147 a8083063 Iustin Pop

148 5c983ee5 Iustin Pop
  This exception will have either one or two arguments. For the
149 5c983ee5 Iustin Pop
  two-argument construction, the second argument should be one of the
150 5c983ee5 Iustin Pop
  ECODE_* codes.
151 5c983ee5 Iustin Pop

152 a8083063 Iustin Pop
  """
153 a8083063 Iustin Pop
154 098c0958 Michael Hanselmann
155 a8083063 Iustin Pop
class OpExecError(GenericError):
156 a8083063 Iustin Pop
  """Error during OpCode execution.
157 a8083063 Iustin Pop

158 a8083063 Iustin Pop
  """
159 a8083063 Iustin Pop
160 098c0958 Michael Hanselmann
161 a8083063 Iustin Pop
class OpCodeUnknown(GenericError):
162 a8083063 Iustin Pop
  """Unknown opcode submitted.
163 a8083063 Iustin Pop

164 a8083063 Iustin Pop
  This signifies a mismatch between the definitions on the client and
165 a8083063 Iustin Pop
  server side.
166 a8083063 Iustin Pop

167 a8083063 Iustin Pop
  """
168 a8083063 Iustin Pop
169 098c0958 Michael Hanselmann
170 685ee993 Iustin Pop
class JobLost(GenericError):
171 685ee993 Iustin Pop
  """Submitted job lost.
172 685ee993 Iustin Pop

173 685ee993 Iustin Pop
  The job was submitted but it cannot be found in the current job
174 685ee993 Iustin Pop
  list.
175 685ee993 Iustin Pop

176 685ee993 Iustin Pop
  """
177 685ee993 Iustin Pop
178 685ee993 Iustin Pop
179 89e1fc26 Iustin Pop
class ResolverError(GenericError):
180 89e1fc26 Iustin Pop
  """Host name cannot be resolved.
181 89e1fc26 Iustin Pop

182 89e1fc26 Iustin Pop
  This is not a normal situation for Ganeti, as we rely on having a
183 89e1fc26 Iustin Pop
  working resolver.
184 89e1fc26 Iustin Pop

185 89e1fc26 Iustin Pop
  The non-resolvable hostname is available as the first element of the
186 89e1fc26 Iustin Pop
  args tuple; the other two elements of the tuple are the first two
187 89e1fc26 Iustin Pop
  args of the socket.gaierror exception (error code and description).
188 89e1fc26 Iustin Pop

189 89e1fc26 Iustin Pop
  """
190 89e1fc26 Iustin Pop
191 89e1fc26 Iustin Pop
192 a8083063 Iustin Pop
class HooksFailure(GenericError):
193 a8083063 Iustin Pop
  """A generic hook failure.
194 a8083063 Iustin Pop

195 a8083063 Iustin Pop
  This signifies usually a setup misconfiguration.
196 a8083063 Iustin Pop

197 a8083063 Iustin Pop
  """
198 a8083063 Iustin Pop
199 098c0958 Michael Hanselmann
200 a8083063 Iustin Pop
class HooksAbort(HooksFailure):
201 a8083063 Iustin Pop
  """A required hook has failed.
202 a8083063 Iustin Pop

203 a8083063 Iustin Pop
  This caused an abort of the operation in the initial phase. This
204 a8083063 Iustin Pop
  exception always has an attribute args which is a list of tuples of:
205 a8083063 Iustin Pop
    - node: the source node on which this hooks has failed
206 a8083063 Iustin Pop
    - script: the name of the script which aborted the run
207 a8083063 Iustin Pop

208 a8083063 Iustin Pop
  """
209 a8083063 Iustin Pop
210 098c0958 Michael Hanselmann
211 a8083063 Iustin Pop
class UnitParseError(GenericError):
212 a8083063 Iustin Pop
  """Unable to parse size unit.
213 a8083063 Iustin Pop

214 a8083063 Iustin Pop
  """
215 a8083063 Iustin Pop
216 ac2d0fe4 Michael Hanselmann
217 a5728081 Guido Trotter
class TypeEnforcementError(GenericError):
218 a5728081 Guido Trotter
  """Unable to enforce data type.
219 a5728081 Guido Trotter

220 a5728081 Guido Trotter
  """
221 a8083063 Iustin Pop
222 ac2d0fe4 Michael Hanselmann
223 a8083063 Iustin Pop
class SshKeyError(GenericError):
224 a8083063 Iustin Pop
  """Invalid SSH key.
225 b0059682 Guido Trotter

226 a8083063 Iustin Pop
  """
227 5c947f38 Iustin Pop
228 5c947f38 Iustin Pop
229 5c947f38 Iustin Pop
class TagError(GenericError):
230 5c947f38 Iustin Pop
  """Generic tag error.
231 5c947f38 Iustin Pop

232 5c947f38 Iustin Pop
  The argument to this exception will show the exact error.
233 5c947f38 Iustin Pop

234 5c947f38 Iustin Pop
  """
235 7bca53e4 Michael Hanselmann
236 7bca53e4 Michael Hanselmann
237 7bca53e4 Michael Hanselmann
class CommandError(GenericError):
238 7bca53e4 Michael Hanselmann
  """External command error.
239 7bca53e4 Michael Hanselmann

240 7bca53e4 Michael Hanselmann
  """
241 e50bdd68 Guido Trotter
242 e50bdd68 Guido Trotter
243 ac2d0fe4 Michael Hanselmann
class StorageError(GenericError):
244 ac2d0fe4 Michael Hanselmann
  """Storage-related exception.
245 ac2d0fe4 Michael Hanselmann

246 ac2d0fe4 Michael Hanselmann
  """
247 ac2d0fe4 Michael Hanselmann
248 589dee9a Guido Trotter
249 589dee9a Guido Trotter
class InotifyError(GenericError):
250 589dee9a Guido Trotter
  """Error raised when there is a failure setting up an inotify watcher.
251 589dee9a Guido Trotter

252 589dee9a Guido Trotter
  """
253 589dee9a Guido Trotter
254 ac2d0fe4 Michael Hanselmann
255 e50bdd68 Guido Trotter
class QuitGanetiException(Exception):
256 e50bdd68 Guido Trotter
  """Signal that Ganeti that it must quit.
257 e50bdd68 Guido Trotter

258 0623d351 Iustin Pop
  This is not necessarily an error (and thus not a subclass of
259 0623d351 Iustin Pop
  GenericError), but it's an exceptional circumstance and it is thus
260 0623d351 Iustin Pop
  treated. This instance should be instantiated with two values. The
261 0623d351 Iustin Pop
  first one will specify the return code to the caller, and the second
262 0623d351 Iustin Pop
  one will be the returned result (either as an error or as a normal
263 0623d351 Iustin Pop
  result). Usually only the leave cluster rpc call should return
264 0623d351 Iustin Pop
  status True (as there it's expected we quit), every other call will
265 0623d351 Iustin Pop
  return status False (as a critical error was encountered).
266 e50bdd68 Guido Trotter

267 c41eea6e Iustin Pop
  Examples::
268 c41eea6e Iustin Pop

269 e50bdd68 Guido Trotter
    # Return a result of "True" to the caller, but quit ganeti afterwards
270 0623d351 Iustin Pop
    raise QuitGanetiException(True, None)
271 e50bdd68 Guido Trotter
    # Send an error to the caller, and quit ganeti
272 0623d351 Iustin Pop
    raise QuitGanetiException(False, "Fatal safety violation, shutting down")
273 e50bdd68 Guido Trotter

274 e50bdd68 Guido Trotter
  """
275 e50bdd68 Guido Trotter
276 f1da30e6 Michael Hanselmann
277 d11bda8d Iustin Pop
class JobQueueError(GenericError):
278 f1da30e6 Michael Hanselmann
  """Job queue error.
279 f1da30e6 Michael Hanselmann

280 f1da30e6 Michael Hanselmann
  """
281 6797ec29 Iustin Pop
282 6797ec29 Iustin Pop
283 686d7433 Iustin Pop
class JobQueueDrainError(JobQueueError):
284 686d7433 Iustin Pop
  """Job queue is marked for drain error.
285 686d7433 Iustin Pop

286 686d7433 Iustin Pop
  This is raised when a job submission attempt is made but the queue
287 686d7433 Iustin Pop
  is marked for drain.
288 686d7433 Iustin Pop

289 686d7433 Iustin Pop
  """
290 686d7433 Iustin Pop
291 686d7433 Iustin Pop
292 f87b405e Michael Hanselmann
class JobQueueFull(JobQueueError):
293 f87b405e Michael Hanselmann
  """Job queue full error.
294 f87b405e Michael Hanselmann

295 f87b405e Michael Hanselmann
  Raised when job queue size reached its hard limit.
296 f87b405e Michael Hanselmann

297 f87b405e Michael Hanselmann
  """
298 f87b405e Michael Hanselmann
299 f87b405e Michael Hanselmann
300 b125e3b3 Guido Trotter
class ConfdFatalError(GenericError):
301 b125e3b3 Guido Trotter
  """A fatal failure in Ganeti confd.
302 b125e3b3 Guido Trotter

303 b125e3b3 Guido Trotter
  Events that compromise the ability of confd to proceed further.
304 b125e3b3 Guido Trotter
  (for example: inability to load the config file)
305 b125e3b3 Guido Trotter

306 b125e3b3 Guido Trotter
  """
307 b125e3b3 Guido Trotter
308 b125e3b3 Guido Trotter
309 b125e3b3 Guido Trotter
class ConfdRequestError(GenericError):
310 b125e3b3 Guido Trotter
  """A request error in Ganeti confd.
311 b125e3b3 Guido Trotter

312 b125e3b3 Guido Trotter
  Events that should make confd abort the current request and proceed serving
313 b125e3b3 Guido Trotter
  different ones.
314 b125e3b3 Guido Trotter

315 b125e3b3 Guido Trotter
  """
316 b125e3b3 Guido Trotter
317 b125e3b3 Guido Trotter
318 9748ab35 Guido Trotter
class ConfdMagicError(GenericError):
319 9748ab35 Guido Trotter
  """A magic fourcc error in Ganeti confd.
320 9748ab35 Guido Trotter

321 9748ab35 Guido Trotter
  Errors processing the fourcc in ganeti confd datagrams.
322 9748ab35 Guido Trotter

323 9748ab35 Guido Trotter
  """
324 9748ab35 Guido Trotter
325 9748ab35 Guido Trotter
326 e4ccf6cd Guido Trotter
class ConfdClientError(GenericError):
327 e4ccf6cd Guido Trotter
  """A magic fourcc error in Ganeti confd.
328 e4ccf6cd Guido Trotter

329 e4ccf6cd Guido Trotter
  Errors in the confd client library.
330 e4ccf6cd Guido Trotter

331 e4ccf6cd Guido Trotter
  """
332 e4ccf6cd Guido Trotter
333 e4ccf6cd Guido Trotter
334 c8eded0b Guido Trotter
class UdpDataSizeError(GenericError):
335 c8eded0b Guido Trotter
  """UDP payload too big.
336 c8eded0b Guido Trotter

337 c8eded0b Guido Trotter
  """
338 c8eded0b Guido Trotter
339 c8eded0b Guido Trotter
340 6797ec29 Iustin Pop
# errors should be added above
341 6797ec29 Iustin Pop
342 6797ec29 Iustin Pop
343 6797ec29 Iustin Pop
def GetErrorClass(name):
344 6797ec29 Iustin Pop
  """Return the class of an exception.
345 6797ec29 Iustin Pop

346 6797ec29 Iustin Pop
  Given the class name, return the class itself.
347 6797ec29 Iustin Pop

348 6797ec29 Iustin Pop
  @type name: str
349 6797ec29 Iustin Pop
  @param name: the exception name
350 6797ec29 Iustin Pop
  @rtype: class
351 6797ec29 Iustin Pop
  @return: the actual class, or None if not found
352 6797ec29 Iustin Pop

353 6797ec29 Iustin Pop
  """
354 6797ec29 Iustin Pop
  item = globals().get(name, None)
355 6797ec29 Iustin Pop
  if item is not None:
356 6797ec29 Iustin Pop
    if not (isinstance(item, type(Exception)) and
357 6797ec29 Iustin Pop
            issubclass(item, GenericError)):
358 6797ec29 Iustin Pop
      item = None
359 6797ec29 Iustin Pop
  return item
360 6956e9cd Iustin Pop
361 6956e9cd Iustin Pop
362 6956e9cd Iustin Pop
def EncodeException(err):
363 6956e9cd Iustin Pop
  """Encodes an exception into a format that L{MaybeRaise} will recognise.
364 6956e9cd Iustin Pop

365 6956e9cd Iustin Pop
  The passed L{err} argument will be formatted as a tuple (exception
366 6956e9cd Iustin Pop
  name, arguments) that the MaybeRaise function will recognise.
367 6956e9cd Iustin Pop

368 6956e9cd Iustin Pop
  @type err: GenericError child
369 6956e9cd Iustin Pop
  @param err: usually a child of GenericError (but any exception
370 6956e9cd Iustin Pop
      will be accepted)
371 6956e9cd Iustin Pop
  @rtype: tuple
372 6956e9cd Iustin Pop
  @return: tuple of (exception name, exception arguments)
373 6956e9cd Iustin Pop

374 6956e9cd Iustin Pop
  """
375 6956e9cd Iustin Pop
  return (err.__class__.__name__, err.args)
376 6956e9cd Iustin Pop
377 6956e9cd Iustin Pop
378 6956e9cd Iustin Pop
def MaybeRaise(result):
379 6956e9cd Iustin Pop
  """Is this looks like an encoded Ganeti exception, raise it.
380 6956e9cd Iustin Pop

381 6956e9cd Iustin Pop
  This function tries to parse the passed argument and if it looks
382 6956e9cd Iustin Pop
  like an encoding done by EncodeException, it will re-raise it.
383 6956e9cd Iustin Pop

384 6956e9cd Iustin Pop
  """
385 6956e9cd Iustin Pop
  tlt = (tuple, list)
386 6956e9cd Iustin Pop
  if (isinstance(result, tlt) and len(result) == 2 and
387 6956e9cd Iustin Pop
      isinstance(result[1], tlt)):
388 6956e9cd Iustin Pop
    # custom ganeti errors
389 6956e9cd Iustin Pop
    err_class = GetErrorClass(result[0])
390 6956e9cd Iustin Pop
    if err_class is not None:
391 6956e9cd Iustin Pop
      raise err_class, tuple(result[1])