From 223806ad2a5d60c9909f32f35b8cea16bf703a69 Mon Sep 17 00:00:00 2001 From: xudan Date: Wed, 22 Mar 2017 07:51:37 +0000 Subject: dovetail tool: Add an option cmd for pushing results into DB JIRA: DOVETAIL-373 1. add an option --report/-r to choose the report type. 2. "-r file" will store results with files. 3. "-r http://192.168.135.2:8000/api/v1" will push results into DB. The DB url can replaced by user's local DB or official DB. 4. Default report type is defined as "report_dest" in dovetail_config.yml. 5. Yardstick can't push results of one testcase into DB now, so both "-r file" and "-r http://..." will be regarded as "file". Change-Id: Ieaa017ab59c5b15235bf306ef57cdc56beb22af8 Signed-off-by: xudan --- dovetail/conf/cmd_config.yml | 5 +++ dovetail/conf/dovetail_config.yml | 1 + dovetail/conf/functest_config.yml | 6 +-- dovetail/conf/yardstick_config.yml | 1 - dovetail/container.py | 88 +++++++++++++++++++++++++++----------- dovetail/report.py | 6 +-- dovetail/run.py | 22 ++++++++-- 7 files changed, 92 insertions(+), 37 deletions(-) diff --git a/dovetail/conf/cmd_config.yml b/dovetail/conf/cmd_config.yml index 2ae0402e..c0da5113 100644 --- a/dovetail/conf/cmd_config.yml +++ b/dovetail/conf/cmd_config.yml @@ -53,3 +53,8 @@ cli: - '-d' is_flag: 'True' help: 'Flag for showing debug log on screen.' + report: + flags: + - '--report' + - '-r' + help: 'push results to DB (e.g. --report http://192.168.135.2:8000/api/v1)' diff --git a/dovetail/conf/dovetail_config.yml b/dovetail/conf/dovetail_config.yml index 9521617e..ea8ecedc 100644 --- a/dovetail/conf/dovetail_config.yml +++ b/dovetail/conf/dovetail_config.yml @@ -2,6 +2,7 @@ result_dir: /home/opnfv/dovetail/results report_file: 'dovetail_report.txt' cli_file_name: 'cmd_config.yml' +report_dest: 'file' # OPENSTACK Credential file openrc: '/home/opnfv/dovetail/openrc.sh' diff --git a/dovetail/conf/functest_config.yml b/dovetail/conf/functest_config.yml index 8195c547..c65504e2 100644 --- a/dovetail/conf/functest_config.yml +++ b/dovetail/conf/functest_config.yml @@ -7,16 +7,12 @@ functest: - 'echo test for precondition in functest' cmds: - 'functest env prepare' - - '[ -f /home/opnfv/functest/results/functest_result.json ] && cp /home/opnfv/functest/results/functest_result.json /home/opnfv/functest/functest_result.json || true' - - sed -i 's/http:\/\/testresults.opnfv.org\/test\/api\/v1/file:\/\/\/home\/opnfv\/functest\/results\/functest_result.json/g' /home/opnfv/repos/functest/functest/ci/config_functest.yaml - 'functest testcase run {{validate_testcase}} -r' - - 'cp /home/opnfv/functest/functest_result.json /home/opnfv/functest/results/functest_result.json' post_condition: - 'echo test for postcondition in functest' result: dir: '/home/opnfv/functest/results' store_type: 'file' - file_path: 'functest_result.json' + file_path: 'dump.txt' tp_path: 'tempest/tempest.log' - db_url: 'http://testresults.opnfv.org/test/api/v1/results?case=%s&last=1' openrc: '/home/opnfv/functest/conf/openstack.creds' diff --git a/dovetail/conf/yardstick_config.yml b/dovetail/conf/yardstick_config.yml index 934cdbdc..a8191db0 100644 --- a/dovetail/conf/yardstick_config.yml +++ b/dovetail/conf/yardstick_config.yml @@ -20,5 +20,4 @@ yardstick: log: '/tmp/yardstick' store_type: 'file' file_path: 'yardstick.log' - db_url: 'http://testresults.opnfv.org/test/api/v1/results?case=%s&last=1' openrc: '/home/opnfv/openrc' diff --git a/dovetail/container.py b/dovetail/container.py index 6d5a8d4f..bfdbeb94 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -40,50 +40,88 @@ class Container(object): return '%s:%s' % (dt_cfg.dovetail_config[type]['image_name'], dt_cfg.dovetail_config[type]['docker_tag']) + # get the openrc_volume for creating the container @classmethod - def create(cls, type): - sshkey = "-v /root/.ssh/id_rsa:/root/.ssh/id_rsa " + def openrc_volume(cls, type): dovetail_config = dt_cfg.dovetail_config - docker_image = cls.get_docker_image(type) - opts = dovetail_config[type]['opts'] - - # credentials file openrc.sh is neccessary dovetail_config['openrc'] = os.path.abspath(dovetail_config['openrc']) if os.path.isfile(dovetail_config['openrc']): openrc = ' -v %s:%s ' % (dovetail_config['openrc'], dovetail_config[type]['openrc']) + return openrc else: cls.logger.error("File %s is not exist", dovetail_config['openrc']) return None + # set functest envs and TEST_DB_URL for creating functest container + @staticmethod + def set_functest_config(): + + # These are all just used by Functest's function push_results_to_db. + # And has nothing to do with DoveTail running test cases. + ins_type = " -e INSTALLER_TYPE=vendor-specific" + scenario = " -e DEPLOY_SCENARIO=default" + node = " -e NODE_NAME=master" + tag = " -e BUILD_TAG=daily-master-001" + envs = "%s %s %s %s" % (ins_type, scenario, node, tag) + + dovetail_config = dt_cfg.dovetail_config + if dovetail_config['report_dest'].startswith("http"): + report = " -e TEST_DB_URL=%s " % dovetail_config['report_dest'] + if dovetail_config['report_dest'] == "file": + file_path = dovetail_config["functest"]['result']['dir'] + file_path = file_path[0:file_path.rfind('/results')] + report = " -e TEST_DB_URL=file://%s " % file_path + return "%s %s" % (envs, report) + + # set yardstick external network name and log volume for its container. + # external network is necessary for yardstick. + @classmethod + def set_yardstick_config(cls): + dovetail_config = dt_cfg.dovetail_config + ext_net = dt_utils.get_ext_net_name(dovetail_config['openrc'], + cls.logger) + if ext_net: + envs = "%s%s" % (" -e EXTERNAL_NETWORK=", ext_net) + else: + cls.logger.error("Can't find any external network.") + return None + + if dovetail_config['report_dest'].startswith("http"): + cls.logger.info("Yardstick can't push results to DB.") + cls.logger.info("Results will be stored with files.") + + log_vol = '-v %s:%s ' % (dovetail_config['result_dir'], + dovetail_config["yardstick"]['result']['log']) + return "%s %s" % (envs, log_vol) + + @classmethod + def create(cls, type): + sshkey = "-v /root/.ssh/id_rsa:/root/.ssh/id_rsa " + dovetail_config = dt_cfg.dovetail_config + docker_image = cls.get_docker_image(type) + opts = dovetail_config[type]['opts'] + + # credentials file openrc.sh is neccessary + openrc = cls.openrc_volume(type) + if not openrc: + return None + # This is used for showing the debug logs of the upstream projects envs = ' -e CI_DEBUG=true' - # These are all just used by Functest's function push_results_to_db + config = "" if type.lower() == "functest": - ins_type = " -e INSTALLER_TYPE=vendor-specific" - scenario = " -e DEPLOY_SCENARIO=default" - node = " -e NODE_NAME=default" - tag = " -e BUILD_TAG=daily-master-001" - - envs = "%s %s %s %s %s" % (envs, ins_type, scenario, node, tag) - + config = cls.set_functest_config() if type.lower() == "yardstick": - ext_net = dt_utils.get_ext_net_name(dovetail_config['openrc'], - cls.logger) - if ext_net: - envs = "%s%s%s" % (envs, " -e EXTERNAL_NETWORK=", ext_net) - else: - cls.logger.error("Can't find any external network.") - return None + config = cls.set_yardstick_config() + if not config: + return None result_volume = ' -v %s:%s ' % (dovetail_config['result_dir'], dovetail_config[type]['result']['dir']) - log_volume = ' -v %s:%s ' % (dovetail_config['result_dir'], - dovetail_config[type]['result']['log']) cmd = 'sudo docker run %s %s %s %s %s %s %s /bin/bash' % \ - (opts, envs, sshkey, openrc, result_volume, - log_volume, docker_image) + (opts, envs, config, sshkey, openrc, result_volume, docker_image) dt_utils.exec_cmd(cmd, cls.logger) ret, container_id = \ dt_utils.exec_cmd("sudo docker ps | grep " + docker_image + diff --git a/dovetail/report.py b/dovetail/report.py index d4be67c6..f2210cb7 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -287,9 +287,9 @@ class FunctestCrawler(object): return json_results def crawl_from_url(self, testcase=None): - url = \ - dt_cfg.dovetail_config[self.type]['result']['db_url'] % \ - testcase.validate_testcase() + url = "%s/results?case=%s&last=1" % \ + (dt_cfg.dovetail_config['report_dest'], + testcase.validate_testcase()) self.logger.debug("Query to rest api: %s", url) try: data = json.load(urllib2.urlopen(url)) diff --git a/dovetail/run.py b/dovetail/run.py index 05f48501..17d7edf4 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -64,8 +64,12 @@ def run_test(testsuite, testarea, logger): end_time = time.time() duration = end_time - start_time - result = Report.get_result(testcase) - Report.check_result(testcase, result) + 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) return duration @@ -82,6 +86,14 @@ def validate_input(input_dict, check_dict, logger): logger.error("yard_tag can't be %s, valid in %s", yard_tag, valid_tag) raise SystemExit(1) + # for 'report' option + report = input_dict['report'] + if report: + if not (report.startswith("http") or report == "file"): + logger.error("report can't be %s", input_dict['report']) + logger.info("valid report types are 'file' and 'http'") + raise SystemExit(1) + def filter_config(input_dict, logger): cli_dict = dt_cfg.dovetail_config['cli'] @@ -156,6 +168,9 @@ def main(*args, **kwargs): if configs is not None: dt_cfg.update_config(configs) + if kwargs['report']: + dt_cfg.dovetail_config['report_dest'] = kwargs['report'] + testarea = kwargs['testarea'] testsuite_validation = False testarea_validation = False @@ -168,7 +183,8 @@ def main(*args, **kwargs): testsuite_yaml = load_testsuite(kwargs['testsuite']) load_testcase() duration = run_test(testsuite_yaml, testarea, logger) - Report.generate(testsuite_yaml, testarea, duration) + if dt_cfg.dovetail_config['report_dest'] == "file": + Report.generate(testsuite_yaml, testarea, duration) else: logger.error('invalid input commands, testsuite %s testarea %s', kwargs['testsuite'], testarea) -- cgit 1.2.3-korg