diff options
author | 2017-05-17 02:06:52 +0000 | |
---|---|---|
committer | 2017-05-17 02:06:52 +0000 | |
commit | 30bedcbde528b832357a296091816cf5e52031cd (patch) | |
tree | 686d7079a799706afe480c5497109d3c4e47a6de /legacy/tests | |
parent | b5a115179cc75be6ca853d740dfce393fc8c1fd2 (diff) | |
parent | 6cf01ef2b8cff0412640b6cc87112852afee9c87 (diff) |
Merge "delete unuse code in directory legacy"
Diffstat (limited to 'legacy/tests')
-rw-r--r-- | legacy/tests/ansible_api_test.py | 22 | ||||
-rw-r--r-- | legacy/tests/args_handler_test.py | 36 | ||||
-rw-r--r-- | legacy/tests/cli_test.py | 52 | ||||
-rw-r--r-- | legacy/tests/driver_test.py | 103 | ||||
-rw-r--r-- | legacy/tests/env_setup_test.py | 120 |
5 files changed, 0 insertions, 333 deletions
diff --git a/legacy/tests/ansible_api_test.py b/legacy/tests/ansible_api_test.py deleted file mode 100644 index 6f286fc3..00000000 --- a/legacy/tests/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/legacy/tests/args_handler_test.py b/legacy/tests/args_handler_test.py deleted file mode 100644 index dceca1f5..00000000 --- a/legacy/tests/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/legacy/tests/cli_test.py b/legacy/tests/cli_test.py deleted file mode 100644 index 5b7eac65..00000000 --- a/legacy/tests/cli_test.py +++ /dev/null @@ -1,52 +0,0 @@ -############################################################################## -# Copyright (c) 2017 ZTE Corporation 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 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/legacy/tests/driver_test.py b/legacy/tests/driver_test.py deleted file mode 100644 index abe8cfbb..00000000 --- a/legacy/tests/driver_test.py +++ /dev/null @@ -1,103 +0,0 @@ -############################################################################## -# Copyright (c) 2017 ZTE Corporation 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 -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/legacy/tests/env_setup_test.py b/legacy/tests/env_setup_test.py deleted file mode 100644 index dea48190..00000000 --- a/legacy/tests/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) |