Change: compact analyze output, minor refactor

Change-Id: If29463ac4d349dffa0dd6817fdace2795ffc6f9a
This commit is contained in:
Dmitry Sutyagin 2016-12-12 20:23:58 -08:00
parent c3c0182c72
commit 9169d0cd13
3 changed files with 29 additions and 29 deletions

View File

@ -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 <dsutyagin@mirantis.com> - 1.25.4
- Change: compact analyze output, minor refactor
* Mon Dec 12 2016 Dmitry Sutyagin <dsutyagin@mirantis.com> - 1.25.3
- Add: dynamic import of analyze modules

View File

@ -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)

View File

@ -16,7 +16,7 @@
# under the License.
project_name = 'timmy'
version = '1.25.3'
version = '1.25.4'
if __name__ == '__main__':
import sys