aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ansible_api_test.py19
-rw-r--r--tests/args_handler_test.py35
-rw-r--r--tests/cli_test.py18
-rw-r--r--tests/data/hosts2
-rw-r--r--tests/data/test.yml4
-rw-r--r--tests/driver_test.py75
-rw-r--r--tests/env_setup_test.py49
-rw-r--r--tests/qtip_server_test.py6
8 files changed, 172 insertions, 36 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 f12e8fed..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
@@ -16,5 +17,18 @@ class TestClass:
def test_cli_error(self, capfd, test_input, expected):
with pytest.raises(SystemExit):
cli(test_input)
- resout, reserr = capfd.readouterr()
- assert expected in resout
+ 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
diff --git a/tests/driver_test.py b/tests/driver_test.py
index 39adc939..a5b13588 100644
--- a/tests/driver_test.py
+++ b/tests/driver_test.py
@@ -16,20 +16,20 @@ class TestClass:
'https_proxy': 'http://10.20.0.1:8118',
'no_proxy': 'localhost,127.0.0.1,10.20.*,192.168.*'},
'fuel'],
- {'Dest_dir': '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"}),
+ [{'Dest_dir': '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"}]),
(["iperf",
[('1-server', ['10.20.0.13']), ('2-host', ['10.20.0.15'])],
"iperf_vm.yaml",
@@ -37,18 +37,29 @@ class TestClass:
[("10.20.0.13", [None]), ("10.20.0.15", [None])],
{},
'joid'],
- {'Dest_dir': 'results',
- 'ip1': '10.20.0.13',
- 'ip2': '',
- 'installer': 'joid',
- "privateip1": "NONE",
- 'workingdir': '/home',
- 'fname': 'iperf_vm.yaml',
- 'username': 'ubuntu',
- 'duration': 20,
- 'protocol': 'tcp',
- 'bandwidthGbps': 0,
- "role": "2-host"})
+ [{'Dest_dir': 'results',
+ 'ip1': '10.20.0.13',
+ 'ip2': '',
+ 'installer': 'joid',
+ "privateip1": "NONE",
+ 'workingdir': '/home',
+ 'fname': 'iperf_vm.yaml',
+ 'username': 'ubuntu',
+ 'duration': 20,
+ 'protocol': 'tcp',
+ 'bandwidthGbps': 0,
+ "role": "1-server"},
+ {'Dest_dir': 'results',
+ 'ip1': '',
+ 'ip2': '',
+ 'installer': 'joid',
+ 'workingdir': '/home',
+ 'fname': 'iperf_vm.yaml',
+ 'username': 'ubuntu',
+ 'duration': 20,
+ 'protocol': 'tcp',
+ 'bandwidthGbps': 0,
+ "role": "2-host"}])
])
@mock.patch('func.driver.os.system')
def test_driver_success(self, mock_system, test_input, expected):
@@ -57,9 +68,11 @@ class TestClass:
k.start()
dri = Driver()
dri.drive_bench(test_input[0], test_input[1], test_input[2], test_input[3], test_input[4], test_input[5])
- call = mock_system.call_args
+ call_list = mock_system.call_args_list
k.stop()
- 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))
+ print call_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)]))
diff --git a/tests/env_setup_test.py b/tests/env_setup_test.py
index 9112ff94..cc3c6b60 100644
--- a/tests/env_setup_test.py
+++ b/tests/env_setup_test.py
@@ -1,6 +1,16 @@
+##############################################################################
+# 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 pytest
import filecmp
from func.env_setup import Env_setup
+import mock
class TestClass:
@@ -31,6 +41,8 @@ class TestClass:
print (test_input)
print (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]
@@ -40,12 +52,16 @@ class TestClass:
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("tests/test_case/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("tests/test_case/bm_without_proxy.yaml")
test_class.update_ansible()
result = filecmp.cmp('tests/output/hosts', 'data/hosts')
@@ -53,7 +69,40 @@ class TestClass:
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("tests/test_case/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/qtip_server_test.py b/tests/qtip_server_test.py
index 31aa96dc..c2b12974 100644
--- a/tests/qtip_server_test.py
+++ b/tests/qtip_server_test.py
@@ -23,7 +23,7 @@ class TestClass:
'installer_ip': '10.20.0.2',
'pod_name': 'default',
'suite_name': 'all',
- 'deadline': 10,
+ 'max-minutes': 10,
'type': 'BM',
'state': 'processing',
'state_detail': [],
@@ -31,7 +31,7 @@ class TestClass:
({'installer_type': 'fuel',
'installer_ip': '10.20.0.2',
'pod_name': 'zte-pod1',
- 'deadline': 20,
+ 'max-minutes': 20,
'suite_name': 'compute',
'type': 'VM'},
{'job_id': '',
@@ -39,7 +39,7 @@ class TestClass:
'installer_ip': '10.20.0.2',
'pod_name': 'zte-pod1',
'suite_name': 'compute',
- 'deadline': 20,
+ 'max-minutes': 20,
'type': 'VM',
'state': 'processing',
'state_detail': [],