FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 06-20-2012, 12:11 AM
Will Woods
 
Default 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
 

Thread Tools




All times are GMT. The time now is 06:28 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org