aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2022-12-15 14:04:22 -0500
committerJake Hunsaker <jhunsake@redhat.com>2023-01-02 16:02:54 -0500
commite2b3fe3690016a16bd82cae6adf554d89b43f2c6 (patch)
tree604abc5ad3ec63d85c4b3386faff4d0ef2ad16e1
parent089839231aa54261f274f9e963f2d07d3dc7de86 (diff)
downloadsos-e2b3fe3690016a16bd82cae6adf554d89b43f2c6.tar.gz
[clusters] Allow cluster profiles to specify sos options directly
Clusters can already pass plugin options to nodes, and can also set arbitrary options on individual nodes or primary nodes. So, rather than requiring a cluster profile specify sos options to both nodes and primaries, instead allow profiles to specify options via a simple `sos_options` dict that will get applied to every node automatically, as is the case with plugin options. Note that user values for these options will override cluster values. For example, if a cluster spceifies a `--log-size` value, and the user does on the command line, then the user's value will have precedence. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/collector/__init__.py32
-rw-r--r--sos/collector/clusters/__init__.py8
-rw-r--r--sos/collector/sosnode.py11
3 files changed, 37 insertions, 14 deletions
diff --git a/sos/collector/__init__.py b/sos/collector/__init__.py
index 107d89e5..965a7003 100644
--- a/sos/collector/__init__.py
+++ b/sos/collector/__init__.py
@@ -934,30 +934,34 @@ class SoSCollector(SoSComponent):
def configure_sos_cmd(self):
"""Configures the sosreport command that is run on the nodes"""
- self.sos_cmd = 'sosreport --batch '
+ sos_cmd = 'sosreport --batch '
- sos_opts = []
+ sos_options = {}
if self.opts.case_id:
- sos_opts.append('--case-id=%s' % (quote(self.opts.case_id)))
+ sos_options['case-id'] = quote(self.opts.case_id)
if self.opts.alloptions:
- sos_opts.append('--alloptions')
+ sos_options['alloptions'] = ''
if self.opts.all_logs:
- sos_opts.append('--all-logs')
+ sos_options['all-logs'] = ''
if self.opts.verify:
- sos_opts.append('--verify')
+ sos_options['verify'] = ''
if self.opts.log_size:
- sos_opts.append(('--log-size=%s' % quote(str(self.opts.log_size))))
+ sos_options['log-size'] = quote(str(self.opts.log_size))
if self.opts.sysroot:
- sos_opts.append('-s %s' % quote(self.opts.sysroot))
+ sos_options['sysroot'] = quote(self.opts.sysroot)
if self.opts.chroot:
- sos_opts.append('-c %s' % quote(self.opts.chroot))
+ sos_options['chroot'] = quote(self.opts.chroot)
if self.opts.compression_type != 'auto':
- sos_opts.append('-z %s' % (quote(self.opts.compression_type)))
- self.sos_cmd = self.sos_cmd + ' '.join(sos_opts)
- self.log_debug("Initial sos cmd set to %s" % self.sos_cmd)
- self.commons['sos_cmd'] = self.sos_cmd
- self.collect_md.add_field('initial_sos_cmd', self.sos_cmd)
+ sos_options['compression-type'] = quote(self.opts.compression_type)
+
+ for k, v in sos_options.items():
+ sos_cmd += f"--{k} {v} "
+ sos_cmd = sos_cmd.rstrip()
+ self.log_debug(f"Initial sos cmd set to {sos_cmd}")
+ self.commons['sos_cmd'] = 'sosreport --batch '
+ self.commons['sos_options'] = sos_options
+ self.collect_md.add_field('initial_sos_cmd', sos_cmd)
def connect_to_primary(self):
"""If run with --primary, we will run cluster checks again that
diff --git a/sos/collector/clusters/__init__.py b/sos/collector/clusters/__init__.py
index 7356e153..66a7b044 100644
--- a/sos/collector/clusters/__init__.py
+++ b/sos/collector/clusters/__init__.py
@@ -41,6 +41,9 @@ class Cluster():
:cvar sos_plugins: Which plugins to forcibly enable for node reports
:vartype sos_plugins: ``list``
+ :cvar sos_options: Options to pass to report on every node
+ :vartype sos_options: ``dict``
+
:cvar sos_plugin_options: Plugin options to forcibly set for nodes
:vartype sos_plugin_options: ``dict``
@@ -54,6 +57,7 @@ class Cluster():
option_list = []
packages = ('',)
sos_plugins = []
+ sos_options = {}
sos_plugin_options = {}
sos_preset = ''
cluster_name = None
@@ -116,6 +120,10 @@ class Cluster():
newline=False
)
+ if cls.sos_options:
+ _opts = ', '.join(f'--{k} {v}' for k, v in cls.sos_options.items())
+ section.add_text(f"Sets the following sos options: {_opts}")
+
if cls.sos_plugins:
section.add_text(
"Enables the following plugins: %s"
diff --git a/sos/collector/sosnode.py b/sos/collector/sosnode.py
index 7ab5d1d1..03546be6 100644
--- a/sos/collector/sosnode.py
+++ b/sos/collector/sosnode.py
@@ -44,6 +44,7 @@ class SosNode():
self.tmpdir = commons['tmpdir']
self.hostlen = commons['hostlen']
self.need_sudo = commons['need_sudo']
+ self.sos_options = commons['sos_options']
self.local = False
self.host = None
self.cluster = None
@@ -550,6 +551,12 @@ class SosNode():
if plug not in self.enable_plugins:
self.enable_plugins.append(plug)
+ if self.cluster.sos_options:
+ for opt in self.cluster.sos_options:
+ # take the user specification over any cluster defaults
+ if opt not in self.sos_options:
+ self.sos_options[opt] = self.cluster.sos_options[opt]
+
if self.cluster.sos_plugin_options:
for opt in self.cluster.sos_plugin_options:
if not any(opt in o for o in self.plugopts):
@@ -643,6 +650,10 @@ class SosNode():
os.path.join(self.host.sos_bin_path, self.sos_bin)
)
+ for opt in self.sos_options:
+ _val = self.sos_options[opt]
+ sos_opts.append(f"--{opt} {_val if _val else ''}")
+
if self.plugopts:
opts = [o for o in self.plugopts
if self._plugin_exists(o.split('.')[0])