aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2018-04-30 15:11:08 +0100
committerBryn M. Reeves <bmr@redhat.com>2018-04-30 15:13:00 +0100
commit0f5a976f825d99c0e27b1db2158764b4fe3ae394 (patch)
treee37901ee009237b85ebc05b80a506df9bac46bc9
parent544aaed57a994dc4e8345158ada85fe9080bf39a (diff)
downloadsos-0f5a976f825d99c0e27b1db2158764b4fe3ae394.tar.gz
[Plugin] add kernel module triggers
Add a new mechanism to trigger plugin execution on the presence of one or more named Linux kernel module. Plugins may now declare a "kernel_mods" list (in the same manner as files, packages etc.) that will cause that plugin to run. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/plugins/__init__.py14
-rw-r--r--sos/policies/__init__.py6
2 files changed, 18 insertions, 2 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index a018472d..580c0941 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -128,6 +128,7 @@ class Plugin(object):
packages = ()
files = ()
commands = ()
+ kernel_mods = ()
archive = None
profiles = ()
sysroot = '/'
@@ -934,7 +935,7 @@ class Plugin(object):
overridden.
"""
# some files or packages have been specified for this package
- if any([self.files, self.packages, self.commands]):
+ if any([self.files, self.packages, self.commands, self.kernel_mods]):
if isinstance(self.files, six.string_types):
self.files = [self.files]
@@ -944,6 +945,9 @@ class Plugin(object):
if isinstance(self.commands, six.string_types):
self.commands = [self.commands]
+ if isinstance(self.kernel_mods, six.string_types):
+ self.kernel_mods = [self.kernel_mods]
+
if isinstance(self, SCLPlugin):
# save SCLs that match files or packages
type(self)._scls_matched = []
@@ -968,9 +972,15 @@ class Plugin(object):
return True
def _files_pkgs_or_cmds_present(self, files, packages, commands):
+ kernel_mods = self.policy.lsmod()
+
+ def have_kmod(kmod):
+ return kmod in kernel_mods
+
return (any(os.path.exists(fname) for fname in files) or
any(self.is_installed(pkg) for pkg in packages) or
- any(is_executable(cmd) for cmd in commands))
+ any(is_executable(cmd) for cmd in commands) or
+ any(have_kmod(kmod) for kmod in self.kernel_mods))
def default_enabled(self):
"""This decides whether a plugin should be automatically loaded or
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 5bdc7d85..9e2b719e 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -508,6 +508,12 @@ class LinuxPolicy(Policy):
def sanitize_case_id(self, case_id):
return re.sub(r"[^-a-z,A-Z.0-9]", "", case_id)
+ def lsmod(self):
+ """Return a list of kernel module names as strings.
+ """
+ lines = shell_out("lsmod", timeout=0).splitlines()
+ return [line.split()[0].strip() for line in lines]
+
def pre_work(self):
# this method will be called before the gathering begins