diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/args_handler_test.py | 6 | ||||
-rw-r--r-- | tests/cli_test.py | 13 | ||||
-rw-r--r-- | tests/driver_test.py | 36 | ||||
-rw-r--r-- | tests/output/hosts | 2 | ||||
-rw-r--r-- | tests/schema/test_bm_schema.yaml | 1 |
5 files changed, 32 insertions, 26 deletions
diff --git a/tests/args_handler_test.py b/tests/args_handler_test.py index 7f977f21..ebf500f3 100644 --- a/tests/args_handler_test.py +++ b/tests/args_handler_test.py @@ -13,8 +13,8 @@ import func.args_handler class TestClass: @pytest.mark.parametrize("test_input, expected", [ - ('./test_cases/zte-pod1/network/iperf_bm.yaml', - ["iperf", + (['fuel', '/home', './test_cases/zte-pod1/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)], @@ -29,7 +29,7 @@ class TestClass: 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) + func.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/cli_test.py b/tests/cli_test.py index f9861dee..fe05327d 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -1,5 +1,6 @@ import pytest import mock +import os from func.cli import cli @@ -15,8 +16,11 @@ class TestClass: 'test'], "Test File Does not exist in test_list") ]) 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() resout, reserr = capfd.readouterr() assert expected in resout @@ -24,11 +28,14 @@ class TestClass: (['-l', 'zte-pod1', '-f', - 'storage'], [('./test_cases/zte-pod1/storage/fio_bm.yaml'), - ('./test_cases/zte-pod1/storage/fio_vm.yaml')]) + 'storage'], [('fuel', '/home', './test_cases/zte-pod1/storage/fio_bm.yaml'), + ('fuel', '/home', './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): + k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel', 'PWD': '/home'}) + k.start() cli(test_input) - call_list = map(lambda x: mock_args_handler.call_args_list[x][0][0], range(len(expected))) + 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/driver_test.py b/tests/driver_test.py index a5b13588..71f01b0e 100644 --- a/tests/driver_test.py +++ b/tests/driver_test.py @@ -1,21 +1,20 @@ import pytest import mock -import os -import json from func.driver import Driver class TestClass: @pytest.mark.parametrize("test_input, expected", [ - (["iperf", + (['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.*'}, - 'fuel'], + 'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*'}], [{'Dest_dir': 'results', 'ip1': '', 'ip2': '', @@ -30,13 +29,14 @@ class TestClass: 'protocol': 'tcp', 'bandwidthGbps': 0, "role": "host"}]), - (["iperf", + (['joid', + '/home', + "iperf", [('1-server', ['10.20.0.13']), ('2-host', ['10.20.0.15'])], "iperf_vm.yaml", [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 0)], [("10.20.0.13", [None]), ("10.20.0.15", [None])], - {}, - 'joid'], + {}], [{'Dest_dir': 'results', 'ip1': '10.20.0.13', 'ip2': '', @@ -61,18 +61,14 @@ class TestClass: 'bandwidthGbps': 0, "role": "2-host"}]) ]) - @mock.patch('func.driver.os.system') - def test_driver_success(self, mock_system, test_input, expected): - mock_system.return_value = True - k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': test_input[6], 'PWD': '/home'}) - k.start() + @mock.patch('func.driver.AnsibleApi') + def test_driver_success(self, mock_ansible, test_input, expected): + mock_ansible.execute_playbook.return_value = True dri = Driver() - dri.drive_bench(test_input[0], test_input[1], test_input[2], test_input[3], test_input[4], test_input[5]) - call_list = mock_system.call_args_list - k.stop() - print call_list + 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.execute_playbook.call_args_list for call in call_list: call_args, call_kwargs = call - real_call = call_args[0].split('extra-vars \'')[1] - real_call = real_call[0: len(real_call) - 1] - assert json.loads(real_call) == json.loads(json.dumps(expected[call_list.index(call)])) + real_call = call_args[3] + assert real_call == expected[call_list.index(call)] diff --git a/tests/output/hosts b/tests/output/hosts index 9b47df0e..b380e475 100644 --- a/tests/output/hosts +++ b/tests/output/hosts @@ -1,3 +1,5 @@ [host] 10.20.0.29 10.20.0.28 +[localhost] +127.0.0.1 diff --git a/tests/schema/test_bm_schema.yaml b/tests/schema/test_bm_schema.yaml index 740725f5..a7c27e3f 100644 --- a/tests/schema/test_bm_schema.yaml +++ b/tests/schema/test_bm_schema.yaml @@ -45,6 +45,7 @@ mapping: type: str ip: type: str + allowempty: True pw: type: str allowempty: True |