diff options
author | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2017-04-26 10:14:59 +0800 |
---|---|---|
committer | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2017-04-26 11:00:18 +0800 |
commit | 1403c94ef114912c5eef3700e123b137b030c2c7 (patch) | |
tree | 80b42128c74d9a06b3c9907bd4e1cab0ebb7647d /qtip/ansible_library | |
parent | 0c10841189cee0eab2dcd0a18ab946bb3ae617a0 (diff) |
Add support for result aggregation
Change-Id: I678b765f3f430cb6a5d130d94960273b8eea85e7
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip/ansible_library')
-rw-r--r-- | qtip/ansible_library/plugins/action/aggregate.py | 22 |
1 files changed, 18 insertions, 4 deletions
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 } |