diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/ansible_library/modules/apex_test.py | 30 | ||||
-rw-r--r-- | tests/unit/ansible_library/plugins/action/calculate_test.py | 85 | ||||
-rw-r--r-- | tests/unit/cli/cmd_metric_test.py | 3 | ||||
-rw-r--r-- | tests/unit/cli/cmd_plan_test.py | 3 | ||||
-rw-r--r-- | tests/unit/cli/cmd_qpi_test.py | 3 | ||||
-rw-r--r-- | tests/unit/cli/options_test.py | 3 |
6 files changed, 126 insertions, 1 deletions
diff --git a/tests/unit/ansible_library/modules/apex_test.py b/tests/unit/ansible_library/modules/apex_test.py new file mode 100644 index 00000000..8a1d0673 --- /dev/null +++ b/tests/unit/ansible_library/modules/apex_test.py @@ -0,0 +1,30 @@ +############################################################### +# 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 +############################################################################## + +import json +import os + +from qtip.ansible_library.modules import apex + + +def test_generate_inventory(data_root): + baremetal_info = json.load(open(os.path.join(data_root, 'external', + 'apex', 'baremetal_info.json'))) + server_info = json.load(open(os.path.join(data_root, 'external', + 'apex', 'server_info.json'))) + inventory = apex.generate_inventory(baremetal_info, server_info) + assert dict(inventory['hosts']) == { + u'compute': [u'192.0.2.5', u'192.0.2.6'], + u'control': [u'192.0.2.7', u'192.0.2.8', u'192.0.2.9']} + assert dict(inventory['hosts_meta']) == { + u'192.0.2.5': {'ansible_ssh_host': u'192.0.2.5'}, + u'192.0.2.6': {'ansible_ssh_host': u'192.0.2.6'}, + u'192.0.2.7': {'ansible_ssh_host': u'192.0.2.7'}, + u'192.0.2.8': {'ansible_ssh_host': u'192.0.2.8'}, + u'192.0.2.9': {'ansible_ssh_host': u'192.0.2.9'}} diff --git a/tests/unit/ansible_library/plugins/action/calculate_test.py b/tests/unit/ansible_library/plugins/action/calculate_test.py new file mode 100644 index 00000000..3b34d9f5 --- /dev/null +++ b/tests/unit/ansible_library/plugins/action/calculate_test.py @@ -0,0 +1,85 @@ +############################################################################## +# 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 { + "description": "QTIP Performance Index of compute", + "name": "compute", + "sections": [section_spec] + } + + +@pytest.fixture() +def metric_result(): + return {'score': 1.0, + 'workload_results': [ + {'name': 'rsa_sign', 'score': 1.0}, + {'name': 'rsa_verify', 'score': 1.0}]} + + +@pytest.fixture() +def section_result(metric_result): + return {'score': 1.0, + 'metric_results': [{'name': 'ssl_rsa', 'result': metric_result}]} + + +@pytest.fixture() +def qpi_result(qpi_spec, section_result, metrics): + return {'score': 2048, + 'spec': qpi_spec, + 'metrics': metrics, + 'section_results': [{'name': 'ssl', 'result': section_result}]} + + +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 diff --git a/tests/unit/cli/cmd_metric_test.py b/tests/unit/cli/cmd_metric_test.py index cd496ad9..c92e944b 100644 --- a/tests/unit/cli/cmd_metric_test.py +++ b/tests/unit/cli/cmd_metric_test.py @@ -41,3 +41,6 @@ def test_show(runner): result = runner.invoke(cli, ['metric', 'show']) assert 'Missing argument "name".' in result.output + + result = runner.invoke(cli, ['metric', 'show', 'xyz']) + assert "ERROR: metric spec: xyz not found" in result.output diff --git a/tests/unit/cli/cmd_plan_test.py b/tests/unit/cli/cmd_plan_test.py index 30025ae0..53a04800 100644 --- a/tests/unit/cli/cmd_plan_test.py +++ b/tests/unit/cli/cmd_plan_test.py @@ -38,3 +38,6 @@ def test_show(runner): result = runner.invoke(cli, ['plan', 'show']) assert 'Missing argument "name".' in result.output + + result = runner.invoke(cli, ['plan', 'show', 'xyz']) + assert "ERROR: plan spec: xyz not found" in result.output diff --git a/tests/unit/cli/cmd_qpi_test.py b/tests/unit/cli/cmd_qpi_test.py index 3d2c2613..e7823c9b 100644 --- a/tests/unit/cli/cmd_qpi_test.py +++ b/tests/unit/cli/cmd_qpi_test.py @@ -38,3 +38,6 @@ def test_show(runner): result = runner.invoke(cli, ['qpi', 'show']) assert 'Missing argument "name".' in result.output + + result = runner.invoke(cli, ['qpi', 'show', 'xyz']) + assert "ERROR: qpi spec: xyz not found" in result.output diff --git a/tests/unit/cli/options_test.py b/tests/unit/cli/options_test.py index 9dbbe6f3..d7c0f700 100644 --- a/tests/unit/cli/options_test.py +++ b/tests/unit/cli/options_test.py @@ -8,6 +8,7 @@ ############################################################################## import pytest +import re import sys from click.testing import CliRunner @@ -26,7 +27,7 @@ class TestClass(object): def test_version(self, runner): result = runner.invoke(cli, ['--version']) - assert 'dev' in result.output + assert re.search(r'\d+\.\d+\.\d+', result.output) def test_debug(self, runner): runner.invoke(cli, ['-d']) |