Commit 6797ec29 authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement transport of ganeti errors across luxi

This patch adds a generic method to identify the ganeti error given its
class name, and implements this across the luxi protocol.

Reviewed-by: imsnah
parent d11bda8d
......@@ -167,6 +167,9 @@ class ClientRqHandler(SocketServer.BaseRequestHandler):
result = self._ops.handle_request(method, args)
success = True
except errors.GenericError, err:
success = False
result = (err.__class__.__name__, err.args)
logging.error("Unexpected exception", exc_info=True)
err = sys.exc_info()
......@@ -241,3 +241,25 @@ class JobQueueError(GenericError):
"""Job queue error.
# errors should be added above
def GetErrorClass(name):
"""Return the class of an exception.
Given the class name, return the class itself.
@type name: str
@param name: the exception name
@rtype: class
@return: the actual class, or None if not found
item = globals().get(name, None)
if item is not None:
if not (isinstance(item, type(Exception)) and
issubclass(item, GenericError)):
item = None
return item
......@@ -36,6 +36,7 @@ import errno
from ganeti import serializer
from ganeti import constants
from ganeti import errors
KEY_METHOD = 'method'
......@@ -275,11 +276,20 @@ class Client(object):
KEY_RESULT not in data):
raise DecodingError("Invalid response from server: %s" % str(data))
result = data[KEY_RESULT]
if not data[KEY_SUCCESS]:
# TODO: decide on a standard exception
raise RequestError(data[KEY_RESULT])
if (isinstance(result, (tuple, list)) and len(result) == 2 and
isinstance(result[1], (tuple, list))):
# custom ganeti errors
err_class = errors.GetErrorClass(result[0])
if err_class is not None:
raise err_class, tuple(result[1])
raise RequestError(result)
return data[KEY_RESULT]
return result
def SubmitJob(self, ops):
ops_state = map(lambda op: op.__getstate__(), ops)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment