From 4c7387f811c01bd74b5ae6e0d0cca4bc98d298e8 Mon Sep 17 00:00:00 2001 From: "zhifeng.jiang" Date: Sun, 3 Jul 2016 23:04:40 +0800 Subject: Add some UT test cases and fix pep8 errors for cli and env_setup. JIRA:QTIP-89 Change-Id: I4a46898071001f679f1a032a560d605dffc8eb9f Signed-off-by: zhifeng.jiang --- tests/cli_test.py | 20 ++++++++++++ tests/env_setup_test.py | 59 +++++++++++++++++++++++++++++++++++ tests/output/hosts | 3 ++ tests/test_case/bm_ping.yaml | 29 +++++++++++++++++ tests/test_case/bm_with_proxy.yaml | 39 +++++++++++++++++++++++ tests/test_case/bm_without_proxy.yaml | 33 ++++++++++++++++++++ tests/test_case/vm.yaml | 48 ++++++++++++++++++++++++++++ tests/test_case/vm_error.yaml | 42 +++++++++++++++++++++++++ 8 files changed, 273 insertions(+) create mode 100644 tests/cli_test.py create mode 100644 tests/env_setup_test.py create mode 100644 tests/output/hosts create mode 100644 tests/test_case/bm_ping.yaml create mode 100644 tests/test_case/bm_with_proxy.yaml create mode 100644 tests/test_case/bm_without_proxy.yaml create mode 100644 tests/test_case/vm.yaml create mode 100644 tests/test_case/vm_error.yaml (limited to 'tests') diff --git a/tests/cli_test.py b/tests/cli_test.py new file mode 100644 index 00000000..f12e8fed --- /dev/null +++ b/tests/cli_test.py @@ -0,0 +1,20 @@ +import pytest +from func.cli import cli + + +class TestClass: + @pytest.mark.parametrize("test_input, expected", [ + (['-l', + 'zte', + '-f', + 'compute'], "You have specified a lab that is not present in test_cases"), + (['-l', + 'zte-pod1', + '-f', + 'test'], "Test File Does not exist in test_list") + ]) + def test_cli_error(self, capfd, test_input, expected): + with pytest.raises(SystemExit): + cli(test_input) + resout, reserr = capfd.readouterr() + assert expected in resout diff --git a/tests/env_setup_test.py b/tests/env_setup_test.py new file mode 100644 index 00000000..9112ff94 --- /dev/null +++ b/tests/env_setup_test.py @@ -0,0 +1,59 @@ +import pytest +import filecmp +from func.env_setup import Env_setup + + +class TestClass: + + @pytest.mark.parametrize("test_input, expected", [ + ("tests/test_case/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.*'}]), + ("tests/test_case/bm_without_proxy.yaml", ["dhrystone", + {}, + [], + {}]), + ("tests/test_case/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): + print (test_input) + print (expected) + test_class = Env_setup() + 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() + 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() + test_class.parse("tests/test_case/bm_without_proxy.yaml") + test_class.update_ansible() + result = filecmp.cmp('tests/output/hosts', 'data/hosts') + assert result + + def test_ping(self, capfd): + test_class = Env_setup() + 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 diff --git a/tests/output/hosts b/tests/output/hosts new file mode 100644 index 00000000..9b47df0e --- /dev/null +++ b/tests/output/hosts @@ -0,0 +1,3 @@ +[host] +10.20.0.29 +10.20.0.28 diff --git a/tests/test_case/bm_ping.yaml b/tests/test_case/bm_ping.yaml new file mode 100644 index 00000000..41d696e2 --- /dev/null +++ b/tests/test_case/bm_ping.yaml @@ -0,0 +1,29 @@ + +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/test_case/bm_with_proxy.yaml b/tests/test_case/bm_with_proxy.yaml new file mode 100644 index 00000000..1d73300b --- /dev/null +++ b/tests/test_case/bm_with_proxy.yaml @@ -0,0 +1,39 @@ + +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/test_case/bm_without_proxy.yaml b/tests/test_case/bm_without_proxy.yaml new file mode 100644 index 00000000..a9ae3b71 --- /dev/null +++ b/tests/test_case/bm_without_proxy.yaml @@ -0,0 +1,33 @@ + +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/test_case/vm.yaml b/tests/test_case/vm.yaml new file mode 100644 index 00000000..4c8453ca --- /dev/null +++ b/tests/test_case/vm.yaml @@ -0,0 +1,48 @@ +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/test_case/vm_error.yaml b/tests/test_case/vm_error.yaml new file mode 100644 index 00000000..f13d3a00 --- /dev/null +++ b/tests/test_case/vm_error.yaml @@ -0,0 +1,42 @@ +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: + ''' + -- cgit 1.2.3-korg