From 171041e1b98ddcee75bed844de0b376b6abd6ef9 Mon Sep 17 00:00:00 2001 From: Thomas Merkel Date: Mon, 16 Aug 2021 12:30:19 +0200 Subject: [PATCH] Fix SLS error output on conformity details per minion On the light theme an sls error is not shown because the font color is also black. Because it's an error the font color should be red and I also recommend to show all errors logged by the state. Using the existing method for the nested_output and adding color support if a string is used. --- api/utils/output/nested_output.py | 5 ++++- api/views/alcali.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/api/utils/output/nested_output.py b/api/utils/output/nested_output.py index 3dd6cabf..430fd7d5 100644 --- a/api/utils/output/nested_output.py +++ b/api/utils/output/nested_output.py @@ -72,9 +72,12 @@ def display(self, ret, indent, prefix, out): ) elif isinstance(ret, str): first_line = True + color = self.GREEN + if self.retcode != 0: + color = self.RED for line in ret.splitlines(): line_prefix = " " * len(prefix) if not first_line else prefix - out.append(self.ustring(indent, self.GREEN, line, prefix=line_prefix)) + out.append(self.ustring(indent, color, line, prefix=line_prefix)) first_line = False elif isinstance(ret, (list, tuple)): color = self.GREEN diff --git a/api/views/alcali.py b/api/views/alcali.py index ffa4540c..e7868221 100644 --- a/api/views/alcali.py +++ b/api/views/alcali.py @@ -178,7 +178,7 @@ def conformity_detail(self, request, minion_id): last_highstate = last_highstate.loaded_ret()["return"] # Sls error if isinstance(last_highstate, list): - failed = {"error": last_highstate[0]} + failed = {'error': conv.convert(nested_output.output('\n'.join(last_highstate), _retcode = 1))} else: for state in last_highstate: state_name = state.split("_|-")[1]