From 24c32b1a62f5255f4dc462656463a6b3cca2f400 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Sun, 19 May 2024 19:29:49 +0100 Subject: [PATCH] [sunbeam] Update plugin to collet more details * Add juju related info for sunbeam * Add logs from the sunbeam snap home user Resolves: SET-682 Signed-off-by: Arif Ali --- sos/report/plugins/sunbeam.py | 40 ++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/sos/report/plugins/sunbeam.py b/sos/report/plugins/sunbeam.py index 433b2a3e6a..3e248bb636 100644 --- a/sos/report/plugins/sunbeam.py +++ b/sos/report/plugins/sunbeam.py @@ -6,7 +6,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.report.plugins import Plugin, UbuntuPlugin +import json +from sos.report.plugins import Plugin, UbuntuPlugin, PluginOpt class Sunbeam(Plugin, UbuntuPlugin): @@ -19,6 +20,11 @@ class Sunbeam(Plugin, UbuntuPlugin): common_dir = '/var/snap/openstack/common' + option_list = [ + PluginOpt('sunbeam-user', default='ubuntu', val_type=str, + desc='The user used for sunbeam installation') + ] + def setup(self): self.add_service_status('snap.openstack.*') @@ -37,6 +43,38 @@ def setup(self): 'sunbeam cluster list --format yaml', ]) + sunbeam_user = self.get_option("sunbeam-user") + + cmd_pre = f"su - {sunbeam_user} -c" + res = self.exec_cmd(f'{cmd_pre} "sunbeam utils juju-login"') + if res['status'] == 0: + + self.add_cmd_output(f'{cmd_pre} "juju models"') + + juju_models = self.collect_cmd_output( + f'{cmd_pre} "juju models --format json"') + + if juju_models['status'] == 0: + juju_status_json = json.loads(juju_models['output']) + + for model in juju_status_json['models']: + + self.add_cmd_output([ + f'{cmd_pre} "juju status -m {model["name"]}"', + f'{cmd_pre} "juju status -m {model["name"]} ' + '--format json"', + ]) + + user_getent = self.exec_cmd(f"getent passwd {sunbeam_user}") + sb_user_homedir = user_getent["output"].split(":")[5] + sb_snap_homedir = f'{sb_user_homedir}/snap/openstack/common' + + self.add_copy_spec([ + f"{sb_snap_homedir}/*.log", + f"{sb_snap_homedir}/etc/*/*.log", + f"{sb_snap_homedir}/logs/*.log", + ]) + def postproc(self): self.do_file_private_sub(