summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorzhifeng.jiang <jiang.zhifeng@zte.com.cn>2016-09-03 16:30:42 +0800
committerzhifeng.jiang <jiang.zhifeng@zte.com.cn>2016-09-04 08:10:13 +0800
commitcf0b4338abd0dc4f8a835440db7c662a37e92911 (patch)
tree982e82820dd437d8ae6a2f99b5cf1084eb185d37 /tests
parent222ebcd6c81c46420d861733b26068cb59fcebdc (diff)
Call ansible playbook by ansible api instead of os.system
JIRA:QTIP-99 Change-Id: Ife53a48d4af1fd3c60efc0673611321b3bc487a7 Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'tests')
-rw-r--r--tests/driver_test.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/tests/driver_test.py b/tests/driver_test.py
index a5b13588..9517d26d 100644
--- a/tests/driver_test.py
+++ b/tests/driver_test.py
@@ -1,7 +1,6 @@
import pytest
import mock
import os
-import json
from func.driver import Driver
@@ -61,18 +60,16 @@ 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
+ @mock.patch('func.driver.AnsibleApi')
+ def test_driver_success(self, mock_ansible, test_input, expected):
+ mock_ansible.execute_playbook.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_list = mock_system.call_args_list
+ call_list = mock_ansible.execute_playbook.call_args_list
k.stop()
- 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)]))
+ real_call = call_args[3]
+ assert real_call == expected[call_list.index(call)]