aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-08-11 17:11:17 -0400
committerJake Hunsaker <jhunsake@redhat.com>2021-08-30 10:26:24 -0400
commit0b6dc021b7ae54688fca70168c70744ad752834a (patch)
treecec639f6e5ddc8226e47792b85c93a8f118f98fe /tests
parent2b8f029004f4f93b9bdadc47e32fe587591f88f4 (diff)
downloadsos-0b6dc021b7ae54688fca70168c70744ad752834a.tar.gz
[Plugin] Make plugin options their own class
Up until now plugin options were defined via tuples, with positional significance of the tuple elements. This made plugin option creation fairly easy, but option handling could easily become confusing. Instead, create a new `PluginOpt` class that plugin options from here on out will need to build from in order to function. These will still be applied to plugins by inserting them into the `option_list` class attr in order to retain an easy way to expand plugin options for authors. Internally, options are now assigned to a dict which is then directly accessed for plugin option manipulations. PluginOpt default values are retained separate from their current value, and elements are assigned directly to meaningful identifiers within the class. This should alleviate some of the overhead when handling plugin options within sos. Not all current tuple elements have been carried over into the new `PluginOpt` class - for example, the 'speed' attribute has been dropped as it does not have a current function. In the planned `sos info` component, the time effects of a plugin option should be documented in the `long_desc` attribute instead. Additionally, the `Plugin.get_option_as_list()` method has been removed as it was not being used anywhere. Note that this particular commit only introduces the new class, and the loading options used by `SoSReport()`. As such, plugins using options currently will report errors during test runs. A commit following this one will shuffle existing plugin options into the new class structure and allow the plugins to execute normally. Resolves: #274 Resolves: #452 Resolves: #1597 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/conformance_tests.py5
-rw-r--r--tests/unittests/option_tests.py20
-rw-r--r--tests/unittests/plugin_tests.py37
3 files changed, 22 insertions, 40 deletions
diff --git a/tests/unittests/conformance_tests.py b/tests/unittests/conformance_tests.py
index 3a3f550f..5419f9d3 100644
--- a/tests/unittests/conformance_tests.py
+++ b/tests/unittests/conformance_tests.py
@@ -8,7 +8,7 @@
import unittest
-from sos.report.plugins import import_plugin
+from sos.report.plugins import import_plugin, PluginOpt
from sos.utilities import ImporterHelper
@@ -50,7 +50,8 @@ class PluginConformance(unittest.TestCase):
for plug in self.plug_classes:
self.assertIsInstance(plug.option_list, list)
for opt in plug.option_list:
- self.assertIsInstance(opt, tuple)
+ self.assertIsInstance(opt, PluginOpt)
+ self.assertFalse(opt.name == 'undefined')
def test_plugin_architectures_set_correctly(self):
for plug in self.plug_classes:
diff --git a/tests/unittests/option_tests.py b/tests/unittests/option_tests.py
index 58f54e94..4a9271ad 100644
--- a/tests/unittests/option_tests.py
+++ b/tests/unittests/option_tests.py
@@ -7,7 +7,7 @@
# See the LICENSE file in the source distribution for further information.
import unittest
-from sos.report.plugins import Plugin
+from sos.report.plugins import Plugin, PluginOpt
from sos.policies.distros import LinuxPolicy
from sos.policies.init_systems import InitSystem
@@ -21,6 +21,18 @@ class MockOptions(object):
skip_files = []
+class MockPlugin(Plugin):
+
+ option_list = [
+ PluginOpt('baz', default=False),
+ PluginOpt('empty', default=None),
+ PluginOpt('test_option', default='foobar')
+ ]
+
+ def __init__(self, commons):
+ super(MockPlugin, self).__init__(commons=commons)
+
+
class GlobalOptionTest(unittest.TestCase):
def setUp(self):
@@ -30,11 +42,7 @@ class GlobalOptionTest(unittest.TestCase):
'cmdlineopts': MockOptions(),
'devices': {}
}
- self.plugin = Plugin(self.commons)
- self.plugin.opt_names = ['baz', 'empty', 'test_option']
- self.plugin.opt_parms = [
- {'enabled': False}, {'enabled': None}, {'enabled': 'foobar'}
- ]
+ self.plugin = MockPlugin(self.commons)
def test_simple_lookup(self):
self.assertEquals(self.plugin.get_option('test_option'), 'foobar')
diff --git a/tests/unittests/plugin_tests.py b/tests/unittests/plugin_tests.py
index 8dc038cb..fcd24143 100644
--- a/tests/unittests/plugin_tests.py
+++ b/tests/unittests/plugin_tests.py
@@ -12,7 +12,7 @@ import shutil
from io import StringIO
-from sos.report.plugins import Plugin, regex_findall, _mangle_command
+from sos.report.plugins import Plugin, regex_findall, _mangle_command, PluginOpt
from sos.archive import TarFileArchive
from sos.policies.distros import LinuxPolicy
from sos.policies.init_systems import InitSystem
@@ -64,8 +64,10 @@ class MockArchive(TarFileArchive):
class MockPlugin(Plugin):
- option_list = [("opt", 'an option', 'fast', None),
- ("opt2", 'another option', 'fast', False)]
+ option_list = [
+ PluginOpt("opt", default=None, desc='an option', val_type=str),
+ PluginOpt("opt2", default=False, desc='another option')
+ ]
def setup(self):
pass
@@ -271,35 +273,6 @@ class PluginTests(unittest.TestCase):
})
self.assertEquals(p.get_option("opt2", True), False)
- def test_get_option_as_list_plugin_option(self):
- p = MockPlugin({
- 'sysroot': self.sysroot,
- 'policy': LinuxPolicy(init=InitSystem(), probe_runtime=False),
- 'cmdlineopts': MockOptions(),
- 'devices': {}
- })
- 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(init=InitSystem(), probe_runtime=False),
- 'cmdlineopts': MockOptions(),
- 'devices': {}
- })
- 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(init=InitSystem(), probe_runtime=False),
- 'cmdlineopts': MockOptions(),
- 'devices': {}
- })
- p.set_option("opt", "testing")
- self.assertEquals(p.get_option_as_list("opt"), ['testing'])
-
def test_copy_dir(self):
self.mp._do_copy_path("tests")
self.assertEquals(