diff options
Diffstat (limited to 'func')
-rw-r--r-- | func/args_handler.py | 11 | ||||
-rw-r--r-- | func/driver.py | 26 |
2 files changed, 25 insertions, 12 deletions
diff --git a/func/args_handler.py b/func/args_handler.py index 90d902b6..50d803eb 100644 --- a/func/args_handler.py +++ b/func/args_handler.py @@ -55,12 +55,13 @@ def prepare_ansible_env(benchmark_test_case): def run_benchmark(installer_type, pwd, benchmark, benchmark_details, proxy_info, env_setup, benchmark_test_case): driver = Driver() - 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) + return 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(installer_type, pwd, benchmark_test_case): benchmark, benchmark_details, proxy_info, env_setup = prepare_ansible_env(benchmark_test_case) - run_benchmark(installer_type, pwd, benchmark, benchmark_details, - proxy_info, env_setup, benchmark_test_case) + return run_benchmark(installer_type, pwd, benchmark, benchmark_details, + proxy_info, env_setup, benchmark_test_case) diff --git a/func/driver.py b/func/driver.py index ff40a4cc..bcda0ce1 100644 --- a/func/driver.py +++ b/func/driver.py @@ -7,8 +7,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## from utils import logger_utils +from operator import add from ansible_api import AnsibleApi + logger = logger_utils.QtipLogger('driver').get @@ -47,7 +49,7 @@ class Driver: def get_special_var_json(self, role, roles, benchmark_detail, pip_dict): special_json = {} index = roles.index(role) + 1 - private_ip = pip_dict[0][1][0] if pip_dict[0][1][0] else 'NONE' + private_ip = pip_dict[0][1] if pip_dict[0][1][0] else 'NONE' map(lambda x: special_json.update({'ip' + str(index): x}), role[1])\ if benchmark_detail and (role[0] == '1-server') else None map(lambda x: special_json.update({'privateip' + str(index): private_ip}), role[1])\ @@ -65,7 +67,7 @@ class Driver: ansible_api.execute_playbook('./data/hosts', './benchmarks/playbooks/{0}.yaml'.format(benchmark), './data/QtipKey', extra_vars) - return ansible_api.get_detail_playbook_stats() + return self.get_ansible_result(extra_vars['role'], ansible_api.get_detail_playbook_stats()) def drive_bench(self, installer_type, pwd, benchmark, roles, benchmark_fname, benchmark_detail=None, pip_dict=None, proxy_info=None): @@ -73,8 +75,18 @@ class Driver: pip_dict = sorted(pip_dict) 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, - benchmark_detail, - pip_dict))), roles) + result = map(lambda role: self.run_ansible_playbook + (benchmark, self.merge_two_dicts(var_json, + self.get_special_var_json(role, roles, + benchmark_detail, + pip_dict))), roles) + return reduce(self._merge_ansible_result, result) + + def get_ansible_result(self, role, stats): + result = reduce(add, map(lambda x: x[1]['failures'] + x[1]['unreachable'], stats)) + return {'result': result, + 'detail': {role: stats}} + + def _merge_ansible_result(self, result_1, result_2): + return {'result': result_1['result'] + result_2['result'], + 'detail': self.merge_two_dicts(result_1['detail'], result_2['detail'])} |