From 599ee321eb778eaef5020a1eae1e4c8adf7b50ae Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 29 Jul 2010 17:14:19 -0400 Subject: [PATCH] Change handling of non-Ganeti errors in jqueue Currently, if a job execution raises a Ganeti-specific error (i.e. subclass of GenericError), then we encode it as (error class, [error args]). This matches the RAPI documentation. However, if we get a non-Ganeti error, then we encode it as simply str(err), a single string. This means that the opresult field is not according to the RAPI docs, and thus it's hard to reliably parse the job results. This patch changes the encoding of a failed job (via failure) to always be an OpExecError, so that we always encode it properly. For the command line interface, the behaviour is the same, as any non-Ganeti errors get re-encoded as OpExecError anyway. For the RAPI clients, it only means that we always present the same type for results. The actual error value is the same, since the err.args is either way str(original_error); compare the original (doesn't contain the ValueError): "opresult": [ "invalid literal for int(): aa" ], with: "opresult": [ [ "OpExecError", [ "invalid literal for int(): aa" ] ] ], Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/jqueue.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/jqueue.py b/lib/jqueue.py index 0958798d0..f27eba688 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -750,9 +750,10 @@ class _JobQueueWorker(workerpool.BaseWorker): try: op.status = constants.OP_STATUS_ERROR if isinstance(err, errors.GenericError): - op.result = errors.EncodeException(err) + to_encode = err else: - op.result = str(err) + to_encode = errors.OpExecError(str(err)) + op.result = errors.EncodeException(to_encode) op.end_timestamp = TimeStampNow() logging.info("Op %s/%s: Error in opcode %s: %s", idx + 1, count, op_summary, err) -- GitLab