From 2b2fa228391a0188a375a9e3c1e8f03f69c7eafd Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 7 Nov 2013 16:27:44 +0000 Subject: Normalize temporary directory path The archive and temporary file handling classes expect to operate on absolute paths. If a user specifies a relative path via the command line --tmp-dir switch it must be normalized before being passed to these classes to provide correct behaviour. Failing to do this causes a variety of errors: the final archive cannot be created since the path is constructed incorrectly and temporary files are not cleaned up since they are not at the "expected" location. Signed-off-by: Bryn M. Reeves --- sos/sosreport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sos/sosreport.py b/sos/sosreport.py index 2451439b..b1f2e1d0 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -534,7 +534,8 @@ class SoSReport(object): self._read_config() self.policy = sos.policies.load() self._is_root = self.policy.is_root() - self.tmpdir = self.policy.get_tmp_dir(self.opts.tmp_dir) + self.tmpdir = os.path.abspath( + self.policy.get_tmp_dir(self.opts.tmp_dir)) if not os.path.isdir(self.tmpdir) \ or not os.access(self.tmpdir, os.W_OK): # write directly to stderr as logging is not initialised yet -- cgit From 7e96ec748f0b0ab906fa246e4fcac0becb2ed1b4 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 7 Nov 2013 17:14:16 +0000 Subject: Restore --build command line option Releases of sos prior to 3.0 included the '--build' option to disable creation of a compressed archive and to leave the temporary build tree in place. This was removed with the reorganisation of the archive classes to support in-line archiving. Since all supported policies are now using an archive that derives from FileCacheArchive (commit 0178d5f) the option can be re-introduced. Archive classes that do not accumulate files in a temporary directory will return the path to the in-progress archive file. Signed-off-by: Bryn M. Reeves --- sos/archive.py | 22 +++++++++++++++++----- sos/policies/__init__.py | 8 -------- sos/sosreport.py | 47 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/sos/archive.py b/sos/archive.py index 080f2593..095777ba 100644 --- a/sos/archive.py +++ b/sos/archive.py @@ -59,6 +59,15 @@ class Archive(object): to be included in the generated archive.""" raise NotImplementedError + def get_archive_path(self): + """Return a string representing the path to the temporary + archive. For archive classes that implement in-line handling + this will be the archive file itself. Archives that use a + directory based cache prior to packaging should return the + path to the temporary directory where the report content is + located""" + pass + def cleanup(self): """Clean up any temporary resources used by an Archive class.""" pass @@ -76,7 +85,7 @@ class FileCacheArchive(Archive): _tmp_dir = "" _archive_root = "" - _archive_path = "" + _archive_name = "" def __init__(self, name, tmpdir): self._name = name @@ -141,6 +150,9 @@ class FileCacheArchive(Archive): def get_tmp_dir(self): return self._archive_root + def get_archive_path(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" @@ -157,8 +169,8 @@ class FileCacheArchive(Archive): self.log.debug("finalizing archive %s" % self._archive_root) self._build_archive() self.cleanup() - self.log.debug("built archive at %s (size=%d)" % (self._archive_path, - os.stat(self._archive_path).st_size)) + self.log.debug("built archive at %s (size=%d)" % (self._archive_name, + os.stat(self._archive_name).st_size)) return self._compress() @@ -170,7 +182,7 @@ class TarFileArchive(FileCacheArchive): def __init__(self, name, tmpdir): super(TarFileArchive, self).__init__(name, tmpdir) self._suffix = "tar" - self._archive_path = os.path.join(tmpdir, self.name()) + self._archive_name = os.path.join(tmpdir, self.name()) def set_tarinfo_from_stat(self, tar_info, fstat, mode=None): tar_info.mtime = fstat.st_mtime @@ -214,7 +226,7 @@ class TarFileArchive(FileCacheArchive): old_pwd = os.getcwd() old_umask = os.umask(0077) os.chdir(self._tmp_dir) - tar = tarfile.open(self._archive_path, mode="w") + tar = tarfile.open(self._archive_name, mode="w") tar.add(os.path.split(self._name)[1], filter=self.copy_permissions_filter) tar.close() diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index 5c2531df..ba2f14b4 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -206,12 +206,6 @@ No changes will be made to system configuration. """ pass - def package_results(self, package_name): - """ - This function is called prior to packaging. - """ - pass - def post_work(self): """ This function is called after the sosreport has been generated. @@ -477,5 +471,3 @@ class LinuxPolicy(Policy): return - def package_results(self, archive_filename): - self._print(_("Creating compressed archive...")) diff --git a/sos/sosreport.py b/sos/sosreport.py index b1f2e1d0..cab7d0c0 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -326,6 +326,19 @@ class SoSOptions(object): raise TypeError("SoSOptions.batch expects a boolean") self._batch = value + @property + def build(self): + if self._options != None: + return self._options.build + return self._build + + @build.setter + def build(self): + self._check_options_initialized() + if not isinstance(value, bool): + raise TypeError("SoSOptions.build expects a boolean") + self._build = value + @property def verbosity(self): if self._options != None: @@ -476,6 +489,9 @@ class SoSOptions(object): parser.add_option("--batch", action="store_true", dest="batch", default=False, help="batch mode - do not prompt interactively") + parser.add_option("--build", action="store_true", \ + dest="build", default=False, \ + help="keep sos tree available and dont package results") parser.add_option("-v", "--verbose", action="count", dest="verbosity", help="increase verbosity") @@ -1097,24 +1113,29 @@ class SoSReport(object): def final_work(self): # package up the results for the support organization - self.policy.package_results(self.archive.name()) + if not self.opts.build: + self.ui_log.info(_("Creating compressed archive...")) - self._finish_logging() + # compression could fail for a number of reasons + try: + final_filename = self.archive.finalize(self.opts.compression_type) + except: + if self.opts.debug: + raise + else: + return False - # compression could fail for a number of reasons - try: - final_filename = self.archive.finalize(self.opts.compression_type) - except: - if self.opts.debug: - raise + # automated submission will go here + if not self.opts.upload: + self.policy.display_results(final_filename) else: - return False + self.policy.upload_results(final_filename) - # automated submission will go here - if not self.opts.upload: - self.policy.display_results(final_filename) else: - self.policy.upload_results(final_filename) + self.ui_log.info(_("\n sosreport build tree is located at : %s\n" + % self.archive.get_archive_path())) + + self._finish_logging() self.tempfile_util.clean() -- cgit From 7af1da54b84ddd3ef82f90d86358f2038db5cb9e Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 7 Nov 2013 17:28:30 +0000 Subject: Fix foreman and katello for sos-3.x The foreman and katello plug-ins committed in 4650d3f use the sos-2.2 APIs and class names. This breaks sos since the plug-ins will not load under 3.0. Fix up the modules to use the new names and API conventions and ensure that they load correctly. Signed-off-by: Bryn M. Reeves --- sos/plugins/foreman.py | 21 ++++++++------------- sos/plugins/katello.py | 21 ++++++++------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/sos/plugins/foreman.py b/sos/plugins/foreman.py index 60ec34df..28ea6a24 100644 --- a/sos/plugins/foreman.py +++ b/sos/plugins/foreman.py @@ -14,23 +14,18 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import sos.plugintools import os +from sos.plugins import Plugin, RedHatPlugin -class foreman(sos.plugintools.PluginBase): +class Foreman(Plugin, RedHatPlugin): """Foreman project related information """ - def defaultenabled(self): - return True - - def checkenabled(self): - self.packages = ["foreman"] - self.files = ["/usr/sbin/foreman-debug"] - return sos.plugintools.PluginBase.checkenabled(self) + plugin_name = 'foreman' + packages = ('foreman') def setup(self): - foreman_debug = "/usr/sbin/foreman-debug" - if os.path.isfile(foreman_debug): - foreman_debug_path = os.path.join(self.cInfo['dstroot'],"foreman-debug") - self.collectExtOutput("%s -a -d %s" % (foreman_debug, foreman_debug_path)) + foreman_debug_path = os.path.join( + self.get_cmd_path(),"foreman-debug") + self.add_cmd_output("%s -a -d %s" + % ("foreman-debug", foreman_debug_path)) diff --git a/sos/plugins/katello.py b/sos/plugins/katello.py index 54b30fac..19993884 100644 --- a/sos/plugins/katello.py +++ b/sos/plugins/katello.py @@ -14,23 +14,18 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import sos.plugintools import os +from sos.plugins import Plugin, RedHatPlugin -class katello(sos.plugintools.PluginBase): +class Katello(Plugin, RedHatPlugin): """Katello project related information """ - def defaultenabled(self): - return True - - def checkenabled(self): - self.packages = ["katello", "katello-common", "katello-headpin"] - self.files = ["/usr/bin/katello-debug"] - return sos.plugintools.PluginBase.checkenabled(self) + plugin_name = 'katello' + packages = ('katello', 'katello-common', 'katello-headpin') def setup(self): - katello_debug = "/usr/bin/katello-debug" - if os.path.isfile(katello_debug): - katello_debug_path = os.path.join(self.cInfo['dstroot'],"katello-debug") - self.collectExtOutput("%s --notar -d %s" % (katello_debug, katello_debug_path)) + katello_debug_path = os.path.join( + self.get_cmd_path(),"katello-debug") + self.add_cmd_output("%s --notar -d %s" + % ("katello-debug", katello_debug_path)) -- cgit From 3439787939f096564ef9b35faf774d0c1e35a8e6 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 7 Nov 2013 17:48:03 +0000 Subject: Fix traceback when sar module is force-enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Forward port of the following sos-2.2 fix: commit d4e3bcc3ed247d8d9a1228c3661b6456f534daf4 Author: Bryn M. Reeves Date: Mon Aug 12 18:42:48 2013 +0100 Fix traceback when sar module is force-enabled The sar plug-in assumes that when it runs the /var/lib/sa directory and binaries exist (they are part of checkenabled() for this module). This leads to a traceback when the plug-in lists a non-existent directory on hosts where sar is not installed but '-o sar' is specified on the command line. Catch the exception and exit gracefully. (Edited by bmr to improve error message logged). Signed-off-by: David Kutálek Signed-off-by: Bryn M. Reeves --- sos/plugins/sar.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sos/plugins/sar.py b/sos/plugins/sar.py index 4f89b533..570262a4 100644 --- a/sos/plugins/sar.py +++ b/sos/plugins/sar.py @@ -43,8 +43,12 @@ class Sar(Plugin,): self.add_copy_spec_limit("/var/log/sa/sar[0-9]*", sizelimit = self.sa_size) self.add_copy_spec_limit("/var/log/sa/sa[0-9]*", - sizelimit = self.sa_size) - dirList = os.listdir(self.sa_path) + sizelimit = self.sa_size) + try: + dirList = os.listdir(self.sa_path) + except: + self.soslog.error("sar: could not list /var/log/sa") + return # find all the sa file that don't have an existing sar file for fname in dirList: if fname[0:2] == 'sa' and fname[2] != 'r': -- cgit From 79c0aa73613e7b57449a6581a77fcad0dda4ae52 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 7 Nov 2013 18:17:18 +0000 Subject: Fix regex substitution in openhpi plug-in Signed-off-by: Bryn M. Reeves --- sos/plugins/openhpi.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sos/plugins/openhpi.py b/sos/plugins/openhpi.py index a75f016d..dbe004d4 100644 --- a/sos/plugins/openhpi.py +++ b/sos/plugins/openhpi.py @@ -28,10 +28,6 @@ class OpenHPI(Plugin, RedHatPlugin): ]) def postproc(self): - self.do_file_sub("/etc/openhpi/openhpi.conf" - r'([Pp]assw(or)?d|[Pp]assphrase)[[:space:]]+\=[[:space:]]"(.*)"', - r"\1******") - self.do_file_sub("/etc/openhpi/openhpiclient.conf" - r'([Pp]assw(or)?d|[Pp]assphrase)[[:space:]]+\=[[:space:]]"(.*)"', - r"\1******") + self.do_file_sub("/etc/openhpi/openhpi.conf", + r'(\s*[Pp]ass.*\s*=\s*).*', r'\1********') -- cgit From 4b9a8c66313ddbda319298772950c440f6113ac7 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Fri, 8 Nov 2013 14:59:56 +0000 Subject: Add simple nfs plug-in There has been an nfsserver plug-in for some time however no corresponding client-side data is collected. This was added to sos-2.2 earlier this year. This commit is a forward port of those changes: commit 71066b4a7d4fd97692b50bf231ad6810df5ec3d0 Author: root Date: Wed Jul 10 17:11:52 2013 +0100 Collect additional nfs-client relevant files Additional NFS client-side data collection: "/etc/nfsmount.conf", "/proc/fs/nfsfs/servers", "/proc/fs/nfsfs/volumes" Signed-off-by: Bryn M. Reeves Signed-off-by: Bryn M. Reeves --- sos/plugins/nfs.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 sos/plugins/nfs.py diff --git a/sos/plugins/nfs.py b/sos/plugins/nfs.py new file mode 100644 index 00000000..4acbe38e --- /dev/null +++ b/sos/plugins/nfs.py @@ -0,0 +1,31 @@ +### This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin + +class Nfs(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): + """NFS related information + """ + plugin_name = 'nfs' + packages = ['nfs-utils'] + + def setup(self): + self.add_copy_specs([ + "/etc/nfsmount.conf", + "/etc/idmapd.conf", + "/proc/fs/nfsfs/servers", + "/proc/fs/nfsfs/volumes" + ]) + return + -- cgit From f6d6b4bd3d50808af5bbaef84ebbe06cdebd743a Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Tue, 12 Nov 2013 13:44:09 +0000 Subject: Fix typo in yum add_forbidden_paths() The PKI files that should be omitted are in /etc/pki/entitlement, not /etc/pki/entitlements as the plug-in currently uses. Signed-off-by: Bryn M. Reeves --- sos/plugins/yum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sos/plugins/yum.py b/sos/plugins/yum.py index 6d473c90..5abf06f6 100644 --- a/sos/plugins/yum.py +++ b/sos/plugins/yum.py @@ -39,8 +39,8 @@ class Yum(Plugin, RedHatPlugin): self.add_cmd_output("yum -C repolist") # candlepin info - self.add_forbidden_path("/etc/pki/entitlements/key.pem") - self.add_forbidden_path("/etc/pki/entitlements/*-key.pem") + self.add_forbidden_path("/etc/pki/entitlement/key.pem") + self.add_forbidden_path("/etc/pki/entitlement/*-key.pem") self.add_copy_specs([ "/etc/pki/product/*.pem", "/etc/pki/consumer/cert.pem", -- cgit