aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2013-06-10 16:51:57 +0100
committerBryn M. Reeves <bmr@redhat.com>2013-06-10 16:51:57 +0100
commit6680f3979fdb8f3f02a2a2a51eb9a3c2ec2b17a9 (patch)
tree9f74ccc53fab11e1190dba073a1dbdf4bde8559e
parentd0c3df0e2c2a0c9ccc81827f01b4cc95e68dffb0 (diff)
downloadsos-6680f3979fdb8f3f02a2a2a51eb9a3c2ec2b17a9.tar.gz
Move tmp directory selection to policy class
Since some distributions may be using features like tmp-on-tmpfs that can cause problems for sos data collection move the selection of this directory into the policy class. The new behaviour respects options passed on the command line but will ignore any environment variables. Users wishing to override the location of sos' temporary files should use the command line option. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/policies/__init__.py4
-rw-r--r--sos/policies/redhat.py5
-rw-r--r--sos/sosreport.py23
3 files changed, 23 insertions, 9 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 522aaff5..8eff9935 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -187,6 +187,10 @@ No changes will be made to system configuration.
self.report_name += "." + self.ticket_number
return "sosreport-%s-%s" % (self.report_name, time.strftime("%Y%m%d%H%M%S"))
+ def get_tmp_dir(self, opt_tmp_dir):
+ if not opt_tmp_dir:
+ return tempfile.gettempdir()
+
def validatePlugin(self, plugin_class):
"""
Verifies that the plugin_class should execute under this policy
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index d9dc6b3e..c3740dce 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -35,6 +35,7 @@ class RedHatPolicy(LinuxPolicy):
distro = "Red Hat"
vendor = "Red Hat"
vendor_url = "http://www.redhat.com/"
+ _tmp_dir = "/var/tmp"
def __init__(self):
super(RedHatPolicy, self).__init__()
@@ -81,6 +82,10 @@ class RedHatPolicy(LinuxPolicy):
ret.append(int(runlevel))
return ret
+ def get_tmp_dir(self, opt_tmp_dir):
+ if not opt_tmp_dir:
+ return self._tmp_dir
+
def get_local_name(self):
return self.host_name()
diff --git a/sos/sosreport.py b/sos/sosreport.py
index 0f162cf4..908cbede 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -495,7 +495,7 @@ class SoSOptions(object):
help="specify alternate configuration file")
parser.add_option("--tmp-dir", action="store",
dest="tmp_dir",
- help="specify alternate temporary directory", default=tempfile.gettempdir())
+ help="specify alternate temporary directory", default=None)
parser.add_option("--report", action="store_true",
dest="report",
help="Enable HTML/XML reporting", default=False)
@@ -517,6 +517,8 @@ class SoSReport(object):
self.all_options = deque()
self.xml_report = XmlReport()
self.global_plugin_options = {}
+ self.archive = None
+ self.tempfile_util = None
try:
import signal
@@ -531,7 +533,8 @@ class SoSReport(object):
self._read_config()
self.policy = sos.policies.load()
self._is_root = self.policy.is_root()
- self.tempfile_util = TempFileUtil(tmp_dir=self.opts.tmp_dir)
+ self.tmpdir = self.policy.get_tmp_dir(self.opts.tmp_dir)
+ self.tempfile_util = TempFileUtil(self.tmpdir)
self._set_directories()
def print_header(self):
@@ -542,7 +545,7 @@ class SoSReport(object):
'cmddir': self.cmddir,
'logdir': self.logdir,
'rptdir': self.rptdir,
- 'tmpdir': self.opts.tmp_dir,
+ 'tmpdir': self.tmpdir,
'soslog': self.soslog,
'proflog' : self.proflog,
'policy': self.policy,
@@ -560,14 +563,14 @@ class SoSReport(object):
if self.opts.compression_type not in ('auto', 'zip', 'bzip2', 'gzip', 'xz'):
raise Exception("Invalid compression type specified. Options are:" +
"auto, zip, bzip2, gzip and xz")
- archive_name = os.path.join(self.opts.tmp_dir,self.policy.get_archive_name())
+ archive_name = os.path.join(self.tmpdir,self.policy.get_archive_name())
if self.opts.compression_type == 'auto':
auto_archive = self.policy.preferred_archive_name()
- self.archive = auto_archive(archive_name, self.opts.tmp_dir)
+ self.archive = auto_archive(archive_name, self.tmpdir)
elif self.opts.compression_type == 'zip':
- self.archive = ZipFileArchive(archive_name, self.opts.tmp_dir)
+ self.archive = ZipFileArchive(archive_name, self.tmpdir)
else:
- self.archive = TarFileArchive(archive_name, self.opts.tmp_dir)
+ self.archive = TarFileArchive(archive_name, self.tmpdir)
def _make_archive_paths(self):
self.archive.makedirs(self.cmddir, 0755)
@@ -1156,8 +1159,10 @@ class SoSReport(object):
return self.final_work()
except (SystemExit, KeyboardInterrupt):
- self.archive.cleanup()
- self.tempfile_util.clean()
+ if self.archive:
+ self.archive.cleanup()
+ if self.tempfile_util:
+ self.tempfile_util.clean()
return False
def main(args):