aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2013-04-09 19:14:10 +0100
committerBryn M. Reeves <bmr@redhat.com>2013-04-09 19:14:10 +0100
commite0d132e60d4be5fcb4a2aeaf8bdb6042f5b42ab5 (patch)
tree3785f3191164d51fc2294b9e1f70017e72f1139d
parent2a917c513b917d0ceace4d4e937cc318d5c82d25 (diff)
downloadsos-e0d132e60d4be5fcb4a2aeaf8bdb6042f5b42ab5.tar.gz
Make PATH policy controlled
Make the PATH environment variable subject to Policy class control. Policies may set PATH to an appropriately formatted string for the platform. This will be exported to the environment and used as the search path for binaries that sos modules execute. Following this change all absolute paths can be removed from plug-in code simplifying maintenance on multiple distributions and distribution versions (e.g. Red Hat UsrMove and various updates that relocate binaries such as lsusb). Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/policies/__init__.py14
-rw-r--r--sos/policies/debian.py2
-rw-r--r--sos/policies/redhat.py18
3 files changed, 29 insertions, 5 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index d99207ba..8148c894 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -5,6 +5,7 @@ import re
import platform
import time
import fnmatch
+from os import environ
from sos.utilities import ImporterHelper, \
import_module, \
@@ -133,16 +134,20 @@ No changes will be made to system configuration.
vendor = "Unknown"
vendor_url = "http://www.example.com/"
vendor_text = ""
+ PATH = ""
def __init__(self):
"""Subclasses that choose to override this initializer should call
super() to ensure that they get the required platform bits attached.
- super(SubClass, self).__init__()"""
+ super(SubClass, self).__init__(). Policies that require runtime
+ tests to construct PATH must call self.set_exec_path() after
+ modifying PATH in their own initializer."""
self._parse_uname()
self.report_name = self.hostname
self.ticket_number = None
self.package_manager = PackageManager()
self._valid_subclasses = []
+ self.set_exec_path()
def get_valid_subclasses(self):
return [IndependentPlugin] + self._valid_subclasses
@@ -221,6 +226,12 @@ No changes will be made to system configuration.
def set_commons(self, commons):
self.commons = commons
+ def _set_PATH(self, path):
+ environ['PATH'] = path
+
+ def set_exec_path(self):
+ self._set_PATH(self.PATH)
+
def is_root(self):
"""This method should return true if the user calling the script is
considered to be a superuser"""
@@ -377,6 +388,7 @@ class LinuxPolicy(Policy):
distro = "Linux"
vendor = "None"
+ PATH = "/bin:/sbin:/usr/bin:/usr/sbin"
def __init__(self):
super(LinuxPolicy, self).__init__()
diff --git a/sos/policies/debian.py b/sos/policies/debian.py
index 94b089f3..409ba85a 100644
--- a/sos/policies/debian.py
+++ b/sos/policies/debian.py
@@ -11,6 +11,8 @@ class DebianPolicy(LinuxPolicy):
ticket_number = ""
package_manager = PackageManager("dpkg-query -W -f='${Package}|${Version}\\n' \*")
valid_subclasses = [DebianPlugin]
+ PATH = "/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" \
+ + ":/usr/loca/sbin:/usr/local/bin"
def __init__(self):
super(DebianPolicy, self).__init__()
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index 7677b806..7a26d811 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -40,14 +40,24 @@ class RedHatPolicy(LinuxPolicy):
super(RedHatPolicy, self).__init__()
self.report_name = ""
self.ticket_number = ""
- self.package_manager = PackageManager('rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"')
+ self.package_manager = PackageManager(
+ 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"')
self.valid_subclasses = [RedHatPlugin]
+ # handle PATH for UsrMove
+ if self.package_manager.all_pkgs()['filesystem']['version'][0] == '3':
+ self.PATH = "/usr/sbin:/usr/bin:/root/bin"
+ else:
+ self.PATH = "/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
+ self.PATH += os.pathsep + "/usr/local/bin"
+ self.PATH += os.pathsep + "/usr/local/sbin"
+ self.set_exec_path()
+
@classmethod
def check(self):
- """This method checks to see if we are running on Red Hat. It must be overriden
- by concrete subclasses to return True when running on a Fedora, RHEL or other
- Red Hat distribution or False otherwise."""
+ """This method checks to see if we are running on Red Hat. It must be
+ overriden by concrete subclasses to return True when running on a
+ Fedora, RHEL or other Red Hat distribution or False otherwise."""
return False
def runlevel_by_service(self, name):