[lorax] Log output of failed command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
index 079c7ca..03a7aed 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):
         '''
-- 
1.7.5.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux