diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ansible_api_test.py | 19 | ||||
-rw-r--r-- | tests/args_handler_test.py | 35 | ||||
-rw-r--r-- | tests/cli_test.py | 14 | ||||
-rw-r--r-- | tests/data/hosts | 2 | ||||
-rw-r--r-- | tests/data/test.yml | 4 |
5 files changed, 74 insertions, 0 deletions
diff --git a/tests/ansible_api_test.py b/tests/ansible_api_test.py new file mode 100644 index 00000000..e9f0a77d --- /dev/null +++ b/tests/ansible_api_test.py @@ -0,0 +1,19 @@ +############################################################################## +# 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 func.ansible_api import AnsibleApi + + +class TestClass: + def test_call_ansible_api_success(self): + ansible_api = AnsibleApi() + ret = ansible_api.execute_playbook('tests/data/hosts', + 'tests/data/test.yml', + 'data/QtipKey', + {'keys': 'test'}) + assert ret == 3 diff --git a/tests/args_handler_test.py b/tests/args_handler_test.py new file mode 100644 index 00000000..7f977f21 --- /dev/null +++ b/tests/args_handler_test.py @@ -0,0 +1,35 @@ +############################################################################## +# 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 func.args_handler + + +class TestClass: + @pytest.mark.parametrize("test_input, expected", [ + ('./test_cases/zte-pod1/network/iperf_bm.yaml', + ["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('func.args_handler.Env_setup.call_ping_test') + @mock.patch('func.args_handler.Env_setup.call_ssh_test') + @mock.patch('func.args_handler.Env_setup.update_ansible') + @mock.patch('func.args_handler.SpawnVM') + @mock.patch('func.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"]) + func.args_handler.Env_setup.fetch_compute_ips = mock_ips + func.args_handler.prepare_and_run_benchmark(test_input) + call = mock_driver.call_args + call_args, call_kwargs = call + assert sorted(map(sorted, call_args)) == sorted(map(sorted, expected)) diff --git a/tests/cli_test.py b/tests/cli_test.py index bd31d987..f9861dee 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -1,4 +1,5 @@ import pytest +import mock from func.cli import cli @@ -18,3 +19,16 @@ class TestClass: cli(test_input) resout, reserr = capfd.readouterr() assert expected in resout + + @pytest.mark.parametrize("test_input, expected", [ + (['-l', + 'zte-pod1', + '-f', + 'storage'], [('./test_cases/zte-pod1/storage/fio_bm.yaml'), + ('./test_cases/zte-pod1/storage/fio_vm.yaml')]) + ]) + @mock.patch('func.cli.args_handler.prepare_and_run_benchmark') + def test_cli_successful(self, mock_args_handler, test_input, expected): + cli(test_input) + call_list = map(lambda x: mock_args_handler.call_args_list[x][0][0], range(len(expected))) + assert sorted(call_list) == sorted(expected) diff --git a/tests/data/hosts b/tests/data/hosts new file mode 100644 index 00000000..0a0ac539 --- /dev/null +++ b/tests/data/hosts @@ -0,0 +1,2 @@ +[sample_group_name] +127.0.0.1 diff --git a/tests/data/test.yml b/tests/data/test.yml new file mode 100644 index 00000000..270e86fd --- /dev/null +++ b/tests/data/test.yml @@ -0,0 +1,4 @@ +- hosts: sample_group_name + tasks: + - name: just an uname + command: uname -a |