diff options
author | 2016-05-20 14:29:51 +0200 | |
---|---|---|
committer | 2016-05-20 14:29:51 +0200 | |
commit | 1ee1c30e539c02924c34bfeb2dd260993f0481b4 (patch) | |
tree | 58089c37a334c5f5df916447560c3542b164bf63 /testcases | |
parent | e12f3661b74d998bdd5b75761f9700fcbb837534 (diff) |
Push bgpvpn_api results into Test DB
JIRA: FUNCTEST-234
Change-Id: I0494043bff6a37dc94724dfee1a718a1ab9fbcf3
Signed-off-by: Morgan Richomme <morgan.richomme@orange.com>
Diffstat (limited to 'testcases')
-rw-r--r-- | testcases/features/bgpvpn.py | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/testcases/features/bgpvpn.py b/testcases/features/bgpvpn.py index a6e66b1f..03aecbb3 100644 --- a/testcases/features/bgpvpn.py +++ b/testcases/features/bgpvpn.py @@ -9,8 +9,9 @@ # # Execute BGPVPN Tempest test cases # - +import argparse import os +import re import yaml import ConfigParser @@ -20,6 +21,16 @@ import functest.utils.functest_utils as ft_utils with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: functest_yaml = yaml.safe_load(f) +""" tests configuration """ +parser = argparse.ArgumentParser() +parser.add_argument("-d", "--debug", + help="Debug mode", + action="store_true") +parser.add_argument("-r", "--report", + help="Create json result file", + action="store_true") +args = parser.parse_args() + dirs = functest_yaml.get('general').get('directories') FUNCTEST_REPO = dirs.get('dir_repo_functest') BGPVPN_REPO = dirs.get('dir_repo_bgpvpn') @@ -48,11 +59,55 @@ def main(): with open(dst_tempest_conf, 'wb') as config_file: config.write(config_file) - cmd = (src_tempest_dir + - '/run_tempest.sh -t -N -- networking_bgpvpn_tempest;' - 'rm -rf ' + dst_tempest_conf) - ft_utils.execute_command(cmd, logger, exit_on_error=False) + cmd_line = (src_tempest_dir + + '/run_tempest.sh -t -N -- networking_bgpvpn_tempest;' + 'rm -rf ' + dst_tempest_conf) + cmd = os.popen(cmd_line) + output = cmd.read() + # Results parsing + error_logs = "" + duration = 0 + tests = 0 + failed = 0 + try: + # Look For errors + error_logs = "" + for match in re.findall('(.*?)[. ]*FAILED', output): + error_logs += match + # look for duration + m = re.search('tests in(.*)sec', output) + duration = m.group(1) + # Look for tests run + m = re.search('Ran:(.*)tests', output) + tests = m.group(1) + # Look for tests failed + m = re.search('Failed:(.*)', output) + failed = m.group(1) + except: + logger.error("Impossible to parse the result file") + + # Generate json results for DB + json_results = {"duration": float(duration), + "tests": int(tests), + "failures": int(failed), + "errors": error_logs} + + logger.info("Results: " + str(json_results)) + criteria = "failed" + if int(tests) > 0 and int(failed) < 1: + criteria = "passed" + # Push results in payload of testcase + if args.report: + logger.debug("Push result into DB") + url = TEST_DB_URL + scenario = ft_utils.get_scenario(logger) + version = ft_utils.get_version(logger) + pod_name = ft_utils.get_pod_name(logger) + build_tag = ft_utils.get_build_tag(logger) + ft_utils.push_results_to_db(url, "sdnvpn", "bgpvpn_api", logger, + pod_name, version, scenario, criteria, + build_tag, json_results) if __name__ == '__main__': main() |