Export error codes from RAPI client module
authorMichael Hanselmann <hansmi@google.com>
Tue, 4 Dec 2012 16:57:13 +0000 (17:57 +0100)
committerMichael Hanselmann <hansmi@google.com>
Fri, 7 Dec 2012 12:47:08 +0000 (13:47 +0100)
Until now the error codes were not available from the RAPI client
module. A newly added unit test ensures all error codes are contained in
“ECODE_ALL”, as well as ensuring consistency between the RAPI client and
the authoritative “errors” module.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/rapi/client.py
test/ganeti.rapi.client_unittest.py

index 04d4160..a19a09e 100644 (file)
@@ -114,6 +114,50 @@ _INST_REINSTALL_REQV1 = INST_REINSTALL_REQV1
 _NODE_MIGRATE_REQV1 = NODE_MIGRATE_REQV1
 _NODE_EVAC_RES1 = NODE_EVAC_RES1
 
+#: Resolver errors
+ECODE_RESOLVER = "resolver_error"
+
+#: Not enough resources (iallocator failure, disk space, memory, etc.)
+ECODE_NORES = "insufficient_resources"
+
+#: Temporarily out of resources; operation can be tried again
+ECODE_TEMP_NORES = "insufficient_resources"
+
+#: Wrong arguments (at syntax level)
+ECODE_INVAL = "wrong_input"
+
+#: Wrong entity state
+ECODE_STATE = "wrong_state"
+
+#: Entity not found
+ECODE_NOENT = "unknown_entity"
+
+#: Entity already exists
+ECODE_EXISTS = "already_exists"
+
+#: Resource not unique (e.g. MAC or IP duplication)
+ECODE_NOTUNIQUE = "resource_not_unique"
+
+#: Internal cluster error
+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_TEMP_NORES,
+  ECODE_INVAL,
+  ECODE_STATE,
+  ECODE_NOENT,
+  ECODE_EXISTS,
+  ECODE_NOTUNIQUE,
+  ECODE_FAULT,
+  ECODE_ENVIRON,
+  ])
+
 # Older pycURL versions don't have all error constants
 try:
   _CURLE_SSL_CACERT = pycurl.E_SSL_CACERT
index e5b2436..d9820c2 100755 (executable)
@@ -34,6 +34,7 @@ from ganeti import utils
 from ganeti import query
 from ganeti import objects
 from ganeti import rapi
+from ganeti import errors
 
 import ganeti.rapi.testutils
 from ganeti.rapi import connector
@@ -136,6 +137,17 @@ class TestConstants(unittest.TestCase):
     self.assertEqual(client._NODE_EVAC_RES1, rlib2._NODE_EVAC_RES1)
     self.assertEqual(client.NODE_EVAC_RES1, rlib2._NODE_EVAC_RES1)
 
+  def testErrors(self):
+    self.assertEqual(client.ECODE_ALL, errors.ECODE_ALL)
+
+    # Make sure all error codes are in both RAPI client and errors module
+    for name in filter(lambda s: (s.startswith("ECODE_") and s != "ECODE_ALL"),
+                       dir(client)):
+      value = getattr(client, name)
+      self.assertEqual(value, getattr(errors, name))
+      self.assertTrue(value in client.ECODE_ALL)
+      self.assertTrue(value in errors.ECODE_ALL)
+
 
 class RapiMockTest(unittest.TestCase):
   def test404(self):