aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--qtip/ansible_library/plugins/action/aggregate.py36
-rw-r--r--qtip/ansible_library/plugins/action/calculate.py4
-rw-r--r--resources/template/qpi-report.j23
-rw-r--r--tests/integration/fixtures/case.json14
-rw-r--r--tests/integration/fixtures/pod.json6
-rw-r--r--tests/integration/fixtures/project.json4
-rw-r--r--tests/integration/group_vars/all1
-rw-r--r--tests/integration/host_vars/localhost7
-rw-r--r--tests/integration/run.yaml30
-rw-r--r--tests/integration/setup.yaml22
-rw-r--r--tests/unit/ansible_library/plugins/action/calculate_test.py2
12 files changed, 127 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 03de790a..2b3bc644 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,5 +77,5 @@ ChangeLog
# integration data
/tests/integration/hosts
/tests/integration/ssh.cfg
+/tests/integration/*.retry
/tests/integration/reports/*
-!/tests/integration/reports/*.sample
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,
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/fixtures/case.json b/tests/integration/fixtures/case.json
new file mode 100644
index 00000000..22abc40f
--- /dev/null
+++ b/tests/integration/fixtures/case.json
@@ -0,0 +1,14 @@
+{
+ "run": "",
+ "name": "compute",
+ "ci_loop": "",
+ "tags": "",
+ "url": "",
+ "domains": "",
+ "dependencies": "",
+ "version": "",
+ "criteria": "",
+ "tier": "",
+ "blocking": "",
+ "description": ""
+} \ No newline at end of file
diff --git a/tests/integration/fixtures/pod.json b/tests/integration/fixtures/pod.json
new file mode 100644
index 00000000..8c2863ba
--- /dev/null
+++ b/tests/integration/fixtures/pod.json
@@ -0,0 +1,6 @@
+{
+ "details": "",
+ "role": "",
+ "name": "internal",
+ "mode": ""
+} \ No newline at end of file
diff --git a/tests/integration/fixtures/project.json b/tests/integration/fixtures/project.json
new file mode 100644
index 00000000..ecd03e83
--- /dev/null
+++ b/tests/integration/fixtures/project.json
@@ -0,0 +1,4 @@
+{
+ "name": "qtip",
+ "description": "Platform Performance Benchmarking"
+} \ No newline at end of file
diff --git a/tests/integration/group_vars/all b/tests/integration/group_vars/all
index 7c56f570..16a93f46 100644
--- a/tests/integration/group_vars/all
+++ b/tests/integration/group_vars/all
@@ -1,2 +1,3 @@
qtip_resources: ../../resources
qtip_reports: ./reports
+qtip_fixtures: ./fixtures
diff --git a/tests/integration/host_vars/localhost b/tests/integration/host_vars/localhost
new file mode 100644
index 00000000..18d764cc
--- /dev/null
+++ b/tests/integration/host_vars/localhost
@@ -0,0 +1,7 @@
+testapi_url: http://localhost:8000/api/v1
+project_name: qtip
+case_name: compute
+pod_name: internal
+installer: fuel
+version: master
+scenario: demo
diff --git a/tests/integration/run.yaml b/tests/integration/run.yaml
index 86b36284..7545a65e 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,24 @@
src: "{{ qtip_resources }}/template/qpi-report.j2"
dest: "{{ qtip_reports }}/qpi-report"
tags: [report]
- # TODO(yujunz) push test result to testapi
+ - name: push result to testapi
+ uri:
+ url: "{{ testapi_url }}/results"
+ body: "{{ item|to_json }}"
+ method: POST
+ body_format: json
+ status_code: 200
+ with_items:
+ -
+ project_name: "{{ project_name }}"
+ case_name: "{{ case_name }}"
+ pod_name: "{{ pod_name }}"
+ installer: "{{ installer }}"
+ version: "{{ version }}"
+ scenario: "{{ scenario }}"
+ start_date: "{{ ansible_date_time.date }}"
+ stop_date: "{{ ansible_date_time.date }}"
+ criteria: ""
+ details: " {{ pod_result }}"
+
+ tags: [testapi]
diff --git a/tests/integration/setup.yaml b/tests/integration/setup.yaml
index 4af9a129..8d055c23 100644
--- a/tests/integration/setup.yaml
+++ b/tests/integration/setup.yaml
@@ -19,3 +19,25 @@
- name: update ssh.cfg file
template: src={{ qtip_resources }}/template/ssh.cfg.j2 dest=./ssh.cfg
delegate_to: localhost
+
+# Initialize testapi database
+- hosts: localhost
+ tasks:
+ - name: create project and pod
+ uri:
+ url: "{{ testapi_url }}/{{item}}s"
+ method: POST
+ body: "{{ lookup('file', '{}/{}.json'.format(qtip_fixtures, item)) }}"
+ status_code: [200, 403]
+ body_format: json
+ with_items:
+ - project
+ - pod
+ - name: create cases
+ uri:
+ url: "{{ testapi_url }}/projects/qtip/cases"
+ method: POST
+ body: "{{ lookup('file', '{}/case.json'.format(qtip_fixtures)) }}"
+ status_code: [200, 403]
+ body_format: json
+ tags: [testapi]
diff --git a/tests/unit/ansible_library/plugins/action/calculate_test.py b/tests/unit/ansible_library/plugins/action/calculate_test.py
index ae163102..3b34d9f5 100644
--- a/tests/unit/ansible_library/plugins/action/calculate_test.py
+++ b/tests/unit/ansible_library/plugins/action/calculate_test.py
@@ -67,7 +67,7 @@ def section_result(metric_result):
@pytest.fixture()
def qpi_result(qpi_spec, section_result, metrics):
- return {'score': 1.0,
+ return {'score': 2048,
'spec': qpi_spec,
'metrics': metrics,
'section_results': [{'name': 'ssl', 'result': section_result}]}