diff --git a/lib/rapi/client.py b/lib/rapi/client.py index 04d4160f540ca4cb5f2f39fbb0282005d2dee82b..a19a09e7c85e8e586e24f44917fc729fce83ddff 100644 --- a/lib/rapi/client.py +++ b/lib/rapi/client.py @@ -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 diff --git a/test/ganeti.rapi.client_unittest.py b/test/ganeti.rapi.client_unittest.py index e5b243682638a29c5f9710d4c2d3a2501c94d71f..d9820c25f0c00aab8cbae0dc23b131eb47c129a4 100755 --- a/test/ganeti.rapi.client_unittest.py +++ b/test/ganeti.rapi.client_unittest.py @@ -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):