Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   CentOS (http://www.linux-archive.org/centos/)
-   -   fix '-runcmd' and improve logging (http://www.linux-archive.org/centos/674738-fix-runcmd-improve-logging.html)

Will Woods 06-20-2012 12:11 AM

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.
---
src/pylorax/ltmpl.py | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
index 994b601..7b5b29e 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, check_output, CalledProcessError
+from subprocess import check_call, check_output, CalledProcessError, STDOUT

from sysutils import joinpaths, cpfile, mvfile, replace, remove
from yumhelper import * # Lorax*Callback classes
@@ -155,8 +155,7 @@ class LoraxTemplateRunner(object):
f(*args)
except Exception:
if skiperror:
- logger.error("template command error in %s (ignored):", self.templatefile)
- logger.error(" %s", " ".join(line))
+ logger.debug("ignoring error")
continue
logger.error("template command error in %s:", self.templatefile)
logger.error(" %s", " ".join(line))
@@ -375,10 +374,15 @@ class LoraxTemplateRunner(object):
cmd = cmd[1:]

try:
- check_output(cmd, preexec_fn=chdir)
+ output = check_output(cmd, preexec_fn=chdir, stderr=STDOUT)
+ if output:
+ logger.debug('command output:
%s', output)
+ logger.debug("command finished successfully")
except CalledProcessError as e:
- logger.debug('command exited with %d: %s', e.returncode, e.output)
- sys.exit(e.returncode)
+ if e.output:
+ logger.debug('command output:
%s', e.output)
+ logger.debug('command returned failure (%d)', e.returncode)
+ raise

def installpkg(self, *pkgs):
'
@@ -399,7 +403,7 @@ class LoraxTemplateRunner(object):
# FIXME: save exception and re-raise after the loop finishes
logger.error("installpkg %s failed: %s",p,str(e))
if required:
- sys.exit(1)
+ raise

def removepkg(self, *pkgs):
'
--
1.7.10.2

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


All times are GMT. The time now is 07:20 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.