diff options
Diffstat (limited to 'functest/utils')
-rw-r--r-- | functest/utils/functest_constants.py | 15 | ||||
-rwxr-xr-x[-rw-r--r--] | functest/utils/functest_logger.py | 60 | ||||
-rw-r--r-- | functest/utils/functest_utils.py | 34 | ||||
-rw-r--r--[-rwxr-xr-x] | functest/utils/openstack_tacker.py | 0 |
4 files changed, 70 insertions, 39 deletions
diff --git a/functest/utils/functest_constants.py b/functest/utils/functest_constants.py index c4be0779..7fb03e8a 100644 --- a/functest/utils/functest_constants.py +++ b/functest/utils/functest_constants.py @@ -241,20 +241,5 @@ EXAMPLE_SECGROUP_NAME = get_value('example.sg_name', 'EXAMPLE_SECGROUP_NAME') EXAMPLE_SECGROUP_DESCR = get_value('example.sg_desc', 'EXAMPLE_SECGROUP_DESCR') -VIMS_DATA_DIR = get_value('general.dir.dir_vIMS_data', - 'VIMS_DATA_DIR') -VIMS_TEST_DIR = get_value('general.dir.dir_repo_vims_test', - 'VIMS_TEST_DIR') -CFY_MANAGER_BLUEPRINT = get_value('vIMS.cloudify.blueprint', - 'CFY_MANAGER_BLUEPRINT') -CFY_MANAGER_REQUIERMENTS = get_value('vIMS.cloudify.requierments', - 'CFY_MANAGER_REQUIERMENTS') -CFY_INPUTS = get_value('vIMS.cloudify.inputs', 'CFY_INPUTS') -CW_BLUEPRINT = get_value('vIMS.clearwater.blueprint', 'CW_BLUEPRINT') -CW_DEPLOYMENT_NAME = get_value('vIMS.clearwater.deployment-name', - 'CW_DEPLOYMENT_NAME') -CW_INPUTS = get_value('vIMS.clearwater.inputs', 'CW_INPUTS') -CW_REQUIERMENTS = get_value('vIMS.clearwater.requierments', - 'CW_REQUIERMENTS') PARSER_REPO_DIR = get_value('general.dir.repo_parser', 'PARSER_REPO_DIR') diff --git a/functest/utils/functest_logger.py b/functest/utils/functest_logger.py index c0fba082..f09f56be 100644..100755 --- a/functest/utils/functest_logger.py +++ b/functest/utils/functest_logger.py @@ -20,36 +20,50 @@ # logger = fl.Logger("script_name").getLogger() # logger.info("message to be shown with - INFO - ") # logger.debug("message to be shown with - DEBUG -") - import logging +import logging.config import os +import json -class Logger: - def __init__(self, logger_name): +from functest.utils.constants import CONST + +logger = logging.getLogger(__name__) + + +def is_debug(): + if CONST.CI_DEBUG and CONST.CI_DEBUG.lower() == "true": + return True + return False - CI_DEBUG = os.getenv('CI_DEBUG') +def setup_logging(default_path=CONST.dir_functest_logging_cfg, + default_level=logging.INFO, + env_key='LOG_CFG'): + path = default_path + value = os.getenv(env_key, None) + if value: + path = value + if os.path.exists(path): + with open(path, 'rt') as f: + config = json.load(f) + if (config['handlers'] and + config['handlers']['console']): + stream_level = logging.INFO + if is_debug(): + stream_level = logging.DEBUG + config['handlers']['console']['level'] = stream_level + logging.config.dictConfig(config) + else: + logging.basicConfig(level=default_level) + + +setup_logging() + + +class Logger: + def __init__(self, logger_name): self.logger = logging.getLogger(logger_name) - self.logger.propagate = 0 - self.logger.setLevel(logging.DEBUG) - - ch = logging.StreamHandler() - formatter = logging.Formatter('%(asctime)s - %(name)s - ' - '%(levelname)s - %(message)s') - ch.setFormatter(formatter) - if CI_DEBUG is not None and CI_DEBUG.lower() == "true": - ch.setLevel(logging.DEBUG) - self.logger.parent.level = logging.DEBUG - else: - ch.setLevel(logging.INFO) - self.logger.parent.level = logging.INFO - self.logger.addHandler(ch) - - hdlr = logging.FileHandler('/home/opnfv/functest/results/functest.log') - hdlr.setFormatter(formatter) - hdlr.setLevel(logging.DEBUG) - self.logger.addHandler(hdlr) def getLogger(self): return self.logger diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index 1879e694..2bf87a05 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -23,8 +23,10 @@ import requests import yaml from git import Repo +from functest.utils.constants import CONST import functest.utils.functest_logger as ft_logger + logger = ft_logger.Logger("functest_utils").getLogger() @@ -181,13 +183,43 @@ def logger_test_results(project, case_name, status, details): 'd': details}) +def write_results_to_file(project, case_name, start_date, + stop_date, criteria, details): + file_path = re.split(r'://', CONST.results_test_db_url)[1] + + try: + installer = os.environ['INSTALLER_TYPE'] + scenario = os.environ['DEPLOY_SCENARIO'] + pod_name = os.environ['NODE_NAME'] + except KeyError as e: + logger.error("Please set env var: " + str(e)) + return False + + test_start = dt.fromtimestamp(start_date).strftime('%Y-%m-%d %H:%M:%S') + test_stop = dt.fromtimestamp(stop_date).strftime('%Y-%m-%d %H:%M:%S') + + params = {"project_name": project, "case_name": case_name, + "pod_name": pod_name, "installer": installer, + "scenario": scenario, "criteria": criteria, + "start_date": test_start, "stop_date": test_stop, + "details": details} + try: + with open(file_path, "a+w") as outfile: + json.dump(params, outfile) + outfile.write("\n") + return True + except Exception as e: + logger.error("write result data into a file failed: %s" % e) + return False + + def push_results_to_db(project, case_name, start_date, stop_date, criteria, details): """ POST results to the Result target DB """ # Retrieve params from CI and conf - url = get_db_url() + "/results" + url = CONST.results_test_db_url + "/results" try: installer = os.environ['INSTALLER_TYPE'] diff --git a/functest/utils/openstack_tacker.py b/functest/utils/openstack_tacker.py index f17b421e..f17b421e 100755..100644 --- a/functest/utils/openstack_tacker.py +++ b/functest/utils/openstack_tacker.py |