From 681f67f954e406a33e657bef46c445078e02611c Mon Sep 17 00:00:00 2001 From: Martin Gracik Date: Thu, 19 Jan 2012 13:50:02 +0100 Subject: [PATCH] Log output of failed command If we run a command from template with runcmd, log it's output if it exits with non-zero return code. --- src/pylorax/ltmpl.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 079c7ca2..03a7aed4 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -25,7 +25,7 @@ logger = logging.getLogger("pylorax.ltmpl") import os, re, glob, shlex, fnmatch from os.path import basename, isdir -from subprocess import check_call +from subprocess import check_call, check_output from sysutils import joinpaths, cpfile, mvfile, replace, remove from yumhelper import * # Lorax*Callback classes @@ -366,11 +366,17 @@ class LoraxTemplateRunner(object): ''' chdir = lambda: None cmd = cmdlist + logger.debug('running command: %s', cmd) if cmd[0].startswith("--chdir="): dirname = cmd[0].split('=',1)[1] chdir = lambda: os.chdir(dirname) cmd = cmd[1:] - check_call(cmd, preexec_fn=chdir) + + try: + check_output(cmd, preexec_fn=chdir) + except CalledProcessError as e: + logger.debug('command exited with %d: %s', e.returncode, e.output) + sys.exit(e.returncode) def installpkg(self, *pkgs): '''