aboutsummaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
authorzhifeng.jiang <jiang.zhifeng@zte.com.cn>2016-09-04 10:03:03 +0800
committerzhifeng jiang <jiang.zhifeng@zte.com.cn>2016-09-08 11:23:35 +0000
commit6612d7c20e329cd5b133a41a6b35c67539f3369b (patch)
tree9d977adb46d347b980b0f49756e5607907d346fe /func
parentcf0b4338abd0dc4f8a835440db7c662a37e92911 (diff)
Remove os environment in driver.py so that it can be called by restful server
modification: Change os environments to parameters in driver.py Pass the parameters in cli.py and arg_handler.py JIRA:QTIP-97 Change-Id: Id67acb7e0ac46fa9e0e32481e947055b6d37dd95 Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'func')
-rw-r--r--func/args_handler.py11
-rw-r--r--func/cli.py8
-rw-r--r--func/driver.py15
3 files changed, 20 insertions, 14 deletions
diff --git a/func/args_handler.py b/func/args_handler.py
index f2726eb8..57ecfcbd 100644
--- a/func/args_handler.py
+++ b/func/args_handler.py
@@ -48,12 +48,15 @@ def prepare_ansible_env(benchmark_test_case):
return benchmark, benchmark_details, proxy_info, env_setup
-def run_benchmark(benchmark, benchmark_details, proxy_info, env_setup, benchmark_test_case):
+def run_benchmark(installer_type, pwd, benchmark, benchmark_details,
+ proxy_info, env_setup, benchmark_test_case):
driver = Driver()
- driver.drive_bench(benchmark, env_setup.roles_dict.items(), _get_f_name(benchmark_test_case),
+ driver.drive_bench(installer_type, pwd, benchmark,
+ env_setup.roles_dict.items(), _get_f_name(benchmark_test_case),
benchmark_details, env_setup.ip_pw_dict.items(), proxy_info)
-def prepare_and_run_benchmark(benchmark_test_case):
+def prepare_and_run_benchmark(installer_type, pwd, benchmark_test_case):
benchmark, benchmark_details, proxy_info, env_setup = prepare_ansible_env(benchmark_test_case)
- run_benchmark(benchmark, benchmark_details, proxy_info, env_setup, benchmark_test_case)
+ run_benchmark(installer_type, pwd, benchmark, benchmark_details,
+ proxy_info, env_setup, benchmark_test_case)
diff --git a/func/cli.py b/func/cli.py
index 01694a9b..66ab2277 100644
--- a/func/cli.py
+++ b/func/cli.py
@@ -8,6 +8,7 @@
##############################################################################
import sys
+import os
import args_handler
import argparse
@@ -37,12 +38,12 @@ class cli:
args = self._parse_args(args)
if not args_handler.check_suit_in_test_list(args.file):
- print '\n\n ERROR: Test File Does not exist in test_list/ please enter correct file \n\n'
+ print('\n\n ERROR: Test File Does not exist in test_list/ please enter correct file \n\n')
sys.exit(0)
if not args_handler.check_lab_name(args.lab):
- print '\n\n You have specified a lab that is not present in test_cases/ please enter \
- correct file. If unsure how to proceed, use -l default.\n\n'
+ print('\n\n You have specified a lab that is not present in test_cases/ please enter \
+ correct file. If unsure how to proceed, use -l default.\n\n')
sys.exit(0)
suite = args.file
benchmarks = args_handler.get_files_in_test_list(suite)
@@ -50,6 +51,7 @@ class cli:
benchmarks_list = filter(lambda x: x in test_cases, benchmarks)
map(lambda x: args_handler.prepare_and_run_benchmark(
+ os.environ['INSTALLER_TYPE'], os.environ['PWD'],
args_handler.get_benchmark_path(args.lab.lower(), suite, x)), benchmarks_list)
print('{0} is not a Template in the Directory Enter a Valid file name.'
diff --git a/func/driver.py b/func/driver.py
index 4ce402a4..859e7f34 100644
--- a/func/driver.py
+++ b/func/driver.py
@@ -6,7 +6,6 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import os
import logging
from func.ansible_api import AnsibleApi
@@ -30,14 +29,15 @@ class Driver:
z.update(y)
return z
- def get_common_var_json(self, benchmark_fname, benchmark_detail, pip_dict, proxy_info):
+ def get_common_var_json(self, installer_type, pwd, benchmark_fname,
+ benchmark_detail, pip_dict, proxy_info):
common_json = {'Dest_dir': 'results',
'ip1': '',
'ip2': '',
- 'installer': str(os.environ['INSTALLER_TYPE']),
- 'workingdir': str(os.environ['PWD']),
+ 'installer': str(installer_type),
+ 'workingdir': str(pwd),
'fname': str(benchmark_fname),
- 'username': self.installer_username[str(os.environ['INSTALLER_TYPE'])]}
+ 'username': self.installer_username[str(installer_type)]}
common_json.update(benchmark_detail) if benchmark_detail else None
common_json.update(proxy_info) if proxy_info else None
return common_json
@@ -61,11 +61,12 @@ class Driver:
'./data/QtipKey', extra_vars)
return ansible_api.get_detail_playbook_stats()
- def drive_bench(self, benchmark, roles, benchmark_fname,
+ def drive_bench(self, installer_type, pwd, benchmark, roles, benchmark_fname,
benchmark_detail=None, pip_dict=None, proxy_info=None):
roles = sorted(roles)
pip_dict = sorted(pip_dict)
- var_json = self.get_common_var_json(benchmark_fname, benchmark_detail, pip_dict, proxy_info)
+ var_json = self.get_common_var_json(installer_type, pwd, benchmark_fname,
+ benchmark_detail, pip_dict, proxy_info)
map(lambda role: self.run_ansible_playbook
(benchmark, self.merge_two_dicts(var_json,
self.get_special_var_json(role, roles,