summaryrefslogtreecommitdiffstats
path: root/qtip
diff options
context:
space:
mode:
Diffstat (limited to 'qtip')
-rw-r--r--qtip/ansible_library/plugins/action/aggregate.py36
-rw-r--r--qtip/ansible_library/plugins/action/calculate.py4
2 files changed, 39 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..6e280419
--- /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': int(mean([r['score'] for r in qpi_results]))
+ }
diff --git a/qtip/ansible_library/plugins/action/calculate.py b/qtip/ansible_library/plugins/action/calculate.py
index ac7f10f2..fade367f 100644
--- a/qtip/ansible_library/plugins/action/calculate.py
+++ b/qtip/ansible_library/plugins/action/calculate.py
@@ -45,8 +45,10 @@ def calc_qpi(qpi_spec, metrics):
section_results = [{'name': s['name'], 'result': calc_section(s, metrics)}
for s in qpi_spec['sections']]
+
# TODO(yujunz): use formula in spec
- qpi_score = mean([r['result']['score'] for r in section_results])
+ standard_score = 2048
+ qpi_score = int(mean([r['result']['score'] for r in section_results]) * standard_score)
return {
'spec': qpi_spec,
'score': qpi_score,