diff options
Diffstat (limited to 'tests')
45 files changed, 105 insertions, 1169 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 8e2ecf7c..7acb75e6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,8 +8,11 @@ ############################################################################## from os import path + import pytest +from qtip.loader.plan import Plan + @pytest.fixture(scope='session') def data_root(): @@ -19,3 +22,8 @@ def data_root(): @pytest.fixture(scope='session') def benchmarks_root(data_root): return path.join(data_root, 'benchmarks') + + +@pytest.fixture(scope='session') +def plan(benchmarks_root): + return Plan('fake-plan.yaml', [benchmarks_root]) diff --git a/tests/data/benchmarks/QPI/compute.yaml b/tests/data/benchmarks/QPI/compute.yaml index 5ad8a4b6..e28efaf9 100644 --- a/tests/data/benchmarks/QPI/compute.yaml +++ b/tests/data/benchmarks/QPI/compute.yaml @@ -1,44 +1,29 @@ title: compute description: sample performance index of computing -algorithm: weighted arithmetic mean +formula: weighted arithmetic mean sections: - name: Integer weight: 0.3 - algorithm: geometric mean + formula: geometric mean metrics: - - spec: dhrystone.yaml - workloads: - - single_cpu - - multi_cpu + - dhrystone.yaml - name: Float weight: 0.3 - algorithm: geometric mean + formula: geometric mean metrics: - - spec: dhrystone.yaml - workloads: - - single_cpu - - multi_cpu + - whetstone.yaml - name: Memory weight: 0.2 - algorithm: geometric mean + formula: geometric mean metrics: - - spec: ramspeed.yaml - workloads: - - int: [add, average, copy, scale, triad] - - float: [add, average, copy, scale, triad] + - ramspeed.yaml - name: DPI weight: 0.1 - algorithm: geometric mean + formula: geometric mean metrics: - - spec: dpi.yaml - workloads: - - bps - - pps + - dpi.yaml - name: SSL weight: 0.1 - algorithm: geometric mean + formula: geometric mean metrics: - - spec: ssl.yaml - workloads: - - aes_128_cbc: [512, 1024, 2048, 4096] - - rsa_sig: [16, 64, 256, 1024, 8192] + - ssl.yaml diff --git a/tests/data/benchmarks/QPI/fake-qpi.yaml b/tests/data/benchmarks/QPI/fake-qpi.yaml new file mode 100644 index 00000000..aa1097f4 --- /dev/null +++ b/tests/data/benchmarks/QPI/fake-qpi.yaml @@ -0,0 +1,9 @@ +name: Fake QPI +description: a fake QPI producing random result +formula: weighted arithmetic mean +sections: +- name: Fake Section + weight: 0.5 + formula: geometric mean + metrics: + - fake-metric.yaml diff --git a/tests/data/benchmarks/metric/dhrystone.yaml b/tests/data/benchmarks/metric/dhrystone.yaml new file mode 100644 index 00000000..220b7841 --- /dev/null +++ b/tests/data/benchmarks/metric/dhrystone.yaml @@ -0,0 +1,9 @@ +name: dhrystone +description: > + A synthetic computing benchmark program intended to be representative of + system (integer) programming. +links: + - https://en.wikipedia.org/wiki/Dhrystone +workloads: + - single_cpu + - multi_cpu diff --git a/tests/data/benchmarks/metrics/dpi.yaml b/tests/data/benchmarks/metric/dpi.yaml index fc24c8d1..fc24c8d1 100644 --- a/tests/data/benchmarks/metrics/dpi.yaml +++ b/tests/data/benchmarks/metric/dpi.yaml diff --git a/tests/data/benchmarks/metric/fake-metric.yaml b/tests/data/benchmarks/metric/fake-metric.yaml new file mode 100644 index 00000000..c5fcc5c2 --- /dev/null +++ b/tests/data/benchmarks/metric/fake-metric.yaml @@ -0,0 +1,7 @@ +name: fake compute +description: > + a fake compute performance index which generate random result +workloads: # all supported workloads + - fake_workload_1 + - fake_workload_2 + - fake_workload_3 diff --git a/tests/data/benchmarks/metrics/ramspeed.yaml b/tests/data/benchmarks/metric/ramspeed.yaml index bb7618b7..bb7618b7 100644 --- a/tests/data/benchmarks/metrics/ramspeed.yaml +++ b/tests/data/benchmarks/metric/ramspeed.yaml diff --git a/tests/data/benchmarks/metrics/ssl.yaml b/tests/data/benchmarks/metric/ssl.yaml index 21e8add7..21e8add7 100644 --- a/tests/data/benchmarks/metrics/ssl.yaml +++ b/tests/data/benchmarks/metric/ssl.yaml diff --git a/tests/data/benchmarks/metric/whetstone.yaml b/tests/data/benchmarks/metric/whetstone.yaml new file mode 100644 index 00000000..448c9645 --- /dev/null +++ b/tests/data/benchmarks/metric/whetstone.yaml @@ -0,0 +1,10 @@ +name: whetstone +description: > + A synthetic benchmark for evaluating the performance of computers. + The Whetstone benchmark primarily measures the floating-point arithmetic + performance. +links: + - https://en.wikipedia.org/wiki/Whetstone_(benchmark) +workloads: + - single_cpu + - multi_cpu diff --git a/tests/data/benchmarks/metrics/dhrystone.yaml b/tests/data/benchmarks/metrics/dhrystone.yaml deleted file mode 100644 index b0d55ed2..00000000 --- a/tests/data/benchmarks/metrics/dhrystone.yaml +++ /dev/null @@ -1,7 +0,0 @@ -name: dhrystone -description: > - a synthetic computing benchmark program intended to be representative of - system (integer) programming -workloads: - - single_cpu - - multi_cpu diff --git a/tests/data/benchmarks/metrics/whetstone.yaml b/tests/data/benchmarks/metrics/whetstone.yaml deleted file mode 100644 index d83680c4..00000000 --- a/tests/data/benchmarks/metrics/whetstone.yaml +++ /dev/null @@ -1,5 +0,0 @@ -name: dhrystone -description: a synthetic benchmark for evaluating the performance of computers -workloads: - - single_cpu - - multi_cpu diff --git a/tests/data/benchmarks/plan/fake-plan.yaml b/tests/data/benchmarks/plan/fake-plan.yaml new file mode 100644 index 00000000..8887f66d --- /dev/null +++ b/tests/data/benchmarks/plan/fake-plan.yaml @@ -0,0 +1,10 @@ +name: fake plan +description: fake benchmark plan for demonstration and testing +config: + facility: local + engineer: local + driver: sample + collector: logfile + reporter: console +QPIs: + - fake-qpi.yaml diff --git a/tests/data/benchmarks/plans/verification.yaml b/tests/data/benchmarks/plans/verification.yaml deleted file mode 100644 index b146ee37..00000000 --- a/tests/data/benchmarks/plans/verification.yaml +++ /dev/null @@ -1,21 +0,0 @@ -title: verification -description: benchmark plan for QTIP verification -info: - facility: opnfv-ci - engineer: opnfv-bot -suites: - - QPI_spec: compute.yaml -# Uncomment next line to setup suite running condition -# condition: {} -# Uncomment the following lines setup case running configuration -# cases: -# - metric_spec: dhrystone.yaml -# config: {} -# - metric_spec: whetstone.yaml -# config: {} -# - metric_spec: ramspeed.yaml -# config: {} -# - metric_spec: dpi.yaml -# config: {} -# - metric_spec: ssl.yaml -# config: {} diff --git a/tests/data/helper/perftest.yaml b/tests/data/helper/perftest.yaml deleted file mode 100644 index 26c58452..00000000 --- a/tests/data/helper/perftest.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- - - tests: - - command: ['perftest', 'run'] - output: "Run a perftest\n" diff --git a/tests/data/helper/suite.yaml b/tests/data/helper/suite.yaml deleted file mode 100644 index 718ae440..00000000 --- a/tests/data/helper/suite.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- - - tests: - - command: ['suite', 'run'] - output: "Run a suite\n" - diff --git a/tests/data/helper/version.yaml b/tests/data/helper/version.yaml deleted file mode 100644 index b23f16f2..00000000 --- a/tests/data/helper/version.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- - - tests: - - command: ['version', 'list'] - output: "Lists all the different versions\n" - - - command: ['version', 'install', 'Colorado'] - output: "Install: Colorado\n" - - - command: ['version', 'uninstall', 'Arno'] - output: "Uninstall: Arno\n" - diff --git a/tests/data/hosts b/tests/data/hosts deleted file mode 100644 index 0a0ac539..00000000 --- a/tests/data/hosts +++ /dev/null @@ -1,2 +0,0 @@ -[sample_group_name] -127.0.0.1 diff --git a/tests/data/output/hosts b/tests/data/output/hosts deleted file mode 100644 index 9b47df0e..00000000 --- a/tests/data/output/hosts +++ /dev/null @@ -1,3 +0,0 @@ -[host] -10.20.0.29 -10.20.0.28 diff --git a/tests/data/schema/test_bm_schema.yaml b/tests/data/schema/test_bm_schema.yaml deleted file mode 100644 index a7c27e3f..00000000 --- a/tests/data/schema/test_bm_schema.yaml +++ /dev/null @@ -1,76 +0,0 @@ -type: map -mapping: - Scenario: - type: map - mapping: - benchmark: - type: str - required: True - host: - type: str - server: - type: str - allowempty: True - client: - type: str - allowempty: True - topology: - type: str - allowempty: True - benchmark_details: - type: map - mapping: - duration: - type: int - protocol: - type: str - bandwidthGbps: - type: int - description: - type: str - 1Run: - type: str - - Context: - type: map - mapping: - Host_Machines: - type: map - required: True - mapping: - regex;(^machine): - type: map - mapping: - role: - type: str - ip: - type: str - allowempty: True - pw: - type: str - allowempty: True - Virtual_Machines: - type: map - allowempty: True - Proxy_Environment: - type: map - mapping: - http_proxy: - type: str - https_proxy: - type: str - no_proxy: - type: str - - Test_Description: - type: map - mapping: - Test_category: - type: str - allowempty: True - Benchmark: - type: str - allowempty: True - Overview: - type: str - allowempty: True diff --git a/tests/data/schema/test_vm_schema.yaml b/tests/data/schema/test_vm_schema.yaml deleted file mode 100644 index 524f8fe4..00000000 --- a/tests/data/schema/test_vm_schema.yaml +++ /dev/null @@ -1,80 +0,0 @@ -type: map -mapping: - Scenario: - type: map - mapping: - benchmark: - type: str - required: True - host: - type: str - server: - type: str - allowempty: True - 1Run: - type: str - client: - type: str - allowempty: True - topology: - type: str - allowempty: True - benchmark_details: - type: map - mapping: - duration: - type: int - protocol: - type: str - bandwidthGbps: - type: int - teststream: - type: str - description: - type: str - - Context: - type: map - mapping: - Host_Machines: - type: map - allowempty: True - Virtual_Machines: - type: map - required: True - mapping: - regex;(^virtualmachine): - type: map - mapping: - availability_zone: - type: str - OS_image: - type: str - public_network: - type: str - role: - type: str - flavor: - type: str - Proxy_Environment: - type: map - mapping: - http_proxy: - type: str - https_proxy: - type: str - no_proxy: - type: str - - Test_Description: - type: map - mapping: - Test_category: - type: str - allowempty: True - Benchmark: - type: str - allowempty: True - Overview: - type: str - allowempty: True diff --git a/tests/data/test.retry b/tests/data/test.retry deleted file mode 100644 index 7b9ad531..00000000 --- a/tests/data/test.retry +++ /dev/null @@ -1 +0,0 @@ -127.0.0.1 diff --git a/tests/data/test.yml b/tests/data/test.yml deleted file mode 100644 index 270e86fd..00000000 --- a/tests/data/test.yml +++ /dev/null @@ -1,4 +0,0 @@ -- hosts: sample_group_name - tasks: - - name: just an uname - command: uname -a diff --git a/tests/data/testplan/bm_ping.yaml b/tests/data/testplan/bm_ping.yaml deleted file mode 100644 index 41d696e2..00000000 --- a/tests/data/testplan/bm_ping.yaml +++ /dev/null @@ -1,29 +0,0 @@ -
-Scenario:
- benchmark: dhrystone
- host: machine_1
- server:
-
-Context:
- Host_Machines:
- machine_1:
- ip: 127.0.0.1
- pw:
- role: host
-
- Virtual_Machines:
-
-
-Test_Description:
- Test_category: "Compute"
- Benchmark: "dhrystone"
- Overview: >
- ''' This test will run the dhrystone benchmark in parallel on machine_1 and machine_2.\n
- if you wish to add a virtual machine add the following information under the Virtual_Machine tag
-
- virtualmachine_1:
- availability_zone:
- public_network:
- OS_image:
- flavor:
- role: '''
diff --git a/tests/data/testplan/bm_with_proxy.yaml b/tests/data/testplan/bm_with_proxy.yaml deleted file mode 100644 index 1d73300b..00000000 --- a/tests/data/testplan/bm_with_proxy.yaml +++ /dev/null @@ -1,39 +0,0 @@ -
-Scenario:
- benchmark: dhrystone
- host: machine_1, machine_2
- server:
-
-Context:
- Host_Machines:
- machine_1:
- ip: 10.20.0.28
- pw:
- role: host
- machine_2:
- ip: 10.20.0.29
- pw:
- role: host
-
- Virtual_Machines:
-
- Proxy_Environment:
- http_proxy: http://10.20.0.1:8118
- https_proxy: http://10.20.0.1:8118
- no_proxy: localhost,127.0.0.1,10.20.*,192.168.*
-
-
-
-Test_Description:
- Test_category: "Compute"
- Benchmark: "dhrystone"
- Overview: >
- ''' This test will run the dhrystone benchmark in parallel on machine_1 and machine_2.\n
- if you wish to add a virtual machine add the following information under the Virtual_Machine tag
-
- virtualmachine_1:
- availability_zone:
- public_network:
- OS_image:
- flavor:
- role: '''
diff --git a/tests/data/testplan/bm_without_proxy.yaml b/tests/data/testplan/bm_without_proxy.yaml deleted file mode 100644 index a9ae3b71..00000000 --- a/tests/data/testplan/bm_without_proxy.yaml +++ /dev/null @@ -1,33 +0,0 @@ -
-Scenario:
- benchmark: dhrystone
- host: machine_1, machine_2
- server:
-
-Context:
- Host_Machines:
- machine_1:
- ip: 10.20.0.28
- pw:
- role: host
- machine_2:
- ip: 10.20.0.29
- pw:
- role: host
-
- Virtual_Machines:
-
-
-Test_Description:
- Test_category: "Compute"
- Benchmark: "dhrystone"
- Overview: >
- ''' This test will run the dhrystone benchmark in parallel on machine_1 and machine_2.\n
- if you wish to add a virtual machine add the following information under the Virtual_Machine tag
-
- virtualmachine_1:
- availability_zone:
- public_network:
- OS_image:
- flavor:
- role: '''
diff --git a/tests/data/testplan/vm.yaml b/tests/data/testplan/vm.yaml deleted file mode 100644 index 4c8453ca..00000000 --- a/tests/data/testplan/vm.yaml +++ /dev/null @@ -1,48 +0,0 @@ -Scenario:
- benchmark: iperf
- topology: Client and Server on ONE compute
- server : virtualmachine_1
- client: virtualmachine_2
- description: 'Leave the bandwidth as 0 to throttle maximum traffic'
- benchmark_details:
- duration: 20
- protocol: tcp
- bandwidthGbps: 0
-
-Context:
- Host_Machines:
-
- Virtual_Machines:
- virtualmachine_1:
- availability_zone: compute1
- OS_image: QTIP_CentOS
- public_network: 'admin-floating_net'
- role: 1-server
- flavor: m1.large
-
- virtualmachine_2:
- availability_zone: compute1
- OS_image: QTIP_CentOS
- public_network: 'admin-floating_net'
- role: 2-host
- flavor: m1.large
-
- Proxy_Environment:
- http_proxy: http://10.20.0.1:8118
- https_proxy: http://10.20.0.1:8118
- no_proxy: localhost,127.0.0.1,10.20.*,192.168.*
-
-Test_Description:
- Test_category: "network"
- Benchmark: "iperf"
- Overview: >
- '''This test will run the IPERF benchmark on virutalmachine_1 and virtualmachine_2. On the\n
- same compute node
- if you wish to add a host machine add the following information under the Host_Machine tag
-
- machine_1:
- ip:
- pw:
- role:
- '''
-
diff --git a/tests/data/testplan/vm_error.yaml b/tests/data/testplan/vm_error.yaml deleted file mode 100644 index f13d3a00..00000000 --- a/tests/data/testplan/vm_error.yaml +++ /dev/null @@ -1,42 +0,0 @@ -Scenario:
- topology: Client and Server on ONE compute
- server : virtualmachine_1
- client: virtualmachine_2
- description: 'Leave the bandwidth as 0 to throttle maximum traffic'
- benchmark_details:
- duration: 20
- protocol: tcp
- bandwidthGbps: 0
-
-Context:
- Host_Machines:
-
- Virtual_Machines:
- virtualmachine_1:
- availability_zone: compute1
- OS_image: QTIP_CentOS
- public_network: 'admin-floating_net'
- role: 1-server
- flavor: m1.large
-
- virtualmachine_2:
- availability_zone: compute1
- OS_image: QTIP_CentOS
- public_network: 'admin-floating_net'
- role: 2-host
- flavor: m1.large
-
-Test_Description:
- Test_category: "network"
- Benchmark: "iperf"
- Overview: >
- '''This test will run the IPERF benchmark on virutalmachine_1 and virtualmachine_2. On the\n
- same compute node
- if you wish to add a host machine add the following information under the Host_Machine tag
-
- machine_1:
- ip:
- pw:
- role:
- '''
-
diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/functional/__init__.py +++ /dev/null diff --git a/tests/functional/yaml_schema_test.py b/tests/functional/yaml_schema_test.py deleted file mode 100644 index a975dca6..00000000 --- a/tests/functional/yaml_schema_test.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import os.path -from pykwalify.core import Core - - -class TestClass: - def test_schema_success(self): - for root, dirs, files in os.walk("test_cases"): - for name in files: - print root + "/" + name - if "_bm" in name: - schema = "tests/schema/test_bm_schema.yaml" - if "_vm" in name: - schema = "tests/schema/test_vm_schema.yaml" - c = Core(source_file=root + "/" + name, schema_files=[schema]) - c.validate(raise_exception=True) diff --git a/tests/unit/api/__init__.py b/tests/unit/api/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/unit/api/__init__.py +++ /dev/null diff --git a/tests/unit/api/test_server.py b/tests/unit/api/test_server.py deleted file mode 100644 index e9364d3d..00000000 --- a/tests/unit/api/test_server.py +++ /dev/null @@ -1,123 +0,0 @@ -import json -import time - -import mock -import pytest - -import qtip.api.cmd.server as server - - -def setup_module(): - server.add_routers() - - -@pytest.fixture -def app(): - return server.app - - -@pytest.fixture -def app_client(app): - client = app.test_client() - return client - - -def side_effect_sleep(sleep_time): - time.sleep(sleep_time) - - -def side_effect_pass(): - pass - - -class TestClass: - @pytest.mark.parametrize("body, expected", [ - ({'installer_type': 'fuel', - 'installer_ip': '10.20.0.2'}, - {'job_id': '', - 'installer_type': 'fuel', - 'installer_ip': '10.20.0.2', - 'pod_name': 'default', - 'suite_name': 'compute', - 'max_minutes': 60, - 'type': 'BM', - 'testdb_url': None, - 'node_name': None, - 'state': 'finished', - 'state_detail': [{'state': 'finished', 'benchmark': 'dhrystone_bm.yaml'}, - {'state': 'finished', 'benchmark': 'whetstone_bm.yaml'}, - {'state': 'finished', 'benchmark': 'ramspeed_bm.yaml'}, - {'state': 'finished', 'benchmark': 'dpi_bm.yaml'}, - {'state': 'finished', 'benchmark': 'ssl_bm.yaml'}], - 'result': 0}), - ({'installer_type': 'fuel', - 'installer_ip': '10.20.0.2', - 'pod_name': 'default', - 'max_minutes': 20, - 'suite_name': 'compute', - 'type': 'VM', - 'benchmark_name': 'dhrystone_vm.yaml', - 'testdb_url': 'http://testresults.opnfv.org/test/api/v1', - 'node_name': 'zte-pod2'}, - {'job_id': '', - 'installer_type': 'fuel', - 'installer_ip': '10.20.0.2', - 'pod_name': 'default', - 'suite_name': 'compute', - 'max_minutes': 20, - 'type': 'VM', - 'testdb_url': 'http://testresults.opnfv.org/test/api/v1', - 'node_name': 'zte-pod2', - 'state': 'finished', - 'state_detail': [{u'state': u'finished', u'benchmark': u'dhrystone_vm.yaml'}], - 'result': 0}) - ]) - @mock.patch('qtip.utils.args_handler.prepare_and_run_benchmark') - def test_post_get_delete_job_successful(self, mock_args_handler, app_client, body, expected): - mock_args_handler.return_value = {'result': 0, - 'detail': {'host': [(u'10.20.6.14', {'unreachable': 0, - 'skipped': 13, - 'ok': 27, - 'changed': 26, - 'failures': 0}), - ('localhost', {'unreachable': 0, - 'skipped': 0, - 'ok': 6, - 'changed': 6, - 'failures': 0}), - (u'10.20.6.13', {'unreachable': 0, - 'skipped': 13, - 'ok': 27, - 'changed': 26, - 'failures': 0})]}} - - reply = app_client.post("/api/v1.0/jobs", data=body) - print(reply.data) - id = json.loads(reply.data)['job_id'] - expected['job_id'] = id - post_process = '' - while post_process != 'finished': - get_reply = app_client.get("/api/v1.0/jobs/%s" % id) - reply_data = json.loads(get_reply.data) - post_process = reply_data['state'] - print(reply_data) - assert len(filter(lambda x: reply_data[x] == expected[x], expected.keys())) == len(expected) - delete_reply = app_client.delete("/api/v1.0/jobs/%s" % id) - assert "successful" in delete_reply.data - - @pytest.mark.parametrize("body, expected", [ - ([{'installer_type': 'fuel', - 'installer_ip': '10.20.0.2'}, - {'installer_type': 'compass', - 'installer_ip': '192.168.20.50'}], - ['job_id', - 'It already has one job running now!']) - ]) - @mock.patch('qtip.utils.args_handler.prepare_and_run_benchmark', - side_effect=[side_effect_sleep(0.5), side_effect_pass]) - def test_post_two_jobs_unsuccessful(self, mock_args_hanler, app_client, body, expected): - reply_1 = app_client.post("/api/v1.0/jobs", data=body[0]) - reply_2 = app_client.post("/api/v1.0/jobs", data=body[1]) - assert expected[0] in json.loads(reply_1.data).keys() - app_client.delete("/api/v1.0/jobs/%s" % json.loads(reply_1.data)['job_id']) - assert expected[1] in json.dumps(reply_2.data) diff --git a/tests/unit/loader/metric_test.py b/tests/unit/loader/metric_test.py index 5eced700..d2be0388 100644 --- a/tests/unit/loader/metric_test.py +++ b/tests/unit/loader/metric_test.py @@ -9,8 +9,8 @@ import pytest -from qtip.base.benchmark import Property -from qtip.spec.metric import MetricSpec +from qtip.base.constant import PropName +from qtip.loader.metric import MetricSpec @pytest.fixture(scope='module') @@ -29,17 +29,17 @@ def init_test(metric_spec): def list_all_test(): metric_list = MetricSpec.list_all() - assert len(list(metric_list)) is 1 + assert len(list(metric_list)) is 6 for desc in metric_list: - assert Property.NAME in desc - assert Property.DESCRIPTION in desc - assert Property.ABSPATH in desc - assert Property.ABSPATH is not None + assert PropName.NAME in desc + assert PropName.DESCRIPTION in desc + assert PropName.ABSPATH in desc + assert PropName.ABSPATH is not None def content_test(metric): - content = metric.content() - assert Property.NAME in content - assert Property.DESCRIPTION in content - assert Property.WORKLOADS in content - assert isinstance(content[Property.WORKLOADS], list) + content = metric.content + assert PropName.NAME in content + assert PropName.DESCRIPTION in content + assert PropName.WORKLOADS in content + assert isinstance(content[PropName.WORKLOADS], list) diff --git a/tests/unit/runner/plan_test.py b/tests/unit/loader/plan_test.py index d783e5e9..6aab5e8a 100644 --- a/tests/unit/runner/plan_test.py +++ b/tests/unit/loader/plan_test.py @@ -9,12 +9,15 @@ import pytest -from qtip.base.benchmark import Property -from qtip.runner.plan import Plan +from qtip.base.constant import PropName +from qtip.loader.plan import Plan, QPISpec def test_init(plan): - assert plan.name == 'verification' + assert plan.name == 'fake plan' + assert isinstance(plan.content, dict) + for qpi in plan.qpis: + assert isinstance(qpi, QPISpec) with pytest.raises(TypeError) as excinfo: Plan() @@ -26,13 +29,15 @@ def test_list_all(benchmarks_root): plan_list = Plan.list_all(paths=[benchmarks_root]) assert len(list(plan_list)) is 1 for desc in plan_list: - assert Property.NAME in desc - assert Property.CONTENT in desc - assert Property.ABSPATH in desc - assert Property.ABSPATH is not None + assert PropName.NAME in desc + assert PropName.CONTENT in desc + assert PropName.ABSPATH in desc + assert PropName.ABSPATH is not None def test_content(plan): - content = plan.content() - assert Property.TITLE in content - assert Property.DESCRIPTION in content + content = plan.content + assert PropName.NAME in content + assert PropName.DESCRIPTION in content + assert PropName.CONFIG in content + assert PropName.QPIS in content diff --git a/tests/unit/loader/qpi_test.py b/tests/unit/loader/qpi_test.py index bfa1f580..4b3fd4d0 100644 --- a/tests/unit/loader/qpi_test.py +++ b/tests/unit/loader/qpi_test.py @@ -9,8 +9,8 @@ import pytest -from qtip.base.benchmark import Algorithm, Property -from qtip.spec.qpi import QPISpec +from qtip.base.constant import FormulaName, PropName +from qtip.loader.qpi import QPISpec QPI_SPEC = 'compute.yaml' @@ -31,22 +31,22 @@ def test_init(qpi_spec): def test_list_all(benchmarks_root): qpi_spec_list = QPISpec.list_all(paths=[benchmarks_root]) - assert len(list(qpi_spec_list)) is 1 + assert len(list(qpi_spec_list)) is 2 for item in qpi_spec_list: - assert Property.NAME in item - assert Property.CONTENT in item - assert Property.ABSPATH in item - assert Property.ABSPATH is not None + assert PropName.NAME in item + assert PropName.CONTENT in item + assert PropName.ABSPATH in item + assert PropName.ABSPATH is not None def test_content(qpi_spec): - content = qpi_spec.content() - assert Property.DESCRIPTION in content - assert Property.ALGORITHM in content - assert Property.SECTIONS in content + content = qpi_spec.content + assert PropName.DESCRIPTION in content + assert PropName.FORMULA in content + assert PropName.SECTIONS in content - assert content[Property.ALGORITHM] in Algorithm.__dict__.values() - sections = content[Property.SECTIONS] + assert content[PropName.FORMULA] in FormulaName.__dict__.values() + sections = content[PropName.SECTIONS] assert isinstance(sections, list) for section in sections: - assert Property.NAME in section + assert PropName.NAME in section diff --git a/tests/unit/runner/case_test.py b/tests/unit/runner/case_test.py deleted file mode 100644 index 59a54a84..00000000 --- a/tests/unit/runner/case_test.py +++ /dev/null @@ -1,15 +0,0 @@ -############################################################### -# Copyright (c) 2016 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 -############################################################################## - -from qtip.spec.metric import MetricSpec - - -def init_test(case): - assert isinstance(case.metric_spec, MetricSpec) - assert isinstance(case.config, dict) diff --git a/tests/unit/runner/conftest.py b/tests/unit/runner/conftest.py deleted file mode 100644 index 6d14f7ae..00000000 --- a/tests/unit/runner/conftest.py +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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.base.benchmark import Property -from qtip.runner.case import Case -from qtip.runner.plan import Plan -from qtip.runner.suite import Suite - - -@pytest.fixture(scope='module') -def plan(benchmarks_root): - return Plan('verification.yaml', paths=[benchmarks_root]) - - -@pytest.fixture(scope='module') -def suite(plan): - return Suite(plan[Property.SUITES][0]) - - -@pytest.fixture(scope='module') -def case(suite): - return Case(suite[Property.CASES][0]) diff --git a/tests/unit/runner/suite_test.py b/tests/unit/runner/suite_test.py deleted file mode 100644 index 7dad8f62..00000000 --- a/tests/unit/runner/suite_test.py +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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.runner.suite import Suite -from qtip.runner.case import Case -from qtip.spec.qpi import QPISpec - - -def init_test(suite): - assert isinstance(suite.qpi, QPISpec) - assert isinstance(suite.condition, dict) - assert isinstance(suite.cases, list) - for case in suite.cases: - assert isinstance(case, Case) - - with pytest.raises(TypeError) as excinfo: - Suite() - assert '__init__() takes exactly 2 arguments (1 given)' \ - in str(excinfo.value) diff --git a/tests/unit/utils/__init__.py b/tests/unit/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/tests/unit/utils/__init__.py +++ /dev/null diff --git a/tests/unit/utils/ansible_api_test.py b/tests/unit/utils/ansible_api_test.py deleted file mode 100644 index 6f286fc3..00000000 --- a/tests/unit/utils/ansible_api_test.py +++ /dev/null @@ -1,22 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 -############################################################################## - -from tests import BaseTest -from qtip.utils.ansible_api import AnsibleApi - - -class TestClass(BaseTest): - - def test_call_ansible_api_success(self): - ansible_api = AnsibleApi() - ret = ansible_api.execute_playbook(self.abspath('hosts'), - self.abspath('test.yml'), - self.abspath('QtipKey'), - {'keys': 'test'}) - assert ret == 3 diff --git a/tests/unit/utils/args_handler_test.py b/tests/unit/utils/args_handler_test.py deleted file mode 100644 index dceca1f5..00000000 --- a/tests/unit/utils/args_handler_test.py +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 -import mock -import qtip.utils.args_handler - - -@pytest.mark.xfail(reason="to be fixed") -class TestClass: - @pytest.mark.parametrize("test_input, expected", [ - (['fuel', '/home', 'benchmarks/testplan/default/network/iperf_bm.yaml'], - ['fuel', '/home', "iperf", - [('1-server', ['10.20.0.23']), ('2-host', ['10.20.0.24'])], - "iperf_bm.yaml", - [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 10)], - [("10.20.0.24", [None]), ("10.20.0.23", [None])], {}]) - ]) - @mock.patch('qtip.utils.args_handler.Env_setup.call_ping_test') - @mock.patch('qtip.utils.args_handler.Env_setup.call_ssh_test') - @mock.patch('qtip.utils.args_handler.Env_setup.update_ansible') - @mock.patch('qtip.utils.args_handler.SpawnVM') - @mock.patch('qtip.utils.args_handler.Driver.drive_bench') - def test_prepare_and_run_benchmark_successful(self, mock_driver, mock_sqawn_vm, mock_env_setup_ping, - mock_env_setup_ssh, mock_update_ansible, test_input, expected): - mock_ips = mock.Mock(return_value=["10.20.0.23", "10.20.0.24"]) - qtip.utils.args_handler.Env_setup.fetch_compute_ips = mock_ips - qtip.utils.args_handler.prepare_and_run_benchmark(test_input[0], test_input[1], test_input[2]) - call = mock_driver.call_args - call_args, call_kwargs = call - assert sorted(map(sorted, call_args)) == sorted(map(sorted, expected)) diff --git a/tests/unit/utils/cli_test.py b/tests/unit/utils/cli_test.py deleted file mode 100644 index 0f3e4158..00000000 --- a/tests/unit/utils/cli_test.py +++ /dev/null @@ -1,44 +0,0 @@ -import pytest -import mock -import os -from qtip.utils.cli import Cli -from os.path import expanduser - - -@pytest.mark.skip("TODO(yujunz) recover test after refactoring") -class TestClass: - @pytest.mark.parametrize("test_input, expected", [ - (['-l', - 'zte', - '-f', - 'compute'], "You have specified a lab that is not present under benchmarks/testplan"), - (['-l', - 'default', - '-f', - 'test'], "This suite file test doesn't exist under benchmarks/suite/") - ]) - def test_cli_error(self, capfd, test_input, expected): - k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel', 'PWD': '/home'}) - with pytest.raises(SystemExit): - k.start() - Cli(test_input) - k.stop() - with open(expanduser('~') + "/qtip/logs/cli.log", "r") as file: - data = file.read() - assert expected in data - - @pytest.mark.parametrize("test_input, expected", [ - (['-l', - 'default', - '-f', - 'storage'], [('fuel', '/home', 'benchmarks/testplan/default/storage/fio_bm.yaml'), - ('fuel', '/home', 'benchmarks/testplan/default/storage/fio_vm.yaml')]) - ]) - @mock.patch('qtip.utils.cli.args_handler.prepare_and_run_benchmark') - def test_cli_successful(self, mock_args_handler, test_input, expected): - k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel', 'PWD': '/home'}) - k.start() - Cli(test_input) - k.stop() - call_list = map(lambda x: mock_args_handler.call_args_list[x][0], range(len(expected))) - assert sorted(call_list) == sorted(expected) diff --git a/tests/unit/utils/create_zones_test.py b/tests/unit/utils/create_zones_test.py deleted file mode 100644 index dcfff5ec..00000000 --- a/tests/unit/utils/create_zones_test.py +++ /dev/null @@ -1,110 +0,0 @@ -import pytest -import mock -from mock import Mock, MagicMock -import os -from qtip.utils.create_zones import AvailabilityZone - -return_list = [] - - -def get_agg_mock(host): - agg = Mock() - agg.name = host - agg.id = host - return agg - - -class HyperMock(MagicMock): - def list(self): - mock_hypervisor = [Mock(service={'host': '10.20.0.4'}), Mock(service={'host': '10.20.0.5'})] - return mock_hypervisor - - -class AggMock(MagicMock): - def get_details(self, agg_id): - print "get_details:{0}".format(agg_id) - return Mock(hosts=[]) - - def create(self, host, agg): - print "create:{0}:{1}".format(host, agg) - return agg - - def list(self): - return return_list - - def delete(self, agg_id): - print "delete:{0}".format(agg_id) - pass - - def add_host(self, aggregate, host): - print "add_host:{0}:{1}".format(aggregate, host) - pass - - def remove_host(self, agg_id, host): - print "remove_host:{0}:{1}".format(agg_id, host) - pass - - -class NovaMock(MagicMock): - hypervisors = HyperMock() - aggregates = AggMock() - - -@pytest.mark.xfail(reason="unstable result") -class TestClass: - @pytest.mark.parametrize("test_input, expected", [ - (['compute1', 'compute2'], - ['create:compute1:compute1', - 'add_host:compute1:10.20.0.4', - 'create:compute2:compute2', - 'add_host:compute2:10.20.0.5']), - (['compute1'], - ['create:compute1:compute1', - 'add_host:compute1:10.20.0.4']), - ]) - @mock.patch('qtip.utils.create_zones.client', autospec=True) - @mock.patch('qtip.utils.create_zones.v2', autospec=True) - @mock.patch('qtip.utils.create_zones.session') - def test_create_zones_success(self, mock_keystone_session, mock_keystone_v2, mock_nova_client, test_input, expected, capfd): - nova_obj = NovaMock() - mock_nova_client.Client.return_value = nova_obj() - k = mock.patch.dict(os.environ, {'OS_AUTH_URL': 'http://172.10.0.5:5000', - 'OS_USERNAME': 'admin', - 'OS_PASSWORD': 'admin', - 'OS_TENANT_NAME': 'admin'}) - k.start() - azone = AvailabilityZone() - azone.create_aggs(test_input) - k.stop() - resout, reserr = capfd.readouterr() - for x in expected: - assert x in resout - - @pytest.mark.parametrize("test_input, expected", [ - ([get_agg_mock('10.20.0.4'), get_agg_mock('10.20.0.5')], - ['get_details:10.20.0.4', - 'delete:10.20.0.4', - 'get_details:10.20.0.5', - 'delete:10.20.0.5']), - ([], - []), - ]) - @mock.patch('qtip.utils.create_zones.client', autospec=True) - @mock.patch('qtip.utils.create_zones.v2', autospec=True) - @mock.patch('qtip.utils.create_zones.session') - def test_clean_all_aggregates(self, mock_keystone_session, mock_keystone_v2, mock_nova_client, test_input, expected, capfd): - global return_list - return_list = test_input - nova_obj = NovaMock() - mock_nova_client.Client.return_value = nova_obj() - k = mock.patch.dict(os.environ, {'OS_AUTH_URL': 'http://172.10.0.5:5000', - 'OS_USERNAME': 'admin', - 'OS_PASSWORD': 'admin', - 'OS_TENANT_NAME': 'admin'}) - k.start() - azone = AvailabilityZone() - azone.clean_all_aggregates() - k.stop() - resout, reserr = capfd.readouterr() - for x in expected: - assert x in resout diff --git a/tests/unit/utils/driver_test.py b/tests/unit/utils/driver_test.py deleted file mode 100644 index 432ce1ae..00000000 --- a/tests/unit/utils/driver_test.py +++ /dev/null @@ -1,95 +0,0 @@ -import pytest -import mock -from qtip.utils.driver import Driver -from os.path import expanduser - -HOME_DIR = expanduser('~') - - -class TestClass: - @pytest.mark.parametrize("test_input, expected", [ - (['fuel', - '/home', - "iperf", - [('host', ['10.20.0.13', '10.20.0.15'])], - "iperf_bm.yaml", - [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 0)], - [("10.20.0.13", [None]), ("10.20.0.15", [None])], - {'http_proxy': 'http://10.20.0.1:8118', - 'https_proxy': 'http://10.20.0.1:8118', - 'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*'}], - [{'Dest_dir': HOME_DIR + '/qtip/results', - 'ip1': '', - 'ip2': '', - 'installer': 'fuel', - 'workingdir': '/home', - 'fname': 'iperf_bm.yaml', - 'username': 'root', - 'http_proxy': 'http://10.20.0.1:8118', - 'https_proxy': 'http://10.20.0.1:8118', - 'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*', - 'duration': 20, - 'protocol': 'tcp', - 'bandwidthGbps': 0, - "role": "host"}]), - (['joid', - '/home', - "iperf", - [('1-server', ['10.20.0.13']), ('2-host', ['10.20.0.15'])], - "iperf_vm.yaml", - [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 0)], - [('1-server', '10.10.17.4'), ('2-host', '10.10.17.5')], - {}], - [{'Dest_dir': HOME_DIR + '/qtip/results', - 'ip1': '10.20.0.13', - 'ip2': '', - 'installer': 'joid', - 'privateip1': '10.10.17.4', - 'workingdir': '/home', - 'fname': 'iperf_vm.yaml', - 'username': 'ubuntu', - 'duration': 20, - 'protocol': 'tcp', - 'bandwidthGbps': 0, - "role": "1-server"}, - {'Dest_dir': HOME_DIR + '/qtip/results', - 'ip1': '10.20.0.13', - 'ip2': '', - 'installer': 'joid', - 'privateip1': '10.10.17.4', - 'workingdir': '/home', - 'fname': 'iperf_vm.yaml', - 'username': 'ubuntu', - 'duration': 20, - 'protocol': 'tcp', - 'bandwidthGbps': 0, - "role": "2-host"}]) - ]) - @mock.patch('qtip.utils.driver.AnsibleApi.execute_playbook') - @mock.patch('qtip.utils.driver.AnsibleApi.get_detail_playbook_stats') - def test_driver_success(self, mock_stats, mock_ansible, test_input, expected): - mock_ansible.return_value = True - mock_stats.return_value = [(u'10.20.6.14', {'unreachable': 0, - 'skipped': 13, - 'ok': 27, - 'changed': 26, - 'failures': 0}), - ('localhost', {'unreachable': 0, - 'skipped': 0, - 'ok': 6, - 'changed': 6, - 'failures': 0}), - (u'10.20.6.13', {'unreachable': 0, - 'skipped': 13, - 'ok': 27, - 'changed': 26, - 'failures': 0})] - dri = Driver() - result = dri.drive_bench(test_input[0], test_input[1], test_input[2], test_input[3], - test_input[4], test_input[5], test_input[6], test_input[7]) - call_list = mock_ansible.call_args_list - for call in call_list: - call_args, call_kwargs = call - real_call = call_args[3] - assert real_call == expected[call_list.index(call)] - assert result['result'] == 0 diff --git a/tests/unit/utils/env_setup_test.py b/tests/unit/utils/env_setup_test.py deleted file mode 100644 index dea48190..00000000 --- a/tests/unit/utils/env_setup_test.py +++ /dev/null @@ -1,120 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 os -import pytest -import filecmp -from qtip.utils.env_setup import Env_setup -import mock - - -DATA_DIR = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'data') - - -def get_test_plan(name): - return os.path.join(DATA_DIR, 'testplan', name) - - -def get_output(name): - return os.path.join(DATA_DIR, 'output', name) - - -class TestClass: - @pytest.mark.parametrize("test_input, expected", [ - (get_test_plan("bm_with_proxy.yaml"), - ["dhrystone", - {}, - [], - {'http_proxy': 'http://10.20.0.1:8118', - 'https_proxy': 'http://10.20.0.1:8118', - 'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*'}]), - (get_test_plan("bm_without_proxy.yaml"), - ["dhrystone", - {}, - [], - {}]), - (get_test_plan("vm.yaml"), - ["iperf", - {'availability_zone': ['compute1', 'compute1'], - 'OS_image': ['QTIP_CentOS', 'QTIP_CentOS'], - 'public_network': ['admin-floating_net', 'admin-floating_net'], - 'flavor': ['m1.large', 'm1.large'], - 'role': ['1-server', '2-host']}, - [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 0)], - {'http_proxy': 'http://10.20.0.1:8118', - 'https_proxy': 'http://10.20.0.1:8118', - 'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*'}])]) - def test_parse_success(self, test_input, expected): - test_class = Env_setup() - mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) - test_class.fetch_compute_ips = mock_ips - benchmark, vm_para, details, proxy = \ - test_class.parse(test_input) - assert benchmark == expected[0] - assert vm_para == expected[1] - assert sorted(details) == sorted(expected[2]) - assert proxy == expected[3] - - def test_parse_vm_error(self): - test_class = Env_setup() - mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) - test_class.fetch_compute_ips = mock_ips - with pytest.raises(KeyError) as excinfo: - test_class.parse(get_test_plan("vm_error.yaml")) - assert "benchmark" in str(excinfo.value) - - def test_update_ansible(self): - test_class = Env_setup() - mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) - test_class.fetch_compute_ips = mock_ips - test_class.parse(get_test_plan("bm_without_proxy.yaml")) - test_class.update_ansible() - result = filecmp.cmp(get_output("hosts"), "config/hosts") - assert result - - @pytest.mark.skip("(yujunz) test hung") - def test_ping(self, capfd): - test_class = Env_setup() - mock_ips = mock.Mock(return_value=["127.0.0.1", "10.20.0.29"]) - test_class.fetch_compute_ips = mock_ips - test_class.parse(get_test_plan("bm_ping.yaml")) - test_class.call_ping_test() - resout, reserr = capfd.readouterr() - assert '127.0.0.1 is UP' in resout - - def test_check_machine_ips_without_ip(self): - test_class = Env_setup() - mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) - test_class.fetch_compute_ips = mock_ips - inputs = {"machine_1": {"ip": "", "pw": "", "role": "host"}, - "machine_2": {"ip": "", "pw": "", "role": "host"}} - test_class.check_machine_ips(inputs) - assert inputs["machine_1"]['ip'] in ["10.20.0.28", "10.20.0.29"] - assert inputs["machine_2"]['ip'] in ["10.20.0.28", "10.20.0.29"] - assert inputs["machine_1"]['ip'] != inputs["machine_2"]['ip'] - - def test_check_machine_ips_with_ip(self): - test_class = Env_setup() - mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) - test_class.fetch_compute_ips = mock_ips - inputs = {"machine_1": {"ip": "10.20.0.28", "pw": "", "role": "host"}, - "machine_2": {"ip": "10.20.0.29", "pw": "", "role": "host"}} - test_class.check_machine_ips(inputs) - assert inputs["machine_1"]['ip'] in ["10.20.0.28", "10.20.0.29"] - assert inputs["machine_2"]['ip'] in ["10.20.0.28", "10.20.0.29"] - assert inputs["machine_1"]['ip'] != inputs["machine_2"]['ip'] - - def test_check_machine_ips_with_invalid_ip(self): - test_class = Env_setup() - mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) - test_class.fetch_compute_ips = mock_ips - inputs = {"machine_1": {"ip": "10.20.0.3", "pw": "", "role": "host"}, - "machine_2": {"ip": "10.20.0.4", "pw": "", "role": "host"}} - with pytest.raises(RuntimeError): - test_class.check_machine_ips(inputs) diff --git a/tests/unit/utils/spawn_vm_test.py b/tests/unit/utils/spawn_vm_test.py deleted file mode 100644 index ba237378..00000000 --- a/tests/unit/utils/spawn_vm_test.py +++ /dev/null @@ -1,56 +0,0 @@ -import pytest -import mock -from mock import Mock, MagicMock -import os -from qtip.utils.spawn_vm import SpawnVM - - -class KeystoneMock(MagicMock): - auth_token = Mock() - v2_0 = Mock() - - -class StackMock(MagicMock): - status = 'COMPLETE' - outputs = [{'output_key': 'availability_instance_1', - 'output_value': 'output_value_1'}, - {'output_key': 'instance_ip_1', - "output_value": "172.10.0.154"}, - {"output_key": "instance_PIP_1", - "output_value": "10.10.17.5"}] - - -class HeatMock(MagicMock): - def list(self): - return [] - - def get(self, stackname): - return StackMock() - - def create(self, stack_name, template): - pass - - -class TestClass: - @pytest.mark.parametrize("test_input, expected", [ - ({'availability_zone': ['compute1', 'compute1'], - 'OS_image': ['QTIP_CentOS', 'QTIP_CentOS'], - 'public_network': ['admin-floating_net', 'admin-floating_net'], - 'flavor': ['m1.large', 'm1.large'], - 'role': ['1-server', '2-host']}, - [('172.10.0.154', '')]), - ]) - @mock.patch('qtip.utils.spawn_vm.Env_setup') - @mock.patch('qtip.utils.spawn_vm.AvailabilityZone') - @mock.patch('qtip.utils.spawn_vm.keystoneclient.v2_0', autospec=True) - @mock.patch('qtip.utils.spawn_vm.heatclient.client', autospec=True) - def test_create_zones_success(self, mock_heat, mock_keystone, - mock_zone, mock_setup, test_input, expected): - open('./config/QtipKey.pub', 'a').close() - mock_heat.Client.return_value = Mock(stacks=HeatMock()) - k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel'}) - k.start() - SpawnVM(test_input) - k.stop() - os.remove('./config/QtipKey.pub') - mock_setup.ip_pw_list.append.assert_called_with(expected[0]) |