summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
Diffstat (limited to 'func')
-rw-r--r--func/ansible_api.py11
-rw-r--r--func/args_handler.py27
-rw-r--r--func/driver.py38
-rw-r--r--func/env_setup.py29
-rw-r--r--func/spawn_vm.py2
5 files changed, 65 insertions, 42 deletions
diff --git a/func/ansible_api.py b/func/ansible_api.py
index 57224eb7..2f02a62e 100644
--- a/func/ansible_api.py
+++ b/func/ansible_api.py
@@ -8,12 +8,15 @@
##############################################################################
import os
from collections import namedtuple
-import logging
+from ansible.executor.playbook_executor import PlaybookExecutor
+from ansible.inventory import Inventory
from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager
-from ansible.inventory import Inventory
-from ansible.executor.playbook_executor import PlaybookExecutor
+
+from utils import logger_utils
+
+logger = logger_utils.QtipLogger('ansible_api').get
class AnsibleApi:
@@ -26,7 +29,7 @@ class AnsibleApi:
def _check_path(self, file_path):
if not os.path.exists(file_path):
- logging.error('The playbook %s does not exist' % file_path)
+ logger.error('The playbook %s does not exist' % file_path)
return False
else:
return True
diff --git a/func/args_handler.py b/func/args_handler.py
index 57ecfcbd..50d803eb 100644
--- a/func/args_handler.py
+++ b/func/args_handler.py
@@ -7,19 +7,23 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import os
+from operator import add
+import simplejson as json
from func.env_setup import Env_setup
from func.spawn_vm import SpawnVM
from func.driver import Driver
-def get_files_in_test_list(suit_name):
- with open('test_list/' + suit_name, 'r') as fin_put:
- benchmark_list = fin_put.readlines()
- return map(lambda x: x.rstrip(), benchmark_list)
+def get_files_in_test_list(suit_name, case_type='all'):
+ benchmark_list = json.load(file('test_list/{0}'.format(suit_name)))
+ return reduce(add, benchmark_list.values()) \
+ if case_type == 'all' else benchmark_list[case_type]
-def get_files_in_test_case(lab, suit_name):
- return os.listdir('./test_cases/{0}/{1}'.format(lab, suit_name))
+def get_files_in_test_case(lab, suit_name, case_type='all'):
+ test_case_all = os.listdir('./test_cases/{0}/{1}'.format(lab, suit_name))
+ return test_case_all if case_type == 'all' else \
+ filter(lambda x: case_type in x, test_case_all)
def get_benchmark_path(lab, suit, benchmark):
@@ -51,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 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'])}
diff --git a/func/env_setup.py b/func/env_setup.py
index 96f984cb..f10f8620 100644
--- a/func/env_setup.py
+++ b/func/env_setup.py
@@ -8,18 +8,19 @@
##############################################################################
import os
+import random
+import socket
import sys
-from collections import defaultdict
-import yaml
import time
-import paramiko
-import socket
+from collections import defaultdict
from os.path import expanduser
-import random
-import logging
-LOG = logging.getLogger(__name__)
-LOG.setLevel(logging.DEBUG)
+import paramiko
+import yaml
+
+from utils import logger_utils
+
+logger = logger_utils.QtipLogger('env_setup').get
class Env_setup:
@@ -100,7 +101,7 @@ class Env_setup:
@staticmethod
def fetch_compute_ips():
- LOG.info("Fetch compute ips through installer")
+ logger.info("Fetch compute ips through installer")
ips = []
installer_type = str(os.environ['INSTALLER_TYPE'].lower())
@@ -112,18 +113,18 @@ class Env_setup:
cmd = "bash ./func/fetch_compute_ips.sh -i %s -a %s" % \
(installer_type, installer_ip)
- LOG.info(cmd)
+ logger.info(cmd)
os.system(cmd)
home = expanduser("~")
with open(home + "/ips.log", "r") as file:
data = file.read()
if data:
ips.extend(data.rstrip('\n').split('\n'))
- LOG.info("All compute ips: %s" % ips)
+ logger.info("All compute ips: %s" % ips)
return ips
def check_machine_ips(self, host_tag):
- LOG.info("Check machine ips")
+ logger.info("Check machine ips")
ips = self.fetch_compute_ips()
ips_num = len(ips)
num = len(host_tag)
@@ -137,7 +138,7 @@ class Env_setup:
if host_tag[hostlabel]['ip'] in ips:
info = "%s's ip %s is defined by test case yaml file" % \
(hostlabel, host_tag[hostlabel]['ip'])
- LOG.info(info)
+ logger.info(info)
else:
err = "%s is not in %s" % (host_tag[hostlabel]['ip'], ips)
raise RuntimeError(err)
@@ -174,7 +175,7 @@ class Env_setup:
def parse(self, config_file_path):
try:
f_name = open(config_file_path, 'r+')
- doc = yaml.load(f_name)
+ doc = yaml.safe_load(f_name)
f_name.close()
if doc['Scenario']['benchmark']:
self.benchmark = doc['Scenario']['benchmark']
diff --git a/func/spawn_vm.py b/func/spawn_vm.py
index 15c26861..5710308b 100644
--- a/func/spawn_vm.py
+++ b/func/spawn_vm.py
@@ -65,7 +65,7 @@ class SpawnVM(Env_setup):
Heat_Dic = {}
try:
with open('./heat/SampleHeat.yaml', 'r+') as H_temp:
- Heat_Dic = yaml.load(H_temp)
+ Heat_Dic = yaml.safe_load(H_temp)
except yaml.YAMLError as exc:
if hasattr(exc, 'problem_mark'):
mark = exc.problem_mark