From 1403c94ef114912c5eef3700e123b137b030c2c7 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Wed, 26 Apr 2017 10:14:59 +0800 Subject: Add support for result aggregation Change-Id: I678b765f3f430cb6a5d130d94960273b8eea85e7 Signed-off-by: Yujun Zhang --- qtip/ansible_library/plugins/action/aggregate.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'qtip/ansible_library/plugins/action') diff --git a/qtip/ansible_library/plugins/action/aggregate.py b/qtip/ansible_library/plugins/action/aggregate.py index 6e280419..f1451e06 100644 --- a/qtip/ansible_library/plugins/action/aggregate.py +++ b/qtip/ansible_library/plugins/action/aggregate.py @@ -9,10 +9,14 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import json from numpy import mean +import os from ansible.plugins.action import ActionBase +from qtip.util.export_to import export_to_file + class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): @@ -25,12 +29,22 @@ class ActionModule(ActionBase): if result.get('skipped', False): return result - return aggregate(self._task.args.get('group'), task_vars) + basepath = self._task.args.get('basepath') + + return aggregate( + hosts=task_vars['groups'][self._task.args.get('group')], + basepath=basepath, + src=self._task.args.get('src'), + dest=os.path.join(basepath, self._task.args.get('dest')) + ) # aggregate QPI results -def aggregate(group, task_vars): - qpi_results = [task_vars['hostvars'][host]['qpi_result'] for host in task_vars['groups'][group]] +@export_to_file +def aggregate(hosts, basepath, src): + host_results = [{'host': host, 'result': json.load(open(os.path.join(basepath, host, src)))} for host in hosts] + score = int(mean([r['result']['score'] for r in host_results])) return { - 'score': int(mean([r['score'] for r in qpi_results])) + 'score': score, + 'host_results': host_results } -- cgit 1.2.3-korg