From cadd57fa0d67926733a63d5c697d21a057c65509 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Thu, 12 Oct 2023 08:25:06 +0100 Subject: [PATCH] [snap] Add more items to collect Resolves: SET-313 Signed-off-by: Arif Ali --- sos/report/plugins/snap.py | 52 +++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/sos/report/plugins/snap.py b/sos/report/plugins/snap.py index 1ad219cb37..6ee8375abf 100644 --- a/sos/report/plugins/snap.py +++ b/sos/report/plugins/snap.py @@ -9,6 +9,8 @@ from sos.report.plugins import Plugin, IndependentPlugin +import re + class Snap(Plugin, IndependentPlugin): @@ -23,8 +25,56 @@ def setup(self): self.add_cmd_output("snap list --all", root_symlink="installed-snaps") self.add_cmd_output([ "snap --version", - "snap changes" + "snap version", + "snap whoami", + "snap model --verbose", + "snap model --serial --verbose", + "snap services", + "snap connections", + "snap changes", + "snap changes --abs-time", + "snap validate", + "snap debug state --abs-time --changes /var/lib/snapd/state.json", + "snap debug stacktraces", + "snap get system -d", ]) + + all_pkgs = self.policy.package_manager.packages + + for pkg_name in all_pkgs: + pkg = self.policy.package_manager.pkg_by_name(pkg_name) + if pkg['pkg_manager'] == 'snap': + self.add_cmd_output(f"snap connections {pkg['name']}") + self.add_cmd_output("snap debug connectivity", timeout=10) + # If we have gadget snaps, then we collect more files, this is + # typically defined in the Notes column + snap_list = self.exec_cmd('snap list') + + if snap_list['status'] == 0: + output = snap_list['output'] + + for line in output.splitlines()[1:]: + if line == "": + continue + snap_pkg = line.split() + if re.match(r".*gadget.*$", snap_pkg[5]): + self.add_copy_spec([ + f"/snap/{snap_pkg[0]}/current/meta/gadget.yaml", + ]) + + snap_changes = self.exec_cmd('snap changes') + + if snap_changes['status'] == 0: + output = snap_changes['output'] + + for line in output.splitlines()[1:]: + if line == "": + continue + change = line.split() + change_id, change_status = change[0], change[1] + if change_status == "Doing" or change_status == "Error": + self.add_cmd_output(f"snap tasks {change_id} --abs-time") + # vim: set et ts=4 sw=4 :