aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sos/__init__.py10
-rw-r--r--sos/plugins/__init__.py6
-rw-r--r--sos/sosreport.py2
-rw-r--r--tests/option_tests.py7
-rw-r--r--tests/plugin_tests.py55
5 files changed, 53 insertions, 27 deletions
diff --git a/sos/__init__.py b/sos/__init__.py
index b0c10f4a..c436bd20 100644
--- a/sos/__init__.py
+++ b/sos/__init__.py
@@ -52,10 +52,11 @@ _sos = _default
_arg_names = [
'add_preset', 'alloptions', 'all_logs', 'batch', 'build', 'case_id',
'chroot', 'compression_type', 'config_file', 'desc', 'debug', 'del_preset',
- 'enableplugins', 'encrypt_key', 'encrypt_pass', 'experimental', 'label',
- 'list_plugins', 'list_presets', 'list_profiles', 'log_size', 'noplugins',
- 'noreport', 'note', 'onlyplugins', 'plugin_timeout', 'plugopts', 'preset',
- 'profiles', 'quiet', 'sysroot', 'threads', 'tmp_dir', 'verbosity', 'verify'
+ 'dry_run', 'enableplugins', 'encrypt_key', 'encrypt_pass', 'experimental',
+ 'label', 'list_plugins', 'list_presets', 'list_profiles', 'log_size',
+ 'noplugins', 'noreport', 'note', 'onlyplugins', 'plugin_timeout',
+ 'plugopts', 'preset', 'profiles', 'quiet', 'sysroot', 'threads', 'tmp_dir',
+ 'verbosity', 'verify'
]
#: Arguments with non-zero default values
@@ -166,6 +167,7 @@ class SoSOptions(object):
self.debug = False
self.del_preset = ""
self.desc = ""
+ self.dry_run = False
self.enableplugins = []
self.encrypt_key = None
self.encrypt_pass = None
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 7b15e192..cfb98325 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -164,6 +164,7 @@ class SoSPredicate(object):
self._owner = owner
self._kmods = list(kmods)
self._services = list(services)
+ self._dry_run = dry_run | self._owner.commons['cmdlineopts'].dry_run
class Plugin(object):
@@ -240,6 +241,9 @@ class Plugin(object):
self.opt_parms.append({'desc': opt[1], 'speed': opt[2],
'enabled': opt[3]})
+ # Initialise the default --dry-run predicate
+ self.set_predicate(SoSPredicate(self))
+
@property
def timeout(self):
'''Returns either the default plugin timeout value, the value as
@@ -373,7 +377,7 @@ class Plugin(object):
"""
if cmd and self.cmd_predicate:
return self.cmd_predicate
- return self.predicate or pred
+ return pred or self.predicate
def do_cmd_private_sub(self, cmd):
'''Remove certificate and key output archived by sosreport. cmd
diff --git a/sos/sosreport.py b/sos/sosreport.py
index 7cd27d96..9bd899dc 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -148,6 +148,8 @@ def _get_parser():
"python debugger")
parser.add_argument("--desc", "--description", type=str, action="store",
help="Description for a new preset", default="")
+ parser.add_argument("--dry-run", action="store_true",
+ help="Run plugins but do not collect data")
parser.add_argument("--experimental", action="store_true",
dest="experimental", default=False,
help="enable experimental plugins")
diff --git a/tests/option_tests.py b/tests/option_tests.py
index a99be4b0..3912375d 100644
--- a/tests/option_tests.py
+++ b/tests/option_tests.py
@@ -6,12 +6,19 @@ from sos.plugins import Plugin
from sos.policies import LinuxPolicy
+class MockOptions(object):
+ all_logs = False
+ dry_run = False
+ log_size = 25
+
+
class GlobalOptionTest(unittest.TestCase):
def setUp(self):
self.commons = {
'sysroot': '/',
'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()
}
self.plugin = Plugin(self.commons)
self.plugin.opt_names = ['baz', 'empty', 'test_option']
diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py
index c03e313e..7d36957b 100644
--- a/tests/plugin_tests.py
+++ b/tests/plugin_tests.py
@@ -92,6 +92,7 @@ class EnablerPlugin(Plugin):
class MockOptions(object):
all_logs = False
+ dry_run = False
log_size = 25
@@ -136,54 +137,58 @@ class PluginTests(unittest.TestCase):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
'policy': LinuxPolicy(),
- 'sysroot': self.sysroot
+ 'sysroot': self.sysroot,
+ 'cmdlineopts': MockOptions()
})
self.mp.archive = MockArchive()
def test_plugin_default_name(self):
- p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertEquals(p.name(), "mockplugin")
def test_plugin_set_name(self):
- p = NamedMockPlugin({
- 'sysroot': self.sysroot,
- 'policy': LinuxPolicy()
- })
+ p = NamedMockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertEquals(p.name(), "testing")
def test_plugin_no_descrip(self):
- p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertEquals(p.get_description(), "<no description available>")
def test_plugin_no_descrip(self):
- p = NamedMockPlugin({
- 'sysroot': self.sysroot,
- 'policy': LinuxPolicy()
- })
+ p = NamedMockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertEquals(p.get_description(), "This plugin has a description.")
def test_set_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
p.set_option("opt", "testing")
self.assertEquals(p.get_option("opt"), "testing")
def test_set_nonexistant_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertFalse(p.set_option("badopt", "testing"))
def test_get_nonexistant_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertEquals(p.get_option("badopt"), 0)
def test_get_unset_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
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, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertEquals(p.get_option("opt", True), True)
def test_get_unset_plugin_option_with_default_not_none(self):
@@ -191,20 +196,24 @@ 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, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
self.assertEquals(p.get_option("opt2", True), False)
def test_get_option_as_list_plugin_option(self):
- p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
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, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
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, 'policy': LinuxPolicy()})
+ p = MockPlugin({'sysroot': self.sysroot, 'policy': LinuxPolicy(),
+ 'cmdlineopts': MockOptions()})
p.set_option("opt", "testing")
self.assertEquals(p.get_option_as_list("opt"), ['testing'])
@@ -236,7 +245,8 @@ class AddCopySpecTests(unittest.TestCase):
self.mp = MockPlugin({
'cmdlineopts': MockOptions(),
'policy': LinuxPolicy(),
- 'sysroot': os.getcwd()
+ 'sysroot': os.getcwd(),
+ 'cmdlineopts': MockOptions()
})
self.mp.archive = MockArchive()
@@ -312,7 +322,8 @@ class CheckEnabledTests(unittest.TestCase):
def setUp(self):
self.mp = EnablerPlugin({
'policy': sos.policies.load(),
- 'sysroot': os.getcwd()
+ 'sysroot': os.getcwd(),
+ 'cmdlineopts': MockOptions()
})
def test_checks_for_file(self):