aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qtip/ansible_library/plugins/action/calculate.py29
-rw-r--r--qtip/ansible_library/plugins/action/collect.py11
-rw-r--r--qtip/util/export_to.py15
-rw-r--r--requirements.txt1
-rw-r--r--resources/QPI/compute.yaml13
-rw-r--r--resources/ansible_roles/openssl/tasks/main.yml5
-rw-r--r--resources/ansible_roles/qtip/tasks/calculate.yml2
-rw-r--r--tests/unit/ansible_library/plugins/action/calculate_test.py7
8 files changed, 72 insertions, 11 deletions
diff --git a/qtip/ansible_library/plugins/action/calculate.py b/qtip/ansible_library/plugins/action/calculate.py
index fade367f..01c80a02 100644
--- a/qtip/ansible_library/plugins/action/calculate.py
+++ b/qtip/ansible_library/plugins/action/calculate.py
@@ -9,12 +9,17 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import humanfriendly
+import numbers
from numpy import mean
import yaml
from ansible.plugins.action import ActionBase
from ansible.utils.display import Display
+from qtip.util.export_to import export_to_file
+
+
display = Display()
@@ -33,11 +38,12 @@ class ActionModule(ActionBase):
spec = yaml.safe_load(stream)
metrics = self._task.args.get('metrics')
+ export_to = self._task.args.get('export_to')
- return calc_qpi(spec, metrics)
+ return calc_qpi(spec, metrics, export_to)
-def calc_qpi(qpi_spec, metrics):
+def calc_qpi(qpi_spec, metrics, dest=None):
display.vv("calculate QPI {}".format(qpi_spec['name']))
display.vvv("spec: {}".format(qpi_spec))
@@ -49,13 +55,19 @@ def calc_qpi(qpi_spec, metrics):
# TODO(yujunz): use formula in spec
standard_score = 2048
qpi_score = int(mean([r['result']['score'] for r in section_results]) * standard_score)
- return {
+
+ results = {
'spec': qpi_spec,
'score': qpi_score,
'section_results': section_results,
'metrics': metrics
}
+ if dest is not None:
+ export_to_file(results, dest)
+
+ return results
+
def calc_section(section_spec, metrics):
@@ -80,11 +92,18 @@ def calc_metric(metric_spec, metrics):
display.vvv("metrics: {}".format(metrics))
# TODO(yujunz): use formula in spec
- # TODO(yujunz): convert metric to float in collector
- workload_results = [{'name': w['name'], 'score': mean([float(m) for m in metrics[w['name']]]) / w['baseline']}
+ workload_results = [{'name': w['name'], 'score': calc_score(metrics[w['name']], w['baseline'])}
for w in metric_spec['workloads']]
metric_score = mean([r['score'] for r in workload_results])
return {
'score': metric_score,
'workload_results': workload_results
}
+
+
+def calc_score(metrics, baseline):
+ if not isinstance(baseline, numbers.Number):
+ baseline = humanfriendly.parse_size(baseline)
+
+ return mean([m if isinstance(m, numbers.Number) else humanfriendly.parse_size(m)
+ for m in metrics]) / baseline
diff --git a/qtip/ansible_library/plugins/action/collect.py b/qtip/ansible_library/plugins/action/collect.py
index e51b8072..c54cbe7d 100644
--- a/qtip/ansible_library/plugins/action/collect.py
+++ b/qtip/ansible_library/plugins/action/collect.py
@@ -10,11 +10,12 @@
##############################################################################
from collections import defaultdict
-import json
import re
from ansible.plugins.action import ActionBase
+from qtip.util.export_to import export_to_file
+
class ActionModule(ActionBase):
@@ -31,7 +32,7 @@ class ActionModule(ActionBase):
return collect(patterns, string, export_to)
-def collect(patterns, string, export_to=None):
+def collect(patterns, string, dest=None):
"""collect all named subgroups of the match into a list keyed by subgroup name
"""
captured = defaultdict(list)
@@ -44,7 +45,7 @@ def collect(patterns, string, export_to=None):
for (key, value) in match_obj.groupdict().items():
captured[key].append(value)
- if export_to is not None:
- with open(export_to, 'w+') as f:
- f.write(json.dumps(captured, indent=2))
+ if dest is not None:
+ export_to_file(captured, dest)
+
return captured
diff --git a/qtip/util/export_to.py b/qtip/util/export_to.py
new file mode 100644
index 00000000..98c39b5f
--- /dev/null
+++ b/qtip/util/export_to.py
@@ -0,0 +1,15 @@
+##############################################################################
+# Copyright (c) 2017 ZTE and others.
+#
+# 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
+##############################################################################
+
+import json
+
+
+def export_to_file(content, filename):
+ with open(filename, 'w+') as f:
+ f.write(json.dumps(content, indent=2))
diff --git a/requirements.txt b/requirements.txt
index 0f408520..e601d10d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,3 +9,4 @@ pbr
prettytable
six
PyYAML
+humanfriendly \ No newline at end of file
diff --git a/resources/QPI/compute.yaml b/resources/QPI/compute.yaml
index 736aef22..7746cbd7 100644
--- a/resources/QPI/compute.yaml
+++ b/resources/QPI/compute.yaml
@@ -34,3 +34,16 @@ sections: # split based on different application
baseline: 102.1
- name: rsa_verify_4096
baseline: 6402.9
+ - name: ssl_aes
+ formual: geometric mean
+ workloads:
+ - name: aes_128_cbc_16_bytes
+ baseline: 612376.96k
+ - name: aes_128_cbc_64_bytes
+ baseline: 657350.74k
+ - name: aes_128_cbc_256_bytes
+ baseline: 669680.04k
+ - name: aes_128_cbc_1024_bytes
+ baseline: 672675.50k
+ - name: aes_128_cbc_8192_bytes
+ baseline: 672344.75k
diff --git a/resources/ansible_roles/openssl/tasks/main.yml b/resources/ansible_roles/openssl/tasks/main.yml
index 6ef24bbc..91c5be93 100644
--- a/resources/ansible_roles/openssl/tasks/main.yml
+++ b/resources/ansible_roles/openssl/tasks/main.yml
@@ -25,6 +25,7 @@
set_fact:
rsa_logfile: "{{ qtip_results }}/openssl_rsa.log"
aes_logfile: "{{ qtip_results }}/openssl_aes.log"
+ tags: always
# TODO(yujunz) `delegate_to` not working under `with_items`
- name: saving rsa output to log
@@ -61,6 +62,7 @@
?(?P<rsa_verify_4096>\d+\.\d)$
export_to: "{{ qtip_results }}/ssl_rsa_metrics.json"
register: ssl_rsa_metrics
+ tags: collect
- name: collect ssl aes metrics
collect:
@@ -75,10 +77,11 @@
?(?P<aes_128_cbc_8192_bytes>\d+\.\w+)$
export_to: "{{ qtip_results }}/ssl_aes_metrics.json"
register: ssl_aes_metrics
+ tags: collect
- name: create SSL report
template:
src: ssl-metrics.j2
dest: "{{ qtip_results }}/ssl-metrics"
delegate_to: localhost
- tags: [report]
+ tags: report
diff --git a/resources/ansible_roles/qtip/tasks/calculate.yml b/resources/ansible_roles/qtip/tasks/calculate.yml
index aae4b453..3bcda9f9 100644
--- a/resources/ansible_roles/qtip/tasks/calculate.yml
+++ b/resources/ansible_roles/qtip/tasks/calculate.yml
@@ -13,6 +13,8 @@
calculate:
metrics:
ssl_rsa: "{{ ssl_rsa_metrics }}"
+ ssl_aes: "{{ ssl_aes_metrics }}"
spec: "{{ qtip_resources }}/QPI/compute.yaml"
+ export_to: "{{ qtip_results }}/qpi_result.json"
register: qpi_result
delegate_to: localhost
diff --git a/tests/unit/ansible_library/plugins/action/calculate_test.py b/tests/unit/ansible_library/plugins/action/calculate_test.py
index 3b34d9f5..68a03e2a 100644
--- a/tests/unit/ansible_library/plugins/action/calculate_test.py
+++ b/tests/unit/ansible_library/plugins/action/calculate_test.py
@@ -83,3 +83,10 @@ def test_calc_section(section_spec, metrics, section_result):
def test_calc_qpi(qpi_spec, metrics, qpi_result):
assert calculate.calc_qpi(qpi_spec, metrics) == qpi_result
+
+
+@pytest.mark.parametrize('metrics, baseline, expected', [
+ (['612376.96k'], '612376.96k', 1)
+])
+def test_calc_score(metrics, baseline, expected):
+ assert calculate.calc_score(metrics, baseline) == expected