summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-17 22:05:56 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-17 22:26:13 +0800
commit6bec7f3a38497222217cf899965bc6d4d5c0c545 (patch)
treee7b756c07ee56aed047580d020e8af55eaf4a4f4
parentbbcbb7f54096c05d83c982d6784646882e2c276a (diff)
Aggregate qpi score from all nodes
Change-Id: Ib711a493a949b013ffe22519861f144dc47d0334 Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
-rw-r--r--qtip/ansible_library/plugins/action/aggregate.py36
-rw-r--r--resources/template/qpi-report.j23
-rw-r--r--tests/integration/run.yaml9
3 files changed, 47 insertions, 1 deletions
diff --git a/qtip/ansible_library/plugins/action/aggregate.py b/qtip/ansible_library/plugins/action/aggregate.py
new file mode 100644
index 00000000..907fa775
--- /dev/null
+++ b/qtip/ansible_library/plugins/action/aggregate.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+
+###############################################################
+# Copyright (c) 2017 ZTE Corporation
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from numpy import mean
+
+from ansible.plugins.action import ActionBase
+
+
+class ActionModule(ActionBase):
+ def run(self, tmp=None, task_vars=None):
+
+ if task_vars is None:
+ task_vars = dict()
+
+ result = super(ActionModule, self).run(tmp, task_vars)
+
+ if result.get('skipped', False):
+ return result
+
+ return aggregate(self._task.args.get('group'), task_vars)
+
+
+# aggregate QPI results
+def aggregate(group, task_vars):
+ qpi_results = [task_vars['hostvars'][host]['qpi_result'] for host in task_vars['groups'][group]]
+ return {
+ 'score': mean([r['score'] for r in qpi_results])
+ }
diff --git a/resources/template/qpi-report.j2 b/resources/template/qpi-report.j2
index afe9bfb8..6ca73634 100644
--- a/resources/template/qpi-report.j2
+++ b/resources/template/qpi-report.j2
@@ -1,4 +1,7 @@
Sample QPI Report
+
+Pod: {{ pod_result.score }}
+
{% for host in groups['compute'] %}
{% set qpi_result = hostvars[host].qpi_result %}
diff --git a/tests/integration/run.yaml b/tests/integration/run.yaml
index 86b36284..eb1bab88 100644
--- a/tests/integration/run.yaml
+++ b/tests/integration/run.yaml
@@ -33,7 +33,15 @@
delegate_to: localhost
tags: [calculate]
+- hosts: local
+ tasks:
+ - name: aggregate QPI results from all tested nodes
+ aggregate:
+ group: compute
+ register: pod_result
+
# Generate and publish report
+
- hosts: local
tasks:
- name: create report folder
@@ -49,4 +57,3 @@
src: "{{ qtip_resources }}/template/qpi-report.j2"
dest: "{{ qtip_reports }}/qpi-report"
tags: [report]
- # TODO(yujunz) push test result to testapi