From 036bbd0fa4c85f97da536717673ca0b668dd5276 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Sat, 8 Sep 2018 17:45:09 +0200 Subject: [juju] catch exceptions when "juju status" command fails Catch exceptions when "juju status" command: - does not exist (and generates empty output), or - does not generate valid/expected JSON output Resolves: #1422 Signed-off-by: Pavel Moravec --- sos/plugins/juju.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sos/plugins/juju.py b/sos/plugins/juju.py index cbd4a17b..8d996041 100644 --- a/sos/plugins/juju.py +++ b/sos/plugins/juju.py @@ -51,7 +51,12 @@ class Juju(Plugin, UbuntuPlugin): cmd = "juju status --format json" status_json = self.call_ext_prog(cmd)['output'] self.add_string_as_file(status_json, "juju_status_json") - return json_loads(status_json)['services'].keys() + # if status_json isn't in JSON format (i.e. 'juju' command not found), + # or if it does not contain 'services' key, return empty list + try: + return json_loads(status_json)['services'].keys() + except ValueError: + return [] @ensure_service_is_running("juju-db") def export_mongodb(self): -- cgit