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.
This commit is contained in:
parent
4758a2aa80
commit
681f67f954
@ -25,7 +25,7 @@ logger = logging.getLogger("pylorax.ltmpl")
|
|||||||
|
|
||||||
import os, re, glob, shlex, fnmatch
|
import os, re, glob, shlex, fnmatch
|
||||||
from os.path import basename, isdir
|
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 sysutils import joinpaths, cpfile, mvfile, replace, remove
|
||||||
from yumhelper import * # Lorax*Callback classes
|
from yumhelper import * # Lorax*Callback classes
|
||||||
@ -366,11 +366,17 @@ class LoraxTemplateRunner(object):
|
|||||||
'''
|
'''
|
||||||
chdir = lambda: None
|
chdir = lambda: None
|
||||||
cmd = cmdlist
|
cmd = cmdlist
|
||||||
|
logger.debug('running command: %s', cmd)
|
||||||
if cmd[0].startswith("--chdir="):
|
if cmd[0].startswith("--chdir="):
|
||||||
dirname = cmd[0].split('=',1)[1]
|
dirname = cmd[0].split('=',1)[1]
|
||||||
chdir = lambda: os.chdir(dirname)
|
chdir = lambda: os.chdir(dirname)
|
||||||
cmd = cmd[1:]
|
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):
|
def installpkg(self, *pkgs):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user