diff --git a/specs/python-timmy.spec b/specs/python-timmy.spec index c6bee92..765a32c 100644 --- a/specs/python-timmy.spec +++ b/specs/python-timmy.spec @@ -4,7 +4,7 @@ %global pypi_name timmy Name: python-%{pypi_name} -Version: 1.25.3 +Version: 1.25.4 Release: 1%{?dist}~mos0 Summary: Log collector tool for OpenStack Fuel @@ -107,6 +107,9 @@ popd %changelog +* Mon Dec 12 2016 Dmitry Sutyagin - 1.25.4 +- Change: compact analyze output, minor refactor + * Mon Dec 12 2016 Dmitry Sutyagin - 1.25.3 - Add: dynamic import of analyze modules diff --git a/timmy/analyze.py b/timmy/analyze.py index ba26310..9091807 100644 --- a/timmy/analyze.py +++ b/timmy/analyze.py @@ -48,50 +48,47 @@ def analyze(node_manager): for script, param in node.mapscr.items(): if script in fn_mapping: if not os.path.exists(param['output_path']): - logger.warning("File %s does not exist" + logger.warning('File %s does not exist' % param['output_path']) continue - with open(param['output_path'], "r") as f: + with open(param['output_path'], 'r') as f: data = [l.rstrip() for l in f.readlines()] health, details = fn_mapping[script](data, script, node) if node.repr not in results: results[node.repr] = [] - results[node.repr].append({"script": script, - "output_file": param['output_path'], - "health": health, - "details": details}) + results[node.repr].append({'script': script, + 'output_file': param['output_path'], + 'health': health, + 'details': details}) node_manager.analyze_results = results def analyze_print_results(node_manager): - code_colors = {GREEN: ["GREEN", "\033[92m"], - UNKNOWN: ["UNKNOWN", "\033[94m"], - YELLOW: ["YELLOW", "\033[93m"], - RED: ["RED", "\033[91m"]} - color_end = "\033[0m" - print("Nodes health analysis:") + code_colors = {GREEN: ['GREEN', '\033[92m'], + UNKNOWN: ['UNKNOWN', '\033[94m'], + YELLOW: ['YELLOW', '\033[93m'], + RED: ['RED', '\033[91m']} + color_end = '\033[0m' + print('Nodes health analysis:') for node, result in node_manager.analyze_results.items(): - node_health = max([x["health"] for x in result]) + node_health = max([x['health'] for x in result]) node_color = code_colors[node_health][1] health_repr = code_colors[node_health][0] - print(" %s%s: %s%s" % (node_color, node, health_repr, color_end)) + print(' %s%s: %s%s' % (node_color, node, health_repr, color_end)) if node_health == 0: continue for r in result: if r['health'] == 0: continue - color = code_colors[r["health"]][1] + color = code_colors[r['health']][1] sys.stdout.write(color) - for key, value in r.items(): - if key == "health": - value = code_colors[value][0] - if key == "details" and len(value) > 0: - if len(value) > 1: - print(" details:") - for d in value: - print(" - %s" % d) - else: - print(" details: %s" % value[0]) - elif key != "details": - print(" %s: %s" % (key, value)) + health_repr = code_colors[r['health']][0] + print(' %s: %s' % (r['script'], health_repr)) + print(' %s: %s' % ('output_file', r['output_file'])) + if len(r['details']) > 1: + print(' details:') + for d in r['details']: + print(' - %s' % d) + else: + print(' details: %s' % r['details'][0]) sys.stdout.write(color_end) diff --git a/timmy/env.py b/timmy/env.py index 5f9e8fd..d46176b 100644 --- a/timmy/env.py +++ b/timmy/env.py @@ -16,7 +16,7 @@ # under the License. project_name = 'timmy' -version = '1.25.3' +version = '1.25.4' if __name__ == '__main__': import sys