caslib/cas.py | 61 ++++++++++++++++++++++++++++++++++-------------------
caslib/rpmutils.py | 2 +
caslib/util.py | 33 ----------------------------
3 files changed, 42 insertions(+), 54 deletions(-)
New commits:
commit e6aa037046bf7e22009e96f67dd27b5821ba82dd
Author: adam stokes <astokes(a)fedoraproject.org>
Date: Thu May 20 16:52:37 2010 -0400
logging
diff --git a/caslib/cas.py b/caslib/cas.py
index c01013e..d6bca2c 100755
--- a/caslib/cas.py
+++ b/caslib/cas.py
@@ -37,6 +37,7 @@ import hashlib
from urlgrabber import grabber
from subprocess import Popen, PIPE, call
import shutil
+import logging
from datetime import datetime
@@ -70,6 +71,20 @@ BUFFERSIZE=None
if config.has_option("advanced", "buffersize"):
BUFFERSIZE=config.get("advanced", "buffersize")
+# logging
+LEVELS={'DEBUG': logging.debug,
+ 'INFO': logging.info}
+
+clog = logging.getLogger("cas")
+clog.setLevel(LEVELS[settings['DEBUGLEVEL']])
+flog = logging.FileHandler("/var/log/cas.log")
+flog.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s'))
+clog.addHandler(flog)
+console = logging.StreamHandler(sys.stderr)
+console.setLevel(logging.INFO)
+console.setFormatter(logging.Formatter('%(name)s - %(message)s'))
+clog.addHandler(console)
+
def coreHandler(uri):
try:
downloadLocation = grabber.urlgrab(uri, filename=os.path.basename(uri),
copy_local=1)
@@ -96,7 +111,8 @@ def timestampHandler(corefile):
timestamp_query =
sess.query(Timestamp).filter(Timestamp.stampKey.like('%'+timestamp+'%')).first()
if timestamp_query:
return (timestamp_query)
- return _e[2]
+ clog.error(_e[2])
+ return False
class CasApplication(object):
def __init__(self, args):
@@ -141,7 +157,8 @@ class CasApplication(object):
if self.opts.compress_core:
out, err = coreCompress(os.path.abspath(self.opts.filename))
if err:
- return _e[8]
+ clog.error(_e[8])
+ return False
# we want to allow for multiple cores under same identifier
# so we base the hierarchy /workDirectory/identifier/datetime
@@ -188,6 +205,7 @@ class CasApplication(object):
self.jobRecord.msg = _i[5]
self.sess.commit()
if type(timestamp) == str:
+ clog.error(timestamp)
return False
corefileArch = self.util.getElfArch(corefile)
@@ -232,6 +250,7 @@ class CasApplication(object):
sts, out, err = (cmdPipe.returncode, cmdData[0].strip(),
cmdData[1].strip())
if sts:
+ clog.error(err)
return (out, err)
elif debugKernelArch == currentMachineArch:
import platform
@@ -251,28 +270,27 @@ class CasApplication(object):
# The machine running cas isn't capable of processing this core, lets
# attempt with paramiko. Assuming paramiko is installed and a server
database
# is configured we attempt to process the core at another machine.
- try:
- serverList = self.sess.query(Server).all()
- ssh_obj = paramiko.SSHClient()
-
ssh_obj.load_host_keys(os.path.expanduser("~/.ssh/known_hosts"))
- if serverList:
- for hostname, arch, port in serverList:
- if arch == debugKernelArch:
- # TODO: Randomize server selection
- cmd = ["cd " + os.path.join(self.storagePath) +
"\n",
- "./crash -i crash.in > crash.out\n"]
- Executor(settings["SSHKEY"], hostname,
- port, settings["CASUSER"],
- cmd).run()
- break
- else:
- return False
+ serverList = self.sess.query(Server).all()
+ ssh_obj = paramiko.SSHClient()
+ ssh_obj.load_host_keys(os.path.expanduser("~/.ssh/known_hosts"))
+ if serverList:
+ for hostname, arch, port in serverList:
+ if arch == debugKernelArch:
+ # TODO: Randomize server selection
+ cmd = ["cd " + os.path.join(self.storagePath) +
"\n",
+ "./crash -i crash.in > crash.out\n"]
+ Executor(settings["SSHKEY"], hostname,
+ port, settings["CASUSER"],
+ cmd).run()
+ break
+ else:
+ clog.error("server failure")
+ return False
else:
self.jobRecord.msg = _e[80]
self.sess.commit()
- return _e[80]
- except ImportError:
- return False
+ clog.error(_e[80])
+ return False
crashOutFile = os.path.join(self.storagePath,"modules")
if os.path.isfile(crashOutFile) and self.extractKernelModules:
# Here we extract kernel modules processed from crash.out
@@ -327,6 +345,7 @@ class CasApplication(object):
except (os.error, socket.error), e:
self.jobRecord.msg = e
self.sess.commit()
+ clog.error(e)
return False
self.jobRecord.msg = _i[4]
self.sess.commit()
diff --git a/caslib/rpmutils.py b/caslib/rpmutils.py
index 1a21c07..07e7c1f 100644
--- a/caslib/rpmutils.py
+++ b/caslib/rpmutils.py
@@ -24,6 +24,8 @@ def extractDebug(rpm, dst, tool="/usr/bin/rpm2cpio",
filter="*/vmlinux", return_results=True):
""" extract file(s) from rpm
"""
+ if not rpm.endswith('rpm'):
+ return
cpio = "/bin/cpio"
cpio_args = "-imudv"
filter_results = []
diff --git a/caslib/util.py b/caslib/util.py
index b79e131..7e794c0 100644
--- a/caslib/util.py
+++ b/caslib/util.py
@@ -14,7 +14,6 @@
import os
import re
import sys
-import logging
from caslib import error_messages as _e
@@ -29,38 +28,6 @@ def genprint(txt):
sys.stdout.write(":: %s\n" % (txt,))
sys.stdout.flush()
-class Logging(object):
- def __init__(self, dst, logger_id, debug_level='DEBUG'):
- self.debug_level = debug_level
- self.dst = dst
- self.logger_id = logger_id
- self.logfile = logger_id+".log"
- self.logfile = os.path.join(self.dst, self.logfile)
- self.log = logging.getLogger(self.logger_id)
- ch = logging.StreamHandler()
- # never fail if directory doesn't exist.
- if not os.path.exists(os.path.dirname(self.logfile)):
- os.makedirs(os.path.dirname(self.logfile))
- fh = logging.FileHandler(self.logfile)
- self.log.addHandler(ch)
- self.log.addHandler(fh)
- ch_fmt = logging.Formatter("%(message)s")
- fh_fmt = logging.Formatter("%(asctime)s %(process)d (%(levelname)s)\t:
%(message)s")
- ch.setFormatter(ch_fmt)
- fh.setFormatter(fh_fmt)
- logging_level = {'DEBUG': logging.DEBUG,
- 'INFO' : logging.INFO}
- self.log.setLevel(logging_level[self.debug_level])
-
- def debug(self, msg):
- if self.debug_level == 'DEBUG':
- self.log.debug("debug :: %s" % (msg,))
-
- def info(self, msg):
- """ function to print procedure
- """
- self.log.info(":: %s" % (msg,))
-
class UtilException(Exception): pass
class Utility(object):