aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authornavid <navid@ef72aa8b-4018-0410-8976-d6e080ef94d8>2007-09-04 08:27:59 +0000
committernavid <navid@ef72aa8b-4018-0410-8976-d6e080ef94d8>2007-09-04 08:27:59 +0000
commit92bf7d380893d3e376a5e358f3d7fe03fec80aae (patch)
tree54b3457d1a525ffc5f6bb0da7ec8b3bd1d8a410d /src/lib
parent347c67b5d8fd925216eebda502182b3d69094090 (diff)
downloadsos-92bf7d380893d3e376a5e358f3d7fe03fec80aae.tar.gz
Merged branch navid-dev r372:389 into the trunk.
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@390 ef72aa8b-4018-0410-8976-d6e080ef94d8
Diffstat (limited to 'src/lib')
-rwxr-xr-xsrc/lib/sos/helpers.py64
-rw-r--r--src/lib/sos/plugins/autofs.py9
-rw-r--r--src/lib/sos/plugins/cluster.py52
-rw-r--r--src/lib/sos/plugins/devicemapper.py22
-rw-r--r--src/lib/sos/plugins/filesys.py24
-rw-r--r--src/lib/sos/plugins/general.py4
-rw-r--r--src/lib/sos/plugins/kernel.py4
-rw-r--r--src/lib/sos/plugins/named.py32
-rw-r--r--src/lib/sos/plugins/networking.py2
-rw-r--r--src/lib/sos/plugins/rpm.py4
-rw-r--r--src/lib/sos/plugins/squid.py6
-rw-r--r--src/lib/sos/plugins/yum.py8
-rw-r--r--src/lib/sos/plugintools.py14
-rwxr-xr-xsrc/lib/sos/policyredhat.py126
14 files changed, 234 insertions, 137 deletions
diff --git a/src/lib/sos/helpers.py b/src/lib/sos/helpers.py
index bc9c51ff..7f2e335d 100755
--- a/src/lib/sos/helpers.py
+++ b/src/lib/sos/helpers.py
@@ -25,8 +25,8 @@
"""
helper functions used by sosreport and plugins
"""
-import os, popen2, fcntl, select, itertools, sys, commands, logging
-from time import time
+import os, popen2, fcntl, select, itertools, sys, commands, logging, signal
+from time import time, sleep
from tempfile import mkdtemp
def importPlugin(pluginname, name):
@@ -57,7 +57,7 @@ def makeNonBlocking(afd):
fcntl.fcntl(afd, fcntl.F_SETFL, fl | os.FNDELAY)
-def sosGetCommandOutput(command):
+def sosGetCommandOutput(command, timeout = 300):
""" Execute a command and gather stdin, stdout, and return status.
"""
soslog = logging.getLogger('sos')
@@ -73,14 +73,49 @@ def sosGetCommandOutput(command):
soslog.log(logging.VERBOSE, "binary '%s' does not exist or is not runnable" % cmdfile)
return (127, "", 0)
- stime = time()
- inpipe, pipe = os.popen4(command, 'r')
- inpipe.close()
- text = pipe.read()
- sts = pipe.close()
- if sts is None: sts = 0
- if text[-1:] == '\n': text = text[:-1]
- return (sts, text, time()-stime)
+ # these are file descriptors, not file objects
+ r, w = os.pipe()
+
+ pid = os.fork()
+
+ if pid:
+ # we are the parent
+ os.close(w) # use os.close() to close a file descriptor
+ r = os.fdopen(r) # turn r into a file object
+ stime=time()
+ txt = ""
+ while True:
+ # read output from pipe
+ txt = txt + r.read()
+ # is child still running ?
+ try: os.waitpid(pid, os.WNOHANG)
+ except: break
+ # has 5 secs timeout passed ?
+ if time() - stime > timeout:
+ soslog.log(logging.VERBOSE, 'killing hung child with pid %s after %d seconds (command was "%s")' % (pid,timeout,command) )
+ os.kill(pid, signal.SIGKILL)
+ break
+ sleep(0.1)
+ # make sure the child process gets cleaned up
+ try: sts = os.waitpid(pid, 0)[1]
+ except: sts = -1
+ if txt[-1:] == '\n': txt = txt[:-1]
+ return (sts, txt, time()-stime)
+ else:
+ # we are the child
+ os.dup2(r, 0)
+ os.dup2(w, 1)
+ os.dup2(w, 2)
+
+ import resource
+ maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
+ if (maxfd == resource.RLIM_INFINITY):
+ maxfd = MAXFD
+ for fd in range(3, maxfd):
+ try: os.close(fd)
+ except OSError: pass
+ os.execl("/bin/sh", "/bin/sh", "-c", command)
+ os._exit(127)
# FIXME: this needs to be made clean and moved to the plugin tools, so
# that it prints nice color output like sysreport if the progress bar
@@ -136,3 +171,10 @@ def sosRelPath(path1, path2, sep=os.path.sep, pardir=os.path.pardir):
if not common:
return path2 # leave path absolute if nothing at all in common
return sep.join( [pardir]*len(u1) + u2 )
+
+def sosReadFile(fname):
+ ''' reads a file and returns its contents'''
+ fp = open(fname,"r")
+ content = fp.read()
+ fp.close()
+ return content
diff --git a/src/lib/sos/plugins/autofs.py b/src/lib/sos/plugins/autofs.py
index 2cb22767..5e8be418 100644
--- a/src/lib/sos/plugins/autofs.py
+++ b/src/lib/sos/plugins/autofs.py
@@ -51,13 +51,8 @@ class autofs(sos.plugintools.PluginBase):
def setup(self):
self.addCopySpec("/etc/auto*")
self.addCopySpec("/etc/sysconfig/autofs")
- self.addCopySpec("/etc/init.d/autofs")
- self.collectExtOutput("/bin/rpm -qV autofs")
- self.collectExtOutput("/etc/init.d/autofs status")
- self.collectExtOutput("ps auxwww | grep automount")
- self.collectExtOutput("/bin/egrep -e 'automount|pid.*nfs' /proc/mounts")
- self.collectExtOutput("/bin/mount | egrep -e 'automount|pid.*nfs'")
- self.collectExtOutput("/sbin/chkconfig --list autofs")
+ self.addCopySpec("/etc/rc.d/init.d/autofs")
+ self.collectExtOutput("service autofs status")
# if debugging to file is enabled, grab that file too
daemon_debug_file = self.getdaemondebug()
diff --git a/src/lib/sos/plugins/cluster.py b/src/lib/sos/plugins/cluster.py
index 6067f9c4..280ad3b1 100644
--- a/src/lib/sos/plugins/cluster.py
+++ b/src/lib/sos/plugins/cluster.py
@@ -25,31 +25,21 @@ class cluster(sos.plugintools.PluginBase):
('taskdump', 'trigger 3 sysrq+t dumps every 5 seconds (dangerous)', 'slow', False)]
def checkenabled(self):
- # enable if any related package is installed
- rhelver = self.cInfo["policy"].rhelVersion()
- if rhelver == 4:
- pkgs_to_check = [ "ccs", "cman", "cman-kernel", "magma", "magma-plugins",
- "rgmanager", "fence", "dlm", "dlm-kernel", "gulm",
- "GFS", "GFS-kernel", "lvm2-cluster" ]
- elif rhelver == 5:
- pkgs_to_check = [ "rgmanager", "luci", "ricci", "system-config-cluster",
- "gfs-utils", "gnbd", "kmod-gfs", "kmod-gnbd", "lvm2-cluster" ]
- else:
- # can't guess what RHEL version we are running
- pkgs_to_check = []
-
- for pkg in pkgs_to_check:
- if self.cInfo["policy"].pkgByName(pkg) != None:
- return True
-
- # enable if any related file is present
- for fname in [ "/etc/cluster/cluster.conf", "/proc/cluster" ]:
- try: os.stat(fname)
- except:pass
- else: return True
-
- # no data related to RHCS/GFS exists
- return False
+ self.files = [ "/etc/yum.conf" ]
+ self.packages = [ "yum" ]
+
+ def checkenabled(self):
+ rhelver = self.cInfo["policy"].rhelVersion()
+ if rhelver == 4:
+ self.packages = [ "ccs", "cman", "cman-kernel", "magma", "magma-plugins",
+ "rgmanager", "fence", "dlm", "dlm-kernel", "gulm",
+ "GFS", "GFS-kernel", "lvm2-cluster" ]
+ elif rhelver == 5:
+ self.packages = [ "rgmanager", "luci", "ricci", "system-config-cluster",
+ "gfs-utils", "gnbd", "kmod-gfs", "kmod-gnbd", "lvm2-cluster" ]
+
+ self.files = [ "/etc/cluster/cluster.conf", "/proc/cluster" ]
+ return sos.plugintools.PluginBase.checkenabled(self)
def has_gfs(self):
try:
@@ -109,6 +99,8 @@ class cluster(sos.plugintools.PluginBase):
break
except IndexError:
pass
+ if found == 2:
+ break
if found == 0:
self.addDiagnose("required kernel package is missing: %s" % pkgname)
@@ -190,6 +182,10 @@ class cluster(sos.plugintools.PluginBase):
if status == 0 and conf_version != cluster_version:
self.addDiagnose("cluster.conf and in-memory configuration version differ (%s != %s)" % (conf_version, cluster_version) )
+ status, output = commands.getstatusoutput("/usr/sbin/rg_test test /etc/cluster/cluster.conf")
+ if output.find("Error: ") > 0:
+ self.addDiagnose("configuration errors are present according to rg_test")
+
# make sure the first part of the lock table matches the cluster name
# and that the locking protocol is sane
cluster_name = xpathContext.xpathEval("/cluster/@name")[0].content
@@ -223,9 +219,9 @@ class cluster(sos.plugintools.PluginBase):
self.collectExtOutput("/sbin/ipvsadm -L")
- if self.isOptionEnabled('gfslockdump'): self.do_gfslockdump()
- if self.isOptionEnabled('lockdump'): self.do_lockdump()
- if self.isOptionEnabled('taskdump'): self.do_taskdump()
+ if self.getOption('gfslockdump'): self.do_gfslockdump()
+ if self.getOption('lockdump'): self.do_lockdump()
+ if self.getOption('taskdump'): self.do_taskdump()
return
diff --git a/src/lib/sos/plugins/devicemapper.py b/src/lib/sos/plugins/devicemapper.py
index a670cae7..46662c70 100644
--- a/src/lib/sos/plugins/devicemapper.py
+++ b/src/lib/sos/plugins/devicemapper.py
@@ -13,19 +13,27 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import sos.plugintools
+import os
+from sos.helpers import sosGetCommandOutput
class devicemapper(sos.plugintools.PluginBase):
"""device-mapper related information (dm, lvm, multipath)
"""
+
+ optionList = [("lvmdump", 'collect raw metadata from PVs', 'slow', False)]
+
+ def do_lvmdump(self):
+ """Collects raw metadata directly from the PVs using dd
+ """
+ sosGetCommandOutput("lvmdump -d %s" % os.path.join(self.cInfo['dstroot'],"lvmdump"), 120)
+
def setup(self):
self.collectExtOutput("/sbin/dmsetup info -c")
self.collectExtOutput("/sbin/dmsetup table")
self.collectExtOutput("/sbin/dmsetup status")
- self.collectExtOutput("/usr/bin/systool -v -C -b scsi")
-
- self.collectExtOutput("/usr/sbin/vgscan -vvv")
self.collectExtOutput("/usr/sbin/vgdisplay -vv", root_symlink = "vgdisplay")
+ self.collectExtOutput("/usr/sbin/vgscan -vvv")
self.collectExtOutput("/usr/sbin/pvscan -v")
self.collectExtOutput("/usr/sbin/lvs -a -o +devices")
self.collectExtOutput("/usr/sbin/pvs -a -v")
@@ -37,4 +45,12 @@ class devicemapper(sos.plugintools.PluginBase):
self.addCopySpec("/var/lib/multipath/bindings")
self.collectExtOutput("/sbin/multipath -v4 -ll")
+ self.collectExtOutput("/usr/bin/systool -v -C -b scsi")
+
+ self.collectExtOutput("/bin/ls -laR /dev")
+ self.collectExtOutput("/bin/ls -laR /sys/block")
+
+ if self.getOption('lvmdump'):
+ self.do_lvmdump()
+
return
diff --git a/src/lib/sos/plugins/filesys.py b/src/lib/sos/plugins/filesys.py
index 73bd3d88..46a3506d 100644
--- a/src/lib/sos/plugins/filesys.py
+++ b/src/lib/sos/plugins/filesys.py
@@ -13,7 +13,8 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import sos.plugintools
-import commands
+from sos.helpers import sosReadFile
+import os
class filesys(sos.plugintools.PluginBase):
"""information on filesystems
@@ -25,21 +26,18 @@ class filesys(sos.plugintools.PluginBase):
self.addCopySpec("/proc/mounts")
self.addCopySpec("/proc/mdstat")
self.addCopySpec("/etc/raidtab")
+ mounts = self.collectOutputNow("/bin/mount -l", root_symlink = "mount")
self.addCopySpec("/etc/mdadm.conf")
self.collectExtOutput("/bin/df -al", root_symlink = "df")
- self.collectExtOutput("/bin/mount -l", root_symlink = "mount")
self.collectExtOutput("/sbin/blkid")
- raiddevs = commands.getoutput("/bin/cat /proc/partitions | /bin/egrep -v \"^major|^$\" | /bin/awk '{print $4}' | /bin/grep \/ | /bin/egrep -v \"p[0123456789]$\"")
- disks = commands.getoutput("/bin/cat /proc/partitions | /bin/egrep -v \"^major|^$\" | /bin/awk '{print $4}' | /bin/grep -v / | /bin/egrep -v \"[0123456789]$\"")
- for disk in raiddevs.split('\n'):
- if '' != disk.strip():
- self.collectExtOutput("/sbin/fdisk -l /dev/%s" % (disk,))
- self.collectExtOutput("/sbin/tune2fs -l /dev/%s" % (disk,))
- for disk in disks.split('\n'):
- if '' != disk.strip():
- self.collectExtOutput("/sbin/fdisk -l /dev/%s" % (disk,))
- self.collectExtOutput("/sbin/tune2fs -l /dev/%s" % (disk,))
- return
+ for disk in os.listdir("/sys/block"):
+ if disk in [ ".", ".." ] or disk.startswith("ram") or sosReadFile("/sys/block/%s/removable" % disk ).strip() == "1":
+ continue
+ self.collectExtOutput("/sbin/fdisk -l /dev/%s" % (disk))
+
+ for extfs in self.doRegexFindAll(r"^(/dev/.+) on .+ type ext.\s+", mounts):
+ self.collectExtOutput("/sbin/tune2fs -l %s" % (extfs))
+ return
diff --git a/src/lib/sos/plugins/general.py b/src/lib/sos/plugins/general.py
index e4be4941..6f1f912c 100644
--- a/src/lib/sos/plugins/general.py
+++ b/src/lib/sos/plugins/general.py
@@ -28,9 +28,9 @@ class general(sos.plugintools.PluginBase):
self.addCopySpec("/proc/stat")
self.addCopySpec("/var/log/dmesg")
self.addCopySpec("/var/log/messages")
- self.addCopySpecLimit("/var/log/messages.*", sizelimit = self.isOptionEnabled("syslogsize"))
+ self.addCopySpecLimit("/var/log/messages.*", sizelimit = self.getOption("syslogsize"))
self.addCopySpec("/var/log/secure")
- self.addCopySpecLimit("/var/log/secure.*", sizelimit = self.isOptionEnabled("syslogsize"))
+ self.addCopySpecLimit("/var/log/secure.*", sizelimit = self.getOption("syslogsize"))
self.addCopySpec("/var/log/sa")
self.addCopySpec("/var/log/up2date")
self.collectExtOutput("/bin/hostname", root_symlink = "hostname")
diff --git a/src/lib/sos/plugins/kernel.py b/src/lib/sos/plugins/kernel.py
index a5ffd855..f2e6def3 100644
--- a/src/lib/sos/plugins/kernel.py
+++ b/src/lib/sos/plugins/kernel.py
@@ -50,7 +50,7 @@ class kernel(sos.plugintools.PluginBase):
self.collectExtOutput("/bin/uname -a", root_symlink = "uname")
self.moduleFile = self.collectOutputNow("/sbin/lsmod", root_symlink = "lsmod")
- if self.isOptionEnabled('modinfo'):
+ if self.getOption('modinfo'):
runcmd = ""
for kmod in commands.getoutput('/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null').split('\n'):
if '' != kmod.strip():
@@ -75,7 +75,7 @@ class kernel(sos.plugintools.PluginBase):
self.addCopySpec("/proc/driver")
self.addCopySpec("/proc/sys/kernel/tainted")
- if self.isOptionEnabled('sysrq') and os.access("/proc/sysrq-trigger", os.W_OK):
+ if self.getOption('sysrq') and os.access("/proc/sysrq-trigger", os.W_OK):
for key in ['m', 'p', 't']:
commands.getoutput("/bin/echo %s > /proc/sysrq-trigger" % (key,))
self.addCopySpec("/var/log/messages")
diff --git a/src/lib/sos/plugins/named.py b/src/lib/sos/plugins/named.py
index 421143cb..f4d24e19 100644
--- a/src/lib/sos/plugins/named.py
+++ b/src/lib/sos/plugins/named.py
@@ -20,21 +20,21 @@ class named(sos.plugintools.PluginBase):
"""named related information
"""
def checkenabled(self):
- if self.cInfo["policy"].pkgByName("bind") or os.path.exists("/etc/named.conf") or os.path.exists("/etc/sysconfig/named"):
- return True
- return False
+ self.files = [ "/etc/named.conf", "/etc/sysconfig/named" ]
+ self.packages = [ "bind" ]
+ return sos.plugintools.PluginBase.checkenabled(self)
def setup(self):
- dnsdir = ""
- self.addCopySpec("/etc/named.boot")
- self.addCopySpec("/etc/named.conf")
- self.addCopySpec("/etc/sysconfig/named")
- if os.access("/etc/named.conf", os.R_OK):
- dnsdir = commands.getoutput("/bin/grep -i directory /etc/named.conf | /bin/gawk '{print $2}' | /bin/sed 's/\\\"//g' | /bin/sed 's/\;//g'")
- if os.access("/etc/named.boot", os.R_OK):
- dnsdir = commands.getoutput("/bin/grep -i directory /etc/named.boot | /bin/gawk '{print $2}' | /bin/sed 's/\\\"//g' | /bin/sed 's/\;//g'")
- if '' != dnsdir.strip():
- self.addCopySpec(dnsdir)
- self.addForbiddenPath('/var/named/chroot/proc')
- self.addForbiddenPath('/var/named/chroot/dev')
- return
+ dnsdir = ""
+ self.addCopySpec("/etc/named.boot")
+ self.addCopySpec("/etc/named.conf")
+ self.addCopySpec("/etc/sysconfig/named")
+ # FIXME: use internal fileGrep() instead
+ if os.access("/etc/named.conf", os.R_OK):
+ dnsdir = commands.getoutput("/bin/grep -i directory /etc/named.conf | /bin/gawk '{print $2}' | /bin/sed 's/\\\"//g' | /bin/sed 's/\;//g'")
+ if os.access("/etc/named.boot", os.R_OK):
+ dnsdir = commands.getoutput("/bin/grep -i directory /etc/named.boot | /bin/gawk '{print $2}' | /bin/sed 's/\\\"//g' | /bin/sed 's/\;//g'")
+ if '' != dnsdir.strip():
+ self.addCopySpec(dnsdir)
+ self.addForbiddenPath('/var/named/chroot/proc')
+ self.addForbiddenPath('/var/named/chroot/dev')
diff --git a/src/lib/sos/plugins/networking.py b/src/lib/sos/plugins/networking.py
index aaf78234..164ed43a 100644
--- a/src/lib/sos/plugins/networking.py
+++ b/src/lib/sos/plugins/networking.py
@@ -65,7 +65,7 @@ class networking(sos.plugintools.PluginBase):
if ifconfigFile:
for eth in self.get_interface_name(ifconfigFile):
self.collectExtOutput("/sbin/ethtool "+eth)
- if self.isOptionEnabled("traceroute"):
+ if self.getOption("traceroute"):
self.collectExtOutput("/bin/traceroute -n rhn.redhat.com")
return
diff --git a/src/lib/sos/plugins/rpm.py b/src/lib/sos/plugins/rpm.py
index bcddaccb..279dde4c 100644
--- a/src/lib/sos/plugins/rpm.py
+++ b/src/lib/sos/plugins/rpm.py
@@ -23,10 +23,10 @@ class rpm(sos.plugintools.PluginBase):
def setup(self):
self.addCopySpec("/var/log/rpmpkgs")
- if self.isOptionEnabled("rpmq"):
+ if self.getOption("rpmq"):
self.collectExtOutput("/bin/rpm -qa --qf \"%{NAME}-%{VERSION}-%{RELEASE}-%{ARCH}\n\"", root_symlink = "installed-rpms")
- if self.isOptionEnabled("rpmva"):
+ if self.getOption("rpmva"):
self.eta_weight += 800 # this plugins takes 200x longer (for ETA)
self.collectExtOutput("/bin/rpm -Va", root_symlink = "rpm-Va")
return
diff --git a/src/lib/sos/plugins/squid.py b/src/lib/sos/plugins/squid.py
index 7e0c3376..3e9b3d8b 100644
--- a/src/lib/sos/plugins/squid.py
+++ b/src/lib/sos/plugins/squid.py
@@ -18,8 +18,10 @@ import os
class squid(sos.plugintools.PluginBase):
"""squid related information
"""
- files = [ "/etc/squid/squid.conf" ]
- packages = [ "squid" ]
+ def checkenabled(self):
+ self.files = [ "/etc/squid/squid.conf" ]
+ self.packages = [ "squid" ]
+ return sos.plugintools.PluginBase.checkenabled(self)
def setup(self):
self.addCopySpec("/etc/squid/squid.conf")
diff --git a/src/lib/sos/plugins/yum.py b/src/lib/sos/plugins/yum.py
index 0f0d049e..672451ee 100644
--- a/src/lib/sos/plugins/yum.py
+++ b/src/lib/sos/plugins/yum.py
@@ -22,9 +22,9 @@ class yum(sos.plugintools.PluginBase):
optionList = [("yumlist", "list repositories and packages", "slow", False)]
def checkenabled(self):
- if self.cInfo["policy"].pkgByName("yum") or os.path.exists("/etc/yum.conf"):
- return True
- return False
+ self.files = [ "/etc/yum.conf" ]
+ self.packages = [ "yum" ]
+ return sos.plugintools.PluginBase.checkenabled(self)
def analyze(self):
# repo sanity checking
@@ -42,7 +42,7 @@ class yum(sos.plugintools.PluginBase):
self.addCopySpec("/etc/yum.conf")
self.addCopySpec("/var/log/yum.log")
- if self.isOptionEnabled("yumlist"):
+ if self.getOption("yumlist"):
# Get a list of channels the machine is subscribed to.
self.collectExtOutput("/bin/echo \"repo list\" | /usr/bin/yum shell")
# List various information about available packages
diff --git a/src/lib/sos/plugintools.py b/src/lib/sos/plugintools.py
index f678297f..303e4fc5 100644
--- a/src/lib/sos/plugintools.py
+++ b/src/lib/sos/plugintools.py
@@ -233,14 +233,22 @@ class PluginBase:
"""
return (self.optNames, self.optParms)
- def setOption(self, optionname, enable):
- ''' enable or disable the named option.
+ def setOption(self, optionname, value):
+ ''' set the named option to value.
'''
for name, parms in zip(self.optNames, self.optParms):
if name == optionname:
- parms['enabled'] = enable
+ parms['enabled'] = value
+ return True
+ else:
+ return False
def isOptionEnabled(self, optionname):
+ ''' Deprecated, use getOption() instead
+ '''
+ return self.getOption(optionname)
+
+ def getOption(self, optionname):
''' see whether the named option is enabled.
'''
for name, parms in zip(self.optNames, self.optParms):
diff --git a/src/lib/sos/policyredhat.py b/src/lib/sos/policyredhat.py
index 9f61e68b..38ded430 100755
--- a/src/lib/sos/policyredhat.py
+++ b/src/lib/sos/policyredhat.py
@@ -27,6 +27,16 @@ import random
import re
import md5
import rpm
+import time
+
+sys.path.insert(0, "/usr/share/rhn/")
+try:
+ from up2date_client import up2dateAuth
+ from up2date_client import config
+ from rhn import rpclib
+except:
+ # might fail if non-RHEL
+ pass
#class SosError(Exception):
# def __init__(self, code, message):
@@ -73,9 +83,6 @@ class SosPolicy:
pkg = self.pkgByName(name)
return pkg['requirename']
- cmd = "/bin/rpm -q --requires %s" % (name)
- return [requires[:-1].split() for requires in os.popen(cmd).readlines()]
-
def allPkgsByName(self, name):
return self.allPkgs("name", name)
@@ -101,14 +108,20 @@ class SosPolicy:
return None
def allPkgs(self, ds = None, value = None):
+ # if possible return the cached values
+ try: return self._cache_rpm[ "%s-%s" % (ds,value) ]
+ except AttributeError: self._cache_rpm = {}
+ except KeyError: pass
+
ts = rpm.TransactionSet()
if ds and value:
mi = ts.dbMatch(ds, value)
else:
mi = ts.dbMatch()
- toret = [pkg for pkg in mi]
+
+ self._cache_rpm[ "%s-%s" % (ds,value) ] = [pkg for pkg in mi]
del mi, ts
- return toret
+ return self._cache_rpm[ "%s-%s" % (ds,value) ]
def runlevelByService(self, name):
ret = []
@@ -136,6 +149,9 @@ class SosPolicy:
def kernelVersion(self):
return commands.getoutput("/bin/uname -r").strip("\n")
+ def hostName(self):
+ return commands.getoutput("/bin/hostname").split(".")[0]
+
def rhelVersion(self):
try:
pkgname = self.pkgByName("redhat-release")["version"]
@@ -146,6 +162,15 @@ class SosPolicy:
except: pass
return False
+ def rhnUsername(self):
+ try:
+ cfg = config.initUp2dateConfig()
+
+ return rpclib.xmlrpclib.loads(up2dateAuth.getSystemId())[0][0]['username']
+ except:
+ # ignore any exception and return an empty username
+ return ""
+
def isKernelSMP(self):
if commands.getoutput("/bin/uname -v").split()[1] == "SMP":
return True
@@ -158,10 +183,22 @@ class SosPolicy:
name = "-".join(fields[:-3])
return (name, version, release, arch)
+ def getDstroot(self):
+ """Find a temp directory to form the root for our gathered information
+ and reports.
+ """
+ dstroot = "/tmp/%s-%s" % (self.hostName(), time.strftime("%Y%m%d%H%M%S"))
+ try:
+ os.mkdir(dstroot, 0700)
+ except:
+ return False
+ return dstroot
+
def preWork(self):
# this method will be called before the gathering begins
- localname = commands.getoutput("/bin/uname -n").split(".")[0]
+ localname = self.rhnUsername()
+ if len(localname) == 0: localname = self.hostName()
try:
self.reportName = raw_input(_("Please enter your first initial and last name [%s]: ") % localname)
@@ -178,70 +215,73 @@ class SosPolicy:
def packageResults(self):
- if len(self.ticketNumber):
- namestr = self.reportName + "." + self.ticketNumber
- else:
- namestr = self.reportName
-
- ourtempdir = gettempdir()
- tarballName = os.path.join(ourtempdir, "sosreport-" + namestr + ".tar.bz2")
+ self.report_file = os.path.join(gettempdir(), "sosreport-%s-%s.tar.bz2" % (self.reportName,time.strftime("%Y%m%d%H%M%S")))
- namestr = namestr + "-" + str(random.randint(1, 999999))
-
- aliasdir = os.path.join(ourtempdir, namestr)
-
- tarcmd = "/bin/tar -jcf %s %s" % (tarballName, namestr)
+ tarcmd = "/bin/tar -jcf %s %s" % (self.report_file, os.path.basename(self.cInfo['dstroot']))
print _("Creating compressed archive...")
- if not os.access(string.split(tarcmd)[0], os.X_OK):
- print "Unable to create tarball"
- return
- # FIXME: gotta be a better way...
- os.system("/bin/mv %s %s" % (self.cInfo['dstroot'], aliasdir))
curwd = os.getcwd()
- os.chdir(ourtempdir)
+ os.chdir(os.path.dirname(self.cInfo['dstroot']))
oldmask = os.umask(077)
- # pylint: disable-msg = W0612
status, shout, runtime = sosGetCommandOutput(tarcmd)
os.umask(oldmask)
os.chdir(curwd)
- # FIXME: use python internal command
- os.system("/bin/mv %s %s" % (aliasdir, self.cInfo['dstroot']))
- # FIXME: encrypt using gnupg
- # gpg --trust-model always --batch --keyring /usr/share/sos/rhsupport.pub --no-default-keyring --compress-level 0 --encrypt --recipient support@redhat.com --output filename.gpg filename.tar
+ return
- # add last 6 chars from md5sum to file name
- fp = open(tarballName, "r")
+ def cleanDstroot(self):
+ if not os.path.isdir(os.path.join(self.cInfo['dstroot'],"sos_commands")):
+ # doesn't look like a dstroot, refusing to clean
+ return False
+ os.system("/bin/rm -rf %s" % self.cInfo['dstroot'])
+
+ def encryptResults(self):
+ # make sure a report exists
+ if not self.report_file:
+ return False
+
+ print _("Encrypting archive...")
+ gpgname = self.report_file + ".gpg"
+ status, output = commands.getstatusoutput("/usr/bin/gpg --trust-model always --batch --keyring /usr/share/sos/rhsupport.pub --no-default-keyring --compress-level 0 --encrypt --recipient support@redhat.com --output %s %s" % (gpgname,self.report_file))
+ if status == 0:
+ os.unlink(self.report_file)
+ self.report_file = gpgname
+ else:
+ print _("There was a problem encrypting your report.")
+ sys.exit(1)
+
+ def displayResults(self):
+ # make sure a report exists
+ if not self.report_file:
+ return False
+
+ # calculate md5
+ fp = open(self.report_file, "r")
md5out = md5.new(fp.read()).hexdigest()
fp.close()
- oldtarballName = tarballName
- tarballName = os.path.join(ourtempdir, "sosreport-%s-%s.tar.bz2" % (namestr, md5out[-6:]) )
- os.system("/bin/mv %s %s" % (oldtarballName, tarballName) )
+
# store md5 to a file
- fp = open(tarballName + ".md5", "w")
+ fp = open(self.report_file + ".md5", "w")
fp.write(md5out + "\n")
fp.close()
- sys.stdout.write("\n")
- print _("Your sosreport has been generated and saved in:\n %s") % tarballName
+ print
+ print _("Your sosreport has been generated and saved in:\n %s") % self.report_file
print
if md5out:
print _("The md5sum is: ") + md5out
print
print _("Please send this file to your support representative.")
- sys.stdout.write("\n")
-
- self.report_file = tarballName
+ print
- return
-
def uploadResults(self):
# make sure a report exists
if not self.report_file:
return False
+ print
+
# make sure it's readable
try:
fp = open(self.report_file, "r")
@@ -261,7 +301,7 @@ class SosPolicy:
except:
print _("There was a problem uploading your report to Red Hat support.")
else:
- print _('Your report was uploaded successfully with name:')
+ print _("Your report was successfully uploaded to Red Hat's ftp server with name:")
print " " + upload_name
print
print _("Please communicate this name to your support representative.")