aboutsummaryrefslogtreecommitdiffstats
path: root/func/driver.py
diff options
context:
space:
mode:
Diffstat (limited to 'func/driver.py')
-rw-r--r--func/driver.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/func/driver.py b/func/driver.py
index 726016a5..bcda0ce1 100644
--- a/func/driver.py
+++ b/func/driver.py
@@ -1,20 +1,24 @@
##############################################################################
-# Copyright (c) 2015 Dell Inc and others.
+# Copyright (c) 2015 Dell Inc, ZTE and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import logging
-from func.ansible_api import AnsibleApi
+from utils import logger_utils
+from operator import add
+from ansible_api import AnsibleApi
+
+
+logger = logger_utils.QtipLogger('driver').get
class Driver:
def __init__(self):
- logging.info("Class driver initialized\n")
+ logger.info("Class driver initialized\n")
self.installer_username = {'fuel': 'root',
'joid': 'ubuntu',
'apex': 'heat-admin'}
@@ -45,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])\
@@ -58,12 +62,12 @@ class Driver:
return special_json
def run_ansible_playbook(self, benchmark, extra_vars):
- logging.info(extra_vars)
+ logger.info(extra_vars)
ansible_api = AnsibleApi()
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):
@@ -71,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'])}