aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/ansible_library/plugins/action/calculate_test.py
blob: 31d72120a6b0a2116b1e64d1460ff2cec5fac7b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
##############################################################################
# Copyright (c) 2017 ZTE Corp 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 pytest

from qtip.ansible_library.plugins.action import calculate


@pytest.fixture()
def metrics():
    return {
        "ssl_rsa": {
            "rsa_sign": [500],
            "rsa_verify": [600]
        }
    }


@pytest.fixture()
def metric_spec():
    return {
        "name": "ssl_rsa",
        "workloads": [
            {"name": "rsa_sign", "baseline": 500},
            {"name": "rsa_verify", "baseline": 600}
        ]
    }


@pytest.fixture()
def section_spec(metric_spec):
    return {
        "name": "ssl",
        "description": "cryptography and SSL/TLS performance",
        "metrics": [metric_spec]
    }


@pytest.fixture
def qpi_spec(section_spec):
    return {
        "name": "compute",
        "description": "QTIP Performance Index of compute",
        "sections": [section_spec]
    }


@pytest.fixture()
def metric_result():
    return {'score': 1.0,
            'name': 'ssl_rsa',
            'description': 'metric',
            'children': [{'description': 'workload', 'name': 'rsa_sign', 'score': 1.0},
                         {'description': 'workload', 'name': 'rsa_verify', 'score': 1.0}]}


@pytest.fixture()
def section_result(metric_result):
    return {'score': 1.0,
            'name': 'ssl',
            'description': 'cryptography and SSL/TLS performance',
            'children': [metric_result]}


@pytest.fixture()
def qpi_result(qpi_spec, section_result, metrics):
    return {'score': 2048,
            'name': 'compute',
            'description': 'QTIP Performance Index of compute',
            'children': [section_result],
            'details': {
                'spec': qpi_spec,
                'metrics': metrics}}


def test_calc_metric(metric_spec, metrics, metric_result):
    assert calculate.calc_metric(metric_spec, metrics['ssl_rsa']) == metric_result


def test_calc_section(section_spec, metrics, section_result):
    assert calculate.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