Statistics
| Branch: | Tag: | Revision:

root / lib / errors.py @ 6e6bb8d5

History | View | Annotate | Download (8 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 a8083063 Iustin Pop
class GenericError(Exception):
26 a8083063 Iustin Pop
  """Base exception for Ganeti.
27 a8083063 Iustin Pop

28 a8083063 Iustin Pop
  """
29 a8083063 Iustin Pop
  pass
30 a8083063 Iustin Pop
31 a8083063 Iustin Pop
32 a8083063 Iustin Pop
class LVMError(GenericError):
33 a8083063 Iustin Pop
  """LVM-related exception.
34 a8083063 Iustin Pop

35 a8083063 Iustin Pop
  This exception codifies problems with LVM setup.
36 a8083063 Iustin Pop

37 a8083063 Iustin Pop
  """
38 a8083063 Iustin Pop
  pass
39 a8083063 Iustin Pop
40 a8083063 Iustin Pop
41 a8083063 Iustin Pop
class LockError(GenericError):
42 a8083063 Iustin Pop
  """Lock error exception.
43 a8083063 Iustin Pop

44 a8083063 Iustin Pop
  This signifies problems in the locking subsystem.
45 a8083063 Iustin Pop

46 a8083063 Iustin Pop
  """
47 a8083063 Iustin Pop
  pass
48 a8083063 Iustin Pop
49 a8083063 Iustin Pop
50 a8083063 Iustin Pop
class HypervisorError(GenericError):
51 a8083063 Iustin Pop
  """Hypervisor-related exception.
52 a8083063 Iustin Pop

53 a8083063 Iustin Pop
  This is raised in case we can't communicate with the hypervisor
54 a8083063 Iustin Pop
  properly.
55 a8083063 Iustin Pop

56 a8083063 Iustin Pop
  """
57 a8083063 Iustin Pop
  pass
58 a8083063 Iustin Pop
59 a8083063 Iustin Pop
60 a8083063 Iustin Pop
class ProgrammerError(GenericError):
61 a8083063 Iustin Pop
  """Programming-related error.
62 a8083063 Iustin Pop

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

67 a8083063 Iustin Pop
  """
68 a8083063 Iustin Pop
  pass
69 a8083063 Iustin Pop
70 a8083063 Iustin Pop
71 a8083063 Iustin Pop
class BlockDeviceError(GenericError):
72 a8083063 Iustin Pop
  """Block-device related exception.
73 a8083063 Iustin Pop

74 a8083063 Iustin Pop
  This is raised in case we can't setup the instance's block devices
75 a8083063 Iustin Pop
  properly.
76 a8083063 Iustin Pop

77 a8083063 Iustin Pop
  """
78 a8083063 Iustin Pop
  pass
79 a8083063 Iustin Pop
80 a8083063 Iustin Pop
81 a8083063 Iustin Pop
class ConfigurationError(GenericError):
82 a8083063 Iustin Pop
  """Configuration related exception.
83 a8083063 Iustin Pop

84 a8083063 Iustin Pop
  Things like having an instance with a primary node that doesn't
85 a8083063 Iustin Pop
  exist in the config or such raise this exception.
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 RemoteError(GenericError):
92 a8083063 Iustin Pop
  """Programming-related error on remote call.
93 a8083063 Iustin Pop

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

97 a8083063 Iustin Pop
  """
98 a8083063 Iustin Pop
  pass
99 a8083063 Iustin Pop
100 a8083063 Iustin Pop
101 f4a2f532 Guido Trotter
class SignatureError(GenericError):
102 f4a2f532 Guido Trotter
  """Error authenticating a remote message.
103 f4a2f532 Guido Trotter

104 f4a2f532 Guido Trotter
  This is raised when the hmac signature on a message doesn't verify correctly
105 f4a2f532 Guido Trotter
  to the message itself. It can happen because of network unreliability or
106 f4a2f532 Guido Trotter
  because of spurious traffic.
107 f4a2f532 Guido Trotter

108 f4a2f532 Guido Trotter
  """
109 f4a2f532 Guido Trotter
  pass
110 f4a2f532 Guido Trotter
111 f4a2f532 Guido Trotter
112 a8083063 Iustin Pop
class ParameterError(GenericError):
113 a8083063 Iustin Pop
  """A passed parameter to a command is invalid.
114 a8083063 Iustin Pop

115 a8083063 Iustin Pop
  This is raised when the parameter passed to a request function is
116 a8083063 Iustin Pop
  invalid. Correct code should have verified this before passing the
117 a8083063 Iustin Pop
  request structure.
118 a8083063 Iustin Pop

119 a8083063 Iustin Pop
  The argument to this exception should be the parameter name.
120 a8083063 Iustin Pop

121 a8083063 Iustin Pop
  """
122 a8083063 Iustin Pop
  pass
123 a8083063 Iustin Pop
124 a8083063 Iustin Pop
125 a8083063 Iustin Pop
class OpPrereqError(GenericError):
126 a8083063 Iustin Pop
  """Prerequisites for the OpCode are not fulfilled.
127 a8083063 Iustin Pop

128 a8083063 Iustin Pop
  """
129 a8083063 Iustin Pop
130 098c0958 Michael Hanselmann
131 a8083063 Iustin Pop
class OpExecError(GenericError):
132 a8083063 Iustin Pop
  """Error during OpCode execution.
133 a8083063 Iustin Pop

134 a8083063 Iustin Pop
  """
135 a8083063 Iustin Pop
136 098c0958 Michael Hanselmann
137 5c947f38 Iustin Pop
class OpRetryError(OpExecError):
138 5c947f38 Iustin Pop
  """Error during OpCode execution, action can be retried.
139 5c947f38 Iustin Pop

140 5c947f38 Iustin Pop
  """
141 5c947f38 Iustin Pop
142 5c947f38 Iustin Pop
143 a8083063 Iustin Pop
class OpCodeUnknown(GenericError):
144 a8083063 Iustin Pop
  """Unknown opcode submitted.
145 a8083063 Iustin Pop

146 a8083063 Iustin Pop
  This signifies a mismatch between the definitions on the client and
147 a8083063 Iustin Pop
  server side.
148 a8083063 Iustin Pop

149 a8083063 Iustin Pop
  """
150 a8083063 Iustin Pop
151 098c0958 Michael Hanselmann
152 685ee993 Iustin Pop
class JobLost(GenericError):
153 685ee993 Iustin Pop
  """Submitted job lost.
154 685ee993 Iustin Pop

155 685ee993 Iustin Pop
  The job was submitted but it cannot be found in the current job
156 685ee993 Iustin Pop
  list.
157 685ee993 Iustin Pop

158 685ee993 Iustin Pop
  """
159 685ee993 Iustin Pop
160 685ee993 Iustin Pop
161 89e1fc26 Iustin Pop
class ResolverError(GenericError):
162 89e1fc26 Iustin Pop
  """Host name cannot be resolved.
163 89e1fc26 Iustin Pop

164 89e1fc26 Iustin Pop
  This is not a normal situation for Ganeti, as we rely on having a
165 89e1fc26 Iustin Pop
  working resolver.
166 89e1fc26 Iustin Pop

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

171 89e1fc26 Iustin Pop
  """
172 89e1fc26 Iustin Pop
173 89e1fc26 Iustin Pop
174 a8083063 Iustin Pop
class HooksFailure(GenericError):
175 a8083063 Iustin Pop
  """A generic hook failure.
176 a8083063 Iustin Pop

177 a8083063 Iustin Pop
  This signifies usually a setup misconfiguration.
178 a8083063 Iustin Pop

179 a8083063 Iustin Pop
  """
180 a8083063 Iustin Pop
181 098c0958 Michael Hanselmann
182 a8083063 Iustin Pop
class HooksAbort(HooksFailure):
183 a8083063 Iustin Pop
  """A required hook has failed.
184 a8083063 Iustin Pop

185 a8083063 Iustin Pop
  This caused an abort of the operation in the initial phase. This
186 a8083063 Iustin Pop
  exception always has an attribute args which is a list of tuples of:
187 a8083063 Iustin Pop
    - node: the source node on which this hooks has failed
188 a8083063 Iustin Pop
    - script: the name of the script which aborted the run
189 a8083063 Iustin Pop

190 a8083063 Iustin Pop
  """
191 a8083063 Iustin Pop
192 098c0958 Michael Hanselmann
193 a8083063 Iustin Pop
class UnitParseError(GenericError):
194 a8083063 Iustin Pop
  """Unable to parse size unit.
195 a8083063 Iustin Pop

196 a8083063 Iustin Pop
  """
197 a8083063 Iustin Pop
198 ac2d0fe4 Michael Hanselmann
199 a5728081 Guido Trotter
class TypeEnforcementError(GenericError):
200 a5728081 Guido Trotter
  """Unable to enforce data type.
201 a5728081 Guido Trotter

202 a5728081 Guido Trotter
  """
203 a8083063 Iustin Pop
204 ac2d0fe4 Michael Hanselmann
205 a8083063 Iustin Pop
class SshKeyError(GenericError):
206 a8083063 Iustin Pop
  """Invalid SSH key.
207 b0059682 Guido Trotter

208 a8083063 Iustin Pop
  """
209 5c947f38 Iustin Pop
210 5c947f38 Iustin Pop
211 5c947f38 Iustin Pop
class TagError(GenericError):
212 5c947f38 Iustin Pop
  """Generic tag error.
213 5c947f38 Iustin Pop

214 5c947f38 Iustin Pop
  The argument to this exception will show the exact error.
215 5c947f38 Iustin Pop

216 5c947f38 Iustin Pop
  """
217 7bca53e4 Michael Hanselmann
218 7bca53e4 Michael Hanselmann
219 7bca53e4 Michael Hanselmann
class CommandError(GenericError):
220 7bca53e4 Michael Hanselmann
  """External command error.
221 7bca53e4 Michael Hanselmann

222 7bca53e4 Michael Hanselmann
  """
223 e50bdd68 Guido Trotter
224 e50bdd68 Guido Trotter
225 ac2d0fe4 Michael Hanselmann
class StorageError(GenericError):
226 ac2d0fe4 Michael Hanselmann
  """Storage-related exception.
227 ac2d0fe4 Michael Hanselmann

228 ac2d0fe4 Michael Hanselmann
  """
229 ac2d0fe4 Michael Hanselmann
230 589dee9a Guido Trotter
231 589dee9a Guido Trotter
class InotifyError(GenericError):
232 589dee9a Guido Trotter
  """Error raised when there is a failure setting up an inotify watcher.
233 589dee9a Guido Trotter

234 589dee9a Guido Trotter
  """
235 589dee9a Guido Trotter
236 ac2d0fe4 Michael Hanselmann
237 e50bdd68 Guido Trotter
class QuitGanetiException(Exception):
238 e50bdd68 Guido Trotter
  """Signal that Ganeti that it must quit.
239 e50bdd68 Guido Trotter

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

249 c41eea6e Iustin Pop
  Examples::
250 c41eea6e Iustin Pop

251 e50bdd68 Guido Trotter
    # Return a result of "True" to the caller, but quit ganeti afterwards
252 0623d351 Iustin Pop
    raise QuitGanetiException(True, None)
253 e50bdd68 Guido Trotter
    # Send an error to the caller, and quit ganeti
254 0623d351 Iustin Pop
    raise QuitGanetiException(False, "Fatal safety violation, shutting down")
255 e50bdd68 Guido Trotter

256 e50bdd68 Guido Trotter
  """
257 e50bdd68 Guido Trotter
258 f1da30e6 Michael Hanselmann
259 d11bda8d Iustin Pop
class JobQueueError(GenericError):
260 f1da30e6 Michael Hanselmann
  """Job queue error.
261 f1da30e6 Michael Hanselmann

262 f1da30e6 Michael Hanselmann
  """
263 6797ec29 Iustin Pop
264 6797ec29 Iustin Pop
265 686d7433 Iustin Pop
class JobQueueDrainError(JobQueueError):
266 686d7433 Iustin Pop
  """Job queue is marked for drain error.
267 686d7433 Iustin Pop

268 686d7433 Iustin Pop
  This is raised when a job submission attempt is made but the queue
269 686d7433 Iustin Pop
  is marked for drain.
270 686d7433 Iustin Pop

271 686d7433 Iustin Pop
  """
272 686d7433 Iustin Pop
273 686d7433 Iustin Pop
274 f87b405e Michael Hanselmann
class JobQueueFull(JobQueueError):
275 f87b405e Michael Hanselmann
  """Job queue full error.
276 f87b405e Michael Hanselmann

277 f87b405e Michael Hanselmann
  Raised when job queue size reached its hard limit.
278 f87b405e Michael Hanselmann

279 f87b405e Michael Hanselmann
  """
280 f87b405e Michael Hanselmann
281 f87b405e Michael Hanselmann
282 b125e3b3 Guido Trotter
class ConfdFatalError(GenericError):
283 b125e3b3 Guido Trotter
  """A fatal failure in Ganeti confd.
284 b125e3b3 Guido Trotter

285 b125e3b3 Guido Trotter
  Events that compromise the ability of confd to proceed further.
286 b125e3b3 Guido Trotter
  (for example: inability to load the config file)
287 b125e3b3 Guido Trotter

288 b125e3b3 Guido Trotter
  """
289 b125e3b3 Guido Trotter
290 b125e3b3 Guido Trotter
291 b125e3b3 Guido Trotter
class ConfdRequestError(GenericError):
292 b125e3b3 Guido Trotter
  """A request error in Ganeti confd.
293 b125e3b3 Guido Trotter

294 b125e3b3 Guido Trotter
  Events that should make confd abort the current request and proceed serving
295 b125e3b3 Guido Trotter
  different ones.
296 b125e3b3 Guido Trotter

297 b125e3b3 Guido Trotter
  """
298 b125e3b3 Guido Trotter
299 b125e3b3 Guido Trotter
300 9748ab35 Guido Trotter
class ConfdMagicError(GenericError):
301 9748ab35 Guido Trotter
  """A magic fourcc error in Ganeti confd.
302 9748ab35 Guido Trotter

303 9748ab35 Guido Trotter
  Errors processing the fourcc in ganeti confd datagrams.
304 9748ab35 Guido Trotter

305 9748ab35 Guido Trotter
  """
306 9748ab35 Guido Trotter
307 9748ab35 Guido Trotter
308 e4ccf6cd Guido Trotter
class ConfdClientError(GenericError):
309 e4ccf6cd Guido Trotter
  """A magic fourcc error in Ganeti confd.
310 e4ccf6cd Guido Trotter

311 e4ccf6cd Guido Trotter
  Errors in the confd client library.
312 e4ccf6cd Guido Trotter

313 e4ccf6cd Guido Trotter
  """
314 e4ccf6cd Guido Trotter
315 e4ccf6cd Guido Trotter
316 c8eded0b Guido Trotter
class UdpDataSizeError(GenericError):
317 c8eded0b Guido Trotter
  """UDP payload too big.
318 c8eded0b Guido Trotter

319 c8eded0b Guido Trotter
  """
320 c8eded0b Guido Trotter
321 c8eded0b Guido Trotter
322 6797ec29 Iustin Pop
# errors should be added above
323 6797ec29 Iustin Pop
324 6797ec29 Iustin Pop
325 6797ec29 Iustin Pop
def GetErrorClass(name):
326 6797ec29 Iustin Pop
  """Return the class of an exception.
327 6797ec29 Iustin Pop

328 6797ec29 Iustin Pop
  Given the class name, return the class itself.
329 6797ec29 Iustin Pop

330 6797ec29 Iustin Pop
  @type name: str
331 6797ec29 Iustin Pop
  @param name: the exception name
332 6797ec29 Iustin Pop
  @rtype: class
333 6797ec29 Iustin Pop
  @return: the actual class, or None if not found
334 6797ec29 Iustin Pop

335 6797ec29 Iustin Pop
  """
336 6797ec29 Iustin Pop
  item = globals().get(name, None)
337 6797ec29 Iustin Pop
  if item is not None:
338 6797ec29 Iustin Pop
    if not (isinstance(item, type(Exception)) and
339 6797ec29 Iustin Pop
            issubclass(item, GenericError)):
340 6797ec29 Iustin Pop
      item = None
341 6797ec29 Iustin Pop
  return item
342 6956e9cd Iustin Pop
343 6956e9cd Iustin Pop
344 6956e9cd Iustin Pop
def EncodeException(err):
345 6956e9cd Iustin Pop
  """Encodes an exception into a format that L{MaybeRaise} will recognise.
346 6956e9cd Iustin Pop

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

350 6956e9cd Iustin Pop
  @type err: GenericError child
351 6956e9cd Iustin Pop
  @param err: usually a child of GenericError (but any exception
352 6956e9cd Iustin Pop
      will be accepted)
353 6956e9cd Iustin Pop
  @rtype: tuple
354 6956e9cd Iustin Pop
  @return: tuple of (exception name, exception arguments)
355 6956e9cd Iustin Pop

356 6956e9cd Iustin Pop
  """
357 6956e9cd Iustin Pop
  return (err.__class__.__name__, err.args)
358 6956e9cd Iustin Pop
359 6956e9cd Iustin Pop
360 6956e9cd Iustin Pop
def MaybeRaise(result):
361 6956e9cd Iustin Pop
  """Is this looks like an encoded Ganeti exception, raise it.
362 6956e9cd Iustin Pop

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

366 6956e9cd Iustin Pop
  """
367 6956e9cd Iustin Pop
  tlt = (tuple, list)
368 6956e9cd Iustin Pop
  if (isinstance(result, tlt) and len(result) == 2 and
369 6956e9cd Iustin Pop
      isinstance(result[1], tlt)):
370 6956e9cd Iustin Pop
    # custom ganeti errors
371 6956e9cd Iustin Pop
    err_class = GetErrorClass(result[0])
372 6956e9cd Iustin Pop
    if err_class is not None:
373 6956e9cd Iustin Pop
      raise err_class, tuple(result[1])