Skip to content

Commit

Permalink
[component] Apply plugopts from cmdline gently
Browse files Browse the repository at this point in the history
When plugopts are set both in a loaded preset and in cmdline, we should
merge the options instead of blindly using cmdline ones.

This means preset plugopt options not present in cmdline are added,
while preset plugopt options also present in cmdline are ignored.

Closes: #3855

Signed-off-by: Pavel Moravec <[email protected]>
  • Loading branch information
pmoravec committed Jan 19, 2025
1 parent ff121f8 commit 00ef201
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sos/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,20 @@ def apply_options_from_cmdline(self, opts):
setattr(opts, oopt, [x for x in getattr(opts, oopt)
if x not in common])

if val != opts.arg_defaults[opt]:
# plugin options as a list should be concatenated, not overriden
# BUT if cmdline plugoption overrides same option in opts, we must
# drop the opts's value; since the items are in form
# 'apache.log=on', we must separate the *name* of each option
if opt == 'plugopts':
oplugopts = getattr(opts, opt)
valnames = [v.split('=')[0] for v in val]
ovalnames = [v.split('=')[0] for v in oplugopts]
for common in set(valnames) & set(ovalnames):
cstring = f"{common}="
oplugopts = [oopt for oopt in oplugopts
if not oopt.startswith(cstring)]
setattr(opts, opt, list(set(val) | set(oplugopts)))
elif val != opts.arg_defaults[opt]:
setattr(opts, opt, val)

return opts
Expand Down

0 comments on commit 00ef201

Please sign in to comment.