aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sos/plugins/__init__.py12
-rw-r--r--sos/plugins/atomichost.py2
-rw-r--r--sos/plugins/etcd.py2
-rw-r--r--sos/plugins/iprconfig.py2
-rw-r--r--sos/plugins/kernel.py2
-rw-r--r--sos/plugins/networking.py2
-rw-r--r--sos/plugins/nfsserver.py4
-rw-r--r--sos/plugins/powerpc.py2
-rw-r--r--sos/plugins/processor.py2
-rw-r--r--sos/plugins/s390.py2
-rw-r--r--sos/plugins/sunrpc.py4
-rw-r--r--tests/option_tests.py3
-rw-r--r--tests/plugin_tests.py39
13 files changed, 45 insertions, 33 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index fbcf235d..c372c0f9 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -148,6 +148,7 @@ class Plugin(object):
self.copy_strings = []
self.collect_cmds = []
self.sysroot = commons['sysroot']
+ self.policy = commons['policy']
self.soslog = self.commons['soslog'] if 'soslog' in self.commons \
else logging.getLogger('sos')
@@ -182,9 +183,6 @@ class Plugin(object):
def _log_debug(self, msg):
self.soslog.debug(self._format_msg(msg))
- def policy(self):
- return self.commons["policy"]
-
def join_sysroot(self, path):
if path[0] == os.sep:
path = path[1:]
@@ -206,7 +204,7 @@ class Plugin(object):
def is_installed(self, package_name):
'''Is the package $package_name installed?'''
- return self.policy().pkg_by_name(package_name) is not None
+ return self.policy.pkg_by_name(package_name) is not None
def do_cmd_private_sub(self, cmd):
'''Remove certificate and key output archived by sosreport. cmd
@@ -989,7 +987,7 @@ class Plugin(object):
else:
return
- pm = self.policy().package_manager
+ pm = self.policy.package_manager
verify_cmd = pm.build_verify_command(self.verify_packages)
if verify_cmd:
self.add_cmd_output(verify_cmd)
@@ -1107,7 +1105,7 @@ class SCLPlugin(RedHatPlugin):
"""wrapping command in "scl enable" call and adds proper PATH
"""
# load default SCL prefix to PATH
- prefix = self.policy().get_default_scl_prefix()
+ prefix = self.policy.get_default_scl_prefix()
# read prefix from /etc/scl/prefixes/${scl} and strip trailing '\n'
try:
prefix = open('/etc/scl/prefixes/%s' % scl, 'r').read()\
@@ -1140,7 +1138,7 @@ class SCLPlugin(RedHatPlugin):
# specific path. So we need to insert the paths after the appropriate root
# dir.
def convert_copyspec_scl(self, scl, copyspec):
- scl_prefix = self.policy().get_default_scl_prefix()
+ scl_prefix = self.policy.get_default_scl_prefix()
for rootdir in ['etc', 'var']:
p = re.compile('^/%s/' % rootdir)
copyspec = p.sub('/%s/%s/%s/' % (rootdir, scl_prefix, scl),
diff --git a/sos/plugins/atomichost.py b/sos/plugins/atomichost.py
index 945f348d..91f64ad8 100644
--- a/sos/plugins/atomichost.py
+++ b/sos/plugins/atomichost.py
@@ -27,7 +27,7 @@ class AtomicHost(Plugin, RedHatPlugin):
]
def check_enabled(self):
- return self.policy().in_container()
+ return self.policy.in_container()
def setup(self):
self.add_copy_spec("/etc/ostree/remotes.d")
diff --git a/sos/plugins/etcd.py b/sos/plugins/etcd.py
index 884aa1bd..fd0dcba7 100644
--- a/sos/plugins/etcd.py
+++ b/sos/plugins/etcd.py
@@ -65,7 +65,7 @@ class etcd(Plugin, RedHatPlugin):
# assume v3 is the default
url = 'http://localhost:2379'
try:
- ver = self.policy().package_manager.get_pkg_list()['etcd']
+ ver = self.policy.package_manager.get_pkg_list()['etcd']
ver = ver['version'][0]
if ver == '2':
url = 'http://localhost:4001'
diff --git a/sos/plugins/iprconfig.py b/sos/plugins/iprconfig.py
index d93e48f8..72d6c284 100644
--- a/sos/plugins/iprconfig.py
+++ b/sos/plugins/iprconfig.py
@@ -27,7 +27,7 @@ class IprConfig(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
plugin_name = 'iprconfig'
def check_enabled(self):
- arch = self.policy().get_arch()
+ arch = self.policy.get_arch()
return "ppc64" in arch and is_executable("iprconfig")
def setup(self):
diff --git a/sos/plugins/kernel.py b/sos/plugins/kernel.py
index 2cab906b..97ef7862 100644
--- a/sos/plugins/kernel.py
+++ b/sos/plugins/kernel.py
@@ -71,7 +71,7 @@ class Kernel(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
"/proc/buddyinfo",
"/proc/slabinfo",
"/proc/zoneinfo",
- "/lib/modules/%s/modules.dep" % self.policy().kernel_version(),
+ "/lib/modules/%s/modules.dep" % self.policy.kernel_version(),
"/etc/conf.modules",
"/etc/modules.conf",
"/etc/modprobe.conf",
diff --git a/sos/plugins/networking.py b/sos/plugins/networking.py
index 86cf6393..9612c424 100644
--- a/sos/plugins/networking.py
+++ b/sos/plugins/networking.py
@@ -352,7 +352,7 @@ class RedHatNetworking(Networking, RedHatPlugin):
def setup(self):
# Handle change from -T to -W in Red Hat netstat 2.0 and greater.
try:
- netstat_pkg = self.policy().package_manager.all_pkgs()['net-tools']
+ netstat_pkg = self.policy.package_manager.all_pkgs()['net-tools']
# major version
if int(netstat_pkg['version'][0]) < 2:
self.ns_wide = "-T"
diff --git a/sos/plugins/nfsserver.py b/sos/plugins/nfsserver.py
index 4100c804..d56dd3f9 100644
--- a/sos/plugins/nfsserver.py
+++ b/sos/plugins/nfsserver.py
@@ -27,8 +27,8 @@ class NfsServer(Plugin, RedHatPlugin):
profiles = ('storage', 'network', 'services', 'nfs')
def check_enabled(self):
- default_runlevel = self.policy().default_runlevel()
- nfs_runlevels = self.policy().runlevel_by_service("nfs")
+ default_runlevel = self.policy.default_runlevel()
+ nfs_runlevels = self.policy.runlevel_by_service("nfs")
if default_runlevel in nfs_runlevels:
return True
diff --git a/sos/plugins/powerpc.py b/sos/plugins/powerpc.py
index abf4759c..e4c80124 100644
--- a/sos/plugins/powerpc.py
+++ b/sos/plugins/powerpc.py
@@ -27,7 +27,7 @@ class PowerPC(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
profiles = ('system', 'hardware')
def check_enabled(self):
- return "ppc64" in self.policy().get_arch()
+ return "ppc64" in self.policy.get_arch()
def setup(self):
try:
diff --git a/sos/plugins/processor.py b/sos/plugins/processor.py
index 80a6a30f..c2c7bbdd 100644
--- a/sos/plugins/processor.py
+++ b/sos/plugins/processor.py
@@ -42,7 +42,7 @@ class Processor(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
"turbostat --debug sleep 10"
])
- if '86' in self.policy().get_arch():
+ if '86' in self.policy.get_arch():
self.add_cmd_output("x86info -a")
diff --git a/sos/plugins/s390.py b/sos/plugins/s390.py
index 7a8b5bc7..dd23a143 100644
--- a/sos/plugins/s390.py
+++ b/sos/plugins/s390.py
@@ -27,7 +27,7 @@ class S390(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
# Check for s390 arch goes here
def check_enabled(self):
- return ("s390" in self.policy().get_arch())
+ return ("s390" in self.policy.get_arch())
# Gather s390 specific information
diff --git a/sos/plugins/sunrpc.py b/sos/plugins/sunrpc.py
index cf2ce0a4..686c46e4 100644
--- a/sos/plugins/sunrpc.py
+++ b/sos/plugins/sunrpc.py
@@ -26,8 +26,8 @@ class SunRPC(Plugin):
service = None
def check_enabled(self):
- if self.policy().default_runlevel() in \
- self.policy().runlevel_by_service(self.service):
+ if self.policy.default_runlevel() in \
+ self.policy.runlevel_by_service(self.service):
return True
return False
diff --git a/tests/option_tests.py b/tests/option_tests.py
index e8a26e2d..a4267e2e 100644
--- a/tests/option_tests.py
+++ b/tests/option_tests.py
@@ -3,12 +3,15 @@
import unittest
from sos.plugins import Plugin
+from sos.policies import LinuxPolicy
+
class GlobalOptionTest(unittest.TestCase):
def setUp(self):
self.commons = {
'sysroot': '/',
+ 'policy': LinuxPolicy(),
'global_plugin_options': {
'test_option': 'foobar',
'baz': None,
diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py
index 0ccea73b..60d59d6f 100644
--- a/tests/plugin_tests.py
+++ b/tests/plugin_tests.py
@@ -12,6 +12,7 @@ except:
from sos.plugins import Plugin, regex_findall, _mangle_command
from sos.archive import TarFileArchive
+from sos.policies import LinuxPolicy
import sos.policies
PATH = os.path.dirname(__file__)
@@ -133,48 +134,55 @@ class PluginTests(unittest.TestCase):
def setUp(self):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
+ 'policy': LinuxPolicy(),
'sysroot': self.sysroot
})
self.mp.archive = MockArchive()
def test_plugin_default_name(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.name(), "mockplugin")
def test_plugin_set_name(self):
- p = NamedMockPlugin({'sysroot': self.sysroot})
+ p = NamedMockPlugin({
+ 'sysroot': self.sysroot,
+ 'policy': LinuxPolicy()
+ })
self.assertEquals(p.name(), "testing")
def test_plugin_no_descrip(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_description(), "<no description available>")
def test_plugin_no_descrip(self):
- p = NamedMockPlugin({'sysroot': self.sysroot})
+ p = NamedMockPlugin({
+ 'sysroot': self.sysroot,
+ 'policy': LinuxPolicy()
+ })
self.assertEquals(p.get_description(), "This plugin has a description.")
def test_set_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
p.set_option("opt", "testing")
self.assertEquals(p.get_option("opt"), "testing")
def test_set_nonexistant_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertFalse(p.set_option("badopt", "testing"))
def test_get_nonexistant_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option("badopt"), 0)
def test_get_unset_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option("opt"), 0)
def test_get_unset_plugin_option_with_default(self):
# this shows that even when we pass in a default to get,
# we'll get the option's default as set in the plugin
# this might not be what we really want
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option("opt", True), True)
def test_get_unset_plugin_option_with_default_not_none(self):
@@ -182,20 +190,20 @@ class PluginTests(unittest.TestCase):
# if the plugin default is not None
# we'll get the option's default as set in the plugin
# this might not be what we really want
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option("opt2", True), False)
def test_get_option_as_list_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
p.set_option("opt", "one,two,three")
self.assertEquals(p.get_option_as_list("opt"), ['one', 'two', 'three'])
def test_get_option_as_list_plugin_option_default(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
self.assertEquals(p.get_option_as_list("opt", default=[]), [])
def test_get_option_as_list_plugin_option_not_list(self):
- p = MockPlugin({'sysroot': self.sysroot})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
p.set_option("opt", "testing")
self.assertEquals(p.get_option_as_list("opt"), ['testing'])
@@ -210,7 +218,8 @@ class PluginTests(unittest.TestCase):
def test_copy_dir_forbidden_path(self):
p = ForbiddenMockPlugin({
'cmdlineopts': MockOptions(),
- 'sysroot': self.sysroot
+ 'sysroot': self.sysroot,
+ 'policy': LinuxPolicy()
})
p.archive = MockArchive()
p.setup()
@@ -225,6 +234,7 @@ class AddCopySpecTests(unittest.TestCase):
def setUp(self):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
+ 'policy': LinuxPolicy(),
'sysroot': os.getcwd()
})
self.mp.archive = MockArchive()
@@ -328,6 +338,7 @@ class RegexSubTests(unittest.TestCase):
def setUp(self):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
+ 'policy': LinuxPolicy(),
'sysroot': os.getcwd()
})
self.mp.archive = MockArchive()