Make error classes more consistent
[ganeti-local] / lib / errors.py
index e089835..688674c 100644 (file)
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2006, 2007, 2010 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -43,12 +43,24 @@ ECODE_FAULT = "internal_error"
 # environment error (e.g. node disk error)
 ECODE_ENVIRON = "environment_error"
 
+#: List of all failure types
+ECODE_ALL = frozenset([
+  ECODE_RESOLVER,
+  ECODE_NORES,
+  ECODE_INVAL,
+  ECODE_STATE,
+  ECODE_NOENT,
+  ECODE_EXISTS,
+  ECODE_NOTUNIQUE,
+  ECODE_FAULT,
+  ECODE_ENVIRON,
+  ])
+
 
 class GenericError(Exception):
   """Base exception for Ganeti.
 
   """
-  pass
 
 
 class LVMError(GenericError):
@@ -57,7 +69,6 @@ class LVMError(GenericError):
   This exception codifies problems with LVM setup.
 
   """
-  pass
 
 
 class LockError(GenericError):
@@ -66,7 +77,12 @@ class LockError(GenericError):
   This signifies problems in the locking subsystem.
 
   """
-  pass
+
+
+class PidFileLockError(LockError):
+  """PID file is already locked by another process.
+
+  """
 
 
 class HypervisorError(GenericError):
@@ -76,7 +92,6 @@ class HypervisorError(GenericError):
   properly.
 
   """
-  pass
 
 
 class ProgrammerError(GenericError):
@@ -87,7 +102,6 @@ class ProgrammerError(GenericError):
   parts of our code. It signifies a real programming bug.
 
   """
-  pass
 
 
 class BlockDeviceError(GenericError):
@@ -97,7 +111,6 @@ class BlockDeviceError(GenericError):
   properly.
 
   """
-  pass
 
 
 class ConfigurationError(GenericError):
@@ -107,7 +120,15 @@ class ConfigurationError(GenericError):
   exist in the config or such raise this exception.
 
   """
-  pass
+
+
+class ConfigVersionMismatch(ConfigurationError):
+  """Version mismatch in the configuration file.
+
+  The error has two arguments: the expected and the actual found
+  version.
+
+  """
 
 
 class ReservationError(GenericError):
@@ -123,7 +144,6 @@ class RemoteError(GenericError):
   remote node.  It usually signifies a real programming bug.
 
   """
-  pass
 
 
 class SignatureError(GenericError):
@@ -134,7 +154,6 @@ class SignatureError(GenericError):
   because of spurious traffic.
 
   """
-  pass
 
 
 class ParameterError(GenericError):
@@ -147,7 +166,6 @@ class ParameterError(GenericError):
   The argument to this exception should be the parameter name.
 
   """
-  pass
 
 
 class OpPrereqError(GenericError):
@@ -166,6 +184,12 @@ class OpExecError(GenericError):
   """
 
 
+class OpResultError(GenericError):
+  """Issue with OpCode result.
+
+  """
+
+
 class OpCodeUnknown(GenericError):
   """Unknown opcode submitted.
 
@@ -248,6 +272,14 @@ class SshKeyError(GenericError):
   """
 
 
+class X509CertError(GenericError):
+  """Invalid X509 certificate.
+
+  This error has two arguments: the certificate filename and the error cause.
+
+  """
+
+
 class TagError(GenericError):
   """Generic tag error.
 
@@ -275,7 +307,7 @@ class InotifyError(GenericError):
 
 
 class QuitGanetiException(Exception):
-  """Signal that Ganeti that it must quit.
+  """Signal Ganeti that it must quit.
 
   This is not necessarily an error (and thus not a subclass of
   GenericError), but it's an exceptional circumstance and it is thus
@@ -362,6 +394,36 @@ class IPAddressError(GenericError):
   """
 
 
+class LuxiError(GenericError):
+  """LUXI error.
+
+  """
+
+
+class QueryFilterParseError(ParseError):
+  """Error while parsing query filter.
+
+  """
+  def GetDetails(self):
+    """Returns a list of strings with details about the error.
+
+    """
+    try:
+      (_, inner) = self.args
+    except IndexError:
+      return None
+
+    return [str(inner.line),
+            (" " * (inner.column - 1)) + "^",
+            str(inner)]
+
+
+class RapiTestResult(GenericError):
+  """Exception containing results from RAPI test utilities.
+
+  """
+
+
 # errors should be added above
 
 
@@ -429,4 +491,5 @@ def MaybeRaise(result):
   error = GetEncodedError(result)
   if error:
     (errcls, args) = error
-    raise errcls, args
+    # pylint: disable=W0142
+    raise errcls(*args)