Aggregate qpi score from all nodes 27/33427/1
authorYujun Zhang <zhang.yujunz@zte.com.cn>
Mon, 17 Apr 2017 14:05:56 +0000 (22:05 +0800)
committerYujun Zhang <zhang.yujunz@zte.com.cn>
Mon, 17 Apr 2017 14:26:13 +0000 (22:26 +0800)
Change-Id: Ib711a493a949b013ffe22519861f144dc47d0334
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
qtip/ansible_library/plugins/action/aggregate.py [new file with mode: 0644]
resources/template/qpi-report.j2
tests/integration/run.yaml

diff --git a/qtip/ansible_library/plugins/action/aggregate.py b/qtip/ansible_library/plugins/action/aggregate.py
new file mode 100644 (file)
index 0000000..907fa77
--- /dev/null
@@ -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])
+    }
index afe9bfb..6ca7363 100644 (file)
@@ -1,4 +1,7 @@
 Sample QPI Report
+
+Pod: {{ pod_result.score }}
+
 {% for host in groups['compute'] %}
 {% set qpi_result = hostvars[host].qpi_result %}
 
index 86b3628..eb1bab8 100644 (file)
     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