diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2019-03-25 11:59:16 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2019-03-25 11:59:16 +0000 |
commit | 41d48770c0c34b58862be57b1aa14618b7422ae9 (patch) | |
tree | 17b150b84d9c084462f51c4133f9b807affd5620 | |
parent | cb9b166e08be51bff9b0a98ce266507c702740eb (diff) | |
download | sos-41d48770c0c34b58862be57b1aa14618b7422ae9.tar.gz |
[Plugin] handle predicates correctly in get_cmd_output_now()
The get_command_output_now() method is used for two distinct
purposes:
* Called directly from user plugin code, to immediately collect
the output of a command during the setup() phase (e.g. to then
process the output to inform further collection, while also
storing the result in the report).
* Internally from the _collect_cmd_output() callback, in order
to collect the commands added at setup() time by user plugins
during the collect() phase.
In the former case, predicates should be applied as normal and
evaluated prior to command execution. In the latter, predicates
have already been applied at the time of the add_cmd_output()
call; any predicate that was not set at the time of that call
must not apply to the collection of the command.
Split the method in two: _g_c_o_n() now collects command output
unconditionally, and is used directly by internal callers, and
g_c_o_n() becomes a wrapper to perform predicate evaluation.
Resolves: #1616
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index da5c2f72..0d245013 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -969,20 +969,15 @@ class Plugin(object): self.copy_strings.append((content, filename)) self._log_debug("added string ...'%s' as '%s'" % (summary, filename)) - def get_cmd_output_now(self, exe, suggest_filename=None, - root_symlink=False, timeout=300, stderr=True, - chroot=True, runat=None, env=None, - binary=False, sizelimit=None, pred=None): + def _get_cmd_output_now(self, exe, suggest_filename=None, + root_symlink=False, timeout=300, stderr=True, + chroot=True, runat=None, env=None, + binary=False, sizelimit=None): """Execute a command and save the output to a file for inclusion in the report. """ start = time() - if not self.test_predicate(cmd=True, pred=pred): - self._log_info("skipped cmd output '%s' due to predicate (%s)" % - (exe, self.get_predicate(cmd=True, pred=pred))) - return None - result = self.get_command_output(exe, timeout=timeout, stderr=stderr, chroot=chroot, runat=runat, env=env, binary=binary, @@ -1009,6 +1004,23 @@ class Plugin(object): return os.path.join(self.archive.get_archive_path(), outfn) + def get_cmd_output_now(self, exe, suggest_filename=None, + root_symlink=False, timeout=300, stderr=True, + chroot=True, runat=None, env=None, + binary=False, sizelimit=None, pred=None): + """Execute a command and save the output to a file for inclusion in the + report. + """ + if not self.test_predicate(cmd=True, pred=pred): + self._log_info("skipped cmd output '%s' due to predicate (%s)" % + (exe, self.get_predicate(cmd=True, pred=pred))) + return None + + return self._get_cmd_output_now(exe, timeout=timeout, stderr=stderr, + chroot=chroot, runat=runat, + env=env, binary=binary, + sizelimit=sizelimit) + def is_module_loaded(self, module_name): """Return whether specified moudle as module_name is loaded or not""" if len(grep("^" + module_name + " ", "/proc/modules")) == 0: @@ -1160,11 +1172,12 @@ class Plugin(object): "('%s', '%s', '%s', %s, '%s', '%s', '%s', '%s'," + "'%s %s')") % progs[0]) self._log_info("collecting output of '%s'" % prog) - self.get_cmd_output_now(prog, suggest_filename=suggest_filename, - root_symlink=root_symlink, timeout=timeout, - stderr=stderr, chroot=chroot, runat=runat, - env=env, binary=binary, - sizelimit=sizelimit) + self._get_cmd_output_now(prog, suggest_filename=suggest_filename, + root_symlink=root_symlink, + timeout=timeout, stderr=stderr, + chroot=chroot, runat=runat, + env=env, binary=binary, + sizelimit=sizelimit) def _collect_strings(self): for string, file_name in self.copy_strings: |