cas | 43 +++++++++++++++++++++--------
cas-admin | 83 +++++++++++++++++++++++++++++++++-----------------------
lib/cas/core.py | 4 +-
lib/cas/util.py | 4 +-
version | 2 -
5 files changed, 86 insertions(+), 50 deletions(-)
New commits:
commit e716cf7cfc5c7bf1f891e17707ef8ae4a018a122
Author: Adam Stokes <adam(a)conans.battleaxe>
Date: Wed Dec 3 11:05:51 2008 -0500
- cas server population working with func
- cas automated core processing in final stages
- todo: testing, bugfix, etc.
diff --git a/cas b/cas
index 2ee4753..bce1e3e 100755
--- a/cas
+++ b/cas
@@ -33,6 +33,7 @@ config.read("/etc/cas.conf")
WORKDIRECTORY = config.get("settings","workDirectory")
RPMS = config.get("settings","rpms")
DPRINT = config.get("settings","dprint")
+SERVERS = config.get("settings", "servers")
class CoreHandler(object):
def __init__(self, filename, dst):
@@ -56,7 +57,7 @@ class CoreHandler(object):
self.tool.extractCore(self.filename, self.dst)
return os.path.realpath(corepath)
except CoreException, err:
- dprint("Unable to proceed with corefile", DPRINT)
+ dprint(err, DPRINT)
sys.exit(1)
class TimestampHandler(object):
@@ -67,17 +68,16 @@ class TimestampHandler(object):
def run(self):
rpmDB = self.util.load(RPMS)
- coreTimestamp = self.tool.timestamp(self.corefile)
- dprint(coreTimestamp, DPRINT)
- if coreTimestamp:
- for k,v in rpmDB.iteritems():
- for coreObj in rpmDB[k]:
- debugKernel, timestamp = coreObj
- if timestamp and coreTimestamp in timestamp:
- return (k, debugKernel)
- else:
- dprint("Cannot process a timestamp from: %s" % (self.corefile,),
DPRINT)
+ try:
+ coreTimestamp = self.tool.timestamp(self.corefile)
+ except CoreException, err:
+ dprint(err, DPRINT)
sys.exit(1)
+ for k,v in rpmDB.iteritems():
+ for coreObj in rpmDB[k]:
+ debugKernel, timestamp = coreObj
+ if timestamp and coreTimestamp in timestamp:
+ return (k, debugKernel)
dprint("Unable to match (%s,%s) with debugKernel" % (self.corefile,
coreTimestamp), DPRINT)
sys.exit(1)
@@ -123,6 +123,27 @@ class CasApplication(object):
# finish with just a location of the data.
try:
import func.overlord.client as fc
+ # Pull the architecture from the elf file to match up with a
+ # server providing this architecture
+ debugKernelArch = self.util.debugKernelArch(debugKernel)
+ if os.path.isfile(SERVERS):
+ serverList = self.util.load(SERVERS)
+ if serverList.has_key(debugKernelArch):
+ # TODO: Randomize server selection
+ casProcessMachine = serverList[debugKernelArch][0]
+ cmd = "cd %s; %s" % (self.storagePath,
+
os.path.join(self.storagePath,"crash")
+ client = fc.Overlord(casProcessMachine)
+ client_dict = client.command.run(cmd)
+ (sts, out, err) = client_dict[client_dict.keys()[0]]
+ else:
+ print("No servers available for arch, please run cas-admin -h \
+ for more information")
+ print("Continueing without processing core.")
+ else:
+ print("No servers database found, please run cas-admin -h for \
+ more information")
+ sys.exit(1)
except ImportError:
print("You need to install func (
http://fedorahosted.org/func if you \
wish to have the data processed automatically.")
diff --git a/cas-admin b/cas-admin
index a344952..6e6f502 100755
--- a/cas-admin
+++ b/cas-admin
@@ -5,9 +5,10 @@ import os
import ConfigParser
import optparse
import sys
+import urlparse
from cas.core import CoreBase
-from cas.util import UtilBase, sprint
+from cas.util import UtilBase, sprint, dprint
from cas.rpmutils import RPMBase
from subprocess import Popen, PIPE
from shutil import rmtree
@@ -76,37 +77,61 @@ class CasDatabaseHandler(object):
# Cleanup extracted debugs
rmtree(dst)
return
+
+class CasServerHandler(object):
+ def __init__(self):
+ self.util = UtilBase()
+
+ def run(self):
+ try:
+ serverList = {}
+ hostname_count = 0
+ # Attempt to load func to automate detection of machine arch
+ import func.overlord.client as fc
+ parent_func = fc.Overlord("*")
+ minions = parent_func.minions
+ for i in minions:
+ scheme, netloc, path, query, frag = urlparse.urlsplit(i)
+ hostname, port = netloc.split(":")
+ client = fc.Overlord(hostname)
+ # Returns as
{"hostname":['sts','stdout','stderr']}
+ # what a pain
+ client_dict = client.command.run("/bin/uname -m")
+ # silly magic to get output from command module
+ # since we are doing one host at a time we just pull the first
+ # key from the dict and parse its return
+ (sts, arch, err) = client_dict[client_dict.keys()[0]]
+ # clean up arch string
+ arch = arch.strip()
+ if serverList.has_key(arch):
+ serverList[arch].append(hostname)
+ else:
+ serverList[arch] = [hostname]
+ hostname_count = hostname_count + 1
+ self.util.save(serverList, SERVERS)
+ dprint("Server database built with %d server(s) added.\n" %
(hostname_count,))
+ except ImportError:
+ dprint("Please install func (
http://fedorahosted.org/func) for " \
+ "an automated machine arch population.\n", DPRINT)
+ sys.exit(1)
+ return
-class CasprintApplication(object):
+class CasAdminApplication(object):
def __init__(self, args):
- self.util = UtilBase()
self.parse_options(args)
def parse_options(self, args):
parser = optparse.OptionParser(usage="casprint -b")
parser.add_option("-b","--build", dest="buildDB",
help="Build CAS DB", action="store_true",
default=False)
- parser.add_option("-s","--server",
dest="hostname",
- help="Add cas server", action="store",
default=None)
+ parser.add_option("-s","--server",
dest="server_init",
+ help="Build SERVER DB",
action="store_true", default=False)
(self.opts, args) = parser.parse_args()
if len(args) > 2:
parser.error("Please only define one administrator action at a
time.")
sys.exit(1)
self.buildDB = self.opts.buildDB
- self.hostname = self.opts.hostname
-
- def addServer(self, hostname, arch):
- """ method for appending, creating new cas servers
"""
- if os.path.isfile(SERVERS):
- serverList = self.util.load(SERVERS)
- else:
- serverList = {}
-
- if serverList.has_key(arch):
- serverList[arch].append(hostname)
- else:
- serverList[arch] = [hostname]
- return
+ self.server_init = self.opts.server_init
def run(self):
""" Make sure necessary directories and configuration is setup
@@ -122,24 +147,14 @@ class CasprintApplication(object):
if self.buildDB:
print("::: Starting CAS DB instance. :::")
dbHandler = CasDatabaseHandler().run()
- elif self.hostname is not None:
- try:
- # Attempt to load func to automate detection of machine arch
- # otherwise we input for a manual and much more error prone
- # approach
- import func.overload.client as fc
- client = fc.Client(self.hostname)
- (sts, arch, err) = client.command.run("/bin/uname -m")
- self.addServer(self.hostname, arch)
- except ImportError:
- print("Please install func (
http://fedorahosted.org/func) for \
- an automated machine arch population, for now prompting for
input")
- # TODO: add user input.
+ elif self.server_init is not None:
+ print("::: Building CAS Server DB instance. :::")
+ serverHandler = CasServerHandler().run()
else:
- print("Please define -b switch to initialize/update the CAS
database.")
+ print("Missing options, please run with --help.")
sys.exit(1)
if __name__=="__main__":
- app = CasprintApplication(sys.argv[1:])
+ app = CasAdminApplication(sys.argv[1:])
sys.exit(app.run())
diff --git a/lib/cas/core.py b/lib/cas/core.py
index b6986a0..e6fcdef 100644
--- a/lib/cas/core.py
+++ b/lib/cas/core.py
@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <
http://www.gnu.org/licenses/>.
-from cas.util.UtilBase import regexSearch
+from cas.util import UtilBase
class CoreException(Exception):
pass
@@ -94,7 +94,7 @@ class CoreBase(object):
return False
fd.seek(0)
b = os.read(fd.fileno(),54000000)
- out = regexSearch(match, b)
+ out = self.util.regexSearch(match, b)
if out:
return out
raise CoreException("Unable to retrieve timestamp from: %s" % (path,))
diff --git a/lib/cas/util.py b/lib/cas/util.py
index 31d002c..6b8b29d 100755
--- a/lib/cas/util.py
+++ b/lib/cas/util.py
@@ -98,10 +98,10 @@ class UtilBase(object):
raise UtilitiesException("%s : Unable to locate/load file." %
(fname,))
return out
- def arch(self, debug):
+ def debugKernelArch(self, debug):
""" determine machine type for debug kernel
"""
- supportArch = {"IBM S/390":"s390",
+ supportArch = {"IBM S/390":"s390x",
"Intel 80386":"i686",
"Advanced Micro Devices X86-64" : "x86_64",
"Intel IA-64": "ia64",
diff --git a/version b/version
index dab81ac..581b07b 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-0.13 74
+0.13 76