From: Alfredo Deza Date: Mon, 29 Jul 2013 20:57:32 +0000 (-0400) Subject: fix stack being eaten by the exception workaround X-Git-Tag: v1.2~16^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F24%2Fhead;p=ceph-deploy.git fix stack being eaten by the exception workaround Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/util/context.py b/ceph_deploy/util/context.py index 44515da..600c355 100644 --- a/ceph_deploy/util/context.py +++ b/ceph_deploy/util/context.py @@ -22,10 +22,11 @@ class remote(object): stderr) or info messages (from stdout). """ - def __init__(self, client, logger, func): + def __init__(self, client, logger, func, mangle_exc=True): self.client = client self.logger = logger self.func = func + self.mangle_exc = mangle_exc def __enter__(self): self.stdout = self.client.modules.sys.stdout @@ -44,6 +45,8 @@ class remote(object): # leave everything as it was self.client.modules.sys.stdout = self.stdout self.client.modules.sys.stdout = self.stderr + if not self.mangle_exc: + return False if e_type is not None: if hasattr(e_val, 'remote_traceback'): @@ -52,7 +55,7 @@ class remote(object): self.logger.error(line) return True # So that we eat up the traceback else: - raise e_type(e_val) + raise e_type def write_log(self, lines, log_level): logger = getattr(self.logger, log_level) diff --git a/ceph_deploy/util/wrappers.py b/ceph_deploy/util/wrappers.py index 5ef36da..8f98da7 100644 --- a/ceph_deploy/util/wrappers.py +++ b/ceph_deploy/util/wrappers.py @@ -14,6 +14,11 @@ def check_call(conn, logger, args, *a, **kw): Wraps ``subprocess.check_call`` for a remote call via ``pushy`` doing all the capturing and logging nicely upon failure/success + The mangling of the traceback when an exception ocurrs, is because the + caller gets eating up by not being executed in the actual function of + a given module (e.g. ``centos/install.py``) but rather here, where the + stack trace is no longer relevant. + :param args: The args to be passed onto ``check_call`` """ command = ' '.join(args) @@ -27,5 +32,22 @@ def check_call(conn, logger, args, *a, **kw): **kw ) - with context.remote(conn, logger, remote_call) as call: - return call(args, *a, **kw) + with context.remote(conn, logger, remote_call, mangle_exc=False) as call: + try: + return call(args, *a, **kw) + except Exception as err: + import inspect + stack = inspect.getframeinfo(inspect.currentframe().f_back) + if hasattr(err, 'remote_traceback'): + logger.error('Traceback (most recent call last):') + logger.error(' File "%s", line %s, in %s' % ( + stack[0], + stack[1], + stack[2]) + ) + err.remote_traceback.pop(0) + for line in err.remote_traceback: + if line: + logger.error(line) + else: + raise err