Skip to content

Commit

Permalink
[common] handle all_logs when snap package is installed
Browse files Browse the repository at this point in the history
Add a new flag to add_cmd_output to suggest a snap_cmd, so that sos
does not direct the command directly to a file.

Resolves: sosreport#3683

Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali authored and TurboTurtle committed Aug 13, 2024
1 parent 95dbbc2 commit db95a3e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
12 changes: 9 additions & 3 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,8 +2007,11 @@ def _add_cmd_output(self, **kwargs):
kwargs['priority'] = 10
if 'changes' not in kwargs:
kwargs['changes'] = False
if self.get_option('all_logs') or kwargs['sizelimit'] == 0:
if (not getattr(SoSCommand(**kwargs), "snap_cmd", False) and
(self.get_option('all_logs') or kwargs['sizelimit'] == 0)):
kwargs['to_file'] = True
if "snap_cmd" in kwargs:
kwargs.pop("snap_cmd")
soscmd = SoSCommand(**kwargs)
self._log_debug("packed command: " + soscmd.__str__())
for _skip_cmd in self.skip_commands:
Expand Down Expand Up @@ -2073,7 +2076,7 @@ def add_cmd_output(self, cmds, suggest_filename=None,
sizelimit=None, pred=None, subdir=None,
changes=False, foreground=False, tags=[],
priority=10, cmd_as_tag=False, container=None,
to_file=False, runas=None):
to_file=False, runas=None, snap_cmd=False):
"""Run a program or a list of programs and collect the output
Output will be limited to `sizelimit`, collecting the last X amount
Expand Down Expand Up @@ -2149,6 +2152,9 @@ def add_cmd_output(self, cmds, suggest_filename=None,
:param runas: Run the `cmd` as the `runas` user
:type runas: ``str``
:param snap_cmd: Are the commands being run from a snap?
:type snap_cmd: ``bool``
"""
if isinstance(cmds, str):
cmds = [cmds]
Expand Down Expand Up @@ -2177,7 +2183,7 @@ def add_cmd_output(self, cmds, suggest_filename=None,
changes=changes, foreground=foreground,
priority=priority, cmd_as_tag=cmd_as_tag,
to_file=to_file, container_cmd=container_cmd,
runas=runas)
runas=runas, snap_cmd=snap_cmd)

def add_cmd_tags(self, tagdict):
"""Retroactively add tags to any commands that have been run by this
Expand Down
4 changes: 2 additions & 2 deletions sos/report/plugins/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setup(self):
log_path = "/var/snap/grafana/common/data/log/"
config_path = "/var/snap/grafana/current/conf/grafana.ini"

self.add_cmd_output("snap info grafana")
self.add_cmd_output("snap info grafana", snap_cmd=True)
else:
grafana_cli = "grafana-cli"
log_path = "/var/log/grafana/"
Expand All @@ -36,7 +36,7 @@ def setup(self):
f'{grafana_cli} plugins list-remote',
f'{grafana_cli} -v',
'grafana-server -v',
])
], snap_cmd=self.is_snap)

log_file_pattern = "*.log*" if self.get_option("all_logs") else "*.log"

Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup(self):
lxd_pred = SoSPredicate(self, services=['snap.lxd.daemon'],
required={'services': 'all'})

self.add_cmd_output("lxd.buginfo", pred=lxd_pred)
self.add_cmd_output("lxd.buginfo", pred=lxd_pred, snap_cmd=True)

self.add_copy_spec([
'/var/snap/lxd/common/config',
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/maas.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _snap_collect(self):
self.add_cmd_output([
'snap info maas',
'maas status',
])
], snap_cmd=True)

self.add_forbidden_path([
"/var/snap/maas/**/*.key",
Expand Down
8 changes: 4 additions & 4 deletions sos/report/plugins/sunbeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def setup(self):
self.add_cmd_output([
'sunbeam cluster list',
'sunbeam cluster list --format yaml',
])
], snap_cmd=True)

sunbeam_user = self.get_option("sunbeam-user")
try:
Expand Down Expand Up @@ -100,7 +100,7 @@ def setup(self):
"login")

def _get_juju_cmd_details(self, user):
self.add_cmd_output("juju controllers", runas=user)
self.add_cmd_output("juju controllers", runas=user, snap_cmd=True)
juju_controllers = self.collect_cmd_output(
"juju controllers --format json", runas=user)

Expand All @@ -113,7 +113,7 @@ def _get_juju_cmd_details(self, user):
f'juju model-defaults -c {controller}',
f'juju controller-config -c {controller}',
f'juju controller-config -c {controller} --format json',
], runas=user)
], runas=user, snap_cmd=True)

juju_models = self.collect_cmd_output(
f'juju models -c {controller} --format json',
Expand All @@ -131,7 +131,7 @@ def _get_juju_cmd_details(self, user):
f'juju status -m {model_name} --format json',
f'juju model-config -m {model_name}',
f'juju model-config -m {model_name} --format json',
], runas=user)
], runas=user, snap_cmd=True)

def postproc(self):

Expand Down

0 comments on commit db95a3e

Please sign in to comment.