fix '-runcmd' and improve logging
The '-cmd' functionality depends on the individual lorax template commands raising errors, so they shouldn't do sys.exit(). Also, capture stderr along with stdout, and put both in the log.
This commit is contained in:
parent
6080ff3b2a
commit
daacb4465d
@ -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, check_output, CalledProcessError
|
from subprocess import check_call, check_output, CalledProcessError, STDOUT
|
||||||
|
|
||||||
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
|
||||||
@ -155,8 +155,7 @@ class LoraxTemplateRunner(object):
|
|||||||
f(*args)
|
f(*args)
|
||||||
except Exception:
|
except Exception:
|
||||||
if skiperror:
|
if skiperror:
|
||||||
logger.error("template command error in %s (ignored):", self.templatefile)
|
logger.debug("ignoring error")
|
||||||
logger.error(" %s", " ".join(line))
|
|
||||||
continue
|
continue
|
||||||
logger.error("template command error in %s:", self.templatefile)
|
logger.error("template command error in %s:", self.templatefile)
|
||||||
logger.error(" %s", " ".join(line))
|
logger.error(" %s", " ".join(line))
|
||||||
@ -375,10 +374,15 @@ class LoraxTemplateRunner(object):
|
|||||||
cmd = cmd[1:]
|
cmd = cmd[1:]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
check_output(cmd, preexec_fn=chdir)
|
output = check_output(cmd, preexec_fn=chdir, stderr=STDOUT)
|
||||||
|
if output:
|
||||||
|
logger.debug('command output:\n%s', output)
|
||||||
|
logger.debug("command finished successfully")
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
logger.debug('command exited with %d: %s', e.returncode, e.output)
|
if e.output:
|
||||||
sys.exit(e.returncode)
|
logger.debug('command output:\n%s', e.output)
|
||||||
|
logger.debug('command returned failure (%d)', e.returncode)
|
||||||
|
raise
|
||||||
|
|
||||||
def installpkg(self, *pkgs):
|
def installpkg(self, *pkgs):
|
||||||
'''
|
'''
|
||||||
@ -399,7 +403,7 @@ class LoraxTemplateRunner(object):
|
|||||||
# FIXME: save exception and re-raise after the loop finishes
|
# FIXME: save exception and re-raise after the loop finishes
|
||||||
logger.error("installpkg %s failed: %s",p,str(e))
|
logger.error("installpkg %s failed: %s",p,str(e))
|
||||||
if required:
|
if required:
|
||||||
sys.exit(1)
|
raise
|
||||||
|
|
||||||
def removepkg(self, *pkgs):
|
def removepkg(self, *pkgs):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user