aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2013-06-10 17:26:11 +0100
committerBryn M. Reeves <bmr@redhat.com>2013-06-10 17:26:11 +0100
commita9eadf941446ae518067aad50bc3fe5539238ccd (patch)
tree6855f5868f8352f637f9e97317bff7e098ffdc14
parent6680f3979fdb8f3f02a2a2a51eb9a3c2ec2b17a9 (diff)
downloadsos-a9eadf941446ae518067aad50bc3fe5539238ccd.tar.gz
Add get_cmd_dir() method to Plugin and make plug-ins use it
As reported in Issue #140 plug-ins that need to write to an arbitrary location in the archive are broken by the in-line tar archive changes. Introduce a 'get_tmp_dir()' method to the Archive classes that must return a writable directory that is included in the archive. Archives deriving from FileCacheArchive simply retun the root of the archive tree. Add a new method to Plugin to use this support, 'get_cmd_dir()', that will return 'Archive.get_tmp_dir() + 'sos_commands' + self.name()'. Fixes problems in lvm2, cloudforms, satellite and rhui. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/archive.py9
-rw-r--r--sos/plugins/__init__.py6
-rw-r--r--sos/plugins/cloudforms.py4
-rw-r--r--sos/plugins/lvm2.py4
-rw-r--r--sos/plugins/rhui.py2
-rw-r--r--sos/plugins/satellite.py3
6 files changed, 21 insertions, 7 deletions
diff --git a/sos/archive.py b/sos/archive.py
index 8e391c3f..1dfea24e 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -59,6 +59,12 @@ class Archive(object):
def add_dir(self, path):
raise NotImplementedError
+ def get_tmp_dir(self):
+ """Return a temporary directory that clients of the archive may
+ use to write content to. The content of the path is guaranteed
+ to be included in the generated archive."""
+ raise NotImplementedError
+
def cleanup(self):
"""Clean up any temporary resources used by an Archive class."""
pass
@@ -136,6 +142,9 @@ class FileCacheArchive(Archive):
def _makedirs(self, path, mode=0700):
os.makedirs(path, mode)
+ def get_tmp_dir(self):
+ return self._archive_root
+
def makedirs(self, path, mode=0700):
self._makedirs(self.dest_path(path))
self.log.debug("created directory at %s in FileCacheArchive %s"
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index c3c2e87a..70711a3e 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -496,6 +496,12 @@ class Plugin(object):
"""Run a program and collect the output"""
self.collect_cmds.append( (exe, suggest_filename, root_symlink, timeout) )
+ def get_cmd_dir(self):
+ """Return a directory into which this module should store
+ collected command output"""
+ return os.path.join(self.archive.get_tmp_dir(),
+ 'sos_commands', self.name())
+
def file_grep(self, regexp, *fnames):
"""Returns lines matched in fnames, where fnames can either be
pathnames to files to grep through or open file objects to grep through
diff --git a/sos/plugins/cloudforms.py b/sos/plugins/cloudforms.py
index 1dc0eae3..d72dc42b 100644
--- a/sos/plugins/cloudforms.py
+++ b/sos/plugins/cloudforms.py
@@ -30,9 +30,9 @@ class Cloudforms(Plugin, RedHatPlugin):
katello_debug = "/usr/share/katello/script/katello-debug"
aeolus_debug = "aeolus-debug"
if os.path.isfile(katello_debug):
- katello_debug_path = os.path.join(self.commons['dstroot'],"katello-debug")
+ katello_debug_path = os.path.join(self.get_cmd_dir(), "katello-debug")
self.add_cmd_output("%s --notar -d %s" % (katello_debug, katello_debug_path))
if os.path.isfile(aeolus_debug):
- aeolus_debug_path = os.path.join(self.commons['dstroot'],"aeolus-debug")
+ aeolus_debug_path = os.path.join(self.get_cmd_dir(), "aeolus-debug")
self.add_cmd_output("%s --notar -d %s" % (aeolus_debug, aeolus_debug_path))
diff --git a/sos/plugins/lvm2.py b/sos/plugins/lvm2.py
index 8fb1843b..4e55f27f 100644
--- a/sos/plugins/lvm2.py
+++ b/sos/plugins/lvm2.py
@@ -29,8 +29,8 @@ class Lvm2(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
"""Collects an lvmdump in standard format with optional metadata
archives for each physical volume present.
"""
- cmd = "lvmdump -d '%s'" % os.path.join(self.commons['dstroot'],
- "lvmdump")
+ lvmdump_cmd = "lvmdump -d '%s'"
+ cmd = lvmdump_cmd % os.path.join(self.get_cmd_dir(), "lvmdump")
if self.get_option('lvmdump-a'):
cmd += " -a"
self.add_cmd_output(cmd)
diff --git a/sos/plugins/rhui.py b/sos/plugins/rhui.py
index 69f3f22a..9bf29590 100644
--- a/sos/plugins/rhui.py
+++ b/sos/plugins/rhui.py
@@ -32,7 +32,7 @@ class Rhui(Plugin, RedHatPlugin):
else:
cds = ""
- rhui_debug_dst_path = os.path.join(self.commons['dstroot'],
+ rhui_debug_dst_path = os.path.join(self.get_cmd_dir(),
self.commons['cmddir'], self.name())
try:
os.mkdir(rhui_debug_dst_path)
diff --git a/sos/plugins/satellite.py b/sos/plugins/satellite.py
index b2d3cde3..75c047fc 100644
--- a/sos/plugins/satellite.py
+++ b/sos/plugins/satellite.py
@@ -78,8 +78,7 @@ class Satellite(Plugin, RedHatPlugin):
"/etc/tomcat6/", "/var/log/tomcat6/"])
if os.path.exists("spacewalk-debug"):
self.add_cmd_output("spacewalk-debug --dir %s"
- % os.path.join(self.commons['dstroot'],
- "sos_commands/rhn"))
+ % os.path.join(self.get_cmd_dir()))
if self.proxy:
self.add_copy_specs(["/etc/squid", "/var/log/squid"])