diff options
-rw-r--r-- | dovetail/conf/dovetail_config.yml | 1 | ||||
-rwxr-xr-x | dovetail/run.py | 38 | ||||
-rw-r--r-- | dovetail/utils/dovetail_utils.py | 16 |
3 files changed, 45 insertions, 10 deletions
diff --git a/dovetail/conf/dovetail_config.yml b/dovetail/conf/dovetail_config.yml index 99e781af..56a5482a 100644 --- a/dovetail/conf/dovetail_config.yml +++ b/dovetail/conf/dovetail_config.yml @@ -1,5 +1,4 @@ --- -result_dir: /home/opnfv/dovetail/results report_file: 'dovetail_report.txt' cli_file_name: 'cmd_config.yml' report_dest: 'file' diff --git a/dovetail/run.py b/dovetail/run.py index 828a2b70..aae35e12 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -44,6 +44,7 @@ def run_test(testsuite, testarea, logger): testarea_list.append(value) duration = 0 + start_time = time.time() for testcase_name in testarea_list: logger.info('>>[testcase]: %s', testcase_name) testcase = Testcase.get(testcase_name) @@ -60,21 +61,33 @@ def run_test(testsuite, testarea, logger): run_testcase = False if run_testcase: - start_time = time.time() testcase.run() - end_time = time.time() - duration = end_time - start_time - if dt_cfg.dovetail_config['report_dest'].startswith("http"): - logger.info("Results has been pushed to database.") - if dt_cfg.dovetail_config['report_dest'] == "file": - logger.info("Results has been stored with files.") - result = Report.get_result(testcase) - Report.check_result(testcase, result) + check_tc_result(testcase, logger) + end_time = time.time() + duration = end_time - start_time return duration +def check_tc_result(testcase, logger): + if dt_cfg.dovetail_config['report_dest'].startswith("http"): + if testcase.validate_type() == 'yardstick': + logger.info("Results have been stored with files.") + else: + if dt_utils.check_db_results(dt_cfg.dovetail_config['report_dest'], + dt_cfg.dovetail_config['build_tag'], + testcase.validate_testcase(), + logger): + logger.info("Results have been pushed to database.") + else: + logger.error("Fail to push results to database.") + if dt_cfg.dovetail_config['report_dest'] == "file": + logger.info("Results have been stored with files.") + result = Report.get_result(testcase) + Report.check_result(testcase, result) + + def validate_input(input_dict, check_dict, logger): # for 'func_tag' and 'yard_tag' options func_tag = input_dict['func_tag'] @@ -153,10 +166,17 @@ def clean_results_dir(): raise SystemExit(1) +def get_result_path(): + dovetail_home = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + result_path = os.path.join(dovetail_home, 'results') + dt_cfg.dovetail_config['result_dir'] = result_path + + def main(*args, **kwargs): """Dovetail compliance test entry!""" build_tag = "daily-master-%s" % str(uuid.uuid4()) dt_cfg.dovetail_config['build_tag'] = build_tag + get_result_path() clean_results_dir() if kwargs['debug']: os.environ['DEBUG'] = 'true' diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index 32d334e8..e72a37ca 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -14,6 +14,8 @@ import os import re import subprocess from collections import Mapping, Set, Sequence +import json +import urllib2 def exec_log(verbose, logger, msg, level, flush=False): @@ -123,6 +125,20 @@ def get_ext_net_name(env_file, logger=None): return None +def check_db_results(db_url, build_tag, testcase, logger): + url = "%s/results?build_tag=%s&case=%s" % (db_url, build_tag, testcase) + logger.debug("Query to rest api: %s", url) + try: + data = json.load(urllib2.urlopen(url)) + if data['results']: + return True + else: + return False + except Exception as e: + logger.error("Cannot read content from %s, exception: %s", url, e) + return False + + def show_progress_bar(length): max_len = 50 length %= max_len |