-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <[email protected]>
- Loading branch information
Showing
1 changed file
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Copyright (C) 2024 Canonical Ltd., Arif Ali <[email protected]> | ||
# | ||
# This file is part of the sos project: https://github.com/sosreport/sos | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
|
@@ -6,7 +8,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 +22,13 @@ 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'), | ||
PluginOpt('juju-allow-login', default=False, val_type=bool, | ||
desc='Allow sos to login to juju'), | ||
] | ||
|
||
def setup(self): | ||
|
||
self.add_service_status('snap.openstack.*') | ||
|
@@ -37,6 +47,65 @@ def setup(self): | |
'sunbeam cluster list --format yaml', | ||
]) | ||
|
||
sunbeam_user = self.get_option("sunbeam-user") | ||
|
||
user_getent = self.exec_cmd(f"getent passwd {sunbeam_user}") | ||
if user_getent['status'] == 0: | ||
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", | ||
]) | ||
|
||
juju_allow_login = self.get_option("juju-allow-login") | ||
|
||
if juju_allow_login and user_getent['status'] == 0: | ||
cmd_pre = f"su - {sunbeam_user} -c" | ||
res = self.exec_cmd(f'{cmd_pre} "sunbeam utils juju-login"') | ||
if res['status'] == 0: | ||
self._get_juju_cmd_details(cmd_pre) | ||
|
||
def _get_juju_cmd_details(self, cmd_pre): | ||
self.add_cmd_output([ | ||
f'{cmd_pre} "juju controllers"', | ||
]) | ||
juju_controllers = self.collect_cmd_output( | ||
f'{cmd_pre} "juju controllers --format json"') | ||
|
||
if juju_controllers['status'] == 0: | ||
juju_ctrl_json = json.loads(juju_controllers['output']) | ||
for controller in juju_ctrl_json['controllers'].keys(): | ||
|
||
self.add_cmd_output([ | ||
f'{cmd_pre} "juju models -c {controller}"', | ||
f'{cmd_pre} "juju model-defaults -c {controller}"', | ||
f'{cmd_pre} "juju controller-config -c {controller}"', | ||
f'{cmd_pre} "juju controller-config -c {controller} ' | ||
'--format json"', | ||
]) | ||
|
||
juju_models = self.collect_cmd_output( | ||
f'{cmd_pre} "juju models -c {controller} --format json"') | ||
|
||
if juju_models['status'] == 0: | ||
juju_status_json = json.loads(juju_models['output']) | ||
|
||
for model in juju_status_json['models']: | ||
|
||
model_name = f'{controller}:{model["name"]}' | ||
|
||
self.add_cmd_output([ | ||
f'{cmd_pre} "juju status -m {model_name}"', | ||
f'{cmd_pre} "juju status -m {model_name} ' | ||
'--format json"', | ||
f'{cmd_pre} "juju model-config -m {model_name}"', | ||
f'{cmd_pre} "juju model-config -m {model_name} ' | ||
'--format json"', | ||
]) | ||
|
||
def postproc(self): | ||
|
||
self.do_file_private_sub( | ||
|