From 6183cefebbc1af8ad1987dc61372d6c2d6a59f6d Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Tue, 20 Sep 2016 13:58:21 +0800 Subject: add unified logger process for qtip log the output information to both file and console, and unify the log file path and level JIRA: QTIP-108 Change-Id: I3a881e9da1f74c6959250a94f05cf90a231c34e6 Signed-off-by: SerenaFeng --- func/ansible_api.py | 11 +++++++---- func/driver.py | 12 +++++++----- func/env_setup.py | 27 ++++++++++++++------------- 3 files changed, 28 insertions(+), 22 deletions(-) (limited to 'func') 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/driver.py b/func/driver.py index 726016a5..ff40a4cc 100644 --- a/func/driver.py +++ b/func/driver.py @@ -1,20 +1,22 @@ ############################################################################## -# 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 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'} @@ -58,7 +60,7 @@ 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), diff --git a/func/env_setup.py b/func/env_setup.py index 96f984cb..cd82f303 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) -- cgit 1.2.3-korg