3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Execute BGPVPN Tempest test cases
18 import functest.utils.functest_logger as ft_logger
19 import functest.utils.functest_utils as ft_utils
21 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
22 functest_yaml = yaml.safe_load(f)
24 """ tests configuration """
25 parser = argparse.ArgumentParser()
26 parser.add_argument("-d", "--debug",
29 parser.add_argument("-r", "--report",
30 help="Create json result file",
32 args = parser.parse_args()
34 dirs = functest_yaml.get('general').get('directories')
35 FUNCTEST_REPO = dirs.get('dir_repo_functest')
36 BGPVPN_REPO = dirs.get('dir_repo_bgpvpn')
37 TEST_DB_URL = functest_yaml.get('results').get('test_db_url')
39 logger = ft_logger.Logger("bgpvpn").getLogger()
43 logger.info("Running BGPVPN Tempest test case...")
45 cmd = 'cd ' + BGPVPN_REPO + ';pip install --no-deps -e .'
46 ft_utils.execute_command(cmd, logger, exit_on_error=False)
48 src_tempest_dir = ft_utils.get_deployment_dir(logger)
49 if not src_tempest_dir:
50 logger.error("Rally deployment not found.")
53 src_tempest_conf = src_tempest_dir + '/tempest.conf'
54 dst_tempest_conf = src_tempest_dir + '/etc/tempest.conf'
56 config = ConfigParser.RawConfigParser()
57 config.read(src_tempest_conf)
58 config.set('service_available', 'bgpvpn', 'True')
59 with open(dst_tempest_conf, 'wb') as config_file:
60 config.write(config_file)
62 cmd_line = (src_tempest_dir +
63 '/run_tempest.sh -t -N -- networking_bgpvpn_tempest;'
64 'rm -rf ' + dst_tempest_conf)
65 cmd = os.popen(cmd_line)
75 for match in re.findall('(.*?)[. ]*FAILED', output):
78 m = re.search('tests in(.*)sec', output)
81 m = re.search('Ran:(.*)tests', output)
83 # Look for tests failed
84 m = re.search('Failed:(.*)', output)
88 logger.error("Impossible to parse the result file")
90 # Generate json results for DB
91 json_results = {"duration": float(duration),
93 "failures": int(failed),
96 logger.info("Results: " + str(json_results))
98 # Push results in payload of testcase
100 logger.debug("Push result into DB")
102 scenario = ft_utils.get_scenario(logger)
103 version = ft_utils.get_version(logger)
104 pod_name = ft_utils.get_pod_name(logger)
105 build_tag = ft_utils.get_build_tag(logger)
107 if int(tests) > 0 and int(failed) < 1:
110 ft_utils.push_results_to_db(url, "sdnvpn", "bgpvpn_api", logger,
111 pod_name, version, scenario, criteria,
112 build_tag, json_results)
114 if __name__ == '__main__':