Skip to content

Commit

Permalink
[juju][collect] Fix new juju collection
Browse files Browse the repository at this point in the history
New version of juju uses colorisation, and therefore juju status
and json.loads doesn't load the juju status correctly. By using
--no-color based on the version of juju this should this
particular use-case

Resolves: #3399
Resolves: SET-339

Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali committed Oct 30, 2023
1 parent fc8333e commit 9e7bc4a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sos/collector/clusters/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import re

from sos.collector.clusters import Cluster
from sos.utilities import parse_version
from sos.utilities import sos_get_command_output


def _parse_option_string(strings=None):
Expand Down Expand Up @@ -156,9 +158,17 @@ def _get_model_info(self, model_name):

return index

def _get_juju_version(self):
"""Grab the version of juju"""
cmd = "juju version"
res = sos_get_command_output(cmd)
return res['output'].split("-")[0]

def _execute_juju_status(self, model_name):
model_option = f"-m {model_name}" if model_name else ""
format_option = "--format json"
if parse_version(self._get_juju_version()) > parse_version("3"):
format_option += " --no-color"
status_cmd = f"{self.cmd} status {model_option} {format_option}"
res = self.exec_primary_cmd(status_cmd)
if not res["status"] == 0:
Expand Down

0 comments on commit 9e7bc4a

Please sign in to comment.