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
19 import functest.utils.functest_logger as ft_logger
20 import functest.utils.functest_utils as ft_utils
22 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
23 functest_yaml = yaml.safe_load(f)
25 """ tests configuration """
26 parser = argparse.ArgumentParser()
27 parser.add_argument("-d", "--debug",
30 parser.add_argument("-r", "--report",
31 help="Create json result file",
33 args = parser.parse_args()
35 dirs = functest_yaml.get('general').get('directories')
36 FUNCTEST_REPO = dirs.get('dir_repo_functest')
37 BGPVPN_REPO = dirs.get('dir_repo_bgpvpn')
38 TEST_DB_URL = functest_yaml.get('results').get('test_db_url')
40 logger = ft_logger.Logger("bgpvpn").getLogger()
44 logger.info("Running BGPVPN Tempest test case...")
45 start_time = time.time()
47 cmd = 'cd ' + BGPVPN_REPO + ';pip install --no-deps -e .'
48 ft_utils.execute_command(cmd, logger, exit_on_error=False)
50 src_tempest_dir = ft_utils.get_deployment_dir(logger)
51 if not src_tempest_dir:
52 logger.error("Rally deployment not found.")
55 src_tempest_conf = src_tempest_dir + '/tempest.conf'
56 dst_tempest_conf = src_tempest_dir + '/etc/tempest.conf'
58 config = ConfigParser.RawConfigParser()
59 config.read(src_tempest_conf)
60 config.set('service_available', 'bgpvpn', 'True')
61 with open(dst_tempest_conf, 'wb') as config_file:
62 config.write(config_file)
64 cmd_line = (src_tempest_dir +
65 '/run_tempest.sh -t -N -- networking_bgpvpn_tempest;'
66 'rm -rf ' + dst_tempest_conf)
67 cmd = os.popen(cmd_line)
77 for match in re.findall('(.*?)[. ]*FAILED', output):
80 m = re.search('tests in(.*)sec', output)
83 m = re.search('Ran:(.*)tests', output)
85 # Look for tests failed
86 m = re.search('Failed:(.*)', output)
89 logger.error("Impossible to parse the result file")
91 # Generate json results for DB
92 json_results = {"duration": float(duration),
94 "failures": int(failed),
97 logger.info("Results: " + str(json_results))
99 # criteria = success rate = 100% (i.e all tests passed)
100 # TODO use criteria defined in config file
101 criteria_run = int(tests)
105 criteria_failed = int(failed)
107 if criteria_run > 0 and criteria_failed < 1:
110 # Push results in payload of testcase
112 logger.debug("Push bgpvpn results into DB")
113 stop_time = time.time()
114 ft_utils.push_results_to_db("sdnvpn",
122 if __name__ == '__main__':