From db95a3ebe0ef16267742cbfcea1b33e0be87fb57 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Sat, 22 Jun 2024 00:34:51 +0100 Subject: [PATCH] [common] handle all_logs when snap package is installed 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: #3683 Signed-off-by: Arif Ali --- sos/report/plugins/__init__.py | 12 +++++++++--- sos/report/plugins/grafana.py | 4 ++-- sos/report/plugins/lxd.py | 2 +- sos/report/plugins/maas.py | 2 +- sos/report/plugins/sunbeam.py | 8 ++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py index b164833846..6b070b45eb 100644 --- a/sos/report/plugins/__init__.py +++ b/sos/report/plugins/__init__.py @@ -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: @@ -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 @@ -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] @@ -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 diff --git a/sos/report/plugins/grafana.py b/sos/report/plugins/grafana.py index 2b0ac44d8d..01819028d6 100644 --- a/sos/report/plugins/grafana.py +++ b/sos/report/plugins/grafana.py @@ -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/" @@ -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" diff --git a/sos/report/plugins/lxd.py b/sos/report/plugins/lxd.py index 29f89dd487..f5c9c27495 100644 --- a/sos/report/plugins/lxd.py +++ b/sos/report/plugins/lxd.py @@ -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', diff --git a/sos/report/plugins/maas.py b/sos/report/plugins/maas.py index 160d74bb8a..d72abb05df 100644 --- a/sos/report/plugins/maas.py +++ b/sos/report/plugins/maas.py @@ -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", diff --git a/sos/report/plugins/sunbeam.py b/sos/report/plugins/sunbeam.py index 150f5b25a2..1854637a63 100644 --- a/sos/report/plugins/sunbeam.py +++ b/sos/report/plugins/sunbeam.py @@ -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: @@ -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) @@ -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', @@ -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):