aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorzhifeng.jiang <jiang.zhifeng@zte.com.cn>2016-07-09 21:25:11 +0800
committerzhifeng.jiang <jiang.zhifeng@zte.com.cn>2016-07-10 07:17:01 +0800
commit01a9660cc42d9f5b03ca3049e0ba69e357508332 (patch)
tree83930b8586ca196f3b225cd0b8efd8bd8a07817a /tests
parent5dbf3c4e2f6ef48676de10b4394de4a45456810d (diff)
Add some UT test cases and fix pep8 errors for driver
JIRA:QTIP-89 Change-Id: I672ebaf733ec967307963a18f32ca0aa4afc672d Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'tests')
-rw-r--r--tests/driver_test.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/driver_test.py b/tests/driver_test.py
new file mode 100644
index 00000000..39adc939
--- /dev/null
+++ b/tests/driver_test.py
@@ -0,0 +1,65 @@
+import pytest
+import mock
+import os
+import json
+from func.driver import Driver
+
+
+class TestClass:
+ @pytest.mark.parametrize("test_input, expected", [
+ (["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'],
+ {'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",
+ [('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': '',
+ 'installer': 'joid',
+ "privateip1": "NONE",
+ '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):
+ mock_system.return_value = True
+ k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': test_input[6], 'PWD': '/home'})
+ 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
+ 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))