cas | 53 +++++++++++++------------------
casprint | 86 +++++++++++++++++++++++++++++----------------------
lib/cas/utilities.py | 36 ++++++++++++++-------
version | 2 -
4 files changed, 99 insertions(+), 78 deletions(-)
New commits:
commit 036899f032bbe838fa08c4d0040dd231e9b732a6
Author: Adam Stokes <ajs(a)redhat.com>
Date: Wed Oct 8 21:17:32 2008 -0400
split workflow on casprint to handle both building new cas db and updating existing debug kernels.
One major problem exists in that the kernel debugs overwrite themselves since the extraction doesn't distinguish between architectures. So that needs to be addressed, I'm thinking we should determine this architecture through the file command and seperate the extraction based on that.
diff --git a/cas b/cas
index d0b8468..099ea6e 100755
--- a/cas
+++ b/cas
@@ -1,16 +1,13 @@
#!/usr/bin/python
-
""" cas - core accessibility system.
"""
-
import sys
import optparse
import os
import ConfigParser
-import logging
import shutil
-from cas.utilities import Utilities, CoreTool, dprint
+from cas.utilities import Utilities, CoreTool, dprint, sprint
if sys.version_info[:2] < (2,4):
raise SystemExit("Python >= 2.4 required")
@@ -22,13 +19,6 @@ RPMS = config.get("settings","rpms")
JOBS = config.get("settings","jobs")
DPRINT = config.get("settings","dprint")
-logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(levelname)-8s %(message)s',
- filename='/var/log/cas.log',
- filemode='a')
-
-class CasException(Exception): pass
-
class CoreHandler(object):
def __init__(self, filename, dst):
self.filename = filename
@@ -37,7 +27,8 @@ class CoreHandler(object):
def run(self):
if not os.path.isfile(self.filename):
- raise CasException("Unable to find file specified by -f FILENAME.")
+ dprint("Unable to find file specified by -f FILENAME.", DPRINT)
+ sys.exit(1)
if self.tool.isCorefile(self.filename):
shutil.move(self.filename,
os.path.join(self.dst,self.filename))
@@ -55,15 +46,17 @@ class TimestampHandler(object):
self.tool = CoreTool()
def run(self):
- if os.path.isfile(self.db):
- rpmsDict = self.util.load(self.db)
- timestamp = self.tool.timestamp(self.corefile)
- if timestamp:
- for k,v in rpmsDict.iteritems():
- if rpmsDict[k].timestamp and timestamp in rpmsDict[k].timestamp:
- return rpmsDict[k]
+ debugList = self.util.load(self.db)
+ coreTimestamp = self.tool.timestamp(self.corefile)
+ if coreTimestamp:
+ dprint(coreTimestamp, DPRINT)
+ for item in debugList:
+ debug, timestamp = item
+ if coreTimestamp and coreTimestamp in timestamp:
+ return debug
else:
- raise CasException("No database found.")
+ dprint("Unable to match fingerprint : %s" % (coreTimestamp,), DPRINT)
+ sys.exit(1)
return False
class CasApplication(object):
@@ -81,9 +74,9 @@ class CasApplication(object):
self.opts, args = parser.parse_args()
if not self.opts.identifier:
- parser.error("Identifier number missing")
+ parser.error("A unique identifier number is missing.")
elif not self.opts.filename:
- parser.error("Corefile missing")
+ parser.error("A file object is missing.")
self.filename = self.opts.filename
self.identifier = self.opts.identifier
@@ -95,18 +88,18 @@ class CasApplication(object):
os.makedirs(self.storagePath)
corefile = CoreHandler(self.filename, self.storagePath).run()
if not corefile:
- raise CasException("Unable to determine a corefile.")
- rpmObj = TimestampHandler(corefile, RPMS).run()
- if not rpmObj:
- raise CasException("Unable to determine fingerprint.")
+ dprint("Unable to determine corefile : %s" % (corefile,), DPRINT)
+ sys.exit(1)
+ debug = TimestampHandler(corefile, RPMS).run()
try:
symlink_dst = os.path.join(self.storagePath,
- os.path.basename(rpmObj.sanitizeFilename))
- os.symlink(rpmObj.sanitizeFilename,symlink_dst)
+ os.path.basename(debug))
+ os.symlink(debug,symlink_dst)
except:
- raise CasException("Unable to perform symlink %s" % (os.path.basename(rpmObj.sanitizeFilename)))
+ dprint("Unable to perform symlink %s" % (os.path.basename(debug)), DPRINT)
+ sys.exit(1)
- crash_cmd = "crash %s %s" % (symlink_dst, corefile)
+ crash_cmd = "/bin/sh\ncrash %s %s" % (symlink_dst, corefile)
crash_exe = os.path.join(self.storagePath,"crash")
fh = open(crash_exe,"w")
fh.write(crash_cmd)
diff --git a/casprint b/casprint
index 02b81d6..c08f2b8 100755
--- a/casprint
+++ b/casprint
@@ -1,22 +1,19 @@
#!/usr/bin/python
-
""" casprint - fingerprinting utility for cas
"""
-
import os
-import re
-import threading
import ConfigParser
-import logging
+import optparse
import sys
-from time import sleep
-from stat import ST_SIZE
from cas.db import Core
from cas.utilities import Utilities, CoreTool, dprint, sprint
from cas.rpmutils import Analyze, Tools
from subprocess import Popen, PIPE
+if sys.version_info[:2] < (2,4):
+ raise SystemExit("Python >= 2.4 required")
+
# Read in configuration
config = ConfigParser.ConfigParser()
config.read("/etc/cas.conf")
@@ -25,27 +22,37 @@ RPMS = config.get("settings","rpms")
DEBUGS = config.get("settings","debugs")
DPRINT = config.get("settings","dprint")
-# setup logging
-logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(levelname)-8s %(message)s',
- filename='/var/log/casprint.log',
- filemode='a')
+class CasTimeStampHandler(object):
+ def __init__(self):
+ self.dst = dst
+ self.cmd = ["find", "-L", DEBUGS, "-iname", "vmlinux"]
+ self.tool = CoreTool()
+ self.util = Utilities()
+ self.debugList = []
+ def run(self):
+ pipe = Popen(self.cmd, stdout=PIPE, stderr=PIPE)
+ for line in pipe.stdout:
+ vmlinux = line.strip()
+ tstamp = CoreTool()
+ timestamp = tstamp.timestamp(vmlinux)
+ self.debugList.append((vmlinux,timestamp))
+ sprint("(timestamp) %-100s" % (os.path.realpath(vmlinux),))
+ self.util.save(self.debugList, RPMS)
+ return
+
class CasDatabaseHandler(object):
def __init__(self):
- util = Utilities()
+ self.util = Utilities()
if os.path.isfile(RPMS):
- self.rpmsList = util.load(RPMS)
+ self.debugList = self.util.load(RPMS)
else:
- self.rpmsList = []
-
- self.util = Utilities()
+ self.debugList = []
def run(self):
rpms = []
- cmd = "find" + " -L %s -iname kernel-debuginfo*rpm" % (KERNELS,)
- dprint("running cmd : %s" % (cmd,), DPRINT)
- pipe = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
+ cmd = ["find", "-L", KERNELS, "-iname", "kernel-debuginfo*rpm"]
+ pipe = Popen(cmd, stdout=PIPE, stderr=PIPE)
for line in pipe.stdout:
rpms.append(line.strip())
sprint("(found) %-100s" % (os.path.basename(line.strip()),))
@@ -56,20 +63,19 @@ class CasDatabaseHandler(object):
rpmTool = Tools()
rpmTool.extract(x, DEBUGS)
sprint("(extracted) [%d/%d] %-100s" % (count, totalRpms, os.path.basename(x)))
- cmd = "find" + " -L %s -iname vmlinux" % (DEBUGS,)
- pipe = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
- for line in pipe.stdout:
- vmlinux = line.strip()
- tstamp = CoreTool()
- timestamp = tstamp.timestamp(vmlinux)
- self.rpmsList.append((vmlinux,timestamp))
- sprint("(timestamp) %s : %s" % (os.path.basename(vmlinux), timestamp))
- util.save(rpmsList, RPMS)
return
class CasprintApplication(object):
- def __init__(self):
- pass
+ def __init__(self, args):
+ self.parse_options(args)
+
+ def parse_options(self, args):
+ parser = optparse.OptionParser(usage="casprint -n -t")
+ parser.add_option("-n","--new", dest="newCasDB",
+ help="Build new CAS database", action="store_true")
+ parser.add_option("-t","--timestamp", dest="timestamp",
+ help="Timestamp existing debug kernels", action="store_true")
+ self.opts, args = parser.parse_args()
def run(self):
""" Make sure necessary directories and configuration is setup
@@ -77,15 +83,23 @@ class CasprintApplication(object):
"""
util = Utilities()
if os.getuid() is not 0:
- raise RuntimeError, "You must be root(0), instead you are id(%d)" \
- % (os.getuid())
+ raise RuntimeError, "You must be root(0), instead you are id(%d)" % (os.getuid())
if not os.path.isdir(os.path.dirname(RPMS)):
util.mkdir(RPMS)
if not os.path.isdir(DEBUGS):
util.mkdir(DEBUGS)
- dbHandler = CasDatabaseHandler().run()
- logging.info("Database index complete.")
+ if self.opts.newCasDB:
+ dprint("Running a new cas database instance.", DPRINT)
+ dbHandler = CasDatabaseHandler().run()
+ elif self.opts.timestamp:
+ dprint("Building an updated cache of timestamps on existing debugs.", DPRINT)
+ timestampHandler = CasTimeStampHandler().run()
+ else:
+ raise RuntimeError("You must define either -n for a new CAS database or \n"
+ "-t to update existing debugs")
if __name__=="__main__":
- sys.exit(CasprintApplication().run())
+ app = CasprintApplication(sys.argv[1:])
+ sys.exit(app.run())
+
diff --git a/lib/cas/utilities.py b/lib/cas/utilities.py
index ef6a051..9a83d5c 100644
--- a/lib/cas/utilities.py
+++ b/lib/cas/utilities.py
@@ -7,12 +7,20 @@ import re
import sys
import shutil
import tarfile
+import logging
from subprocess import Popen, PIPE
+# setup logging
+logging.basicConfig(level=logging.DEBUG,
+ format='%(asctime)s %(levelname)-8s %(message)s',
+ filename='/var/log/cas.log',
+ filemode='a')
+
def dprint(msg, debug=True):
if debug:
- print "(debug) %s" % (msg,)
+ sys.stderr.write("(debug) %s" % (msg,))
+ logging.error(msg)
def sprint(msg):
""" function to print status messages
@@ -81,9 +89,12 @@ class Utilities(object):
def load(self, fname):
''' grab data from pickle file
'''
- FILE=open(fname, 'r')
- out=cPickle.load(FILE)
- FILE.close()
+ if os.path.isfile(fname):
+ FILE=open(fname, 'r')
+ out=cPickle.load(FILE)
+ FILE.close()
+ else:
+ raise UtilitiesException("%s : Unable to locate/load file." % (fname,))
return out
def moveFiles(self, regex, start, end):
@@ -157,6 +168,9 @@ class Utilities(object):
return(0)
+class CoreException(Exception):
+ pass
+
class CoreTool(object):
def __init__(self):
self.util = Utilities()
@@ -167,7 +181,7 @@ class CoreTool(object):
self.dst = dst
self.filepath = filepath
if not tarfile.is_tarfile(self.filepath):
- return False
+ raise CoreException("%s : is not a properly compressed tarfile." % (self.filepath,))
else:
tar = tarfile.open(self.filepath, "r")
tar.extractall(self.dst)
@@ -175,11 +189,11 @@ class CoreTool(object):
for file in files:
if self.isCorefile(file):
return os.path.join(root,file)
- return False
+ raise CoreException("Can not determine a corefile from tarball : %s" % (self.filepath,))
def isCorefile(self, corefile):
- cmd = "file -i %s" % (corefile,)
- p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
+ cmd = ["file","-i",corefile]
+ p = Popen(cmd, stdout=PIPE, stderr=PIPE)
txt = p.stdout.read()
items = ['application/x-coredump',
'application/octet-stream',
@@ -195,11 +209,11 @@ class CoreTool(object):
match='Linux\sversion.*\d{1,4}|#1\s.*\d{1,2}'
try:
fd=open('%s' % (path))
- except IOError: return False
+ except IOError:
+ return False
fd.seek(0)
b = os.read(fd.fileno(),54000000)
out = self.util.regexSearch(match, b)
if out:
return out
- return False
-
+ raise CoreException("Unable to retrieve timestamp from: %s" % (path,))
diff --git a/version b/version
index a5a0abb..54dfa8a 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-0.13 58
+0.13 60