From ef4e4b60eeaef33fa5e4ee074c6736cd3412397b Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 12 Mar 2014 16:27:34 +0000 Subject: [PATCH 31/72] Clean up get_cmd_path/make_cmd_path/make_cmd_dirs mess Clean up the Plugin helper methods for handling command output paths. This better matches the proposal in Issue #181 and simplifies code for plugins that need to generate their own paths under sos_commands//. - Rename get_cmd_path() to get_cmd_output_path() - Add an optional 'name' parameter to specify a subdirectory name in the plugin's sos_commands// directory. - Default to creating directories if they do not exist Finally fix up all existing users of get_cmd_path() to use the new interface and remove handrolled uses of os.path.join(...) for generating these paths. Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 26 +++++++++----------------- sos/plugins/cluster.py | 2 +- sos/plugins/foreman.py | 6 ++---- sos/plugins/katello.py | 6 ++---- sos/plugins/lvm2.py | 2 +- sos/plugins/rhui.py | 8 +------- sos/plugins/satellite.py | 2 +- sos/plugins/yum.py | 2 +- 8 files changed, 18 insertions(+), 36 deletions(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 9b643ab..efb6950 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -512,26 +512,18 @@ class Plugin(object): """Run a program and collect the output""" self.collect_cmds.append( (exe, suggest_filename, root_symlink, timeout) ) - def get_cmd_path(self): + def get_cmd_output_path(self, name=None, make=True): """Return a path into which this module should store collected command output """ - return os.path.join(self.archive.get_tmp_dir(), - 'sos_commands', self.name()) - - def make_cmd_path(self, path): - """Return a string representing an absolute path within this - plug-in's command output directory by apending the relative path - name 'path'. - """ - return os.path.join(self.get_cmd_path(), path) - - - def make_cmd_dirs(self, path): - """Recursively create new subdirectories under this plug-in's - command output path. - """ - os.makedirs(self.make_cmd_path(path)) + cmd_output_path = os.path.join(self.archive.get_tmp_dir(), + 'sos_commands', self.name()) + if name: + cmd_output_path = os.path.join(cmd_output_path, name) + if make: + os.makedirs(cmd_output_path) + + return cmd_output_path def file_grep(self, regexp, *fnames): """Returns lines matched in fnames, where fnames can either be diff --git a/sos/plugins/cluster.py b/sos/plugins/cluster.py index 7957498..0b839fa 100644 --- a/sos/plugins/cluster.py +++ b/sos/plugins/cluster.py @@ -97,7 +97,7 @@ class Cluster(Plugin, RedHatPlugin): "crm_from parameter '%s' is not a valid date: using default" % self.get_option('crm_from')) - crm_dest = os.path.join(self.get_cmd_path(), 'crm_report') + crm_dest = self.get_cmd_output_path(name='crm_report') self.add_cmd_output('crm_report -S -d --dest %s --from "%s"' % (crm_dest, crm_from)) diff --git a/sos/plugins/foreman.py b/sos/plugins/foreman.py index ab4dfcb..a2f2881 100644 --- a/sos/plugins/foreman.py +++ b/sos/plugins/foreman.py @@ -25,7 +25,5 @@ class Foreman(Plugin, RedHatPlugin): packages = ('foreman') def setup(self): - foreman_debug_path = os.path.join( - self.get_cmd_path(),"foreman-debug") - self.add_cmd_output("%s -q -a -d %s" - % ("foreman-debug", foreman_debug_path)) + self.add_cmd_output("%s -q -a -d %s" % ("foreman-debug", + self.get_cmd_output_path(name="foreman-debug"))) diff --git a/sos/plugins/katello.py b/sos/plugins/katello.py index 1999388..acf5d90 100644 --- a/sos/plugins/katello.py +++ b/sos/plugins/katello.py @@ -25,7 +25,5 @@ class Katello(Plugin, RedHatPlugin): packages = ('katello', 'katello-common', 'katello-headpin') def setup(self): - 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)) + self.add_cmd_output("katello-debug --notar -d %s" + % self.get_cmd_output_path(name="katello-debug")) diff --git a/sos/plugins/lvm2.py b/sos/plugins/lvm2.py index 1a4d589..102df26 100644 --- a/sos/plugins/lvm2.py +++ b/sos/plugins/lvm2.py @@ -34,7 +34,7 @@ class Lvm2(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): if metadata: lvmdump_opts = "-a -m" cmd = lvmdump_cmd % (lvmdump_opts, - os.path.join(self.get_cmd_path(), "lvmdump")) + self.get_cmd_output_path(name="lvmdump")) self.add_cmd_output(cmd) def setup(self): diff --git a/sos/plugins/rhui.py b/sos/plugins/rhui.py index a291515..f0413b4 100644 --- a/sos/plugins/rhui.py +++ b/sos/plugins/rhui.py @@ -32,13 +32,7 @@ class Rhui(Plugin, RedHatPlugin): else: cds = "" - rhui_debug_dst_path = os.path.join(self.get_cmd_path(), - self.commons['cmddir'], self.name()) - try: - os.mkdir(rhui_debug_dst_path) - except: - return - + rhui_debug_dst_path = self.get_cmd_output_path() self.add_cmd_output("python %s %s --dir %s" % (self.rhui_debug_path, cds, rhui_debug_dst_path), suggest_filename="rhui-debug") diff --git a/sos/plugins/satellite.py b/sos/plugins/satellite.py index 7f4aafd..474933a 100644 --- a/sos/plugins/satellite.py +++ b/sos/plugins/satellite.py @@ -78,7 +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.get_cmd_path())) + % self.get_cmd_output_path(name="spacewalk-debug")) if self.proxy: self.add_copy_specs(["/etc/squid", "/var/log/squid"]) diff --git a/sos/plugins/yum.py b/sos/plugins/yum.py index aa8cb18..c978842 100644 --- a/sos/plugins/yum.py +++ b/sos/plugins/yum.py @@ -49,7 +49,7 @@ class Yum(Plugin, RedHatPlugin): self.add_cmd_output("subscription-manager list --installed") self.add_cmd_output("subscription-manager list --consumed") self.add_cmd_output("rhsm-debug system --no-archive --destination %s" - % self.get_cmd_path()) + % self.get_cmd_output_path()) if self.get_option("yumlist"): # List various information about available packages -- 1.9.3