# 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()
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))
# 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):
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
##############################################################################
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):
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)
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
--- /dev/null
+##############################################################################
+# 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))
prettytable
six
PyYAML
+humanfriendly
\ No newline at end of file
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
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
?(?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:
?(?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
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
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